Skip to content

Commit

Permalink
libtrx: use new enum maps
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 27, 2024
1 parent cc12f81 commit 50e97e3
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 100 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ sources = [
'src/game/stats.c',
'src/game/text.c',
'src/game/viewport.c',
'src/global/enum_str.c',
'src/global/enum_map.c',
'src/global/vars.c',
'src/math/math.c',
'src/math/math_misc.c',
Expand Down
8 changes: 4 additions & 4 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include "game/requester.h"
#include "game/sound.h"
#include "global/const.h"
#include "global/enum_str.h"
#include "global/types.h"
#include "global/vars.h"

#include <libtrx/config/file.h>
#include <libtrx/enum_map.h>
#include <libtrx/filesystem.h>
#include <libtrx/game/console/common.h>
#include <libtrx/game/ui/events.h>
Expand Down Expand Up @@ -156,13 +156,13 @@ static void M_LoadLegacyOptions(JSON_OBJECT *const parent_obj)
{
g_Config.healthbar_show_mode = ConfigFile_ReadEnum(
parent_obj, "healthbar_showing_mode", g_Config.healthbar_show_mode,
ENUM_STRING_MAP(BAR_SHOW_MODE));
ENUM_MAP_NAME(BAR_SHOW_MODE));
g_Config.airbar_show_mode = ConfigFile_ReadEnum(
parent_obj, "airbar_showing_mode", g_Config.airbar_show_mode,
ENUM_STRING_MAP(BAR_SHOW_MODE));
ENUM_MAP_NAME(BAR_SHOW_MODE));
g_Config.enemy_healthbar_show_mode = ConfigFile_ReadEnum(
parent_obj, "enemy_healthbar_showing_mode",
g_Config.enemy_healthbar_show_mode, ENUM_STRING_MAP(BAR_SHOW_MODE));
g_Config.enemy_healthbar_show_mode, ENUM_MAP_NAME(BAR_SHOW_MODE));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/config_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
4 changes: 2 additions & 2 deletions src/game/gameflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include "game/phase/phase_picture.h"
#include "game/phase/phase_stats.h"
#include "game/room.h"
#include "global/enum_str.h"
#include "global/vars.h"

#include <libtrx/enum_map.h>
#include <libtrx/filesystem.h>
#include <libtrx/game/objects/names.h>
#include <libtrx/json.h>
Expand Down Expand Up @@ -1484,7 +1484,7 @@ void GameFlow_LoadStrings(int32_t level_num)
const GAMEFLOW_STRING_ENTRY *entry = level->object_strings;
while (entry != NULL && entry->key != NULL) {
const GAME_OBJECT_ID object_id =
ENUM_STRING_GET(GAME_OBJECT_ID, entry->key, NO_OBJECT);
ENUM_MAP_GET(GAME_OBJECT_ID, entry->key, NO_OBJECT);
if (object_id != NO_OBJECT) {
Object_SetName(object_id, entry->value);
}
Expand Down
3 changes: 3 additions & 0 deletions src/game/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "global/vars.h"
#include "specific/s_shell.h"

#include <libtrx/enum_map.h>
#include <libtrx/filesystem.h>
#include <libtrx/game/ui/common.h>
#include <libtrx/log.h>
Expand Down Expand Up @@ -161,6 +162,7 @@ void Shell_Shutdown(void)
void Shell_Main(void)
{
GameString_Init();
EnumMap_Init();
Config_Init();
Config_Read();

Expand Down Expand Up @@ -275,6 +277,7 @@ void Shell_Main(void)
}

Config_Write();
EnumMap_Shutdown();
GameString_Shutdown();
}

Expand Down
14 changes: 14 additions & 0 deletions src/global/enum_map.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "global/types.h"

#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>
}
41 changes: 41 additions & 0 deletions src/global/enum_map.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
ENUM_MAP_DEFINE(UI_STYLE, UI_STYLE_PS1, "ps1")
ENUM_MAP_DEFINE(UI_STYLE, UI_STYLE_PC, "pc")

