diff options
| author | mzxrules <mzxrules@gmail.com> | 2025-02-24 20:55:55 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-24 20:55:55 -0500 |
| commit | 2e4c42719b4dd10b328810cd2c58391063497d41 (patch) | |
| tree | 8c393d01b65983134665f106f7ec1b61107396d9 /include | |
| parent | 70fde8ac3b591a993a2ca0a4361a528fdd07d158 (diff) | |
Reduce dependencies on global.h (9) (#2488)
* split game states
* split all GameState headers
* match fig names
* deduplicate headers from bad merge
* split z64actor.h into z64actor_profile.h, z_actor_dlftbls.h
* fix compile error
* .bss
Diffstat (limited to 'include')
| -rw-r--r-- | include/console_logo_state.h | 2 | ||||
| -rw-r--r-- | include/file_select_state.h | 8 | ||||
| -rw-r--r-- | include/functions.h | 12 | ||||
| -rw-r--r-- | include/libu64/overlay.h | 2 | ||||
| -rw-r--r-- | include/macros.h | 8 | ||||
| -rw-r--r-- | include/variables.h | 5 | ||||
| -rw-r--r-- | include/z64actor.h | 106 | ||||
| -rw-r--r-- | include/z64actor_profile.h | 52 | ||||
| -rw-r--r-- | include/z64effect.h | 2 | ||||
| -rw-r--r-- | include/z64game.h | 35 | ||||
| -rw-r--r-- | include/z64sram.h | 3 | ||||
| -rw-r--r-- | include/z_actor_dlftbls.h | 74 | ||||
| -rw-r--r-- | include/z_game_dlftbls.h | 37 | ||||
| -rw-r--r-- | include/zelda_arena.h | 2 |
14 files changed, 186 insertions, 162 deletions
diff --git a/include/console_logo_state.h b/include/console_logo_state.h index 56e8ece64..09b7d6654 100644 --- a/include/console_logo_state.h +++ b/include/console_logo_state.h @@ -3,8 +3,8 @@ #include "ultra64.h" #include "z64game.h" -#include "z64view.h" #include "z64sram.h" +#include "z64view.h" typedef struct ConsoleLogoState { /* 0x0000 */ GameState state; diff --git a/include/file_select_state.h b/include/file_select_state.h index 9a2df3f08..0a831caa0 100644 --- a/include/file_select_state.h +++ b/include/file_select_state.h @@ -2,12 +2,12 @@ #define FILE_SELECT_STATE_H #include "ultra64.h" +#include "z64environment.h" #include "z64game.h" -#include "z64view.h" -#include "z64sram.h" -#include "z64skybox.h" #include "z64message.h" -#include "z64environment.h" +#include "z64skybox.h" +#include "z64sram.h" +#include "z64view.h" typedef struct FileSelectState { /* 0x00000 */ GameState state; diff --git a/include/functions.h b/include/functions.h index 0a8af7f55..fbf16a1ea 100644 --- a/include/functions.h +++ b/include/functions.h @@ -28,12 +28,6 @@ OSPiHandle* osDriveRomInit(void); void Mio0_Decompress(u8* src, u8* dst); void FlagSet_Update(PlayState* play); -void Overlay_LoadGameState(GameStateOverlay* overlayEntry); -void Overlay_FreeGameState(GameStateOverlay* overlayEntry); - -void ActorOverlayTable_LogPrint(void); -void ActorOverlayTable_Init(void); -void ActorOverlayTable_Cleanup(void); void SaveContext_Init(void); @@ -102,12 +96,6 @@ void func_800C213C(PreRender* this, Gfx** gfxP); void PreRender_RestoreFramebuffer(PreRender* this, Gfx** gfxP); void PreRender_CopyImageRegion(PreRender* this, Gfx** gfxP); void PreRender_ApplyFilters(PreRender* this); -void Graph_InitTHGA(GraphicsContext* gfxCtx); -GameStateOverlay* Graph_GetNextGameState(GameState* gameState); -void Graph_Init(GraphicsContext* gfxCtx); -void Graph_Destroy(GraphicsContext* gfxCtx); -void Graph_TaskSet00(GraphicsContext* gfxCtx); -void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState); void Graph_ThreadEntry(void*); ListAlloc* ListAlloc_Init(ListAlloc* this); diff --git a/include/libu64/overlay.h b/include/libu64/overlay.h index 258dfba77..47f327657 100644 --- a/include/libu64/overlay.h +++ b/include/libu64/overlay.h @@ -33,6 +33,8 @@ typedef struct OverlayRelocationSection { /* 0x14 */ u32 relocations[1]; // size is nRelocations } OverlayRelocationSection; // size >= 0x18 +extern s32 gOverlayLogSeverity; + void* Overlay_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd); void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelocs, void* vramStart); size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr); diff --git a/include/macros.h b/include/macros.h index 22f66810e..aa81ef061 100644 --- a/include/macros.h +++ b/include/macros.h @@ -89,14 +89,6 @@ #define PRINTF_RST() (void)0 #endif -#define SET_NEXT_GAMESTATE(curState, newInit, newStruct) \ - if (1) { \ - GameState* state = curState; \ - \ - (state)->init = newInit; \ - (state)->size = sizeof(newStruct); \ - } (void)0 - #if DEBUG_FEATURES #define DMA_REQUEST_SYNC(ram, vrom, size, file, line) DmaMgr_RequestSyncDebug(ram, vrom, size, file, line) #define DMA_REQUEST_ASYNC(req, ram, vrom, size, unk5, queue, msg, file, line) DmaMgr_RequestAsyncDebug(req, ram, vrom, size, unk5, queue, msg, file, line) diff --git a/include/variables.h b/include/variables.h index f4ecad468..ea5d188a6 100644 --- a/include/variables.h +++ b/include/variables.h @@ -65,10 +65,6 @@ extern OSTime __osCurrentTime; extern u32 __osBaseCounter; extern u32 __osViIntrCount; extern u32 __osTimerCounter; -extern EffectSsOverlay gEffectSsOverlayTable[EFFECT_SS_TYPE_MAX]; -extern ActorOverlay gActorOverlayTable[ACTOR_ID_MAX]; // original name: "actor_dlftbls" 801162A0 -extern s32 gMaxActorId; // original name: "MaxProfile" -extern s32 gZeldaArenaLogSeverity; extern MapData gMapDataTable; extern s16 gSpoilingItems[3]; extern s16 gSpoilingItemReverts[3]; @@ -134,7 +130,6 @@ extern u8 gSoundModeList[]; extern u8 gAudioSpecId; extern u8 D_80133418; extern AudioSpec gAudioSpecs[18]; -extern s32 gOverlayLogSeverity; extern s32 gSystemArenaLogSeverity; extern u8 __osPfsInodeCacheBank; extern s32 __osPfsLastChannel; diff --git a/include/z64actor.h b/include/z64actor.h index 0cd73a831..8986c801c 100644 --- a/include/z64actor.h +++ b/include/z64actor.h @@ -3,6 +3,7 @@ #include "color.h" #include "romfile.h" +#include "z64actor_profile.h" #include "z64animation.h" #include "z64math.h" #include "z64collision_check.h" @@ -23,88 +24,16 @@ struct Actor; struct ActorEntry; +struct ActorOverlay; struct CollisionPoly; struct Lights; struct Player; struct PlayState; -typedef void (*ActorFunc)(struct Actor*, struct PlayState*); typedef void (*ActorShadowFunc)(struct Actor*, struct Lights*, struct PlayState*); typedef u16 (*NpcGetTextIdFunc)(struct PlayState*, struct Actor*); typedef s16 (*NpcUpdateTalkStateFunc)(struct PlayState*, struct Actor*); -typedef struct ActorProfile { - /* 0x00 */ s16 id; - /* 0x02 */ u8 category; // Classifies actor and determines when it will update or draw - /* 0x04 */ u32 flags; - /* 0x08 */ s16 objectId; - /* 0x0C */ u32 instanceSize; - /* 0x10 */ ActorFunc init; // Constructor - /* 0x14 */ ActorFunc destroy; // Destructor - /* 0x18 */ ActorFunc update; // Update Function - /* 0x1C */ ActorFunc draw; // Draw function -} ActorProfile; // size = 0x20 - -/** - * @see ACTOROVL_ALLOC_ABSOLUTE - */ -#if DEBUG_FEATURES -#define ACTOROVL_ABSOLUTE_SPACE_SIZE 0x27A0 -#else -#define ACTOROVL_ABSOLUTE_SPACE_SIZE 0x24E0 -#endif - -/** - * The actor overlay should be allocated memory for when loading, - * and the memory deallocated when there is no more actor using the overlay. - * - * `ACTOROVL_ALLOC_` defines indicate how an actor overlay should be loaded. - * - * @note Bitwise or-ing `ACTOROVL_ALLOC_` types is not meaningful. - * The `ACTOROVL_ALLOC_` types are 0, 1, 2 but checked against with a bitwise and. - * - * @see ACTOROVL_ALLOC_ABSOLUTE - * @see ACTOROVL_ALLOC_PERSISTENT - * @see actor_table.h - */ -#define ACTOROVL_ALLOC_NORMAL 0 - -/** - * The actor overlay should be loaded to "absolute space". - * - * Absolute space is a fixed amount of memory allocated once. - * The overlay will still need to be loaded again if at some point there is no more actor using the overlay. - * - * @note Only one such overlay may be loaded at a time. - * This is not checked: a newly loaded overlay will overwrite the previous one in absolute space, - * even if actors are still relying on the previous one. Actors using absolute-allocated overlays should be deleted - * when another absolute-allocated overlay is about to be used. - * - * @see ACTOROVL_ABSOLUTE_SPACE_SIZE - * @see ActorContext.absoluteSpace - * @see ACTOROVL_ALLOC_NORMAL - */ -#define ACTOROVL_ALLOC_ABSOLUTE (1 << 0) - -/** - * The actor overlay should be loaded persistently. - * It will stay loaded until the current game state instance ends. - * - * @see ACTOROVL_ALLOC_NORMAL - */ -#define ACTOROVL_ALLOC_PERSISTENT (1 << 1) - -typedef struct ActorOverlay { - /* 0x00 */ RomFile file; - /* 0x08 */ void* vramStart; - /* 0x0C */ void* vramEnd; - /* 0x10 */ void* loadedRamAddr; // original name: "allocp" - /* 0x14 */ ActorProfile* profile; - /* 0x18 */ char* name; - /* 0x1C */ u16 allocType; // See `ACTOROVL_ALLOC_` defines - /* 0x1E */ s8 numLoaded; // original name: "clients" -} ActorOverlay; // size = 0x20 - typedef struct ActorShape { /* 0x00 */ Vec3s rot; // Current actor shape rotation /* 0x06 */ s16 face; // Used to index eyes and mouth textures. Only used by player @@ -309,7 +238,7 @@ typedef struct Actor { /* 0x12C */ ActorFunc destroy; // Destruction Routine. Called by `Actor_Destroy` /* 0x130 */ ActorFunc update; // Update Routine. Called by `Actor_UpdateAll` /* 0x134 */ ActorFunc draw; // Draw Routine. Called by `Actor_Draw` - /* 0x138 */ ActorOverlay* overlayEntry; // Pointer to the overlay table entry for this actor + /* 0x138 */ struct ActorOverlay* overlayEntry; // Pointer to the overlay table entry for this actor #if DEBUG_FEATURES /* 0x13C */ char dbgPad[0x10]; #endif @@ -396,35 +325,6 @@ typedef struct EnAObj { /* 0x17C */ ColliderCylinder collider; } EnAObj; // size = 0x1C8 -typedef enum ActorCategory { - /* 0x00 */ ACTORCAT_SWITCH, - /* 0x01 */ ACTORCAT_BG, - /* 0x02 */ ACTORCAT_PLAYER, - /* 0x03 */ ACTORCAT_EXPLOSIVE, - /* 0x04 */ ACTORCAT_NPC, - /* 0x05 */ ACTORCAT_ENEMY, - /* 0x06 */ ACTORCAT_PROP, - /* 0x07 */ ACTORCAT_ITEMACTION, - /* 0x08 */ ACTORCAT_MISC, - /* 0x09 */ ACTORCAT_BOSS, - /* 0x0A */ ACTORCAT_DOOR, - /* 0x0B */ ACTORCAT_CHEST, - /* 0x0C */ ACTORCAT_MAX -} ActorCategory; - -#define DEFINE_ACTOR(_0, enum, _2, _3) enum, -#define DEFINE_ACTOR_INTERNAL(_0, enum, _2, _3) enum, -#define DEFINE_ACTOR_UNSET(enum) enum, - -typedef enum ActorID { - #include "tables/actor_table.h" - /* 0x0192 */ ACTOR_ID_MAX // originally "ACTOR_DLF_MAX" -} ActorID; - -#undef DEFINE_ACTOR -#undef DEFINE_ACTOR_INTERNAL -#undef DEFINE_ACTOR_UNSET - typedef enum DoorLockType { DOORLOCK_NORMAL, DOORLOCK_BOSS, diff --git a/include/z64actor_profile.h b/include/z64actor_profile.h new file mode 100644 index 000000000..82ec9f957 --- /dev/null +++ b/include/z64actor_profile.h @@ -0,0 +1,52 @@ +#ifndef Z64ACTOR_PROFILE_H +#define Z64ACTOR_PROFILE_H + +#include "ultra64.h" + +struct Actor; +struct PlayState; + +#define DEFINE_ACTOR(_0, enum, _2, _3) enum, +#define DEFINE_ACTOR_INTERNAL(_0, enum, _2, _3) enum, +#define DEFINE_ACTOR_UNSET(enum) enum, + +typedef enum ActorID { + #include "tables/actor_table.h" + /* 0x0192 */ ACTOR_ID_MAX // originally "ACTOR_DLF_MAX" +} ActorID; + +#undef DEFINE_ACTOR +#undef DEFINE_ACTOR_INTERNAL +#undef DEFINE_ACTOR_UNSET + +typedef enum ActorCategory { + /* 0x00 */ ACTORCAT_SWITCH, + /* 0x01 */ ACTORCAT_BG, + /* 0x02 */ ACTORCAT_PLAYER, + /* 0x03 */ ACTORCAT_EXPLOSIVE, + /* 0x04 */ ACTORCAT_NPC, + /* 0x05 */ ACTORCAT_ENEMY, + /* 0x06 */ ACTORCAT_PROP, + /* 0x07 */ ACTORCAT_ITEMACTION, + /* 0x08 */ ACTORCAT_MISC, + /* 0x09 */ ACTORCAT_BOSS, + /* 0x0A */ ACTORCAT_DOOR, + /* 0x0B */ ACTORCAT_CHEST, + /* 0x0C */ ACTORCAT_MAX +} ActorCategory; + +typedef void (*ActorFunc)(struct Actor*, struct PlayState*); + +typedef struct ActorProfile { + /* 0x00 */ s16 id; + /* 0x02 */ u8 category; // Classifies actor and determines when it will update or draw + /* 0x04 */ u32 flags; + /* 0x08 */ s16 objectId; + /* 0x0C */ u32 instanceSize; + /* 0x10 */ ActorFunc init; // Constructor + /* 0x14 */ ActorFunc destroy; // Destructor + /* 0x18 */ ActorFunc update; // Update Function + /* 0x1C */ ActorFunc draw; // Draw function +} ActorProfile; // size = 0x20 + +#endif diff --git a/include/z64effect.h b/include/z64effect.h index bad2b1d32..0c07cc512 100644 --- a/include/z64effect.h +++ b/include/z64effect.h @@ -262,6 +262,8 @@ typedef enum EffectSsType { #undef DEFINE_EFFECT_SS #undef DEFINE_EFFECT_SS_UNSET +extern EffectSsOverlay gEffectSsOverlayTable[EFFECT_SS_TYPE_MAX]; + void EffectBlure_AddVertex(EffectBlure* this, Vec3f* p1, Vec3f* p2); void EffectBlure_AddSpace(EffectBlure* this); void EffectBlure_Init1(void* thisx, void* initParamsx); diff --git a/include/z64game.h b/include/z64game.h index 72a8f501e..fe683777b 100644 --- a/include/z64game.h +++ b/include/z64game.h @@ -9,33 +9,6 @@ #include "tha.h" struct GraphicsContext; - -// 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 GameStateId { -#include "tables/gamestate_table.h" - GAMESTATE_ID_MAX -} GameStateId; -#undef DEFINE_GAMESTATE -#undef DEFINE_GAMESTATE_INTERNAL - -typedef struct GameStateOverlay { - /* 0x00 */ void* loadedRamAddr; - /* 0x04 */ RomFile file; // if applicable - /* 0x0C */ void* vramStart; // if applicable - /* 0x10 */ void* vramEnd; // if applicable - /* 0x14 */ void* unk_14; - /* 0x18 */ void* init; - /* 0x1C */ void* destroy; - /* 0x20 */ void* unk_20; - /* 0x24 */ void* unk_24; - /* 0x28 */ s32 unk_28; - /* 0x2C */ u32 instanceSize; -} GameStateOverlay; // size = 0x30 - -extern GameStateOverlay gGameStateOverlayTable[GAMESTATE_ID_MAX]; - struct GameState; typedef void (*GameStateFunc)(struct GameState* gameState); @@ -54,6 +27,14 @@ typedef struct GameState { /* 0xA0 */ u32 inPreNMIState; } GameState; // size = 0xA4 +#define SET_NEXT_GAMESTATE(curState, newInit, newStruct) \ + if (1) { \ + GameState* state = curState; \ + \ + (state)->init = newInit; \ + (state)->size = sizeof(newStruct); \ + } (void)0 + void GameState_ReqPadData(GameState* gameState); void GameState_Update(GameState* gameState); void GameState_InitArena(GameState* gameState, size_t size); diff --git a/include/z64sram.h b/include/z64sram.h index 9fcaf83b0..90617d1e6 100644 --- a/include/z64sram.h +++ b/include/z64sram.h @@ -5,7 +5,6 @@ struct FileSelectState; struct GameState; -struct PlayState; typedef struct SramContext { /* 0x00 */ u8* readBuff; @@ -32,6 +31,6 @@ void Sram_CopySave(struct FileSelectState* fileSelect, SramContext* sramCtx); void Sram_WriteSramHeader(SramContext* sramCtx); void Sram_InitSram(struct GameState* gameState, SramContext* sramCtx); void Sram_Alloc(struct GameState* gameState, SramContext* sramCtx); -void Sram_Init(struct PlayState* play, SramContext* sramCtx); +void Sram_Init(struct GameState* play, SramContext* sramCtx); #endif diff --git a/include/z_actor_dlftbls.h b/include/z_actor_dlftbls.h new file mode 100644 index 000000000..e9e2dc7d9 --- /dev/null +++ b/include/z_actor_dlftbls.h @@ -0,0 +1,74 @@ +#ifndef Z_ACTOR_DLFTBLS_H +#define Z_ACTOR_DLFTBLS_H + +#include "romfile.h" +#include "z64actor_profile.h" + +/** + * @see ACTOROVL_ALLOC_ABSOLUTE + */ +#if DEBUG_FEATURES +#define ACTOROVL_ABSOLUTE_SPACE_SIZE 0x27A0 +#else +#define ACTOROVL_ABSOLUTE_SPACE_SIZE 0x24E0 +#endif + +/** + * The actor overlay should be allocated memory for when loading, + * and the memory deallocated when there is no more actor using the overlay. + * + * `ACTOROVL_ALLOC_` defines indicate how an actor overlay should be loaded. + * + * @note Bitwise or-ing `ACTOROVL_ALLOC_` types is not meaningful. + * The `ACTOROVL_ALLOC_` types are 0, 1, 2 but checked against with a bitwise and. + * + * @see ACTOROVL_ALLOC_ABSOLUTE + * @see ACTOROVL_ALLOC_PERSISTENT + * @see actor_table.h + */ +#define ACTOROVL_ALLOC_NORMAL 0 + +/** + * The actor overlay should be loaded to "absolute space". + * + * Absolute space is a fixed amount of memory allocated once. + * The overlay will still need to be loaded again if at some point there is no more actor using the overlay. + * + * @note Only one such overlay may be loaded at a time. + * This is not checked: a newly loaded overlay will overwrite the previous one in absolute space, + * even if actors are still relying on the previous one. Actors using absolute-allocated overlays should be deleted + * when another absolute-allocated overlay is about to be used. + * + * @see ACTOROVL_ABSOLUTE_SPACE_SIZE + * @see ActorContext.absoluteSpace + * @see ACTOROVL_ALLOC_NORMAL + */ +#define ACTOROVL_ALLOC_ABSOLUTE (1 << 0) + +/** + * The actor overlay should be loaded persistently. + * It will stay loaded until the current game state instance ends. + * + * @see ACTOROVL_ALLOC_NORMAL + */ +#define ACTOROVL_ALLOC_PERSISTENT (1 << 1) + +typedef struct ActorOverlay { + /* 0x00 */ RomFile file; + /* 0x08 */ void* vramStart; + /* 0x0C */ void* vramEnd; + /* 0x10 */ void* loadedRamAddr; // original name: "allocp" + /* 0x14 */ ActorProfile* profile; + /* 0x18 */ char* name; + /* 0x1C */ u16 allocType; // See `ACTOROVL_ALLOC_` defines + /* 0x1E */ s8 numLoaded; // original name: "clients" +} ActorOverlay; // size = 0x20 + +extern ActorOverlay gActorOverlayTable[ACTOR_ID_MAX]; // original name: "actor_dlftbls" 801162A0 +extern s32 gMaxActorId; // original name: "MaxProfile" + +void ActorOverlayTable_LogPrint(void); +void ActorOverlayTable_Init(void); +void ActorOverlayTable_Cleanup(void); + +#endif diff --git a/include/z_game_dlftbls.h b/include/z_game_dlftbls.h new file mode 100644 index 000000000..691cda27c --- /dev/null +++ b/include/z_game_dlftbls.h @@ -0,0 +1,37 @@ +#ifndef Z_GAME_DLFTBLS_H +#define Z_GAME_DLFTBLS_H + +#include "ultra64.h" +#include "romfile.h" +#include "unk.h" + +typedef struct GameStateOverlay { + /* 0x00 */ void* loadedRamAddr; + /* 0x04 */ RomFile file; // if applicable + /* 0x0C */ void* vramStart; // if applicable + /* 0x10 */ void* vramEnd; // if applicable + /* 0x14 */ void* unk_14; + /* 0x18 */ void* init; // initializes and executes the given context + /* 0x1C */ void* destroy; // deconstructs the context, and sets the next context to load + /* 0x20 */ void* unk_20; + /* 0x24 */ void* unk_24; + /* 0x28 */ UNK_TYPE4 unk_28; + /* 0x2C */ u32 instanceSize; +} GameStateOverlay; // size = 0x30 + +// 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 GameStateId { +#include "tables/gamestate_table.h" + GAMESTATE_ID_MAX +} GameStateId; +#undef DEFINE_GAMESTATE +#undef DEFINE_GAMESTATE_INTERNAL + +extern GameStateOverlay gGameStateOverlayTable[GAMESTATE_ID_MAX]; + +void Overlay_LoadGameState(GameStateOverlay* overlayEntry); +void Overlay_FreeGameState(GameStateOverlay* overlayEntry); + +#endif diff --git a/include/zelda_arena.h b/include/zelda_arena.h index 1d035a0bb..cf6740657 100644 --- a/include/zelda_arena.h +++ b/include/zelda_arena.h @@ -3,6 +3,8 @@ #include "ultra64.h" +extern s32 gZeldaArenaLogSeverity; + void* ZeldaArena_Malloc(u32 size); void* ZeldaArena_MallocR(u32 size); void* ZeldaArena_Realloc(void* ptr, u32 newSize); |
