From c7b998b33b034270a29e21861984a9df4d2964bc Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 23 Aug 2022 23:48:14 -0400 Subject: [PATCH] Implements better way to use new draw functions and adds Double Defense colors. --- soh/include/functions.h | 1 + soh/soh/Enhancements/randomizer/draw.cpp | 74 ++++++++++--------- soh/soh/Enhancements/randomizer/draw.h | 1 + .../Enhancements/randomizer/randomizer.cpp | 2 + soh/src/code/z_draw.c | 12 +++ soh/src/code/z_en_item00.c | 18 ++--- .../actors/ovl_Demo_Effect/z_demo_effect.c | 4 + .../actors/ovl_En_Ex_Item/z_en_ex_item.c | 4 +- soh/src/overlays/actors/ovl_En_Si/z_en_si.c | 2 +- .../actors/ovl_Item_B_Heart/z_item_b_heart.c | 4 +- .../ovl_Item_Etcetera/z_item_etcetera.c | 7 +- .../actors/ovl_Item_Ocarina/z_item_ocarina.c | 2 +- 12 files changed, 75 insertions(+), 56 deletions(-) diff --git a/soh/include/functions.h b/soh/include/functions.h index a458505e7..d3c5cfe2b 100644 --- a/soh/include/functions.h +++ b/soh/include/functions.h @@ -859,6 +859,7 @@ void Cutscene_HandleEntranceTriggers(GlobalContext* globalCtx); void Cutscene_HandleConditionalTriggers(GlobalContext* globalCtx); void Cutscene_SetSegment(GlobalContext* globalCtx, void* segment); void GetItem_Draw(GlobalContext* globalCtx, s16 drawId); +void GetItemEntry_Draw(GlobalContext* globalCtx, GetItemEntry getItemEntry); void SoundSource_InitAll(GlobalContext* globalCtx); void SoundSource_UpdateAll(GlobalContext* globalCtx); void SoundSource_PlaySfxAtFixedWorldPos(GlobalContext* globalCtx, Vec3f* pos, s32 duration, u16 sfxId); diff --git a/soh/soh/Enhancements/randomizer/draw.cpp b/soh/soh/Enhancements/randomizer/draw.cpp index fbf97c671..05cbe0165 100644 --- a/soh/soh/Enhancements/randomizer/draw.cpp +++ b/soh/soh/Enhancements/randomizer/draw.cpp @@ -6,49 +6,31 @@ #include #include "objects/object_gi_key/object_gi_key.h" #include "objects/object_gi_bosskey/object_gi_bosskey.h" +#include "objects/object_gi_hearts/object_gi_hearts.h" extern "C" void Randomizer_DrawSmallKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry) { s32 pad; - - std::array color; - switch(getItemEntry->getItemId) { - case RG_FOREST_TEMPLE_SMALL_KEY: - color = {4, 195, 46}; - break; - case RG_FIRE_TEMPLE_SMALL_KEY: - color = {237, 95, 95}; - break; - case RG_WATER_TEMPLE_SMALL_KEY: - color = {85, 180, 223}; - break; - case RG_SPIRIT_TEMPLE_SMALL_KEY: - color = {222, 158, 47}; - break; - case RG_SHADOW_TEMPLE_SMALL_KEY: - color = {126, 16, 177}; - break; - case RG_GERUDO_TRAINING_GROUNDS_SMALL_KEY: - color = {221, 212, 60}; - break; - case RG_BOTTOM_OF_THE_WELL_SMALL_KEY: - color = {227, 110, 255}; - break; - case RG_GANONS_CASTLE_SMALL_KEY: - color = {80, 80, 80}; - break; - } + + s16 color_slot = getItemEntry->getItemId - RG_FOREST_TEMPLE_SMALL_KEY; + s16 colors[8][3] = { + { 4, 195, 46 }, // Forest Temple + { 237, 95, 95 }, // Fire Temple + { 85, 180, 223 }, // Water Temple + { 222, 158, 47 }, // Spirit Temple + { 126, 16, 177 }, // Shadow Temple + { 221, 212, 60 }, // Gerudo Training Grounds + { 227, 110, 255 }, // Bottom of the Well + { 80, 80, 80 } // Ganon's Castle + }; OPEN_DISPS(globalCtx->state.gfxCtx); func_80093D18(globalCtx->state.gfxCtx); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), - G_MTX_MODELVIEW | G_MTX_LOAD); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), G_MTX_MODELVIEW | G_MTX_LOAD); - gsDPSetGrayscaleColor(POLY_OPA_DISP++, color[0], color[1], color[2], 255); + gsDPSetGrayscaleColor(POLY_OPA_DISP++, colors[color_slot][0], colors[color_slot][1], colors[color_slot][2], 255); gsSPGrayscale(POLY_OPA_DISP++, true); gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gGiSmallKeyDL); @@ -74,8 +56,6 @@ extern "C" void Randomizer_DrawBossKey(GlobalContext* globalCtx, GetItemEntry* g OPEN_DISPS(globalCtx->state.gfxCtx); func_80093D18(globalCtx->state.gfxCtx); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), - G_MTX_MODELVIEW | G_MTX_LOAD); gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), G_MTX_MODELVIEW | G_MTX_LOAD); @@ -92,8 +72,6 @@ extern "C" void Randomizer_DrawBossKey(GlobalContext* globalCtx, GetItemEntry* g } func_80093D84(globalCtx->state.gfxCtx); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), - G_MTX_MODELVIEW | G_MTX_LOAD); gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), G_MTX_MODELVIEW | G_MTX_LOAD); @@ -110,5 +88,29 @@ extern "C" void Randomizer_DrawBossKey(GlobalContext* globalCtx, GetItemEntry* g gsSPGrayscale(POLY_XLU_DISP++, false); } + CLOSE_DISPS(globalCtx->state.gfxCtx); +} + +extern "C" void Randomizer_DrawDoubleDefense(GlobalContext* globalCtx, GetItemEntry getItemEntry) { + s32 pad; + OPEN_DISPS(globalCtx->state.gfxCtx); + + func_80093D84(globalCtx->state.gfxCtx); + + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), G_MTX_MODELVIEW | G_MTX_LOAD); + + // if (drawId == doubleDef) { + gsDPSetGrayscaleColor(POLY_XLU_DISP++, 255, 255, 255, 255); + gsSPGrayscale(POLY_XLU_DISP++, true); + // } + + gSPDisplayList(POLY_XLU_DISP++, (Gfx*)gGiHeartBorderDL); + + // if (drawId == doubleDef) { + gsSPGrayscale(POLY_XLU_DISP++, false); + // } + + gSPDisplayList(POLY_XLU_DISP++, (Gfx*)gGiHeartContainerDL); + CLOSE_DISPS(globalCtx->state.gfxCtx); } \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/draw.h b/soh/soh/Enhancements/randomizer/draw.h index a703fb600..a38e99589 100644 --- a/soh/soh/Enhancements/randomizer/draw.h +++ b/soh/soh/Enhancements/randomizer/draw.h @@ -8,5 +8,6 @@ typedef struct GlobalContext GlobalContext; extern "C" void Randomizer_DrawSmallKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry); extern "C" void Randomizer_DrawBossKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry); +extern "C" void Randomizer_DrawDoubleDefense(GlobalContext* globalCtx, GetItemEntry getItemEntry); #endif \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index dbb441702..aa0427d7f 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -3894,6 +3894,8 @@ void InitRandoItemTable() { randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawSmallKey; } else if (randoGetItemTable[i].itemId >= RG_FOREST_TEMPLE_BOSS_KEY && randoGetItemTable[i].itemId <= RG_GANONS_CASTLE_BOSS_KEY) { randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawBossKey; + } else if (randoGetItemTable[i].itemId == RG_DOUBLE_DEFENSE) { + randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawDoubleDefense; } ItemTableManager::Instance->AddItemEntry(MOD_RANDOMIZER, randoGetItemTable[i].itemId, randoGetItemTable[i]); } diff --git a/soh/src/code/z_draw.c b/soh/src/code/z_draw.c index 60c3a7ee4..d85521efa 100644 --- a/soh/src/code/z_draw.c +++ b/soh/src/code/z_draw.c @@ -395,6 +395,18 @@ void GetItem_Draw(GlobalContext* globalCtx, s16 drawId) { sDrawItemTable[drawId].drawFunc(globalCtx, drawId); } +/** + * Draw "Get Item" Model from a `GetItemEntry` + * Uses the Custom Draw Function if it exists, or just calls `GetItem_Draw` + */ +void GetItemEntry_Draw(GlobalContext* globalCtx, GetItemEntry getItemEntry) { + if (getItemEntry.drawFunc != NULL) { + getItemEntry.drawFunc(globalCtx, &getItemEntry); + } else { + GetItem_Draw(globalCtx, getItemEntry.gid); + } +} + // All remaining functions in this file are draw functions referenced in the table and called by the function above /* 0x0178 */ u8 primXluColor[3]; diff --git a/soh/src/code/z_en_item00.c b/soh/src/code/z_en_item00.c index 60e33b0bd..7843583c2 100644 --- a/soh/src/code/z_en_item00.c +++ b/soh/src/code/z_en_item00.c @@ -1272,7 +1272,7 @@ void EnItem00_CustomItemsParticles(Actor* Parent, GlobalContext* globalCtx, GetI color_slot = 0; break; case RG_DOUBLE_DEFENSE: - color_slot = 1; + color_slot = 8; break; default: return; @@ -1284,14 +1284,14 @@ void EnItem00_CustomItemsParticles(Actor* Parent, GlobalContext* globalCtx, GetI s16* colors[9][3] = { { 34, 255, 76 }, // Minuet and Magic Upgrades Colors - { 177, 35, 35 }, // Bolero and Double Defense Colors + { 177, 35, 35 }, // Bolero Colors { 115, 251, 253 }, // Serenade Color { 177, 122, 35 }, // Requiem Color { 177, 28, 212 }, // Nocturne Color { 255, 255, 92 }, // Prelude Color { 31, 152, 49 }, // Stick Upgrade Color { 222, 182, 20 }, // Nut Upgrade Color - { 255, 255, 255 } // White Color placeholder + { 255, 255, 255 } // Double Defense Color }; s16* colorsEnv[9][3] = { @@ -1360,11 +1360,7 @@ void EnItem00_DrawCollectible(EnItem00* this, GlobalContext* globalCtx) { GetItemEntry randoGetItemEntry = Randomizer_GetRandomizedItem(this->getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum); EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemEntry); - if (randoGetItemEntry.drawFunc != NULL) { - randoGetItemEntry.drawFunc(globalCtx, &randoGetItemEntry); - } else { - GetItem_Draw(globalCtx, randoGetItemEntry.gid); - } + GetItemEntry_Draw(globalCtx, randoGetItemEntry); } else { s32 texIndex = this->actor.params - 3; @@ -1423,11 +1419,7 @@ void EnItem00_DrawHeartPiece(EnItem00* this, GlobalContext* globalCtx) { GetItemEntry randoGetItemEntry = Randomizer_GetRandomizedItem(GI_HEART_PIECE, this->actor.id, this->ogParams, globalCtx->sceneNum); EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemEntry); - if (randoGetItemEntry.drawFunc != NULL) { - randoGetItemEntry.drawFunc(globalCtx, &randoGetItemEntry); - } else { - GetItem_Draw(globalCtx, randoGetItemEntry.gid); - } + GetItemEntry_Draw(globalCtx, randoGetItemEntry); } else { s32 pad; diff --git a/soh/src/overlays/actors/ovl_Demo_Effect/z_demo_effect.c b/soh/src/overlays/actors/ovl_Demo_Effect/z_demo_effect.c index 8d81b41c4..12c42358b 100644 --- a/soh/src/overlays/actors/ovl_Demo_Effect/z_demo_effect.c +++ b/soh/src/overlays/actors/ovl_Demo_Effect/z_demo_effect.c @@ -2089,6 +2089,10 @@ void DemoEffect_DrawGetItem(Actor* thisx, GlobalContext* globalCtx) { if (gSaveContext.n64ddFlag && globalCtx->sceneNum == SCENE_BDAN) { GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheck(RC_BARINADE, RG_ZORA_SAPPHIRE); this->getItem.drawId = getItemEntry.gid; + func_8002EBCC(thisx, globalCtx, 0); + func_8002ED80(thisx, globalCtx, 0); + GetItemEntry_Draw(globalCtx, getItemEntry); + return; } func_8002EBCC(thisx, globalCtx, 0); func_8002ED80(thisx, globalCtx, 0); diff --git a/soh/src/overlays/actors/ovl_En_Ex_Item/z_en_ex_item.c b/soh/src/overlays/actors/ovl_En_Ex_Item/z_en_ex_item.c index 0cbc370af..495f80270 100644 --- a/soh/src/overlays/actors/ovl_En_Ex_Item/z_en_ex_item.c +++ b/soh/src/overlays/actors/ovl_En_Ex_Item/z_en_ex_item.c @@ -524,6 +524,8 @@ void EnExItem_DrawItems(EnExItem* this, GlobalContext* globalCtx) { } EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItem); + GetItemEntry_Draw(globalCtx, randoGetItem); + return; } GetItem_Draw(globalCtx, this->giDrawId); @@ -536,7 +538,7 @@ void EnExItem_DrawHeartPiece(EnExItem* this, GlobalContext* globalCtx) { GetItemEntry randoGetItem = Randomizer_GetItemFromKnownCheck(RC_MARKET_BOMBCHU_BOWLING_SECOND_PRIZE, GI_HEART_PIECE); EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItem); - GetItem_Draw(globalCtx, randoGetItem.gid); + GetItemEntry_Draw(globalCtx, randoGetItem); } else { GetItem_Draw(globalCtx, GID_HEART_PIECE); } diff --git a/soh/src/overlays/actors/ovl_En_Si/z_en_si.c b/soh/src/overlays/actors/ovl_En_Si/z_en_si.c index a9c3cb258..36fc46abb 100644 --- a/soh/src/overlays/actors/ovl_En_Si/z_en_si.c +++ b/soh/src/overlays/actors/ovl_En_Si/z_en_si.c @@ -184,7 +184,7 @@ void EnSi_Draw(Actor* thisx, GlobalContext* globalCtx) { f32 mtxScale = 1.5f; Matrix_Scale(mtxScale, mtxScale, mtxScale, MTXMODE_APPLY); } - GetItem_Draw(globalCtx, getItem.gid); + GetItemEntry_Draw(globalCtx, getItem); } } diff --git a/soh/src/overlays/actors/ovl_Item_B_Heart/z_item_b_heart.c b/soh/src/overlays/actors/ovl_Item_B_Heart/z_item_b_heart.c index 304c3053d..f4181146a 100644 --- a/soh/src/overlays/actors/ovl_Item_B_Heart/z_item_b_heart.c +++ b/soh/src/overlays/actors/ovl_Item_B_Heart/z_item_b_heart.c @@ -99,8 +99,8 @@ void ItemBHeart_Draw(Actor* thisx, GlobalContext* globalCtx) { } if (gSaveContext.n64ddFlag) { - GetItem_Draw(globalCtx, Randomizer_GetRandomizedItem(GI_HEART_CONTAINER_2, - this->actor.id,this->actor.params, globalCtx->sceneNum).gid); + GetItemEntry_Draw(globalCtx, Randomizer_GetRandomizedItem(GI_HEART_CONTAINER_2, + this->actor.id,this->actor.params, globalCtx->sceneNum)); } else { if (flag) { func_80093D84(globalCtx->state.gfxCtx); diff --git a/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.c b/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.c index eb6efef7b..c8e57237f 100644 --- a/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.c +++ b/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.c @@ -233,7 +233,7 @@ void ItemEtcetera_DrawThroughLens(Actor* thisx, GlobalContext* globalCtx) { GetItemEntry randoGetItem = GetChestGameRandoGetItem(this->actor.room, this->giDrawId, globalCtx); EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItem); if (randoGetItem.itemId != ITEM_NONE) { - GetItem_Draw(globalCtx, randoGetItem.gid); + GetItemEntry_Draw(globalCtx, randoGetItem); return; } } @@ -257,7 +257,10 @@ void ItemEtcetera_Draw(Actor* thisx, GlobalContext* globalCtx) { EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItem); if (randoGetItem.itemId != RG_NONE) { - this->giDrawId = randoGetItem.gid; + func_8002EBCC(&this->actor, globalCtx, 0); + func_8002ED80(&this->actor, globalCtx, 0); + GetItemEntry_Draw(globalCtx, randoGetItem); + return; } } diff --git a/soh/src/overlays/actors/ovl_Item_Ocarina/z_item_ocarina.c b/soh/src/overlays/actors/ovl_Item_Ocarina/z_item_ocarina.c index a8db425da..1cc8752cb 100644 --- a/soh/src/overlays/actors/ovl_Item_Ocarina/z_item_ocarina.c +++ b/soh/src/overlays/actors/ovl_Item_Ocarina/z_item_ocarina.c @@ -218,7 +218,7 @@ void ItemOcarina_Draw(Actor* thisx, GlobalContext* globalCtx) { if (gSaveContext.n64ddFlag) { GetItemEntry randoGetItem = Randomizer_GetItemFromKnownCheck(RC_HF_OCARINA_OF_TIME_ITEM, GI_OCARINA_OOT); EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItem); - GetItem_Draw(globalCtx, randoGetItem.gid); + GetItemEntry_Draw(globalCtx, randoGetItem); return; }