ENUM_MAP_DEFINE(BAR_SHOW_MODE, BSM_DEFAULT, "default")
ENUM_MAP_DEFINE(BAR_SHOW_MODE, BSM_FLASHING_OR_DEFAULT, "flashing-or-default")
ENUM_MAP_DEFINE(BAR_SHOW_MODE, BSM_FLASHING_ONLY, "flashing-only")
ENUM_MAP_DEFINE(BAR_SHOW_MODE, BSM_ALWAYS, "always")
ENUM_MAP_DEFINE(BAR_SHOW_MODE, BSM_NEVER, "never")
ENUM_MAP_DEFINE(BAR_SHOW_MODE, BSM_PS1, "ps1")
ENUM_MAP_DEFINE(BAR_SHOW_MODE, BSM_BOSS_ONLY, "boss-only")

ENUM_MAP_DEFINE(BAR_LOCATION, BL_TOP_LEFT, "top-left")
ENUM_MAP_DEFINE(BAR_LOCATION, BL_TOP_CENTER, "top-center")
ENUM_MAP_DEFINE(BAR_LOCATION, BL_TOP_RIGHT, "top-right")
ENUM_MAP_DEFINE(BAR_LOCATION, BL_BOTTOM_LEFT, "bottom-left")
ENUM_MAP_DEFINE(BAR_LOCATION, BL_BOTTOM_CENTER, "bottom-center")
ENUM_MAP_DEFINE(BAR_LOCATION, BL_BOTTOM_RIGHT, "bottom-right")

ENUM_MAP_DEFINE(BAR_COLOR, BC_GOLD, "gold")
ENUM_MAP_DEFINE(BAR_COLOR, BC_BLUE, "blue")
ENUM_MAP_DEFINE(BAR_COLOR, BC_GREY, "grey")
ENUM_MAP_DEFINE(BAR_COLOR, BC_RED, "red")
ENUM_MAP_DEFINE(BAR_COLOR, BC_SILVER, "silver")
ENUM_MAP_DEFINE(BAR_COLOR, BC_GREEN, "green")
ENUM_MAP_DEFINE(BAR_COLOR, BC_GOLD2, "gold2")
ENUM_MAP_DEFINE(BAR_COLOR, BC_BLUE2, "blue2")
ENUM_MAP_DEFINE(BAR_COLOR, BC_PINK, "pink")

ENUM_MAP_DEFINE(TARGET_LOCK_MODE, TLM_FULL, "full-lock")
ENUM_MAP_DEFINE(TARGET_LOCK_MODE, TLM_SEMI, "semi-lock")
ENUM_MAP_DEFINE(TARGET_LOCK_MODE, TLM_NONE, "no-lock")

ENUM_MAP_DEFINE(SCREENSHOT_FORMAT, SCREENSHOT_FORMAT_JPEG, "jpg")
ENUM_MAP_DEFINE(SCREENSHOT_FORMAT, SCREENSHOT_FORMAT_JPEG, "jpeg")
ENUM_MAP_DEFINE(SCREENSHOT_FORMAT, SCREENSHOT_FORMAT_PNG, "png")

ENUM_MAP_DEFINE(UNDERWATER_MUSIC_MODE, UMM_FULL, "full")
ENUM_MAP_DEFINE(UNDERWATER_MUSIC_MODE, UMM_QUIET, "quiet")
ENUM_MAP_DEFINE(UNDERWATER_MUSIC_MODE, UMM_FULL_NO_AMBIENT, "full_no_ambient")
ENUM_MAP_DEFINE(UNDERWATER_MUSIC_MODE, UMM_QUIET_NO_AMBIENT, "quiet_no_ambient")
ENUM_MAP_DEFINE(UNDERWATER_MUSIC_MODE, UMM_NONE, "none")
3 changes: 0 additions & 3 deletions src/global/enum_str.c

This file was deleted.

77 changes: 0 additions & 77 deletions src/global/enum_str.def

This file was deleted.

11 changes: 0 additions & 11 deletions src/global/enum_str.h

This file was deleted.

2 changes: 1 addition & 1 deletion subprojects/libtrx

0 comments on commit 50e97e3

Please sign in to comment.