From 397a7bc363e23e5f1634bed65e4de99bd6b2120b Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 27 Sep 2024 23:49:34 +0200 Subject: [PATCH] libtrx: use new enum maps --- meson.build | 2 +- src/config_map.c | 1 - src/game/gameflow/gameflow_new.c | 10 +++++----- src/game/shell.c | 3 +++ src/global/enum_map.c | 12 ++++++++++++ src/global/enum_map.def | 0 src/global/enum_str.c | 3 --- src/global/enum_str.def | 14 -------------- src/global/enum_str.h | 11 ----------- subprojects/libtrx | 2 +- 10 files changed, 22 insertions(+), 36 deletions(-) create mode 100644 src/global/enum_map.c create mode 100644 src/global/enum_map.def delete mode 100644 src/global/enum_str.c delete mode 100644 src/global/enum_str.def delete mode 100644 src/global/enum_str.h diff --git a/meson.build b/meson.build index c87f17f3..28b6d8b5 100644 --- a/meson.build +++ b/meson.build @@ -169,7 +169,7 @@ dll_sources = [ 'src/game/ui/widgets/label.c', 'src/game/ui/widgets/prompt.c', 'src/game/ui/widgets/window.c', - 'src/global/enum_str.c', + 'src/global/enum_map.c', 'src/global/vars.c', 'src/inject_exec.c', 'src/inject_util.c', diff --git a/src/config_map.c b/src/config_map.c index a6e431fb..82a3299d 100644 --- a/src/config_map.c +++ b/src/config_map.c @@ -6,7 +6,6 @@ #include // import order guard -#include "global/enum_str.h" #include "global/types.h" const CONFIG_OPTION g_ConfigOptionMap[] = { diff --git a/src/game/gameflow/gameflow_new.c b/src/game/gameflow/gameflow_new.c index 174bb997..d8c39cf4 100644 --- a/src/game/gameflow/gameflow_new.c +++ b/src/game/gameflow/gameflow_new.c @@ -1,10 +1,10 @@ #include "game/gameflow/gameflow_new.h" #include "game/game_string.h" -#include "global/enum_str.h" #include "global/types.h" #include "global/vars.h" +#include #include #include #include @@ -21,10 +21,10 @@ static void M_LoadGameStrings(const int32_t level_num); static void M_LoadObjectString(const char *const key, const char *const value) { - const GAME_OBJECT_ID object = - ENUM_STRING_GET(GAME_OBJECT_ID, key, NO_OBJECT); - if (object != NO_OBJECT) { - Object_SetName(object, value); + const GAME_OBJECT_ID object_id = + ENUM_MAP_GET(GAME_OBJECT_ID, key, NO_OBJECT); + if (object_id != NO_OBJECT) { + Object_SetName(object_id, value); } } diff --git a/src/game/shell.c b/src/game/shell.c index 13ca488b..1f6eeee4 100644 --- a/src/game/shell.c +++ b/src/game/shell.c @@ -13,6 +13,7 @@ #include "global/funcs.h" #include "global/vars.h" +#include #include #include @@ -28,6 +29,7 @@ BOOL __cdecl Shell_Main(void) g_GameSizerCopy = 1.0; GameString_Init(); + EnumMap_Init(); Config_Init(); UI_Init(); @@ -161,6 +163,7 @@ BOOL __cdecl Shell_Main(void) S_SaveSettings(); GameBuf_Shutdown(); + EnumMap_Shutdown(); GameString_Shutdown(); return true; } diff --git a/src/global/enum_map.c b/src/global/enum_map.c new file mode 100644 index 00000000..1acba19e --- /dev/null +++ b/src/global/enum_map.c @@ -0,0 +1,12 @@ +#include +#include + +void EnumMap_Init(void) +{ +#include "global/enum_map.def" + +#undef OBJ_ID_DEFINE +#define OBJ_ID_DEFINE(object_id, value) \ + EnumMap_Define("GAME_OBJECT_ID", object_id, #object_id); +#include +} diff --git a/src/global/enum_map.def b/src/global/enum_map.def new file mode 100644 index 00000000..e69de29b diff --git a/src/global/enum_str.c b/src/global/enum_str.c deleted file mode 100644 index c516b12c..00000000 --- a/src/global/enum_str.c +++ /dev/null @@ -1,3 +0,0 @@ -#define ENUM_STR_IMPL - -#include "global/enum_str.h" diff --git a/src/global/enum_str.def b/src/global/enum_str.def deleted file mode 100644 index 02c6835d..00000000 --- a/src/global/enum_str.def +++ /dev/null @@ -1,14 +0,0 @@ -// TODO: this is garbage -#ifdef ENUM_STR_IMPL -#define OBJ_NAME_DEFINE(id, str) \ - { \ - #id, \ - id, \ - }, -ENUM_STRING_MAP ENUM_STRING_MAP(GAME_OBJECT_ID)[] = { -#include - { NULL, -1 } -}; -#else -extern ENUM_STRING_MAP ENUM_STRING_MAP(GAME_OBJECT_ID)[]; -#endif diff --git a/src/global/enum_str.h b/src/global/enum_str.h deleted file mode 100644 index 44793bf4..00000000 --- a/src/global/enum_str.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -// import order guard -#include -// import order guard - -// import order guard -#include "global/types.h" -// import order guard - -#include "global/enum_str.def" diff --git a/subprojects/libtrx b/subprojects/libtrx index ba38d9e7..3e514225 160000 --- a/subprojects/libtrx +++ b/subprojects/libtrx @@ -1 +1 @@ -Subproject commit ba38d9e762ea7320e896e4eb02a9e382ce55f40b +Subproject commit 3e51422534f81fcc3178bb9516567ed0b15b8618