refactor a huge part of the code

this allows for creating only input and output streams and allows me to
finally print out the generated config struct
This commit is contained in:
jacekpoz 2024-04-20 13:37:06 +02:00
parent 82929e16bf
commit c5491dbc9f
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
8 changed files with 120 additions and 64 deletions

View file

@ -6,6 +6,7 @@
#include <SFML/Graphics/Color.hpp>
#include <foreach.hpp>
#include <util_stream_ops.hpp>
#define CONFIG(name, ...) \
struct name {\
@ -82,20 +83,13 @@
#define VAR_STRUCT_P(section, name, prefix) VAR_STRUCT(section, name)
#define VAR_STRUCT_D(section, name, struct_type, default) struct_type name = default;
#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) \
std::getline(is, input, ',');\
ss = std::stringstream(input);\
ss >> str.field;
#define STRUCT_STREAM_OPS(name, ...) \
inline std::ostream &operator<<(std::ostream &os, const name &str) {\
os << #name << " {\n";\
FOR_EACH(STRUCT_FIELD_TO_STRING, name, __VA_ARGS__)\
os << "}\n";\
return os;\
}\
\
#define STRUCT_INPUT_STREAM_OP(name, ...) \
inline std::istream &operator>>(std::istream &is, name &str) {\
std::string input;\
std::stringstream ss;\
@ -103,6 +97,18 @@
return is;\
}
#define STRUCT_OUTPUT_STREAM_OP(name, ...) \
inline std::ostream &operator<<(std::ostream &os, const name &str) {\
os << #name << " {\n";\
FOR_EACH(STRUCT_FIELD_TO_STRING, name, __VA_ARGS__)\
os << "}\n";\
return os;\
}\
#define STRUCT_STREAM_OPS(name, ...) \
STRUCT_INPUT_STREAM_OP(name, __VA_ARGS__) \
STRUCT_OUTPUT_STREAM_OP(name, __VA_ARGS__)
#include <config_def.hpp>
#undef CONFIG
@ -150,6 +156,8 @@
#undef STRUCT_FIELD_TO_STRING
#undef STRUCT_FROM_STRING
#undef STRUCT_INPUT_STREAM_OP
#undef STRUCT_OUTPUT_STREAM_OP
#undef STRUCT_STREAM_OPS
#undef VAR_LIST

View file

@ -38,6 +38,8 @@
#define VAR_STRUCT_P(section, name, prefix)
#define VAR_STRUCT_D(section, name, struct_type, default)
#define STRUCT_INPUT_STREAM_OP(name, ...)
#define STRUCT_OUTPUT_STREAM_OP(name, ...)
#define STRUCT_STREAM_OPS(name, ...)
#define VAR_LIST(section, name, type)
@ -169,6 +171,51 @@ CONFIG(Difficulty,
VAR_LIST(, hitObjects, HitObject)
)
STRUCT_OUTPUT_STREAM_OP(Difficulty,
formatVersion,
general.audioFilename,
general.audioLeadIn,
general.previewTime,
general.countdown,
general.sampleSet,
general.stackLeniency,
general.mode,
general.letterboxInBreaks,
general.useSkinSprites,
general.overlayPosition,
general.skinPreference,
general.epilepsyWarning,
general.countdownOffset,
general.specialStyle,
general.widescreenStoryboard,
general.sampleMatchPlaybackRate,
editor.bookmarks,
editor.distanceSpacing,
editor.beatDivisor,
editor.gridSize,
editor.timelineZoom,
metadata.title,
metadata.titleUnicode,
metadata.artist,
metadata.artistUnicode,
metadata.creator,
metadata.version,
metadata.source,
metadata.tags,
metadata.beatmapID,
metadata.beatmapSetID,
difficulty.hpDrainRate,
difficulty.circleSize,
difficulty.overallDifficulty,
difficulty.approachRate,
difficulty.sliderMultiplier,
difficulty.sliderTickRate,
timingPoints,
colours.combo,
colours.sliderTrackOverride,
colours.sliderBorder,
hitObjects
)
#ifdef CONFIG_DEFINED
#undef CONFIG
@ -208,6 +255,8 @@ CONFIG(Difficulty,
#undef VAR_STRUCT_P
#undef VAR_STRUCT_D
#undef STRUCT_INPUT_STREAM_OP
#undef STRUCT_OUTPUT_STREAM_OP
#undef STRUCT_STREAM_OPS
#undef VAR_LIST

View file

@ -11,7 +11,47 @@
#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 FE_10(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_9(WHAT, extra_arg, __VA_ARGS__)
#define FE_11(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_10(WHAT, extra_arg, __VA_ARGS__)
#define FE_12(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_11(WHAT, extra_arg, __VA_ARGS__)
#define FE_13(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_12(WHAT, extra_arg, __VA_ARGS__)
#define FE_14(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_13(WHAT, extra_arg, __VA_ARGS__)
#define FE_15(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_14(WHAT, extra_arg, __VA_ARGS__)
#define FE_16(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_15(WHAT, extra_arg, __VA_ARGS__)
#define FE_17(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_16(WHAT, extra_arg, __VA_ARGS__)
#define FE_18(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_17(WHAT, extra_arg, __VA_ARGS__)
#define FE_19(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_18(WHAT, extra_arg, __VA_ARGS__)
#define FE_20(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_19(WHAT, extra_arg, __VA_ARGS__)
#define FE_21(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_20(WHAT, extra_arg, __VA_ARGS__)
#define FE_22(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_21(WHAT, extra_arg, __VA_ARGS__)
#define FE_23(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_22(WHAT, extra_arg, __VA_ARGS__)
#define FE_24(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_23(WHAT, extra_arg, __VA_ARGS__)
#define FE_25(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_24(WHAT, extra_arg, __VA_ARGS__)
#define FE_26(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_25(WHAT, extra_arg, __VA_ARGS__)
#define FE_27(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_26(WHAT, extra_arg, __VA_ARGS__)
#define FE_28(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_27(WHAT, extra_arg, __VA_ARGS__)
#define FE_29(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_28(WHAT, extra_arg, __VA_ARGS__)
#define FE_30(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_29(WHAT, extra_arg, __VA_ARGS__)
#define FE_31(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_30(WHAT, extra_arg, __VA_ARGS__)
#define FE_32(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_31(WHAT, extra_arg, __VA_ARGS__)
#define FE_33(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_32(WHAT, extra_arg, __VA_ARGS__)
#define FE_34(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_33(WHAT, extra_arg, __VA_ARGS__)
#define FE_35(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_34(WHAT, extra_arg, __VA_ARGS__)
#define FE_36(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_35(WHAT, extra_arg, __VA_ARGS__)
#define FE_37(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_36(WHAT, extra_arg, __VA_ARGS__)
#define FE_38(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_37(WHAT, extra_arg, __VA_ARGS__)
#define FE_39(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_38(WHAT, extra_arg, __VA_ARGS__)
#define FE_40(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_39(WHAT, extra_arg, __VA_ARGS__)
#define FE_41(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_40(WHAT, extra_arg, __VA_ARGS__)
#define FE_42(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_41(WHAT, extra_arg, __VA_ARGS__)
#define FE_43(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_42(WHAT, extra_arg, __VA_ARGS__)
#define FE_44(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_43(WHAT, extra_arg, __VA_ARGS__)
#define FE_45(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_44(WHAT, extra_arg, __VA_ARGS__)
#define FE_46(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_45(WHAT, extra_arg, __VA_ARGS__)
#define FE_47(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_46(WHAT, extra_arg, __VA_ARGS__)
#define FE_48(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_47(WHAT, extra_arg, __VA_ARGS__)
#define FE_49(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_48(WHAT, extra_arg, __VA_ARGS__)
#define FE_50(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_49(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 GET_MACRO(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,NAME,...) NAME
#define FOR_EACH(action,extra_arg,...) GET_MACRO(_0,__VA_ARGS__,FE_50,FE_49,FE_48,FE_47,FE_46,FE_45,FE_44,FE_43,FE_42,FE_41,FE_40,FE_39,FE_38,FE_37,FE_36,FE_35,FE_34,FE_33,FE_32,FE_31,FE_30,FE_29,FE_28,FE_27,FE_26,FE_25,FE_24,FE_23,FE_22,FE_21,FE_20,FE_19,FE_18,FE_17,FE_16,FE_15,FE_14,FE_13,FE_12,FE_11,FE_10,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__)

View file

@ -31,6 +31,8 @@ namespace fs = std::filesystem;
#define VAR_ENUM(section, name, enum_type)
#define VAR_ENUM_D(section, name, enum_type, default)
#define STRUCT_INPUT_STREAM_OP(name, ...)
#define STRUCT_OUTPUT_STREAM_OP(name, ...)
#define STRUCT_STREAM_OPS(name, ...)
#define STRUCT(name, ...)
@ -68,6 +70,8 @@ namespace fs = std::filesystem;
#undef VAR_ENUM
#undef VAR_ENUM_D
#undef STRUCT_INPUT_STREAM_OP
#undef STRUCT_OUTPUT_STREAM_OP
#undef STRUCT_STREAM_OPS
#undef STRUCT

View file

@ -6,13 +6,13 @@
#include <SFML/Graphics/Color.hpp>
std::ostream &operator<<(std::ostream &stream, const sf::Color &color) {
inline std::ostream &operator<<(std::ostream &stream, const sf::Color &color) {
stream << "Color(" << color.r << ", " << color.g << ", " << color.b << ", " << color.a << ")";
return stream;
}
template <typename T>
std::ostream &operator<<(std::ostream &stream, const std::vector<T> &vec) {
inline std::ostream &operator<<(std::ostream &stream, const std::vector<T> &vec) {
stream << "[";
for (size_t i = 0; i < vec.size(); ++i) {
stream << vec.at(i);

View file

@ -1,5 +1,7 @@
#include <HitObjectDrawable.hpp>
#include <util_stream_ops.hpp>
#include <iostream>
HitObjectDrawable::HitObjectDrawable(TextureManager &tman, const HitObject &hitObject, const DifficultySettings &diff, const uint comboCount)

View file

@ -63,56 +63,7 @@ int main(int argc, char *argv[]) {
i += 1;
Difficulty diff = parseDifficulty(argv[i]);
std::cout << "osu format version: " << diff.formatVersion << "\n";
std::cout << "general.audioFilename: " << diff.general.audioFilename << "\n";
std::cout << "general.audioLeadIn: " << diff.general.audioLeadIn << "\n";
std::cout << "general.previewTime: " << diff.general.previewTime << "\n";
std::cout << "general.countdown: " << diff.general.countdown << "\n";
std::cout << "general.sampleSet: " << diff.general.sampleSet << "\n";
std::cout << "general.stackLeniency: " << diff.general.stackLeniency << "\n";
std::cout << "general.mode: " << diff.general.mode << "\n";
std::cout << "general.letterboxInBreaks: " << diff.general.letterboxInBreaks << "\n";
std::cout << "general.useSkinSprites: " << diff.general.useSkinSprites << "\n";
std::cout << "general.overlayPosition: " << diff.general.overlayPosition << "\n";
std::cout << "general.skinPreference: " << diff.general.skinPreference << "\n";
std::cout << "general.epilepsyWarning: " << diff.general.epilepsyWarning << "\n";
std::cout << "general.countdownOffset: " << diff.general.countdownOffset << "\n";
std::cout << "general.specialStyle: " << diff.general.specialStyle << "\n";
std::cout << "general.widescreenStoryboard: " << diff.general.widescreenStoryboard << "\n";
std::cout << "general.sampleMatchPlaybackRate: " << diff.general.sampleMatchPlaybackRate << "\n";
std::cout << "editor.bookmarks: " << diff.editor.bookmarks << "\n";
std::cout << "editor.distanceSpacing: " << diff.editor.distanceSpacing << "\n";
std::cout << "editor.beatDivisor: " << diff.editor.beatDivisor << "\n";
std::cout << "editor.gridSize: " << diff.editor.gridSize << "\n";
std::cout << "editor.timelineZoom: " << diff.editor.timelineZoom << "\n";
std::cout << "metadata.title: " << diff.metadata.title << "\n";
std::cout << "metadata.titleUnicode: " << diff.metadata.titleUnicode << "\n";
std::cout << "metadata.artist: " << diff.metadata.artist << "\n";
std::cout << "metadata.artistUnicode: " << diff.metadata.artistUnicode << "\n";
std::cout << "metadata.creator: " << diff.metadata.creator << "\n";
std::cout << "metadata.version: " << diff.metadata.version << "\n";
std::cout << "metadata.source: " << diff.metadata.source << "\n";
std::cout << "metadata.tags: " << diff.metadata.tags << "\n";
std::cout << "metadata.beatmapID: " << diff.metadata.beatmapID << "\n";
std::cout << "metadata.beatmapSetID: " << diff.metadata.beatmapSetID << "\n";
std::cout << "difficulty.hpDrainRate: " << diff.difficulty.hpDrainRate << "\n";
std::cout << "difficulty.circleSize: " << diff.difficulty.circleSize << "\n";
std::cout << "difficulty.overallDifficulty: " << diff.difficulty.overallDifficulty << "\n";
std::cout << "difficulty.approachRate: " << diff.difficulty.approachRate << "\n";
std::cout << "difficulty.sliderMultiplier: " << diff.difficulty.sliderMultiplier << "\n";
std::cout << "difficulty.sliderTickRate: " << diff.difficulty.sliderTickRate << "\n";
std::cout << "timingPoints: " << diff.timingPoints << "\n";
std::cout << "colours.combo: " << diff.colours.combo << "\n";
std::cout << "colours.sliderTrackOverride: " << diff.colours.sliderTrackOverride << "\n";
std::cout << "colours.sliderBorder: " << diff.colours.sliderBorder << "\n";
std::cout << "hitObjects: " << diff.hitObjects << "\n";
std::cout << diff << "\n";
std::exit(EXIT_SUCCESS);
}

View file

@ -216,6 +216,8 @@ inline void toLower(std::string &str) {
ss >> value;\
)
#define STRUCT_INPUT_STREAM_OP(name, ...)
#define STRUCT_OUTPUT_STREAM_OP(name, ...)
#define STRUCT_STREAM_OPS(name, ...)
#define STRUCT(name, ...)