libtrx: use new enum maps

This commit is contained in:
Marcin Kurczewski 2024-09-27 23:49:34 +02:00
parent 1933238739
commit 397a7bc363
No known key found for this signature in database
GPG Key ID: CC65E6FD28CAE42A
10 changed files with 22 additions and 36 deletions

View File

@ -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',

View File

@ -6,7 +6,6 @@
#include <libtrx/config/map.h>
// import order guard
#include "global/enum_str.h"
#include "global/types.h"
const CONFIG_OPTION g_ConfigOptionMap[] = {

View File

@ -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 <libtrx/enum_map.h>
#include <libtrx/game/gameflow/types.h>
#include <libtrx/game/objects/names.h>
#include <libtrx/log.h>
@ -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);
}
}

View File

@ -13,6 +13,7 @@
#include "global/funcs.h"
#include "global/vars.h"
#include <libtrx/enum_map.h>
#include <libtrx/game/ui/common.h>
#include <libtrx/memory.h>
@ -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;
}

12
src/global/enum_map.c Normal file
View File

@ -0,0 +1,12 @@
#include <libtrx/enum_map.h>
#include <libtrx/game/objects/ids.h>
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 <libtrx/game/objects/ids.def>
}

0
src/global/enum_map.def Normal file
View File

View File

@ -1,3 +0,0 @@
#define ENUM_STR_IMPL
#include "global/enum_str.h"

View File

@ -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 <libtrx/game/objects/names.def>
{ NULL, -1 }
};
#else
extern ENUM_STRING_MAP ENUM_STRING_MAP(GAME_OBJECT_ID)[];
#endif

View File

@ -1,11 +0,0 @@
#pragma once
// import order guard
#include <libtrx/enum_str.h>
// import order guard
// import order guard
#include "global/types.h"
// import order guard
#include "global/enum_str.def"

@ -1 +1 @@
Subproject commit ba38d9e762ea7320e896e4eb02a9e382ce55f40b
Subproject commit 3e51422534f81fcc3178bb9516567ed0b15b8618