a LOT of things (read description)
I might not list everything in this commit but: - fix struct stream operators while making them a bit less convenient - refactor some stuff around like the FOR_EACH macros - fix 2/3 minor bugs I stumbled upon when actually trying to compile
This commit is contained in:
parent
19910fa8bc
commit
7d34861da8
4 changed files with 64 additions and 54 deletions
|
@ -1,26 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
|
|
||||||
// https://stackoverflow.com/a/11994395 modified to fit my needs
|
#include <foreach.hpp>
|
||||||
#define FE_0(WHAT)
|
|
||||||
#define FE_1(WHAT, extra_arg, X) WHAT(extra_arg, X)
|
|
||||||
#define FE_2(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_1(WHAT, extra_arg, __VA_ARGS__)
|
|
||||||
#define FE_3(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_2(WHAT, extra_arg, __VA_ARGS__)
|
|
||||||
#define FE_4(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_3(WHAT, extra_arg, __VA_ARGS__)
|
|
||||||
#define FE_5(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_4(WHAT, extra_arg, __VA_ARGS__)
|
|
||||||
#define FE_6(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_5(WHAT, extra_arg, __VA_ARGS__)
|
|
||||||
#define FE_7(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_6(WHAT, extra_arg, __VA_ARGS__)
|
|
||||||
#define FE_8(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_7(WHAT, extra_arg, __VA_ARGS__)
|
|
||||||
#define FE_9(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_8(WHAT, extra_arg, __VA_ARGS__)
|
|
||||||
|
|
||||||
#define GET_MACRO(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME
|
|
||||||
#define FOR_EACH(action,extra_arg,...) \
|
|
||||||
GET_MACRO(_0,__VA_ARGS__,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1,FE_0)(action,extra_arg,__VA_ARGS__)
|
|
||||||
|
|
||||||
#define CONFIG(name, ...) \
|
#define CONFIG(name, ...) \
|
||||||
struct name {\
|
struct name {\
|
||||||
|
@ -32,41 +17,51 @@
|
||||||
__VA_ARGS__\
|
__VA_ARGS__\
|
||||||
} name;
|
} name;
|
||||||
|
|
||||||
#define UINT uintmax_t
|
#define VAR_UINT(section, name) uint name;
|
||||||
#define VAR_UINT(section, name) UINT name;
|
#define VAR_UINT_D(section, name, default) uint name = default;
|
||||||
#define VAR_UINT_D(section, name, default) UINT name = default;
|
|
||||||
|
|
||||||
#define INT intmax_t
|
#define VAR_INT(section, name) int name;
|
||||||
#define VAR_INT(section, name) INT name;
|
#define VAR_INT_D(section, name, default) int name = default;
|
||||||
#define VAR_INT_D(section, name, default) INT name = default;
|
|
||||||
|
|
||||||
#define STRING std::string
|
#define VAR_STRING(section, name) std::string name;
|
||||||
#define VAR_STRING(section, name) STRING name;
|
#define VAR_STRING_D(section, name, default) std::string name = default;
|
||||||
#define VAR_STRING_D(section, name, default) STRING name = default;
|
|
||||||
|
|
||||||
#define BOOL bool
|
#define VAR_BOOL(section, name) bool name;
|
||||||
#define VAR_BOOL(section, name) BOOL name;
|
#define VAR_BOOL_D(section, name, default) bool name = default;
|
||||||
#define VAR_BOOL_D(section, name, default) BOOL name = default;
|
|
||||||
|
|
||||||
#define FLOAT double
|
#define VAR_FLOAT(section, name) double name;
|
||||||
#define VAR_FLOAT(section, name) FLOAT name;
|
#define VAR_FLOAT_D(section, name, default) double name = default;
|
||||||
#define VAR_FLOAT_D(section, name, default) FLOAT name = default;
|
|
||||||
#define COLOUR sf::Color
|
#define VAR_COLOUR(section, name) sf::Color name;
|
||||||
#define VAR_COLOUR(section, name) COLOUR name;
|
#define VAR_COLOUR_D(section, name, default) sf::Color name = default;
|
||||||
#define VAR_COLOUR_D(section, name, default) COLOUR name = default;
|
|
||||||
|
|
||||||
#define VAR_LIST(section, name, type) std::vector<type> name;
|
#define VAR_LIST(section, name, type) std::vector<type> name;
|
||||||
#define VAR_LIST_SEP(section, name, type, sep) std::vector<type> name;
|
#define VAR_LIST_SEP(section, name, type, sep) std::vector<type> name;
|
||||||
#define VAR_LIST_NUMBERED(section, name, type) std::vector<type> name;
|
#define VAR_LIST_NUMBERED(section, name, type) std::vector<type> name;
|
||||||
|
|
||||||
#define ENUM_TO_STRING_CASE(name, e) case name::e: os << #e;
|
|
||||||
#define ENUM_FROM_STRING(name, e) if (input == #e) en = name::e;
|
|
||||||
|
|
||||||
#define ENUM(name, ...) \
|
#define ENUM(name, ...) \
|
||||||
enum class name {\
|
enum class name {\
|
||||||
__VA_ARGS__\
|
__VA_ARGS__\
|
||||||
};\
|
};\
|
||||||
\
|
ENUM_STREAM_OPS(name, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define VAR_ENUM(section, name, enum_type) enum_type name;
|
||||||
|
#define VAR_ENUM_D(section, name, enum_type, default) enum_type name = enum_type::default;
|
||||||
|
|
||||||
|
#define VAR_BITS(section, name, amount, offset) unsigned int name : amount;
|
||||||
|
|
||||||
|
#define STRUCT(name, ...) \
|
||||||
|
struct name {\
|
||||||
|
__VA_ARGS__\
|
||||||
|
};
|
||||||
|
|
||||||
|
#define VAR_STRUCT(section, name, struct_type) struct_type name;
|
||||||
|
#define VAR_STRUCT_D(section, name, struct_type, default) struct_type name = default;
|
||||||
|
|
||||||
|
#define ENUM_TO_STRING_CASE(name, e) case name::e: os << #e;
|
||||||
|
#define ENUM_FROM_STRING(name, e) if (input == #e) en = name::e;
|
||||||
|
|
||||||
|
#define ENUM_STREAM_OPS(name, ...) \
|
||||||
inline std::ostream &operator<<(std::ostream &os, const name &en) {\
|
inline std::ostream &operator<<(std::ostream &os, const name &en) {\
|
||||||
switch (en) {\
|
switch (en) {\
|
||||||
FOR_EACH(ENUM_TO_STRING_CASE, name, __VA_ARGS__)\
|
FOR_EACH(ENUM_TO_STRING_CASE, name, __VA_ARGS__)\
|
||||||
|
@ -81,22 +76,13 @@
|
||||||
return is;\
|
return is;\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define VAR_ENUM(section, name, enum_type) enum_type name;
|
|
||||||
#define VAR_ENUM_D(section, name, enum_type, default) enum_type name = enum_type::default;
|
|
||||||
|
|
||||||
#define VAR_BITS(section, name, amount, offset) unsigned int name : amount;
|
|
||||||
|
|
||||||
#define STRUCT_FIELD_TO_STRING(name, field) os << #field << ": " << str.field << "\n";
|
#define STRUCT_FIELD_TO_STRING(name, field) os << #field << ": " << str.field << "\n";
|
||||||
#define STRUCT_FROM_STRING(name, field) \
|
#define STRUCT_FROM_STRING(name, field) \
|
||||||
std::getline(is, input, ",");\
|
std::getline(is, input, ',');\
|
||||||
std::stringstream ss(input);\
|
ss = std::stringstream(input);\
|
||||||
ss >> str.field;
|
ss >> str.field;
|
||||||
|
|
||||||
#define STRUCT(name, ...) \
|
#define STRUCT_STREAM_OPS(name, ...) \
|
||||||
struct name {\
|
|
||||||
__VA_ARGS__\
|
|
||||||
};\
|
|
||||||
\
|
|
||||||
inline std::ostream &operator<<(std::ostream &os, const name &str) {\
|
inline std::ostream &operator<<(std::ostream &os, const name &str) {\
|
||||||
os << #name << " {\n";\
|
os << #name << " {\n";\
|
||||||
FOR_EACH(STRUCT_FIELD_TO_STRING, name, __VA_ARGS__)\
|
FOR_EACH(STRUCT_FIELD_TO_STRING, name, __VA_ARGS__)\
|
||||||
|
@ -106,13 +92,11 @@
|
||||||
\
|
\
|
||||||
inline std::istream &operator>>(std::istream &is, name &str) {\
|
inline std::istream &operator>>(std::istream &is, name &str) {\
|
||||||
std::string input;\
|
std::string input;\
|
||||||
|
std::stringstream ss;\
|
||||||
FOR_EACH(STRUCT_FROM_STRING, name, __VA_ARGS__)\
|
FOR_EACH(STRUCT_FROM_STRING, name, __VA_ARGS__)\
|
||||||
return is;\
|
return is;\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define VAR_STRUCT(section, name, struct_type) struct_type name;
|
|
||||||
#define VAR_STRUCT_D(section, name, struct_type, default) struct_type name = default;
|
|
||||||
|
|
||||||
#include <config_def.hpp>
|
#include <config_def.hpp>
|
||||||
|
|
||||||
#undef FE_0
|
#undef FE_0
|
||||||
|
@ -160,6 +144,9 @@
|
||||||
|
|
||||||
#undef VAR_BITS
|
#undef VAR_BITS
|
||||||
|
|
||||||
|
#undef STRUCT_FIELD_TO_STRING
|
||||||
|
#undef STRUCT_FROM_STRING
|
||||||
|
|
||||||
#undef STRUCT
|
#undef STRUCT
|
||||||
#undef VAR_STRUCT
|
#undef VAR_STRUCT
|
||||||
#undef VAR_STRUCT_D
|
#undef VAR_STRUCT_D
|
||||||
|
|
|
@ -33,6 +33,8 @@
|
||||||
|
|
||||||
#define VAR_BITS(section, name, amount, offset)
|
#define VAR_BITS(section, name, amount, offset)
|
||||||
|
|
||||||
|
#define STRUCT_STREAM_OPS(name, ...)
|
||||||
|
|
||||||
#define STRUCT(name, ...)
|
#define STRUCT(name, ...)
|
||||||
#define VAR_STRUCT(section, name, struct_type)
|
#define VAR_STRUCT(section, name, struct_type)
|
||||||
#define VAR_STRUCT_D(section, name, struct_type, default)
|
#define VAR_STRUCT_D(section, name, struct_type, default)
|
||||||
|
@ -79,7 +81,7 @@ STRUCT(TimingPoint,
|
||||||
VAR_BOOL(, uninherited)
|
VAR_BOOL(, uninherited)
|
||||||
VAR_UINT(, effects)
|
VAR_UINT(, effects)
|
||||||
)
|
)
|
||||||
|
STRUCT_STREAM_OPS(TimingPoint, time, beatLength, meter, sampleSet, sampleIndex, volume, uninherited, effects)
|
||||||
|
|
||||||
STRUCT(HitObjectType,
|
STRUCT(HitObjectType,
|
||||||
VAR_BITS(, hitCircle, 1, 0)
|
VAR_BITS(, hitCircle, 1, 0)
|
||||||
|
@ -89,6 +91,7 @@ STRUCT(HitObjectType,
|
||||||
VAR_BITS(, colourHax, 3, 4)
|
VAR_BITS(, colourHax, 3, 4)
|
||||||
VAR_BITS(, holdNote, 1, 7)
|
VAR_BITS(, holdNote, 1, 7)
|
||||||
)
|
)
|
||||||
|
STRUCT_STREAM_OPS(HitObjectType, hitCircle, slider, newCombo, spinner, colourHax, holdNote)
|
||||||
|
|
||||||
STRUCT(HitSound,
|
STRUCT(HitSound,
|
||||||
VAR_BITS(, normal, 1, 0)
|
VAR_BITS(, normal, 1, 0)
|
||||||
|
@ -96,6 +99,7 @@ STRUCT(HitSound,
|
||||||
VAR_BITS(, finish, 1, 2)
|
VAR_BITS(, finish, 1, 2)
|
||||||
VAR_BITS(, clap, 1, 3)
|
VAR_BITS(, clap, 1, 3)
|
||||||
)
|
)
|
||||||
|
STRUCT_STREAM_OPS(HitSound, normal, whistle, finish, clap)
|
||||||
|
|
||||||
STRUCT(HitObject,
|
STRUCT(HitObject,
|
||||||
VAR_INT(, x)
|
VAR_INT(, x)
|
||||||
|
@ -104,6 +108,7 @@ STRUCT(HitObject,
|
||||||
VAR_STRUCT(, type, HitObjectType)
|
VAR_STRUCT(, type, HitObjectType)
|
||||||
VAR_STRUCT(, hitSound ,HitSound)
|
VAR_STRUCT(, hitSound ,HitSound)
|
||||||
)
|
)
|
||||||
|
STRUCT_STREAM_OPS(HitObject, x, y, time, type, hitSound)
|
||||||
|
|
||||||
// https://osu.ppy.sh/wiki/en/Client/File_formats/osu_%28file_format%29
|
// https://osu.ppy.sh/wiki/en/Client/File_formats/osu_%28file_format%29
|
||||||
CONFIG(Difficulty,
|
CONFIG(Difficulty,
|
||||||
|
|
17
include/foreach.hpp
Normal file
17
include/foreach.hpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/11994395 modified to fit my needs
|
||||||
|
#define FE_0(WHAT)
|
||||||
|
#define FE_1(WHAT, extra_arg, X) WHAT(extra_arg, X)
|
||||||
|
#define FE_2(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_1(WHAT, extra_arg, __VA_ARGS__)
|
||||||
|
#define FE_3(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_2(WHAT, extra_arg, __VA_ARGS__)
|
||||||
|
#define FE_4(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_3(WHAT, extra_arg, __VA_ARGS__)
|
||||||
|
#define FE_5(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_4(WHAT, extra_arg, __VA_ARGS__)
|
||||||
|
#define FE_6(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_5(WHAT, extra_arg, __VA_ARGS__)
|
||||||
|
#define FE_7(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_6(WHAT, extra_arg, __VA_ARGS__)
|
||||||
|
#define FE_8(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_7(WHAT, extra_arg, __VA_ARGS__)
|
||||||
|
#define FE_9(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_8(WHAT, extra_arg, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define GET_MACRO(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME
|
||||||
|
#define FOR_EACH(action,extra_arg,...) \
|
||||||
|
GET_MACRO(_0,__VA_ARGS__,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1,FE_0)(action,extra_arg,__VA_ARGS__)
|
|
@ -4,6 +4,7 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
inline std::string checkAndRemove(const std::string &str, const std::string &prefix) {
|
inline std::string checkAndRemove(const std::string &str, const std::string &prefix) {
|
||||||
if (!str.starts_with(prefix)) {
|
if (!str.starts_with(prefix)) {
|
||||||
|
|
Loading…
Reference in a new issue