MapObj: Implement ElectricTargetInfo (#978)

This commit is contained in:
guymakinggames 2026-04-05 16:39:48 +01:00 committed by GitHub
parent 4e7041e57e
commit 08748a421b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 127 additions and 11 deletions

View file

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

View file

@ -0,0 +1,77 @@
#include "MapObj/ElectricTargetInfo.h"
#include <math/seadMathCalcCommon.h>
#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<TargetInfo>();
mPool = new sead::PtrArray<TargetInfo>();
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();
}

View file

@ -0,0 +1,39 @@
#pragma once
#include <container/seadPtrArray.h>
#include <math/seadVector.h>
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<TargetInfo>* mInfos;
sead::PtrArray<TargetInfo>* mPool;
};