* z64game.h

* grrrrr

* fix missing stuff

* Update include/z64game.h

Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>

* Update include/z64game.h

Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>

* review

* global.h to the top

* reiew

* fix

---------

Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
This commit is contained in:
Anghelo Carvajal 2023-06-06 08:54:18 -04:00 committed by GitHub
parent 4cce444661
commit a0701c170b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 155 additions and 123 deletions

View File

@ -1874,25 +1874,6 @@ void AudioMgr_ThreadEntry(void* arg);
void AudioMgr_Unlock(AudioMgr* audioMgr);
void AudioMgr_Init(AudioMgr* audioMgr, void* stack, OSPri pri, OSId id, SchedContext* sched, IrqMgr* irqMgr);
void Game_UpdateFramerateVariables(s32 divisor);
void Game_SetFramerateDivisor(GameState* gameState, s32 divisor);
void GameState_SetFBFilter(Gfx** gfx, void* zbuffer);
void Game_Nop80173534(GameState* gameState);
void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx);
void GameState_SetFrameBuffer(GraphicsContext* gfxCtx);
void func_801736DC(GraphicsContext* gfxCtx);
void Game_UpdateInput(GameState* gameState);
void Game_Update(GameState* gameState);
void Game_IncrementFrameCount(GameState* gameState);
void GameState_InitArena(GameState* gameState, size_t size);
void GameState_Realloc(GameState* gameState, size_t size);
void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* gfxCtx);
void GameState_Destroy(GameState* gameState);
GameStateFunc GameState_GetInit(GameState* gameState);
size_t GameState_GetSize(GameState* gameState);
u32 GameState_IsRunning(GameState* gameState);
s32 GameState_GetArenaSize(GameState* gameState);
s32 func_80173B48(GameState* gameState);
void GameAlloc_Log(GameAlloc* this);
void* GameAlloc_Malloc(GameAlloc* this, size_t size);
void GameAlloc_Free(GameAlloc* this, void* data);

View File

@ -28,21 +28,6 @@
#define GET_ACTIVE_CAM(play) ((play)->cameraPtrs[(play)->activeCamId])
#define STOP_GAMESTATE(curState) \
do { \
GameState* state = curState; \
\
state->running = false; \
} while(0)
#define SET_NEXT_GAMESTATE(curState, nextInit, nextSize) \
do { \
GameState* state = curState; \
\
(state)->init = nextInit; \
(state)->size = nextSize; \
} while (0)
#define GET_PLAYER(play) ((Player*)(play)->actorCtx.actorLists[ACTORCAT_PLAYER].first)
#define GET_FIRST_ENEMY(play) ((Actor*)(play)->actorCtx.actorLists[ACTORCAT_ENEMY].first)

View File

@ -745,10 +745,7 @@ extern Input* D_801D0D60;
// extern UNK_TYPE2 D_801D14E4;
// extern UNK_TYPE2 D_801D14E8;
// extern UNK_TYPE4 D_801D14F0;
extern s32 gFramerateDivisor;
extern f32 gFramerateDivisorF;
extern f32 gFramerateDivisorHalf;
extern f32 gFramerateDivisorThird;
extern u32 retryCount;
extern u32 cfbIdx[3];
extern s32 gScreenWidth;

View File

