diff --git a/.gitignore b/.gitignore index a078454..8daab9f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,7 @@ __pycache__/ subprojects/packagecache/ subprojects/dwarfstack-*/ subprojects/dwarfstack.wrap +subprojects/uthash-*/ +subprojects/uthash.wrap .dotnet/ .local/ diff --git a/src/game/game_string.c b/src/game/game_string.c index abb8a81..264a97f 100644 --- a/src/game/game_string.c +++ b/src/game/game_string.c @@ -1,46 +1,15 @@ #include "game_string.h" -#include -#include +#include -#include -#include -#include - -static char *m_StringMap[GS_NUMBER_OF] = { 0 }; - -#undef GS_DEFINE -#define GS_DEFINE(id, str) str, -static const char *m_DefaultStringMap[GS_NUMBER_OF] = { -#include "game/game_string.def" -}; - -#undef GS_DEFINE -#define GS_DEFINE(id, str) \ - { \ - QUOTE(id), \ - GS_##id, \ - }, -ENUM_STRING_MAP ENUM_STRING_MAP(GAME_STRING_ID)[] = { -#include "game/game_string.def" - { NULL, -1 } -}; - -void GameString_Set(const GAME_STRING_ID id, const char *const value) +void GameString_Init(void) { - assert(id >= 0); - assert(id < GS_NUMBER_OF); - Memory_FreePointer(&m_StringMap[id]); - m_StringMap[id] = Memory_DupStr(value); + // IWYU pragma: begin_keep +#include "game_string.def" + // IWYU pragma: end_keep } -const char *GameString_Get(const GAME_STRING_ID id) +void GameString_Shutdown(void) { - return m_StringMap[id] != NULL ? (const char *)m_StringMap[id] - : m_DefaultStringMap[id]; -} - -GAME_STRING_ID GameString_IDFromEnum(const char *const key) -{ - return ENUM_STRING_GET(GAME_STRING_ID, key, GS_INVALID); + GameString_Clear(); } diff --git a/src/game/game_string.h b/src/game/game_string.h index 81782cd..78c02b1 100644 --- a/src/game/game_string.h +++ b/src/game/game_string.h @@ -1,19 +1,6 @@ #pragma once -#include +#include -#define GS(id) GameString_Get(GS_##id) - -#undef GS_DEFINE -#define GS_DEFINE(id, str) GS_##id, -typedef enum GAME_STRING_ID { - GS_INVALID = -1, -#include "game/game_string.def" - GS_NUMBER_OF, -} GAME_STRING_ID; - -extern ENUM_STRING_MAP ENUM_STRING_MAP(GAME_STRING_ID)[]; - -void GameString_Set(GAME_STRING_ID id, const char *value); -const char *GameString_Get(GAME_STRING_ID id); -GAME_STRING_ID GameString_IDFromEnum(const char *str); +void GameString_Init(void); +void GameString_Shutdown(void); diff --git a/src/game/gameflow/gameflow_new.c b/src/game/gameflow/gameflow_new.c index 7d0305f..2d2eb70 100644 --- a/src/game/gameflow/gameflow_new.c +++ b/src/game/gameflow/gameflow_new.c @@ -5,6 +5,8 @@ #include "global/enum_str.h" #include "global/types.h" +#include + #include GAMEFLOW_NEW g_GameflowNew; @@ -27,10 +29,12 @@ static void GF_N_LoadObjectString( static void GF_N_LoadGameString(const char *const key, const char *const value) { - const GAME_STRING_ID game_string = - ENUM_STRING_GET(GAME_STRING_ID, key, GS_INVALID); - if (game_string != GS_INVALID) { - GameString_Set(game_string, value); + if (!GameString_IsKnown(key)) { + LOG_ERROR("Invalid game string key: %s", key); + } else if (value == NULL) { + LOG_ERROR("Invalid game string value: %s", key); + } else { + GameString_Define(key, value); } } diff --git a/src/game/shell.c b/src/game/shell.c index 5e2e1c0..e3ab187 100644 --- a/src/game/shell.c +++ b/src/game/shell.c @@ -4,6 +4,7 @@ #include "decomp/decomp.h" #include "game/console.h" #include "game/demo.h" +#include "game/game_string.h" #include "game/gameflow.h" #include "game/gameflow/reader.h" #include "game/input.h" @@ -25,6 +26,8 @@ BOOL __cdecl Shell_Main(void) g_GameSizer = 1.0; g_GameSizerCopy = 1.0; + GameString_Init(); + Config_Read(); if (!S_InitialiseSystem()) { return false; @@ -160,6 +163,7 @@ BOOL __cdecl Shell_Main(void) S_SaveSettings(); GameBuf_Shutdown(); Config_Write(); + GameString_Shutdown(); return true; } diff --git a/subprojects/libtrx b/subprojects/libtrx index 8ad35cc..0d395b7 160000 --- a/subprojects/libtrx +++ b/subprojects/libtrx @@ -1 +1 @@ -Subproject commit 8ad35cc897de2af3d1b58407adfbf2908ade5dd6 +Subproject commit 0d395b79ec7cea7afd40fe241a535b3bb48602a6