diff --git a/soh/soh/ActorExtension/ActorExtension.cpp b/soh/soh/ActorExtension/ActorExtension.cpp index 576e1c695..df82cd769 100644 --- a/soh/soh/ActorExtension/ActorExtension.cpp +++ b/soh/soh/ActorExtension/ActorExtension.cpp @@ -60,7 +60,7 @@ void ActorExtension_Free(Actor* actor) { return; } - for (auto& [ id, size ] : sGlobalSizes) { + for (auto& [id, size] : sGlobalSizes) { auto it = sData.find(std::make_pair(actor, id)); if (it != sData.end()) { free(it->second); diff --git a/soh/soh/ActorExtension/ActorExtension.h b/soh/soh/ActorExtension/ActorExtension.h index 70850889c..01441f76d 100644 --- a/soh/soh/ActorExtension/ActorExtension.h +++ b/soh/soh/ActorExtension/ActorExtension.h @@ -5,7 +5,7 @@ #ifdef __cplusplus extern "C" { - #include +#include #endif typedef uint32_t ActorExtensionId; @@ -24,4 +24,4 @@ void ActorExtension_Free(Actor* actor); } #endif -#endif //ACTOR_EXTENSION_H \ No newline at end of file +#endif // ACTOR_EXTENSION_H \ No newline at end of file diff --git a/soh/soh/ActorExtension/ActorListIndex.cpp b/soh/soh/ActorExtension/ActorListIndex.cpp new file mode 100644 index 000000000..e46436d85 --- /dev/null +++ b/soh/soh/ActorExtension/ActorListIndex.cpp @@ -0,0 +1,32 @@ +#include "ActorListIndex.h" +#include "soh/ShipInit.hpp" +#include "soh/Enhancements/game-interactor/GameInteractor.h" + +ActorExtensionId actorListIndexActorExt = 0; +int16_t currentActorListIndex = -1; + +static RegisterShipInitFunc initFunc( + []() { + if (actorListIndexActorExt == 0) { + actorListIndexActorExt = ActorExtension_CreateForAll(sizeof(int16_t)); + } + }, + {}); + +int16_t GetActorListIndex(Actor* actor) { + int16_t* listIndex = (int16_t*)ActorExtension_Get(actor, actorListIndexActorExt); + if (listIndex == nullptr) { + return -1; + } + return *listIndex; +} + +void SetActorListIndex(Actor* actor, int16_t index) { + int16_t* listIndex = (int16_t*)ActorExtension_Get(actor, actorListIndexActorExt); + + if (listIndex == nullptr) { + assert(false); + } else { + *listIndex = index; + } +} \ No newline at end of file diff --git a/soh/soh/ActorExtension/ActorListIndex.h b/soh/soh/ActorExtension/ActorListIndex.h new file mode 100644 index 000000000..397cc7e37 --- /dev/null +++ b/soh/soh/ActorExtension/ActorListIndex.h @@ -0,0 +1,22 @@ +#ifndef ACTOR_LIST_INDEX_H +#define ACTOR_LIST_INDEX_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#include "z64actor.h" +#endif + +extern ActorExtensionId actorListIndexActorExt; +extern int16_t currentActorListIndex; + +int16_t GetActorListIndex(Actor* actor); +void SetActorListIndex(Actor* actor, int16_t index); + +#ifdef __cplusplus +} +#endif + +#endif // ACTOR_LIST_INDEX_H \ No newline at end of file diff --git a/soh/soh/Enhancements/debugger/actorViewer.cpp b/soh/soh/Enhancements/debugger/actorViewer.cpp index 8ae940ffb..bbd57ee3a 100644 --- a/soh/soh/Enhancements/debugger/actorViewer.cpp +++ b/soh/soh/Enhancements/debugger/actorViewer.cpp @@ -26,6 +26,7 @@ extern PlayState* gPlayState; #include "textures/icon_item_static/icon_item_static.h" #include "textures/icon_item_24_static/icon_item_24_static.h" +#include } #define DEKUNUTS_FLOWER 10 @@ -924,6 +925,7 @@ void ActorViewerWindow::DrawElement() { ImGui::Text("Category: %s", acMapping[display->category]); ImGui::Text("ID: %d", display->id); ImGui::Text("Parameters: %d", display->params); + ImGui::Text("Actor List Index: %d", GetActorListIndex(display)); }, "Selected Actor"); ImGui::SameLine(); diff --git a/soh/src/code/z_actor.c b/soh/src/code/z_actor.c index 5e942d5fd..56f65516c 100644 --- a/soh/src/code/z_actor.c +++ b/soh/src/code/z_actor.c @@ -81,6 +81,7 @@ #include "textures/place_title_cards/g_pn_56.h" #include "textures/place_title_cards/g_pn_57.h" #endif +#include static CollisionPoly* sCurCeilingPoly; static s32 sCurCeilingBgId; @@ -2575,8 +2576,14 @@ void Actor_UpdateAll(PlayState* play, ActorContext* actorCtx) { if (play->numSetupActors != 0) { actorEntry = &play->setupActorList[0]; for (i = 0; i < play->numSetupActors; i++) { + // #region SOH [ActorExtension] ActorListIndex tracking + currentActorListIndex = i; + // #endregion Actor_SpawnEntry(&play->actorCtx, actorEntry++, play); } + // #region SOH [ActorExtension] ActorListIndex tracking + currentActorListIndex = -1; + // #endregion play->numSetupActors = 0; GameInteractor_ExecuteOnSceneSpawnActors(); } @@ -3355,6 +3362,8 @@ Actor* Actor_Spawn(ActorContext* actorCtx, PlayState* play, s16 actorId, f32 pos // #region SOH [ActorExtension] ActorExtension_Alloc(actor, dbEntry->id); + SetActorListIndex(actor, currentActorListIndex); + currentActorListIndex = -1; // #endregion assert(dbEntry->numLoaded < 255);