Add the ActorListIndex to ActorExtensions

This commit is contained in:
Christopher Leggett 2025-03-13 14:23:28 -04:00
parent b27eb59e2b
commit 64710b537f
No known key found for this signature in database
GPG key ID: F2121C0AF9938ABF
6 changed files with 68 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -0,0 +1,22 @@
#ifndef ACTOR_LIST_INDEX_H
#define ACTOR_LIST_INDEX_H
#include <libultraship/libultraship.h>
#include <soh/ActorExtension/ActorExtension.h>
#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

View file

@ -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 <soh/ActorExtension/ActorListIndex.h>
}
#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();

View file

@ -81,6 +81,7 @@
#include "textures/place_title_cards/g_pn_56.h"
#include "textures/place_title_cards/g_pn_57.h"
#endif
#include <soh/ActorExtension/ActorListIndex.h>
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);