@ -44,6 +44,7 @@
#include "z64effect.h"
#include "z64frameadvance.h"
#include "z64game_over.h"
#include "z64game.h"
#include "z64interface.h"
#include "z64item.h"
#include "z64light.h"
@ -407,54 +408,6 @@ typedef struct {
/* 0x844 */ void* fb;
} FaultThreadStruct; // size = 0x848
struct GameState;
typedef void (*GameStateFunc)(struct GameState* gameState);
typedef struct {
/* 0x00 */ void* loadedRamAddr;
/* 0x04 */ uintptr_t vromStart; // if applicable
/* 0x08 */ uintptr_t vromEnd; // if applicable
/* 0x0C */ void* vramStart; // if applicable
/* 0x10 */ void* vramEnd; // if applicable
/* 0x14 */ UNK_PTR unk_14;
/* 0x18 */ GameStateFunc init; // initializes and executes the given context
/* 0x1C */ GameStateFunc destroy; // deconstructs the context, and sets the next context to load
/* 0x20 */ UNK_PTR unk_20;
/* 0x24 */ UNK_PTR unk_24;
/* 0x28 */ UNK_TYPE unk_28;
/* 0x2C */ size_t instanceSize;
} GameStateOverlay; // size = 0x30
typedef struct GameAllocEntry {
/* 0x0 */ struct GameAllocEntry* next;
/* 0x4 */ struct GameAllocEntry* prev;
/* 0x8 */ size_t size;
/* 0xC */ u32 unk_0C;
} GameAllocEntry; // size = 0x10
typedef struct GameAlloc {
/* 0x00 */ GameAllocEntry base;
/* 0x10 */ GameAllocEntry* head;
} GameAlloc; // size = 0x14
typedef struct GameState {
/* 0x00 */ GraphicsContext* gfxCtx;
/* 0x04 */ GameStateFunc main;
/* 0x08 */ GameStateFunc destroy;
/* 0x0C */ GameStateFunc init; // Usually the current game state's init, though after stopping, the graph thread will look here to determine the next game state to load.
/* 0x10 */ size_t size;
/* 0x14 */ Input input[MAXCONTROLLERS];
/* 0x74 */ TwoHeadArena heap;
/* 0x84 */ GameAlloc alloc;
/* 0x98 */ UNK_TYPE1 pad98[0x3];
/* 0x9B */ u8 running; // If 0, switch to next game state
/* 0x9C */ u32 frames;
/* 0xA0 */ u8 padA0[0x2];
/* 0xA2 */ u8 framerateDivisor; // game speed?
/* 0xA3 */ u8 unk_A3;
} GameState; // size = 0xA4
struct PlayState;
typedef s32 (*ColChkResetFunc)(struct PlayState*, Collider*);

104
include/z64game.h Normal file
View File

@ -0,0 +1,104 @@
#ifndef Z64_GAME_H
#define Z64_GAME_H
#include "ultra64.h"
#include "libc/stdbool.h"
#include "libc/stdint.h"
#include "io/controller.h"
#include "tha.h"
#include "padmgr.h"
struct GraphicsContext;
struct GameState;
typedef void (*GameStateFunc)(struct GameState* gameState);
typedef struct {
/* 0x00 */ void* loadedRamAddr;
/* 0x04 */ uintptr_t vromStart; // if applicable
/* 0x08 */ uintptr_t vromEnd; // if applicable
/* 0x0C */ void* vramStart; // if applicable
/* 0x10 */ void* vramEnd; // if applicable
/* 0x14 */ UNK_PTR unk_14;
/* 0x18 */ GameStateFunc init; // initializes and executes the given context
/* 0x1C */ GameStateFunc destroy; // deconstructs the context, and sets the next context to load
/* 0x20 */ UNK_PTR unk_20;
/* 0x24 */ UNK_PTR unk_24;
/* 0x28 */ UNK_TYPE unk_28;
/* 0x2C */ size_t instanceSize;
} GameStateOverlay; // size = 0x30
typedef struct GameAllocEntry {
/* 0x0 */ struct GameAllocEntry* next;
/* 0x4 */ struct GameAllocEntry* prev;
/* 0x8 */ size_t size;
/* 0xC */ u32 unk_0C;
} GameAllocEntry; // size = 0x10
typedef struct GameAlloc {
/* 0x00 */ GameAllocEntry base;
/* 0x10 */ GameAllocEntry* head;
} GameAlloc; // size = 0x14
typedef struct GameState {
/* 0x00 */ struct GraphicsContext* gfxCtx;
/* 0x04 */ GameStateFunc main;
/* 0x08 */ GameStateFunc destroy;
/* 0x0C */ GameStateFunc init; // Usually the current game state's init, though after stopping, the graph thread will look here to determine the next game state to load.
/* 0x10 */ size_t size;
/* 0x14 */ Input input[MAXCONTROLLERS];
/* 0x74 */ TwoHeadArena heap;
/* 0x84 */ GameAlloc alloc;
/* 0x98 */ UNK_TYPE1 pad98[0x3];
/* 0x9B */ u8 running; // If 0, switch to next game state
/* 0x9C */ u32 frames;
/* 0xA0 */ u8 padA0[0x2];
/* 0xA2 */ u8 framerateDivisor;
/* 0xA3 */ u8 unk_A3;
} GameState; // size = 0xA4
void Game_UpdateFramerateVariables(s32 divisor);
void Game_SetFramerateDivisor(GameState* gameState, s32 divisor);
void GameState_SetFBFilter(Gfx** gfx, void* zbuffer);
void Game_Nop80173534(GameState* gameState);
void GameState_Draw(GameState* gameState, struct GraphicsContext* gfxCtx);
void GameState_SetFrameBuffer(struct GraphicsContext* gfxCtx);
void func_801736DC(struct GraphicsContext* gfxCtx);
void Game_UpdateInput(GameState* gameState);
void Game_Update(GameState* gameState);
void Game_IncrementFrameCount(GameState* gameState);
void GameState_InitArena(GameState* gameState, size_t size);
void GameState_Realloc(GameState* gameState, size_t size);
void GameState_Init(GameState* gameState, GameStateFunc init, struct GraphicsContext* gfxCtx);
void GameState_Destroy(GameState* gameState);
GameStateFunc GameState_GetInit(GameState* gameState);
size_t GameState_GetSize(GameState* gameState);
u32 GameState_IsRunning(GameState* gameState);
s32 GameState_GetArenaSize(GameState* gameState);
s32 func_80173B48(GameState* gameState);
extern s32 gFramerateDivisor;
extern f32 gFramerateDivisorF;
extern f32 gFramerateDivisorHalf;
extern f32 gFramerateDivisorThird;
#define STOP_GAMESTATE(curState) \
do { \
GameState* state = curState; \
\
state->running = false; \
} while(0)
#define SET_NEXT_GAMESTATE(curState, nextInit, nextSize) \
do { \
GameState* state = curState; \
\
(state)->init = nextInit; \
(state)->size = nextSize; \
} while (0)
#endif

