1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-01 15:26:01 +00:00

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
This commit is contained in:
Tharo 2023-07-04 17:36:55 +01:00 committed by GitHub
parent 100576edc9
commit 47ffb59f68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 38 deletions

View file

@ -64,10 +64,6 @@ DECLARE_SEGMENT(code)
DECLARE_ROM_SEGMENT(code) DECLARE_ROM_SEGMENT(code)
DECLARE_BSS_SEGMENT(code) DECLARE_BSS_SEGMENT(code)
DECLARE_OVERLAY_SEGMENT(title)
DECLARE_OVERLAY_SEGMENT(select)
DECLARE_OVERLAY_SEGMENT(opening)
DECLARE_OVERLAY_SEGMENT(file_choose)
DECLARE_OVERLAY_SEGMENT(kaleido_scope) DECLARE_OVERLAY_SEGMENT(kaleido_scope)
DECLARE_OVERLAY_SEGMENT(player_actor) DECLARE_OVERLAY_SEGMENT(player_actor)
DECLARE_OVERLAY_SEGMENT(map_mark_data) DECLARE_OVERLAY_SEGMENT(map_mark_data)

View file

@ -0,0 +1,16 @@
/**
* Gamestate Table
*
* DEFINE_GAMESTATE should be used for gamestates with code loaded from an overlay
* - Argument 1: Gamestate type name (without State suffix, also used for Init and Destroy function names)
* - Argument 2: Gamestate id enum name
* - Argument 3: Gamestate overlay spec segment name
*
* DEFINE_GAMESTATE_INTERNAL should be used for gamestates that aren't an overlay, the first two arguments are the same as for DEFINE_GAMESTATE
*/
/* 0x00 */ DEFINE_GAMESTATE_INTERNAL(Setup, GAMESTATE_SETUP)
/* 0x01 */ DEFINE_GAMESTATE(MapSelect, GAMESTATE_MAP_SELECT, select)
/* 0x02 */ DEFINE_GAMESTATE(ConsoleLogo, GAMESTATE_CONSOLE_LOGO, title)
/* 0x03 */ DEFINE_GAMESTATE_INTERNAL(Play, GAMESTATE_PLAY)
/* 0x04 */ DEFINE_GAMESTATE(TitleSetup, GAMESTATE_TITLE_SETUP, opening)
/* 0x05 */ DEFINE_GAMESTATE(FileSelect, GAMESTATE_FILE_SELECT, file_choose)

View file

@ -697,6 +697,16 @@ typedef struct {
/* 0x10 */ GameAllocEntry* head; /* 0x10 */ GameAllocEntry* head;
} GameAlloc; // size = 0x14 } GameAlloc; // size = 0x14
// Used in Graph_GetNextGameState in graph.c
#define DEFINE_GAMESTATE_INTERNAL(typeName, enumName) enumName,
#define DEFINE_GAMESTATE(typeName, enumName, name) DEFINE_GAMESTATE_INTERNAL(typeName, enumName)
typedef enum {
#include "tables/gamestate_table.h"
GAMESTATE_ID_MAX
} GameStateId;
#undef DEFINE_GAMESTATE
#undef DEFINE_GAMESTATE_INTERNAL
struct GameState; struct GameState;
typedef void (*GameStateFunc)(struct GameState* gameState); typedef void (*GameStateFunc)(struct GameState* gameState);

View file

@ -116,24 +116,15 @@ void Graph_InitTHGA(GraphicsContext* gfxCtx) {
GameStateOverlay* Graph_GetNextGameState(GameState* gameState) { GameStateOverlay* Graph_GetNextGameState(GameState* gameState) {
void* gameStateInitFunc = GameState_GetInit(gameState); void* gameStateInitFunc = GameState_GetInit(gameState);
if (gameStateInitFunc == Setup_Init) { // Generates code to match gameStateInitFunc to a gamestate entry and returns it if found
return &gGameStateOverlayTable[0]; #define DEFINE_GAMESTATE_INTERNAL(typeName, enumName) \
} if (gameStateInitFunc == typeName##_Init) { \
if (gameStateInitFunc == MapSelect_Init) { return &gGameStateOverlayTable[enumName]; \
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];
} }
#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); LOG_ADDRESS("game_init_func", gameStateInitFunc, "../graph.c", 696);
return NULL; return NULL;
@ -421,16 +412,14 @@ void Graph_ThreadEntry(void* arg0) {
GraphicsContext gfxCtx; GraphicsContext gfxCtx;
GameState* gameState; GameState* gameState;
u32 size; u32 size;
GameStateOverlay* nextOvl; GameStateOverlay* nextOvl = &gGameStateOverlayTable[GAMESTATE_SETUP];
GameStateOverlay* ovl; GameStateOverlay* ovl;
char faultMsg[0x50]; char faultMsg[0x50];
nextOvl = &gGameStateOverlayTable[0];
osSyncPrintf("グラフィックスレッド実行開始\n"); // "Start graphic thread execution" osSyncPrintf("グラフィックスレッド実行開始\n"); // "Start graphic thread execution"
Graph_Init(&gfxCtx); Graph_Init(&gfxCtx);
while (nextOvl) { while (nextOvl != NULL) {
ovl = nextOvl; ovl = nextOvl;
Overlay_LoadGameState(ovl); Overlay_LoadGameState(ovl);

View file

@ -1,18 +1,35 @@
#include "global.h" #include "global.h"
#define GAMESTATE_OVERLAY(name, init, destroy, size) \ // Linker symbol declarations (used in the table below)
{ \ #define DEFINE_GAMESTATE(typeName, enumName, name) DECLARE_OVERLAY_SEGMENT(name)
NULL, (uintptr_t)_ovl_##name##SegmentRomStart, (uintptr_t)_ovl_##name##SegmentRomEnd, \ #define DEFINE_GAMESTATE_INTERNAL(typeName, enumName)
_ovl_##name##SegmentStart, _ovl_##name##SegmentEnd, NULL, init, destroy, NULL, NULL, 0, size \
} #include "tables/gamestate_table.h"
#define GAMESTATE_OVERLAY_INTERNAL(init, destroy, size) \
{ NULL, 0, 0, NULL, NULL, NULL, init, destroy, NULL, NULL, 0, size } #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[] = { GameStateOverlay gGameStateOverlayTable[] = {
GAMESTATE_OVERLAY_INTERNAL(Setup_Init, Setup_Destroy, sizeof(SetupState)), #include "tables/gamestate_table.h"
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)),
}; };
#undef DEFINE_GAMESTATE
#undef DEFINE_GAMESTATE_INTERNAL