1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-25 01:34:18 +00:00

implement Open/Close using macros

This commit is contained in:
mzxrules 2024-10-01 14:05:02 -04:00
parent 7db957042f
commit 4c40183da4
12 changed files with 106 additions and 121 deletions

View file

@ -2,9 +2,33 @@
#define GFXALLOC_H
#include "ultra64.h"
#include "gfx.h"
Gfx* Gfx_Open(Gfx* gfx);
Gfx* Gfx_Close(Gfx* gfx, Gfx* dst);
Gfx* Gfx_Open(Gfx* gfxDisp);
Gfx* Gfx_Close(Gfx* gfxDisp, Gfx* gfxAllocDisp);
void* Gfx_Alloc(Gfx** gfxP, u32 size);
/**
* Creates a new temporary graphics display list pointer, using the memory reserved by POLY_OPA_DISP
* POLY_OPA_DISP cannot be written to until GFX_ALLOC_CLOSE is called.
*
* @param gfxAllocDisp is the new temporary graphics display list pointer.
* @param tempGfx is an intermediate Gfx* variable that should not be touched.
* @param disp is the top level display list that is being given more memory.
*/
#define GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, disp) \
gfxAllocDisp = Gfx_Open(tempGfx = POLY_OPA_DISP); \
gSPDisplayList(disp++, gfxAllocDisp)
/**
* Closes the graphics display list created by GFX_ALLOC_OPEN.
*
* @param gfxAllocDisp is the graphics display list pointer that was created with GFX_ALLOC_OPEN
* @param tempGfx is the same Gfx* variable that was passed into GFX_ALLOC_OPEN
*/
#define GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx) \
gSPEndDisplayList(gfxAllocDisp++); \
Gfx_Close(tempGfx, gfxAllocDisp); \
POLY_OPA_DISP = gfxAllocDisp
#endif

View file

