From 08748a421ba6153f1334afb2d76dfb7577615d7a Mon Sep 17 00:00:00 2001 From: guymakinggames <66076221+guymakinggames@users.noreply.github.com> Date: Sun, 5 Apr 2026 16:39:48 +0100 Subject: [PATCH] MapObj: Implement `ElectricTargetInfo` (#978) --- data/file_list.yml | 22 ++++----- src/MapObj/ElectricTargetInfo.cpp | 77 +++++++++++++++++++++++++++++++ src/MapObj/ElectricTargetInfo.h | 39 ++++++++++++++++ 3 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 src/MapObj/ElectricTargetInfo.cpp create mode 100644 src/MapObj/ElectricTargetInfo.h diff --git a/data/file_list.yml b/data/file_list.yml index 42fac3c2..5b4540cf 100644 --- a/data/file_list.yml +++ b/data/file_list.yml @@ -67724,45 +67724,45 @@ MapObj/ElectricTargetInfo.o: - offset: 0x266a74 size: 144 label: _ZNK10TargetInfo4distEv - status: NotDecompiled + status: Matching - offset: 0x266b04 size: 188 label: - _ZN14TargetInfoListC1Ev - _ZN14TargetInfoListC2Ev - status: NotDecompiled + status: Matching - offset: 0x266bc0 size: 100 label: _ZN14TargetInfoList5clearEv - status: NotDecompiled + status: Matching - offset: 0x266c24 size: 104 label: _ZN14TargetInfoList6appendEPKN2al9LiveActorES3_i - status: NotDecompiled + status: Matching - offset: 0x266c8c size: 144 label: _ZN14TargetInfoList6removeEPKN2al9LiveActorE - status: NotDecompiled + status: Matching - offset: 0x266d1c size: 88 label: _ZN14TargetInfoList6removeEi - status: NotDecompiled + status: Matching - offset: 0x266d74 size: 76 label: _ZNK14TargetInfoList9isIncludeEPKN2al9LiveActorE - status: NotDecompiled + status: Matching - offset: 0x266dc0 size: 88 label: _ZN14TargetInfoList6elapseEv - status: NotDecompiled + status: Matching - offset: 0x266e18 size: 180 label: _ZN14TargetInfoList7surviveEv - status: NotDecompiled + status: Matching - offset: 0x266ecc size: 16 label: _ZN14TargetInfoList4sortEv - status: NotDecompiled + status: Matching MapObj/ElectricWire.o: '.text': - offset: 0x266edc @@ -68045,7 +68045,7 @@ MapObj/ElectricWire.o: - offset: 0x26d954 size: 408 label: _ZN4sead8PtrArrayI10TargetInfoE8compareTEPKS1_S4_ - status: NotDecompiled + status: Matching lazy: true - offset: 0x26daec size: 28 diff --git a/src/MapObj/ElectricTargetInfo.cpp b/src/MapObj/ElectricTargetInfo.cpp new file mode 100644 index 00000000..51b156c1 --- /dev/null +++ b/src/MapObj/ElectricTargetInfo.cpp @@ -0,0 +1,77 @@ +#include "MapObj/ElectricTargetInfo.h" + +#include + +#include "Library/LiveActor/ActorPoseUtil.h" + +f32 TargetInfo::dist() const { + sead::Vector3f targetPos = al::getTrans(target); + const sead::Vector3f& actorPos = al::getTrans(actor); + return (targetPos - actorPos).length(); +} + +TargetInfoList::TargetInfoList() { + mInfos = new sead::PtrArray(); + mPool = new sead::PtrArray(); + mInfos->allocBuffer(8, nullptr); + mPool->allocBuffer(8, nullptr); + for (s32 i = 0; i < 8; i++) + mPool->pushBack(new TargetInfo()); +} + +void TargetInfoList::clear() { + while (mInfos->size() != 0) + mPool->pushBack(mInfos->popBack()); +} + +void TargetInfoList::append(const al::LiveActor* actor, const al::LiveActor* target, s32 timer) { + if (mPool->isEmpty()) + return; + + TargetInfo* info = mPool->popBack(); + info->actor = actor; + info->target = target; + info->timer = timer; + mInfos->pushBack(info); +} + +void TargetInfoList::remove(const al::LiveActor* actor) { + for (s32 i = 0; i < mInfos->size(); i++) { + if ((*mInfos)[i]->actor == actor) { + remove(i); + return; + } + } +} + +void TargetInfoList::remove(s32 index) { + mPool->pushBack((*mInfos)[index]); + mInfos->erase(index); +} + +bool TargetInfoList::isInclude(const al::LiveActor* actor) const { + for (s32 i = 0; i < mInfos->size(); i++) + if ((*mInfos)[i]->actor == actor) + return true; + return false; +} + +void TargetInfoList::elapse() { + for (s32 i = 0; i < mInfos->size(); i++) { + TargetInfo* info = (*mInfos)[i]; + if (info->timer != 0) + info->timer--; + } +} + +void TargetInfoList::survive() { + for (s32 i = 0; i < mInfos->size();) + if ((*mInfos)[i]->timer != 0) + i++; + else + remove(i); +} + +void TargetInfoList::sort() { + mInfos->sort(); +} diff --git a/src/MapObj/ElectricTargetInfo.h b/src/MapObj/ElectricTargetInfo.h new file mode 100644 index 00000000..77b7d39e --- /dev/null +++ b/src/MapObj/ElectricTargetInfo.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include + +namespace al { +class LiveActor; +} + +struct TargetInfo { + TargetInfo() {} + + f32 dist() const; + + bool operator<(const TargetInfo& other) const { return dist() < other.dist(); } + + const al::LiveActor* actor = nullptr; + s32 timer = 0; + const al::LiveActor* target = nullptr; +}; + +static_assert(sizeof(TargetInfo) == 0x18); + +class TargetInfoList { +public: + TargetInfoList(); + void clear(); + void append(const al::LiveActor* actor, const al::LiveActor* target, s32 timer); + void remove(const al::LiveActor* actor); + void remove(s32 index); + bool isInclude(const al::LiveActor* actor) const; + void elapse(); + void survive(); + void sort(); + +private: + sead::PtrArray* mInfos; + sead::PtrArray* mPool; +};