mirror of
https://github.com/zeldaret/mm.git
synced 2026-07-08 21:34:48 -04:00
Game bss and cleanup (#1356)
* Game bss and cleanup * Match Oot with rdp time variables * PR review * Namefixer
This commit is contained in:
+54
-54
@@ -5,38 +5,39 @@
|
||||
#include "system_malloc.h"
|
||||
#include "z64debug_text.h"
|
||||
#include "z64rumble.h"
|
||||
#include "z64speed_meter.h"
|
||||
#include "z64vimode.h"
|
||||
#include "z64viscvg.h"
|
||||
#include "z64vismono.h"
|
||||
#include "z64viszbuf.h"
|
||||
#include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h"
|
||||
|
||||
extern UNK_TYPE1 D_801F7FF0;
|
||||
extern VisCvg sGameVisCvg;
|
||||
extern VisZbuf sGameVisZbuf;
|
||||
extern VisMono sGameVisMono;
|
||||
extern ViMode sGameViMode;
|
||||
|
||||
s32 gFramerateDivisor = 1;
|
||||
f32 gFramerateDivisorF = 1.0f;
|
||||
f32 gFramerateDivisorHalf = 1.0f / 2.0f;
|
||||
f32 gFramerateDivisorThird = 1.0f / 3.0f;
|
||||
|
||||
void Game_UpdateFramerateVariables(s32 divisor) {
|
||||
SpeedMeter sGameSpeedMeter;
|
||||
VisCvg sGameVisCvg;
|
||||
VisZbuf sGameVisZbuf;
|
||||
VisMono sGameVisMono;
|
||||
ViMode sGameViMode;
|
||||
|
||||
void GameState_UpdateFramerateDivisors(s32 divisor) {
|
||||
gFramerateDivisor = divisor;
|
||||
gFramerateDivisorF = divisor;
|
||||
gFramerateDivisorHalf = divisor / 2.0f;
|
||||
gFramerateDivisorThird = divisor / 3.0f;
|
||||
}
|
||||
|
||||
void Game_SetFramerateDivisor(GameState* gameState, s32 divisor) {
|
||||
R_UPDATE_RATE = (s16)divisor;
|
||||
void GameState_SetFramerateDivisor(GameState* gameState, s32 divisor) {
|
||||
R_UPDATE_RATE = divisor;
|
||||
gameState->framerateDivisor = divisor;
|
||||
Game_UpdateFramerateVariables(divisor);
|
||||
GameState_UpdateFramerateDivisors(divisor);
|
||||
}
|
||||
|
||||
void GameState_SetFBFilter(Gfx** gfx, void* zbuffer) {
|
||||
Gfx* dlist = *gfx;
|
||||
void GameState_SetFBFilter(Gfx** gfxP, void* zbuffer) {
|
||||
Gfx* gfx = *gfxP;
|
||||
|
||||
if ((R_FB_FILTER_TYPE > 0) && (R_FB_FILTER_TYPE < 5)) {
|
||||
sGameVisCvg.type = R_FB_FILTER_TYPE;
|
||||
@@ -44,7 +45,7 @@ void GameState_SetFBFilter(Gfx** gfx, void* zbuffer) {
|
||||
sGameVisCvg.color.g = R_FB_FILTER_PRIM_COLOR(1);
|
||||
sGameVisCvg.color.b = R_FB_FILTER_PRIM_COLOR(2);
|
||||
sGameVisCvg.color.a = R_FB_FILTER_A;
|
||||
VisCvg_Draw(&sGameVisCvg, &dlist);
|
||||
VisCvg_Draw(&sGameVisCvg, &gfx);
|
||||
} else if ((R_FB_FILTER_TYPE == 5) || (R_FB_FILTER_TYPE == 6)) {
|
||||
sGameVisZbuf.useRgba = (R_FB_FILTER_TYPE == 6);
|
||||
sGameVisZbuf.primColor.r = R_FB_FILTER_PRIM_COLOR(0);
|
||||
@@ -55,7 +56,7 @@ void GameState_SetFBFilter(Gfx** gfx, void* zbuffer) {
|
||||
sGameVisZbuf.envColor.g = R_FB_FILTER_ENV_COLOR(1);
|
||||
sGameVisZbuf.envColor.b = R_FB_FILTER_ENV_COLOR(2);
|
||||
sGameVisZbuf.envColor.a = R_FB_FILTER_A;
|
||||
VisZbuf_Draw(&sGameVisZbuf, &dlist, zbuffer);
|
||||
VisZbuf_Draw(&sGameVisZbuf, &gfx, zbuffer);
|
||||
} else if (R_FB_FILTER_TYPE == 7) {
|
||||
sGameVisMono.unk_00 = 0;
|
||||
sGameVisMono.primColor.r = R_FB_FILTER_PRIM_COLOR(0);
|
||||
@@ -66,43 +67,43 @@ void GameState_SetFBFilter(Gfx** gfx, void* zbuffer) {
|
||||
sGameVisMono.envColor.g = R_FB_FILTER_ENV_COLOR(1);
|
||||
sGameVisMono.envColor.b = R_FB_FILTER_ENV_COLOR(2);
|
||||
sGameVisMono.envColor.a = R_FB_FILTER_A;
|
||||
VisMono_Draw(&sGameVisMono, &dlist);
|
||||
VisMono_Draw(&sGameVisMono, &gfx);
|
||||
}
|
||||
|
||||
*gfx = dlist;
|
||||
*gfxP = gfx;
|
||||
}
|
||||
|
||||
void Game_Nop80173534(GameState* gameState) {
|
||||
void GameState_Noop(GameState* gameState) {
|
||||
}
|
||||
|
||||
void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx) {
|
||||
Gfx* nextDisplayList;
|
||||
Gfx* polyOpa;
|
||||
Gfx* gfx;
|
||||
Gfx* gfxHead;
|
||||
|
||||
OPEN_DISPS(gfxCtx);
|
||||
|
||||
nextDisplayList = Graph_GfxPlusOne(polyOpa = POLY_OPA_DISP);
|
||||
gSPDisplayList(OVERLAY_DISP++, nextDisplayList);
|
||||
gfx = Graph_GfxPlusOne(gfxHead = POLY_OPA_DISP);
|
||||
gSPDisplayList(OVERLAY_DISP++, gfx);
|
||||
|
||||
if (R_FB_FILTER_TYPE && R_FB_FILTER_ENV_COLOR(3) == 0) {
|
||||
GameState_SetFBFilter(&nextDisplayList, gfxCtx->zbuffer);
|
||||
if ((R_FB_FILTER_TYPE != 0) && (R_FB_FILTER_ENV_COLOR(3) == 0)) {
|
||||
GameState_SetFBFilter(&gfx, gfxCtx->zbuffer);
|
||||
}
|
||||
|
||||
if (R_ENABLE_ARENA_DBG < 0) {
|
||||
R_ENABLE_ARENA_DBG = 0;
|
||||
}
|
||||
|
||||
gSPEndDisplayList(nextDisplayList++);
|
||||
Graph_BranchDlist(polyOpa, nextDisplayList);
|
||||
POLY_OPA_DISP = nextDisplayList;
|
||||
gSPEndDisplayList(gfx++);
|
||||
Graph_BranchDlist(gfxHead, gfx);
|
||||
POLY_OPA_DISP = gfx;
|
||||
|
||||
CLOSE_DISPS(gfxCtx);
|
||||
|
||||
Debug_DrawText(gfxCtx);
|
||||
|
||||
if (R_ENABLE_ARENA_DBG != 0) {
|
||||
SpeedMeter_DrawTimeEntries(&D_801F7FF0, gfxCtx);
|
||||
SpeedMeter_DrawAllocEntries(&D_801F7FF0, gfxCtx, gameState);
|
||||
SpeedMeter_DrawTimeEntries(&sGameSpeedMeter, gfxCtx);
|
||||
SpeedMeter_DrawAllocEntries(&sGameSpeedMeter, gfxCtx, gameState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,27 +120,27 @@ void GameState_SetFrameBuffer(GraphicsContext* gfxCtx) {
|
||||
CLOSE_DISPS(gfxCtx);
|
||||
}
|
||||
|
||||
void func_801736DC(GraphicsContext* gfxCtx) {
|
||||
Gfx* nextDisplayList;
|
||||
Gfx* polyOpa;
|
||||
void GameState_DrawEnd(GraphicsContext* gfxCtx) {
|
||||
Gfx* gfx;
|
||||
Gfx* gfxHead;
|
||||
|
||||
OPEN_DISPS(gfxCtx);
|
||||
|
||||
nextDisplayList = Graph_GfxPlusOne(polyOpa = gfxCtx->polyOpa.p);
|
||||
gSPDisplayList(OVERLAY_DISP++, nextDisplayList);
|
||||
gSPEndDisplayList(nextDisplayList++);
|
||||
Graph_BranchDlist(polyOpa, nextDisplayList);
|
||||
gfx = Graph_GfxPlusOne(gfxHead = POLY_OPA_DISP);
|
||||
gSPDisplayList(OVERLAY_DISP++, gfx);
|
||||
gSPEndDisplayList(gfx++);
|
||||
Graph_BranchDlist(gfxHead, gfx);
|
||||
|
||||
POLY_OPA_DISP = nextDisplayList;
|
||||
POLY_OPA_DISP = gfx;
|
||||
|
||||
CLOSE_DISPS(gfxCtx);
|
||||
}
|
||||
|
||||
void Game_UpdateInput(GameState* gameState) {
|
||||
void GameState_GetInput(GameState* gameState) {
|
||||
PadMgr_GetInput(gameState->input, true);
|
||||
}
|
||||
|
||||
void Game_Update(GameState* gameState) {
|
||||
void GameState_Update(GameState* gameState) {
|
||||
GraphicsContext* gfxCtx = gameState->gfxCtx;
|
||||
|
||||
GameState_SetFrameBuffer(gameState->gfxCtx);
|
||||
@@ -148,12 +149,12 @@ void Game_Update(GameState* gameState) {
|
||||
|
||||
if (R_PAUSE_BG_PRERENDER_STATE != PAUSE_BG_PRERENDER_PROCESS) {
|
||||
GameState_Draw(gameState, gfxCtx);
|
||||
func_801736DC(gfxCtx);
|
||||
GameState_DrawEnd(gfxCtx);
|
||||
}
|
||||
}
|
||||
|
||||
void Game_IncrementFrameCount(GameState* gameState) {
|
||||
Game_Nop80173534(gameState);
|
||||
void GameState_IncrementFrameCount(GameState* gameState) {
|
||||
GameState_Noop(gameState);
|
||||
gameState->frames++;
|
||||
}
|
||||
|
||||
@@ -171,27 +172,26 @@ void GameState_InitArena(GameState* gameState, size_t size) {
|
||||
}
|
||||
|
||||
void GameState_Realloc(GameState* gameState, size_t size) {
|
||||
GameAlloc* alloc;
|
||||
GameAlloc* alloc = &gameState->alloc;
|
||||
void* gameArena;
|
||||
size_t systemMaxFree;
|
||||
size_t bytesFree;
|
||||
size_t bytesAllocated;
|
||||
void* heapStart;
|
||||
void* heapStart = gameState->heap.start;
|
||||
|
||||
heapStart = gameState->heap.start;
|
||||
alloc = &gameState->alloc;
|
||||
THA_Destroy(&gameState->heap);
|
||||
GameAlloc_Free(alloc, heapStart);
|
||||
SystemArena_GetSizes(&systemMaxFree, &bytesFree, &bytesAllocated);
|
||||
size = ((systemMaxFree - (sizeof(ArenaNode))) < size) ? (0) : (size);
|
||||
size = ((systemMaxFree - sizeof(ArenaNode)) < size) ? 0 : size;
|
||||
if (size == 0) {
|
||||
size = systemMaxFree - (sizeof(ArenaNode));
|
||||
size = systemMaxFree - sizeof(ArenaNode);
|
||||
}
|
||||
|
||||
if ((gameArena = GameAlloc_Malloc(alloc, size)) != NULL) {
|
||||
gameArena = GameAlloc_Malloc(alloc, size);
|
||||
if (gameArena != NULL) {
|
||||
THA_Init(&gameState->heap, gameArena, size);
|
||||
} else {
|
||||
THA_Init(&gameState->heap, 0, 0);
|
||||
THA_Init(&gameState->heap, NULL, 0);
|
||||
__assert("../game.c", 1074);
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* g
|
||||
gameState->frames = 0;
|
||||
gameState->main = NULL;
|
||||
gameState->destroy = NULL;
|
||||
gameState->running = 1;
|
||||
gameState->running = true;
|
||||
gfxCtx->viMode = gActiveViMode;
|
||||
gfxCtx->viConfigFeatures = gViConfigFeatures;
|
||||
gfxCtx->xScale = gViConfigXScale;
|
||||
@@ -216,7 +216,7 @@ void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* g
|
||||
}
|
||||
|
||||
GameState_InitArena(gameState, 0x100000);
|
||||
Game_SetFramerateDivisor(gameState, 3);
|
||||
GameState_SetFramerateDivisor(gameState, 3);
|
||||
|
||||
init(gameState);
|
||||
|
||||
@@ -224,7 +224,7 @@ void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* g
|
||||
VisZbuf_Init(&sGameVisZbuf);
|
||||
VisMono_Init(&sGameVisMono);
|
||||
ViMode_Init(&sGameViMode);
|
||||
func_801773A0(&D_801F7FF0);
|
||||
SpeedMeter_Init(&sGameSpeedMeter);
|
||||
Rumble_Init();
|
||||
|
||||
osSendMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK);
|
||||
@@ -240,7 +240,7 @@ void GameState_Destroy(GameState* gameState) {
|
||||
}
|
||||
|
||||
Rumble_Destroy();
|
||||
func_801773C4(&D_801F7FF0);
|
||||
SpeedMeter_Destroy(&sGameSpeedMeter);
|
||||
VisCvg_Destroy(&sGameVisCvg);
|
||||
VisZbuf_Destroy(&sGameVisZbuf);
|
||||
VisMono_Destroy(&sGameVisMono);
|
||||
@@ -266,7 +266,7 @@ s32 GameState_GetArenaSize(GameState* gameState) {
|
||||
}
|
||||
|
||||
s32 func_80173B48(GameState* gameState) {
|
||||
s32 result = OS_CYCLES_TO_NSEC(gameState->framerateDivisor * sIrqMgrRetraceTime) - OS_CYCLES_TO_NSEC(D_801FBAF0);
|
||||
s32 result = OS_CYCLES_TO_NSEC(gameState->framerateDivisor * sIrqMgrRetraceTime) - OS_CYCLES_TO_NSEC(gRDPTimeTotal);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+5
-5
@@ -228,8 +228,8 @@ retry:
|
||||
}
|
||||
|
||||
void Graph_UpdateGame(GameState* gameState) {
|
||||
Game_UpdateInput(gameState);
|
||||
Game_IncrementFrameCount(gameState);
|
||||
GameState_GetInput(gameState);
|
||||
GameState_IncrementFrameCount(gameState);
|
||||
if (SREG(20) < 3) {
|
||||
Audio_Update();
|
||||
}
|
||||
@@ -245,7 +245,7 @@ void Graph_ExecuteAndDraw(GraphicsContext* gfxCtx, GameState* gameState) {
|
||||
gameState->unk_A3 = 0;
|
||||
Graph_SetNextGfxPool(gfxCtx);
|
||||
|
||||
Game_Update(gameState);
|
||||
GameState_Update(gameState);
|
||||
|
||||
OPEN_DISPS(gfxCtx);
|
||||
|
||||
@@ -312,10 +312,10 @@ void Graph_ExecuteAndDraw(GraphicsContext* gfxCtx, GameState* gameState) {
|
||||
|
||||
D_801FBAE8 = sRSPGFXTotalTime;
|
||||
D_801FBAE0 = gRSPAudioTotalTime;
|
||||
D_801FBAF0 = gRDPTotalTime;
|
||||
gRDPTimeTotal = gRDPTimeAcc;
|
||||
sRSPGFXTotalTime = 0;
|
||||
gRSPAudioTotalTime = 0;
|
||||
gRDPTotalTime = 0;
|
||||
gRDPTimeAcc = 0;
|
||||
|
||||
if (sGraphTaskStartTime != 0) {
|
||||
lastRenderFrameDuration = time - sGraphTaskStartTime;
|
||||
|
||||
+1
-1
@@ -481,7 +481,7 @@ void Sched_HandleRDPDone(SchedContext* sched) {
|
||||
}
|
||||
|
||||
// Log run time
|
||||
gRDPTotalTime = osGetTime() - sRDPStartTime;
|
||||
gRDPTimeAcc = osGetTime() - sRDPStartTime;
|
||||
|
||||
// Mark task done
|
||||
curRDP = sched->curRDPTask;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "global.h"
|
||||
#include "z64speed_meter.h"
|
||||
#include "z64view.h"
|
||||
#include "system_malloc.h"
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/speed_meter/func_80177390.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/speed_meter/func_801773A0.s")
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/speed_meter/SpeedMeter_Init.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/speed_meter/func_801773C4.s")
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/speed_meter/SpeedMeter_Destroy.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/speed_meter/SpeedMeter_DrawTimeEntries.s")
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ void KaleidoSetup_Update(PlayState* play) {
|
||||
}
|
||||
|
||||
if (pauseCtx->state == PAUSE_STATE_OPENING_0) {
|
||||
Game_SetFramerateDivisor(&play->state, 2);
|
||||
GameState_SetFramerateDivisor(&play->state, 2);
|
||||
if (ShrinkWindow_Letterbox_GetSizeTarget() != 0) {
|
||||
ShrinkWindow_Letterbox_SetSizeTarget(0);
|
||||
}
|
||||
|
||||
+7
-7
@@ -728,7 +728,7 @@ void Play_UpdateTransition(PlayState* this) {
|
||||
if (gTransitionTileState == TRANS_TILE_READY) {
|
||||
TransitionTile_Destroy(&sTransitionTile);
|
||||
gTransitionTileState = TRANS_TILE_OFF;
|
||||
Game_SetFramerateDivisor(&this->state, 3);
|
||||
GameState_SetFramerateDivisor(&this->state, 3);
|
||||
}
|
||||
}
|
||||
this->transitionTrigger = TRANS_TRIGGER_OFF;
|
||||
@@ -775,7 +775,7 @@ void Play_UpdateTransition(PlayState* this) {
|
||||
|
||||
if (sTransitionFillTimer >= 20) {
|
||||
gTransitionTileState = TRANS_TILE_OFF;
|
||||
Game_SetFramerateDivisor(&this->state, 3);
|
||||
GameState_SetFramerateDivisor(&this->state, 3);
|
||||
this->transitionTrigger = TRANS_TRIGGER_OFF;
|
||||
this->transitionMode = TRANS_MODE_OFF;
|
||||
this->envCtx.fillScreen = false;
|
||||
@@ -809,7 +809,7 @@ void Play_UpdateTransition(PlayState* this) {
|
||||
this->transitionMode = TRANS_MODE_OFF;
|
||||
} else {
|
||||
gTransitionTileState = TRANS_TILE_OFF;
|
||||
Game_SetFramerateDivisor(&this->state, 3);
|
||||
GameState_SetFramerateDivisor(&this->state, 3);
|
||||
this->transitionTrigger = TRANS_TRIGGER_OFF;
|
||||
this->transitionMode = TRANS_MODE_OFF;
|
||||
}
|
||||
@@ -838,7 +838,7 @@ void Play_UpdateTransition(PlayState* this) {
|
||||
if (this->transitionTrigger == TRANS_TRIGGER_END) {
|
||||
if (this->envCtx.sandstormPrimA < 110) {
|
||||
gTransitionTileState = TRANS_TILE_OFF;
|
||||
Game_SetFramerateDivisor(&this->state, 3);
|
||||
GameState_SetFramerateDivisor(&this->state, 3);
|
||||
this->transitionTrigger = TRANS_TRIGGER_OFF;
|
||||
this->transitionMode = TRANS_MODE_OFF;
|
||||
}
|
||||
@@ -874,7 +874,7 @@ void Play_UpdateTransition(PlayState* this) {
|
||||
if (this->transitionTrigger == TRANS_TRIGGER_END) {
|
||||
if (this->envCtx.sandstormPrimA <= 0) {
|
||||
gTransitionTileState = TRANS_TILE_OFF;
|
||||
Game_SetFramerateDivisor(&this->state, 3);
|
||||
GameState_SetFramerateDivisor(&this->state, 3);
|
||||
this->transitionTrigger = TRANS_TRIGGER_OFF;
|
||||
this->transitionMode = TRANS_MODE_OFF;
|
||||
}
|
||||
@@ -897,7 +897,7 @@ void Play_UpdateTransition(PlayState* this) {
|
||||
|
||||
if (gSaveContext.cutsceneTransitionControl <= 100) {
|
||||
gTransitionTileState = TRANS_TILE_OFF;
|
||||
Game_SetFramerateDivisor(&this->state, 3);
|
||||
GameState_SetFramerateDivisor(&this->state, 3);
|
||||
this->transitionTrigger = TRANS_TRIGGER_OFF;
|
||||
this->transitionMode = TRANS_MODE_OFF;
|
||||
}
|
||||
@@ -945,7 +945,7 @@ void Play_UpdateMain(PlayState* this) {
|
||||
} else {
|
||||
sTransitionTile.zBuffer = gZBufferPtr;
|
||||
gTransitionTileState = TRANS_TILE_READY;
|
||||
Game_SetFramerateDivisor(&this->state, 1);
|
||||
GameState_SetFramerateDivisor(&this->state, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
+1
-1
@@ -50,5 +50,5 @@ void PreNMI_Init(GameState* thisx) {
|
||||
this->timer = 30;
|
||||
this->unk_A8 = 10;
|
||||
|
||||
Game_SetFramerateDivisor(&this->state, 1);
|
||||
GameState_SetFramerateDivisor(&this->state, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user