View File

@ -1,15 +1,15 @@
#ifndef Z64PRENMI_H
#define Z64PRENMI_H
#include "global.h"
void PreNMI_Destroy(GameState* thisx);
void PreNMI_Init(GameState* thisx);
#include "z64game.h"
typedef struct {
/* 0x00 */ GameState state;
/* 0xA4 */ u32 timer;
/* 0xA8 */ UNK_TYPE4 unkA8;
/* 0xA8 */ s32 unk_A8;
} PreNMIState; // size = 0xAC
void PreNMI_Destroy(GameState* thisx);
void PreNMI_Init(GameState* thisx);
#endif

View File

@ -1,13 +1,13 @@
#ifndef Z64TITLE_SETUP_H
#define Z64TITLE_SETUP_H
#include "global.h"
void Setup_Destroy(GameState* gameState);
void Setup_Init(GameState* thisx);
#include "z64game.h"
typedef struct {
/* 0x00 */ GameState state;
} SetupState; // size = 0xA4
void Setup_Destroy(GameState* gameState);
void Setup_Init(GameState* thisx);
#endif

View File

@ -11,9 +11,9 @@ f32 gFramerateDivisorThird = 1.0f / 3.0f;
void Game_UpdateFramerateVariables(s32 divisor) {
gFramerateDivisor = divisor;
gFramerateDivisorF = (f32)divisor;
gFramerateDivisorHalf = (f32)(divisor * 0.5f);
gFramerateDivisorThird = (f32)(divisor / 3.0f);
gFramerateDivisorF = divisor;
gFramerateDivisorHalf = divisor / 2.0f;
gFramerateDivisorThird = divisor / 3.0f;
}
void Game_SetFramerateDivisor(GameState* gameState, s32 divisor) {

View File

@ -1,3 +1,4 @@
#include "global.h"
#include "z_prenmi.h"
void PreNMI_Stop(PreNMIState* this) {
@ -9,10 +10,9 @@ void PreNMI_Update(PreNMIState* this) {
if (this->timer == 0) {
ViConfig_UpdateVi(1);
PreNMI_Stop(this);
return;
} else {
this->timer--;
}
this->timer--;
}
void PreNMI_Draw(PreNMIState* this) {
@ -48,7 +48,7 @@ void PreNMI_Init(GameState* thisx) {
this->state.main = PreNMI_Main;
this->state.destroy = PreNMI_Destroy;
this->timer = 30;
this->unkA8 = 10;
this->unk_A8 = 10;
Game_SetFramerateDivisor(&this->state, 1);
}

View File

@ -4,9 +4,10 @@
* Description: "Dawn of ... day" screen
*/
#include "global.h"
#include "z_daytelop.h"
#include "z64save.h"
#include "z64shrink_window.h"
#include "z64view.h"
#include "misc/daytelop_static/daytelop_static.h"
#include "interface/icon_item_gameover_static/icon_item_gameover_static.h"

View File

@ -1,16 +1,13 @@
#ifndef Z64_DAYTELOP_H
#define Z64_DAYTELOP_H
#include "global.h"
void DayTelop_Init(GameState* thisx);
void DayTelop_Destroy(GameState* thisx);
#include "z64game.h"
#include "z64view.h"
typedef struct {
/* 0x000 */ GameState state;
/* 0x0A4 */ void* daytelopStaticFile;
/* 0x0A8 */ void* gameoverStaticFile;
/* 0x0AC */ UNK_TYPE1 unk_AC[0x4];
/* 0x0B0 */ View view;
/* 0x218 */ UNK_TYPE1 unk_218[0x28];
/* 0x240 */ s16 transitionCountdown;
@ -24,4 +21,7 @@ typedef enum {
/* 2 */ DAYTELOP_HOURSTEXT_ON
} DaytelopFadeState;
void DayTelop_Init(GameState* thisx);
void DayTelop_Destroy(GameState* thisx);
#endif

View File

@ -2,6 +2,11 @@
#define FILE_SELECT_H
#include "global.h"
#include "z64game.h"
#include "z64message.h"
#include "z64skybox.h"
#include "z64view.h"
// `sramCtx->noFlashSaveBuf` is never allocated space, so should never be used
// Slot offsets are also based on OoT SaveContext sizes, and contains incorrect sizes from MM

View File

@ -4,9 +4,12 @@
* Description: Initializes the game into the title screen
*/
#include "global.h"
#include "z_opening.h"
#include "z64save.h"
#include "z64shrink_window.h"
#include "z64view.h"
#include "regs.h"
void TitleSetup_SetupTitleScreen(TitleSetupState* this) {
static s32 sOpeningEntrances[] = { ENTRANCE(CUTSCENE, 0), ENTRANCE(CUTSCENE, 1) };

View File

@ -1,15 +1,15 @@
#ifndef _Z64_OPENING_H_
#define _Z64_OPENING_H_
#ifndef Z64_OPENING_H
#define Z64_OPENING_H
#include "global.h"
#include "z64game.h"
#include "z64view.h"
typedef struct {
/* 0x000 */ GameState state;
/* 0x0A8 */ View view;
} TitleSetupState; // size = 0x210
void TitleSetup_Init(GameState* thisx);
void TitleSetup_Destroy(GameState* thisx);
typedef struct {
/* 0x000 */ GameState state;
/* 0x0A4 */ UNK_TYPE1 unk_A4[0x4];
/* 0x0A8 */ View view;
} TitleSetupState; // size = 0x210
#endif

View File

@ -1,7 +1,8 @@
#ifndef _Z64_SELECT_H_
#define _Z64_SELECT_H_
#ifndef Z64_SELECT_H
#define Z64_SELECT_H
#include "global.h"
#include "z64game.h"
#include "z64view.h"
struct MapSelectState;

View File

@ -2,9 +2,8 @@
#define Z64_TITLE_H
#include "global.h"
void ConsoleLogo_Init(GameState* thisx);
void ConsoleLogo_Destroy(GameState* thisx);
#include "z64game.h"
#include "z64view.h"
typedef struct {
/* 0x000 */ GameState state;
@ -20,4 +19,7 @@ typedef struct {
/* 0x244 */ u8 exit;
} ConsoleLogoState; // size = 0x248
void ConsoleLogo_Init(GameState* thisx);
void ConsoleLogo_Destroy(GameState* thisx);
#endif