This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
game-string: manage game strings in libtrx
- Loading branch information
Showing
6 changed files
with
25 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,15 @@ | ||
#include "game_string.h" | ||
|
||
#include <libtrx/memory.h> | ||
#include <libtrx/utils.h> | ||
#include <libtrx/game/game_string.h> | ||
|
||
#include <assert.h> | ||
#include <stddef.h> | ||
#include <string.h> | ||
|
||
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) | ||
{ | ||
assert(id >= 0); | ||
assert(id < GS_NUMBER_OF); | ||
Memory_FreePointer(&m_StringMap[id]); | ||
m_StringMap[id] = Memory_DupStr(value); | ||
} | ||
|
||
const char *GameString_Get(const GAME_STRING_ID id) | ||
void GameString_Init(void) | ||
{ | ||
return m_StringMap[id] != NULL ? (const char *)m_StringMap[id] | ||
: m_DefaultStringMap[id]; | ||
// IWYU pragma: begin_keep | ||
#include "game_string.def" | ||
// IWYU pragma: end_keep | ||
} | ||
|
||
GAME_STRING_ID GameString_IDFromEnum(const char *const key) | ||
void GameString_Shutdown(void) | ||
{ | ||
return ENUM_STRING_GET(GAME_STRING_ID, key, GS_INVALID); | ||
GS_Clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,6 @@ | ||
#pragma once | ||
|
||
#include <libtrx/enum_str.h> | ||
#include <libtrx/game/game_string.h> | ||
|
||
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule libtrx
updated
4 files
+15 −0 | include/libtrx/game/game_string.h | |
+5 −1 | meson.build | |
+57 −0 | src/game/game_string.c | |
+11 −0 | subprojects/uthash.wrap |