diff --git a/src/common/clipboard/ClipboardImpls.template.h b/src/common/clipboard/ClipboardImpls.template.h index e0de0bcd0..13a4cfc7b 100644 --- a/src/common/clipboard/ClipboardImpls.template.h +++ b/src/common/clipboard/ClipboardImpls.template.h @@ -1,10 +1,5 @@ -#ifdef CLIPBOARD_IMPLS_DECLARE -# define IMPL_DEFINE(subsystem, factory) std::unique_ptr factory(); -#endif -#ifdef CLIPBOARD_IMPLS_DEFINE -# define IMPL_DEFINE(subsystem, factory) { subsystem, factory }, -#endif +#pragma once -@impl_defs@ - -#undef IMPL_DEFINE +#define CLIPBOARD_IMPLS(X) \ + @clipboard_impls@ + // last line of the macro, do not remove diff --git a/src/common/clipboard/Dynamic.cpp b/src/common/clipboard/Dynamic.cpp index 40dfb9f71..37b8030b2 100644 --- a/src/common/clipboard/Dynamic.cpp +++ b/src/common/clipboard/Dynamic.cpp @@ -3,13 +3,14 @@ #include "client/GameSave.h" #include "prefs/GlobalPrefs.h" #include "PowderToySDL.h" +#include "ClipboardImpls.h" #include #include namespace Clipboard { -#define CLIPBOARD_IMPLS_DECLARE -#include "ClipboardImpls.h" +#define CLIPBOARD_IMPLS_DECLARE(subsystem, factory) std::unique_ptr factory(); + CLIPBOARD_IMPLS(CLIPBOARD_IMPLS_DECLARE) #undef CLIPBOARD_IMPLS_DECLARE struct ClipboardImplEntry @@ -17,8 +18,8 @@ namespace Clipboard SDL_SYSWM_TYPE subsystem; std::unique_ptr (*factory)(); } clipboardImpls[] = { -#define CLIPBOARD_IMPLS_DEFINE -#include "ClipboardImpls.h" +#define CLIPBOARD_IMPLS_DEFINE(subsystem, factory) { subsystem, factory }, + CLIPBOARD_IMPLS(CLIPBOARD_IMPLS_DEFINE) #undef CLIPBOARD_IMPLS_DEFINE { SDL_SYSWM_UNKNOWN, nullptr }, }; diff --git a/src/meson.build b/src/meson.build index 471e3ed96..e93542cf7 100644 --- a/src/meson.build +++ b/src/meson.build @@ -203,42 +203,42 @@ subdir('resampler') subdir('simulation') subdir('tasks') -simulation_elem_defs = [] +element_numbers_x = [] foreach elem_name_id : simulation_elem_ids - simulation_elem_defs += 'ELEMENT_DEFINE(' + elem_name_id[0] + ', ' + elem_name_id[1].to_string() + ');' + element_numbers_x += 'X(@0@, @1@) \\'.format(elem_name_id[0], elem_name_id[1]) endforeach -elements_conf_data = configuration_data() -elements_conf_data.set('element_defs', '\n'.join(simulation_elem_defs)) configure_file( input: 'simulation/ElementNumbers.template.h', output: 'ElementNumbers.h', - configuration: elements_conf_data + configuration: configuration_data({ + 'element_numbers': '\n\t'.join(element_numbers_x), + }), ) if platform_clipboard - clipboard_impl_defs = [] + clipboard_impls_x = [] foreach impl_subsys_factory : clipboard_impl_factories - clipboard_impl_defs += 'IMPL_DEFINE(' + impl_subsys_factory[0] + ', ' + impl_subsys_factory[1] + ')' + clipboard_impls_x += 'X(@0@, @1@) \\'.format(impl_subsys_factory[0], impl_subsys_factory[1]) endforeach - clipboard_impls_data = configuration_data() - clipboard_impls_data.set('impl_defs', '\n'.join(clipboard_impl_defs)) configure_file( input: 'common/clipboard/ClipboardImpls.template.h', output: 'ClipboardImpls.h', - configuration: clipboard_impls_data + configuration: configuration_data({ + 'clipboard_impls': '\n\t'.join(clipboard_impls_x), + }), ) endif -simulation_tool_defs = [] +tool_numbers_x = [] foreach tool_name_id : simulation_tool_ids - simulation_tool_defs += 'TOOL_DEFINE(' + tool_name_id[0] + ', ' + tool_name_id[1].to_string() + ');' + tool_numbers_x += 'X(@0@, @1@) \\'.format(tool_name_id[0], tool_name_id[1]) endforeach -tools_conf_data = configuration_data() -tools_conf_data.set('tool_defs', '\n'.join(simulation_tool_defs)) configure_file( input: 'simulation/ToolNumbers.template.h', output: 'ToolNumbers.h', - configuration: tools_conf_data + configuration: configuration_data({ + 'tool_numbers': '\n\t'.join(tool_numbers_x), + }), ) configure_file( diff --git a/src/simulation/Element.h b/src/simulation/Element.h index cea5f6591..5b7ca091a 100644 --- a/src/simulation/Element.h +++ b/src/simulation/Element.h @@ -1,10 +1,11 @@ #pragma once -#include #include "common/Vec2.h" #include "graphics/Pixel.h" #include "ElementDefs.h" #include "Particle.h" #include "StructProperty.h" +#include "ElementNumbers.h" +#include class Simulation; class Renderer; @@ -77,7 +78,7 @@ public: by higher-level processes referring to them by name such as Lua or the property tool **/ static std::vector const &GetProperties(); -#define ELEMENT_NUMBERS_DECLARE -#include "ElementNumbers.h" +#define ELEMENT_NUMBERS_DECLARE(name, id) void Element_ ## name (); + ELEMENT_NUMBERS(ELEMENT_NUMBERS_DECLARE) #undef ELEMENT_NUMBERS_DECLARE }; diff --git a/src/simulation/ElementClasses.cpp b/src/simulation/ElementClasses.cpp index 2dc7ae7b6..34057d727 100644 --- a/src/simulation/ElementClasses.cpp +++ b/src/simulation/ElementClasses.cpp @@ -1,4 +1,5 @@ #include "ElementCommon.h" +#include "ElementNumbers.h" std::array const &GetElements() { @@ -8,8 +9,8 @@ std::array const &GetElements() DoOnce() { -#define ELEMENT_NUMBERS_CALL -#include "ElementNumbers.h" +#define ELEMENT_NUMBERS_CALL(name, id) elements[id].Element_ ## name (); + ELEMENT_NUMBERS(ELEMENT_NUMBERS_CALL) #undef ELEMENT_NUMBERS_CALL } }; diff --git a/src/simulation/ElementClasses.h b/src/simulation/ElementClasses.h index a6f9a7100..697e2a6ac 100644 --- a/src/simulation/ElementClasses.h +++ b/src/simulation/ElementClasses.h @@ -1,11 +1,11 @@ #pragma once -#include - #include "SimulationData.h" #include "Element.h" - -#define ELEMENT_NUMBERS_ENUMERATE #include "ElementNumbers.h" +#include + +#define ELEMENT_NUMBERS_ENUMERATE(name, id) constexpr int PT_ ## name = id; +ELEMENT_NUMBERS(ELEMENT_NUMBERS_ENUMERATE); #undef ELEMENT_NUMBERS_ENUMERATE std::array const &GetElements(); diff --git a/src/simulation/ElementNumbers.template.h b/src/simulation/ElementNumbers.template.h index 73febb8d0..1abd807bb 100644 --- a/src/simulation/ElementNumbers.template.h +++ b/src/simulation/ElementNumbers.template.h @@ -1,13 +1,5 @@ -#ifdef ELEMENT_NUMBERS_CALL -# define ELEMENT_DEFINE(name, id) elements[id].Element_ ## name () -#endif -#ifdef ELEMENT_NUMBERS_DECLARE -# define ELEMENT_DEFINE(name, id) void Element_ ## name () -#endif -#ifdef ELEMENT_NUMBERS_ENUMERATE -# define ELEMENT_DEFINE(name, id) constexpr int PT_ ## name = id -#endif +#pragma once -@element_defs@ - -#undef ELEMENT_DEFINE +#define ELEMENT_NUMBERS(X) \ + @element_numbers@ + // last line of the macro, do not remove diff --git a/src/simulation/SimTool.h b/src/simulation/SimTool.h index 7b69dfe23..46c15dc1a 100644 --- a/src/simulation/SimTool.h +++ b/src/simulation/SimTool.h @@ -2,6 +2,7 @@ #include "gui/game/tool/Tool.h" #include "common/String.h" #include "graphics/Pixel.h" +#include "ToolNumbers.h" class Simulation; struct Particle; @@ -17,9 +18,8 @@ public: void (*PerformDrawFill)(SimTool *tool, Simulation *sim, const Brush &brush, ui::Point position); void (*PerformSelect )(SimTool *tool, int toolSelection); - -#define TOOL_NUMBERS_DECLARE -#include "ToolNumbers.h" +#define TOOL_NUMBERS_DECLARE(name, id) void Tool_ ## name (); +TOOL_NUMBERS(TOOL_NUMBERS_DECLARE) #undef TOOL_NUMBERS_DECLARE SimTool(); diff --git a/src/simulation/ToolClasses.cpp b/src/simulation/ToolClasses.cpp index de8732a66..57b32170f 100644 --- a/src/simulation/ToolClasses.cpp +++ b/src/simulation/ToolClasses.cpp @@ -1,4 +1,5 @@ #include "ToolClasses.h" +#include "ToolNumbers.h" std::vector const &GetTools() { @@ -8,8 +9,8 @@ std::vector const &GetTools() DoOnce() { -#define TOOL_NUMBERS_CALL -#include "ToolNumbers.h" +#define TOOL_NUMBERS_CALL(name, id) tools.push_back(SimTool()), tools.back().Tool_ ## name (); +TOOL_NUMBERS(TOOL_NUMBERS_CALL) #undef TOOL_NUMBERS_CALL } }; diff --git a/src/simulation/ToolClasses.h b/src/simulation/ToolClasses.h index eb947e616..4fddaf2c4 100644 --- a/src/simulation/ToolClasses.h +++ b/src/simulation/ToolClasses.h @@ -1,11 +1,11 @@ #pragma once +#include "SimTool.h" +#include "ToolNumbers.h" #include #include -#include "SimTool.h" - -#define TOOL_NUMBERS_ENUMERATE -#include "ToolNumbers.h" +#define TOOL_NUMBERS_ENUMERATE(name, id) constexpr int TOOL_ ## name = id; +TOOL_NUMBERS(TOOL_NUMBERS_ENUMERATE) #undef TOOL_NUMBERS_ENUMERATE std::vector const &GetTools(); diff --git a/src/simulation/ToolNumbers.template.h b/src/simulation/ToolNumbers.template.h index d964fa2f1..3259ed6d1 100644 --- a/src/simulation/ToolNumbers.template.h +++ b/src/simulation/ToolNumbers.template.h @@ -1,13 +1,5 @@ -#ifdef TOOL_NUMBERS_CALL -# define TOOL_DEFINE(name, id) tools.push_back(SimTool()), tools.back().Tool_ ## name () -#endif -#ifdef TOOL_NUMBERS_DECLARE -# define TOOL_DEFINE(name, id) void Tool_ ## name () -#endif -#ifdef TOOL_NUMBERS_ENUMERATE -# define TOOL_DEFINE(name, id) constexpr int TOOL_ ## name = id -#endif +#pragma once -@tool_defs@ - -#undef TOOL_DEFINE +#define TOOL_NUMBERS(X) \ + @tool_numbers@ + // last line of the macro, do not remove