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
This commit is contained in:
mzxrules
2025-02-24 20:55:55 -05:00
committed by GitHub
parent 70fde8ac3b
commit 2e4c42719b
48 changed files with 310 additions and 221 deletions
+1 -1
View File
@@ -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;
+5 -5
View File
@@ -2,12 +2,12 @@
#define FILE_SELECT_STATE_H
#include "ultra64.h"
#include "z64game.h"
#include "z64view.h"
#include "z64sram.h"
#include "z64skybox.h"
#include "z64message.h"
#include "z64environment.h"
#include "z64game.h"
#include "z64message.h"
#include "z64skybox.h"
#include "z64sram.h"
#include "z64view.h"
typedef struct FileSelectState {
/* 0x00000 */ GameState state;
-12
View File
@@ -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);
+2
View File
@@ -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);
-8
View File
@@ -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)
-5
View File
@@ -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;
+3 -103
View File
@@ -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,
+52
View File
@@ -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
+2
View File
@@ -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);
+8 -27
View File
@@ -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);
+1 -2
View File
@@ -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
+74
View File
@@ -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
+37
View File
@@ -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
+2
View File
@@ -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);