diff options
| author | Tharo <17233964+Thar0@users.noreply.github.com> | 2023-07-04 17:36:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-04 12:36:55 -0400 |
| commit | 47ffb59f68c9285b8f90b3bef2934178b3641e92 (patch) | |
| tree | f93aac37120297ae66cc6b5f4a5cb200707cd73e /src/code | |
| parent | 100576edc9277c06db3ffcbb0ebf5e392f860d25 (diff) | |
Generate gamestate overlay table with an `include/tables/` header (#1504)
* Generate gamestate overlay table from an include/tables/ header
* GameStateIndex -> GameStateId, move to z64.h, add GameStateId enum name field to the gamestate table, adjust and improve gamestate table comment
* Shorten zeros in table definition
* Generate linker symbols, other suggested changes
* GAMESTATE_MAX -> GAMESTATE_ID_MAX like the others
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/graph.c | 31 | ||||
| -rw-r--r-- | src/code/z_game_dlftbls.c | 43 |
2 files changed, 40 insertions, 34 deletions
diff --git a/src/code/graph.c b/src/code/graph.c index e5309966c..3d53f891c 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -116,24 +116,15 @@ void Graph_InitTHGA(GraphicsContext* gfxCtx) { GameStateOverlay* Graph_GetNextGameState(GameState* gameState) { void* gameStateInitFunc = GameState_GetInit(gameState); - if (gameStateInitFunc == Setup_Init) { - return &gGameStateOverlayTable[0]; - } - if (gameStateInitFunc == MapSelect_Init) { - return &gGameStateOverlayTable[1]; - } - if (gameStateInitFunc == ConsoleLogo_Init) { - return &gGameStateOverlayTable[2]; - } - if (gameStateInitFunc == Play_Init) { - return &gGameStateOverlayTable[3]; - } - if (gameStateInitFunc == TitleSetup_Init) { - return &gGameStateOverlayTable[4]; - } - if (gameStateInitFunc == FileSelect_Init) { - return &gGameStateOverlayTable[5]; + // Generates code to match gameStateInitFunc to a gamestate entry and returns it if found +#define DEFINE_GAMESTATE_INTERNAL(typeName, enumName) \ + if (gameStateInitFunc == typeName##_Init) { \ + return &gGameStateOverlayTable[enumName]; \ } +#define DEFINE_GAMESTATE(typeName, enumName, name) DEFINE_GAMESTATE_INTERNAL(typeName, enumName) +#include "tables/gamestate_table.h" +#undef DEFINE_GAMESTATE +#undef DEFINE_GAMESTATE_INTERNAL LOG_ADDRESS("game_init_func", gameStateInitFunc, "../graph.c", 696); return NULL; @@ -421,16 +412,14 @@ void Graph_ThreadEntry(void* arg0) { GraphicsContext gfxCtx; GameState* gameState; u32 size; - GameStateOverlay* nextOvl; + GameStateOverlay* nextOvl = &gGameStateOverlayTable[GAMESTATE_SETUP]; GameStateOverlay* ovl; char faultMsg[0x50]; - nextOvl = &gGameStateOverlayTable[0]; - osSyncPrintf("グラフィックスレッド実行開始\n"); // "Start graphic thread execution" Graph_Init(&gfxCtx); - while (nextOvl) { + while (nextOvl != NULL) { ovl = nextOvl; Overlay_LoadGameState(ovl); diff --git a/src/code/z_game_dlftbls.c b/src/code/z_game_dlftbls.c index bfce66248..8e9f00fec 100644 --- a/src/code/z_game_dlftbls.c +++ b/src/code/z_game_dlftbls.c @@ -1,18 +1,35 @@ #include "global.h" -#define GAMESTATE_OVERLAY(name, init, destroy, size) \ - { \ - NULL, (uintptr_t)_ovl_##name##SegmentRomStart, (uintptr_t)_ovl_##name##SegmentRomEnd, \ - _ovl_##name##SegmentStart, _ovl_##name##SegmentEnd, NULL, init, destroy, NULL, NULL, 0, size \ - } -#define GAMESTATE_OVERLAY_INTERNAL(init, destroy, size) \ - { NULL, 0, 0, NULL, NULL, NULL, init, destroy, NULL, NULL, 0, size } +// Linker symbol declarations (used in the table below) +#define DEFINE_GAMESTATE(typeName, enumName, name) DECLARE_OVERLAY_SEGMENT(name) +#define DEFINE_GAMESTATE_INTERNAL(typeName, enumName) + +#include "tables/gamestate_table.h" + +#undef DEFINE_GAMESTATE +#undef DEFINE_GAMESTATE_INTERNAL + +// Gamestate Overlay Table definition +#define DEFINE_GAMESTATE_INTERNAL(typeName, enumName) \ + { NULL, 0, 0, NULL, NULL, NULL, typeName##_Init, typeName##_Destroy, NULL, NULL, 0, sizeof(typeName##State) }, + +#define DEFINE_GAMESTATE(typeName, enumName, name) \ + { NULL, \ + (uintptr_t)_ovl_##name##SegmentRomStart, \ + (uintptr_t)_ovl_##name##SegmentRomEnd, \ + _ovl_##name##SegmentStart, \ + _ovl_##name##SegmentEnd, \ + NULL, \ + typeName##_Init, \ + typeName##_Destroy, \ + NULL, \ + NULL, \ + 0, \ + sizeof(typeName##State) }, GameStateOverlay gGameStateOverlayTable[] = { - GAMESTATE_OVERLAY_INTERNAL(Setup_Init, Setup_Destroy, sizeof(SetupState)), - GAMESTATE_OVERLAY(select, MapSelect_Init, MapSelect_Destroy, sizeof(MapSelectState)), - GAMESTATE_OVERLAY(title, ConsoleLogo_Init, ConsoleLogo_Destroy, sizeof(ConsoleLogoState)), - GAMESTATE_OVERLAY_INTERNAL(Play_Init, Play_Destroy, sizeof(PlayState)), - GAMESTATE_OVERLAY(opening, TitleSetup_Init, TitleSetup_Destroy, sizeof(TitleSetupState)), - GAMESTATE_OVERLAY(file_choose, FileSelect_Init, FileSelect_Destroy, sizeof(FileSelectState)), +#include "tables/gamestate_table.h" }; + +#undef DEFINE_GAMESTATE +#undef DEFINE_GAMESTATE_INTERNAL |