@ -68,8 +68,8 @@ void FlagSet_Update(PlayState* play) {
GraphicsContext* gfxCtx = play->state.gfxCtx;
Input* input = &play->state.input[0];
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
OPEN_DISPS(gfxCtx, "../flg_set.c", 131);
@ -77,11 +77,10 @@ void FlagSet_Update(PlayState* play) {
GfxPrint printer;
s32 pad;
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
GfxPrint_Init(&printer);
GfxPrint_Open(&printer, tempGfxDisp);
GfxPrint_Open(&printer, gfxAllocDisp);
GfxPrint_SetColor(&printer, 250, 50, 50, 255);
GfxPrint_SetPos(&printer, 4, 13);
GfxPrint_Printf(&printer, entries[entryIdx].name);
@ -166,12 +165,10 @@ void FlagSet_Update(PlayState* play) {
timer--;
}
tempGfxDisp = GfxPrint_Close(&printer);
gfxAllocDisp = GfxPrint_Close(&printer);
GfxPrint_Destroy(&printer);
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
}
if (CHECK_BTN_ALL(input->press.button, BTN_L)) {

View file

@ -164,22 +164,21 @@ void GameState_DrawInputDisplay(u16 input, Gfx** gfxP) {
#endif
void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx) {
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
OPEN_DISPS(gfxCtx, "../game.c", 746);
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
if (R_ENABLE_FB_FILTER == 1) {
GameState_SetFBFilter(&tempGfxDisp);
GameState_SetFBFilter(&gfxAllocDisp);
}
#if OOT_DEBUG
sLastButtonPressed = gameState->input[0].press.button | gameState->input[0].cur.button;
if (R_DISABLE_INPUT_DISPLAY == 0) {
GameState_DrawInputDisplay(sLastButtonPressed, &tempGfxDisp);
GameState_DrawInputDisplay(sLastButtonPressed, &gfxAllocDisp);
}
if (R_ENABLE_AUDIO_DBG & 1) {
@ -187,9 +186,9 @@ void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx) {
GfxPrint printer;
GfxPrint_Init(&printer);
GfxPrint_Open(&printer, tempGfxDisp);
GfxPrint_Open(&printer, gfxAllocDisp);
AudioDebug_Draw(&printer);
tempGfxDisp = GfxPrint_Close(&printer);
gfxAllocDisp = GfxPrint_Close(&printer);
GfxPrint_Destroy(&printer);
}
#endif
@ -206,9 +205,7 @@ void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx) {
R_ENABLE_ARENA_DBG = 0;
}
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
CLOSE_DISPS(gfxCtx, "../game.c", 800);
@ -237,23 +234,20 @@ void GameState_SetFrameBuffer(GraphicsContext* gfxCtx) {
}
void func_800C49F4(GraphicsContext* gfxCtx) {
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
OPEN_DISPS(gfxCtx, "../game.c", 846);
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
#if PLATFORM_N64
if (D_80121212 != 0) {
func_801C6EA0(&tempGfxDisp);
func_801C6EA0(&gfxAllocDisp);
}
#endif
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
CLOSE_DISPS(gfxCtx, "../game.c", 865);
}

View file

@ -1,12 +1,14 @@
#include "global.h"
#include "ultra64.h"
#include "gfxalloc.h"
/**
* Creates a new temporary graphics display list pointer, using the memory reserved by gfxDisp
*
* @param gfxDisp is the display list yielding memory. It cannot be written to until Gfx_Close is called.
* @returns a new graphics display list pointer.
* @return a new graphics display list pointer.
*
* @note This is used to give WORK_DISP more memory to write instructions without increasing the WORK_DISP buffer size.
* @note This is used to take memory allocated to a larger display buffer and use it for a smaller display buffer.
* For example, space in POLY_OPA_DISP can be reserved for WORK_DISP and OVERLAY_DISP task data.
*/
Gfx* Gfx_Open(Gfx* gfxDisp) {
// reserve space for a gSPBranchList command when Gfx_Close is called
@ -18,11 +20,13 @@ Gfx* Gfx_Open(Gfx* gfxDisp) {
*
* @param gfxDisp is the display list yielding memory.
* @param gfx is the graphics display list pointer that was created with Gfx_Open
* @returns gfxDisp's new position
* @return gfxDisp's new position.
*
* @note gfxDisp must be updated after the call with the return value of this function to complete the operation.
*/
Gfx* Gfx_Close(Gfx* gfxDisp, Gfx* gfx) {
gSPBranchList(gfxDisp, gfx);
return gfx;
Gfx* Gfx_Close(Gfx* gfxDisp, Gfx* gfxAllocDisp) {
gSPBranchList(gfxDisp, gfxAllocDisp);
return gfxAllocDisp;
}
/**
@ -30,17 +34,16 @@ Gfx* Gfx_Close(Gfx* gfxDisp, Gfx* gfx) {
*
* @param gfxP is a pointer to a graphics display list pointer
* @param size is the number of bytes to reserve
* @returns start pointer to the allocated memory
* @return the start pointer to the allocated memory
*/
void* Gfx_Alloc(Gfx** gfxP, u32 size) {
u8* ptr;
Gfx* dst;
size = ALIGN8(size);
ptr = (u8*)(*gfxP + 1);
dst = (Gfx*)(ptr + size);
gSPBranchList(*gfxP, dst);
*gfxP = dst;

View file

@ -281,17 +281,16 @@ void Regs_DrawEditor(GfxPrint* printer) {
* Draws the Reg Editor and Debug Camera text on screen
*/
void Debug_DrawText(GraphicsContext* gfxCtx) {
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
GfxPrint printer;
s32 pad;
OPEN_DISPS(gfxCtx, "../z_debug.c", 628);
GfxPrint_Init(&printer);
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
GfxPrint_Open(&printer, tempGfxDisp);
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
GfxPrint_Open(&printer, gfxAllocDisp);
if ((OREG(0) == 1) || (OREG(0) == 8)) {
DebugCamera_DrawScreenText(&printer);
@ -305,10 +304,8 @@ void Debug_DrawText(GraphicsContext* gfxCtx) {
sDebugCamTextEntryCount = 0;
tempGfxDisp = GfxPrint_Close(&printer);
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
gfxAllocDisp = GfxPrint_Close(&printer);
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
CLOSE_DISPS(gfxCtx, "../z_debug.c", 664);

View file

@ -2217,18 +2217,14 @@ void CutsceneHandler_RunScript(PlayState* play, CutsceneContext* csCtx) {
if (gSaveContext.save.cutsceneIndex >= 0xFFF0) {
#if OOT_DEBUG
if (BREG(0) != 0) {
Gfx* displayList;
Gfx* prevDisplayList;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
OPEN_DISPS(play->state.gfxCtx, "../z_demo.c", 4101);
prevDisplayList = POLY_OPA_DISP;
displayList = Gfx_Open(POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, displayList);
Cutscene_DrawDebugInfo(play, &displayList, csCtx);
gSPEndDisplayList(displayList++);
Gfx_Close(prevDisplayList, displayList);
POLY_OPA_DISP = displayList;
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
Cutscene_DrawDebugInfo(play, &gfxAllocDisp, csCtx);
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
CLOSE_DISPS(play->state.gfxCtx, "../z_demo.c", 4108);
}

View file

@ -981,18 +981,14 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex
#if OOT_DEBUG
if (R_ENABLE_ARENA_DBG != 0 || CREG(2) != 0) {
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
OPEN_DISPS(play->state.gfxCtx, "../z_kankyo.c", 1682);
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
Environment_PrintDebugInfo(play, &tempGfxDisp);
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
Environment_PrintDebugInfo(play, &gfxAllocDisp);
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
CLOSE_DISPS(play->state.gfxCtx, "../z_kankyo.c", 1690);
}

View file

@ -3973,8 +3973,8 @@ void Message_DrawDebugText(PlayState* play, Gfx** p) {
#endif
void Message_Draw(PlayState* play) {
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
#if OOT_VERSION < GC_US
s32 pad;
#endif
@ -3988,21 +3988,15 @@ void Message_Draw(PlayState* play) {
watchVar = gSaveContext.save.info.scarecrowLongSongSet;
Message_DrawDebugVariableChanged(&watchVar, play->state.gfxCtx);
if (BREG(0) != 0 && play->msgCtx.textId != 0) {
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
Message_DrawDebugText(play, &tempGfxDisp);
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
Message_DrawDebugText(play, &gfxAllocDisp);
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
}
#endif
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
Message_DrawMain(play, &tempGfxDisp);
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
Message_DrawMain(play, &gfxAllocDisp);
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
CLOSE_DISPS(play->state.gfxCtx, "../z_message_PAL.c", 3582);
}

View file

@ -1159,11 +1159,10 @@ void Play_Draw(PlayState* this) {
gSPSegment(POLY_OPA_DISP++, 0x01, this->billboardMtx);
if (!OOT_DEBUG || (R_HREG_MODE != HREG_MODE_PLAY) || R_PLAY_DRAW_COVER_ELEMENTS) {
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
if ((this->transitionMode == TRANS_MODE_INSTANCE_RUNNING) ||
(this->transitionMode == TRANS_MODE_INSTANCE_WAIT) || (this->transitionCtx.transitionType >= 56)) {
@ -1174,11 +1173,11 @@ void Play_Draw(PlayState* this) {
SET_FULLSCREEN_VIEWPORT(&view);
View_ApplyTo(&view, VIEW_ALL, &tempGfxDisp);
this->transitionCtx.draw(&this->transitionCtx.instanceData, &tempGfxDisp);
View_ApplyTo(&view, VIEW_ALL, &gfxAllocDisp);
this->transitionCtx.draw(&this->transitionCtx.instanceData, &gfxAllocDisp);
}
TransitionFade_Draw(&this->transitionFadeFlash, &tempGfxDisp);
TransitionFade_Draw(&this->transitionFadeFlash, &gfxAllocDisp);
#if PLATFORM_N64
if (gVisMonoColor.a != 0)
@ -1187,12 +1186,10 @@ void Play_Draw(PlayState* this) {
#endif
{
gPlayVisMono.vis.primColor.rgba = gVisMonoColor.rgba;
VisMono_Draw(&gPlayVisMono, &tempGfxDisp);
VisMono_Draw(&gPlayVisMono, &gfxAllocDisp);
}
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
}
if (gTransitionTileState == TRANS_TILE_READY) {

View file

@ -803,19 +803,14 @@ void EnMag_DrawInner(Actor* thisx, PlayState* play, Gfx** gfxP) {
void EnMag_Draw(Actor* thisx, PlayState* play) {
s32 pad;
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
OPEN_DISPS(play->state.gfxCtx, "../z_en_mag.c", 1151);
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
EnMag_DrawInner(thisx, play, &tempGfxDisp);
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
EnMag_DrawInner(thisx, play, &gfxAllocDisp);
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
CLOSE_DISPS(play->state.gfxCtx, "../z_en_mag.c", 1161);
}

View file

@ -98,8 +98,8 @@ void KaleidoScope_DrawDebugEditor(PlayState* play) {
static s32 heldDBtnTimer = 0;
PauseContext* pauseCtx = &play->pauseCtx;
Input* input = &play->state.input[0];
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
s16 spD8[4];
s16 slot;
s16 i;
@ -123,14 +123,9 @@ void KaleidoScope_DrawDebugEditor(PlayState* play) {
gDPSetCombineLERP(POLY_OPA_DISP++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0,
PRIMITIVE, 0);
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempGfxDisp);
KaleidoScope_DrawDebugEditorText(&tempGfxDisp);
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, OVERLAY_DISP);
KaleidoScope_DrawDebugEditorText(&gfxAllocDisp);
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
gDPPipeSync(POLY_OPA_DISP++);
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 0, 0, 255);

View file

@ -907,24 +907,21 @@ static PreRender sPlayerPreRender;
static void* sPreRenderCvg;
void KaleidoScope_SetupPlayerPreRender(PlayState* play) {
Gfx* tempGfxDisp;
Gfx* lockedGfxDisp;
Gfx* gfxAllocDisp;
Gfx* tempGfx;
void* fbuf;
fbuf = play->state.gfxCtx->curFrameBuffer;
OPEN_DISPS(play->state.gfxCtx, "../z_kaleido_scope_PAL.c", 496);
tempGfxDisp = Gfx_Open(lockedGfxDisp = POLY_OPA_DISP);
gSPDisplayList(WORK_DISP++, tempGfxDisp);
GFX_ALLOC_OPEN(gfxAllocDisp, tempGfx, WORK_DISP);
PreRender_SetValues(&sPlayerPreRender, PAUSE_EQUIP_PLAYER_WIDTH, PAUSE_EQUIP_PLAYER_HEIGHT, fbuf, NULL);
PreRender_SaveFramebuffer(&sPlayerPreRender, &tempGfxDisp);
PreRender_DrawCoverage(&sPlayerPreRender, &tempGfxDisp);
PreRender_SaveFramebuffer(&sPlayerPreRender, &gfxAllocDisp);
PreRender_DrawCoverage(&sPlayerPreRender, &gfxAllocDisp);
gSPEndDisplayList(tempGfxDisp++);
Gfx_Close(lockedGfxDisp, tempGfxDisp);
POLY_OPA_DISP = tempGfxDisp;
GFX_ALLOC_CLOSE(gfxAllocDisp, tempGfx);
R_GRAPH_TASKSET00_FLAGS |= 1;