From ec9b5839ade6b9ab5b9aa51260865ea7b894b496 Mon Sep 17 00:00:00 2001 From: engineer124 <47598039+engineer124@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:51:00 +1100 Subject: Cleanup gSPMatrix, rename `Matrix_New` -> `Matrix_Finalize`, add MATRIX_FINALIZE_AND_LOAD (#1729) * mtx-finalize * cleanup gSPMatrix --- src/code/z_player_lib.c | 51 +++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) (limited to 'src/code/z_player_lib.c') diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index bee458ad5..c311202b2 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -299,7 +299,7 @@ void func_80122D44(PlayState* play, struct_80122D44_arg1* arg1) { Scene_SetRenderModeXlu(play, 1, 2); gDPSetEnvColor(POLY_XLU_DISP++, temp_s3->color.r, temp_s3->color.g, temp_s3->color.b, phi_s2->alpha); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_XLU_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_XLU_DISP++, temp_s3->dList); } @@ -2046,7 +2046,7 @@ void Player_DrawHookshotReticle(PlayState* play, Player* player, f32 hookshotDis Matrix_Translate(pos.x, pos.y, pos.z, MTXMODE_NEW); Matrix_Scale(scale, scale, scale, MTXMODE_APPLY); - gSPMatrix(OVERLAY_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(OVERLAY_DISP++, play->state.gfxCtx); gSPSegment(OVERLAY_DISP++, 0x06, play->objectCtx.slots[player->actor.objectSlot].segment); gSPDisplayList(OVERLAY_DISP++, gHookshotReticleDL); @@ -2182,7 +2182,7 @@ void Player_DrawZoraShield(PlayState* play, Player* player) { gfx = POLY_XLU_DISP; - gSPMatrix(&gfx[0], Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(&gfx[0], play->state.gfxCtx); gSPDisplayList(&gfx[1], object_link_zora_DL_011760); POLY_XLU_DISP = &gfx[2]; @@ -2848,7 +2848,7 @@ void func_80126BD0(PlayState* play, Player* player, s32 arg2) { if ((arg2 != 0) && (player->stateFlags1 & PLAYER_STATE1_400000)) { OPEN_DISPS(play->state.gfxCtx); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, object_link_zora_DL_0110A8); CLOSE_DISPS(play->state.gfxCtx); @@ -2895,7 +2895,7 @@ void func_80126BD0(PlayState* play, Player* player, s32 arg2) { Matrix_Push(); Matrix_Scale(player->unk_AF0[0].x, player->unk_AF0[0].y, player->unk_AF0[0].z, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, D_801C0AB4[arg2]); @@ -2936,7 +2936,7 @@ void func_80126BD0(PlayState* play, Player* player, s32 arg2) { Matrix_Push(); Matrix_Scale(player->unk_AF0[0].x, player->unk_AF0[0].y, player->unk_AF0[0].z, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, D_801C0ABC[arg2]); Matrix_MultVec3f(&D_801C0AC4[arg2], &sp58); @@ -2976,7 +2976,7 @@ s32 func_801271B0(PlayState* play, Player* player, s32 arg2) { func_80124618(sp3C[0], player->skelAnime.curFrame, &player->unk_AF0[1]); Matrix_Scale(player->unk_AF0[1].x, player->unk_AF0[1].y, player->unk_AF0[1].z, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, D_801C0B14[arg2]); @@ -2985,7 +2985,7 @@ s32 func_801271B0(PlayState* play, Player* player, s32 arg2) { func_80124618(sp3C[1], player->skelAnime.curFrame, &player->unk_AF0[1]); Matrix_Scale(player->unk_AF0[1].x, player->unk_AF0[1].y, player->unk_AF0[1].z, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); // Close flower / Open flower gSPDisplayList(POLY_OPA_DISP++, @@ -3021,7 +3021,7 @@ s32 func_80127438(PlayState* play, Player* player, s32 currentMask) { void func_80127488(PlayState* play, Player* player, u8 alpha) { OPEN_DISPS(play->state.gfxCtx); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_XLU_DISP++, play->state.gfxCtx); gDPSetEnvColor(POLY_XLU_DISP++, 255, 0, 0, alpha); gSPDisplayList(POLY_XLU_DISP++, gLinkGoronGoronPunchEffectDL); @@ -3062,7 +3062,7 @@ void Player_DrawCircusLeadersMask(PlayState* play, Player* player) { Matrix_Translate(D_801F59B0[i].x, D_801F59B0[i].y, D_801F59B0[i].z, MTXMODE_NEW); Matrix_Scale(scaleXZ, scaleY, scaleXZ, MTXMODE_APPLY); - gSPMatrix(&gfx[0], Matrix_NewMtx(play->state.gfxCtx), G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(&gfx[0], Matrix_Finalize(play->state.gfxCtx), G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPSegment(&gfx[1], 0x08, OS_K0_TO_PHYSICAL(SEGMENTED_TO_K0(gEffBubble1Tex))); gDPSetPrimColor(&gfx[2], 0, 0, 255, 255, 255, 255); gDPSetEnvColor(&gfx[3], 150, 150, 150, 0); @@ -3466,7 +3466,7 @@ s32 func_80128640(PlayState* play, Player* player, Gfx* dList) { Matrix_Translate(-323.67f, 412.15f, -969.96f, MTXMODE_APPLY); Matrix_RotateZYX(-0x32BE, -0x50DE, -0x7717, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, D_801C0B20[mask - 1]); @@ -3483,7 +3483,7 @@ s32 func_80128640(PlayState* play, Player* player, Gfx* dList) { Matrix_RotateZYX(-0x8000, 0, 0x4000, MTXMODE_APPLY); Matrix_Scale(1.0f, player->unk_B0C, 1.0f, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, gDekuStickDL); Matrix_Pop(); @@ -3497,7 +3497,7 @@ s32 func_80128640(PlayState* play, Player* player, Gfx* dList) { Matrix_Push(); Matrix_Translate(temp_v1_2->x, temp_v1_2->y, temp_v1_2->z, MTXMODE_APPLY); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_XLU_DISP++, play->state.gfxCtx); // Note this does not check for PLAYER_BOTTLE_NONE, which would produce an OoB access on sPlayerBottleColors. // Under normal circunstances it should not be a problem because of the previous @@ -3524,7 +3524,7 @@ s32 func_80128640(PlayState* play, Player* player, Gfx* dList) { Matrix_RotateXS(sp26, MTXMODE_APPLY); Matrix_RotateYS(sp24, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, object_link_zora_DL_00E088); // hand Matrix_Pop(); @@ -3656,8 +3656,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList1, G } Matrix_Scale(1.0f, player->unk_B08, 1.0f, MTXMODE_APPLY); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), - G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_XLU_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_XLU_DISP++, D_801C0D94); Matrix_Pop(); @@ -3765,8 +3764,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList1, G Matrix_Push(); Matrix_Scale(player->unk_AF0[1].x, player->unk_AF0[1].y, player->unk_AF0[1].z, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), - G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, object_link_goron_DL_00FC18); @@ -3776,8 +3774,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList1, G Matrix_Push(); Matrix_Scale(sp178[i].x, sp178[i].y, sp178[i].z, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), - G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, D_801C0DF0[i]); Matrix_Pop(); @@ -3823,8 +3820,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList1, G Matrix_Translate(temp_s0_4->x, temp_s0_4->z, 0.0f, MTXMODE_APPLY); Matrix_Scale(1.0f, 1.0f - player->unk_B10[3], 1.0f - player->unk_B10[2], MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), - G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); Matrix_Pop(); @@ -3848,8 +3844,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList1, G Matrix_Scale(player->unk_AF0[0].x, player->unk_AF0[0].y, player->unk_AF0[0].z, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), - G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, object_link_nuts_DL_00A348); Matrix_Pop(); @@ -3897,8 +3892,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList1, G Matrix_Push(); Matrix_Scale(player->arr_AF0[0], player->arr_AF0[0], player->arr_AF0[0], MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), - G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); gSPDisplayList(POLY_OPA_DISP++, object_link_nuts_DL_007390); Matrix_Pop(); @@ -3907,8 +3901,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList1, G Matrix_Push(); Matrix_Scale(spF0[i].x, spF0[i].y, spF0[i].z, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), - G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_OPA_DISP++, play->state.gfxCtx); //! FAKE: (yes, all of them are required) // https://decomp.me/scratch/AdU3G if (1) {} @@ -3946,7 +3939,7 @@ void Player_PostLimbDrawGameplay(PlayState* play, s32 limbIndex, Gfx** dList1, G Matrix_Scale(0.7f, 0.7f, 0.7f, MTXMODE_APPLY); } - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + MATRIX_FINALIZE_AND_LOAD(POLY_XLU_DISP++, play->state.gfxCtx); gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 255, (u8)player->av2.actionVar2); gSPDisplayList(POLY_XLU_DISP++, gameplay_keep_DL_054C90); -- cgit v1.2.3