2022-06-16 21:33:18 +00:00
|
|
|
#include "puppets/PuppetHolder.hpp"
|
2022-07-08 08:02:28 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include "actors/PuppetActor.h"
|
2022-06-16 21:33:18 +00:00
|
|
|
#include "al/util.hpp"
|
2022-07-08 22:09:04 +00:00
|
|
|
#include "al/util/LiveActorUtil.h"
|
2022-07-08 08:02:28 +00:00
|
|
|
#include "container/seadPtrArray.h"
|
|
|
|
#include "heap/seadHeap.h"
|
|
|
|
#include "heap/seadHeapMgr.h"
|
2022-06-16 21:33:18 +00:00
|
|
|
#include "logger.hpp"
|
|
|
|
|
|
|
|
PuppetHolder::PuppetHolder(int size) {
|
|
|
|
if(!mPuppetArr.tryAllocBuffer(size, nullptr)) {
|
|
|
|
Logger::log("Buffer Alloc Failed on Puppet Holder!\n");
|
|
|
|
}
|
|
|
|
}
|
2022-07-08 08:02:28 +00:00
|
|
|
/**
|
|
|
|
* @brief resizes puppet ptr array by creating a new ptr array and storing previous ptrs in it, before freeing the previous array
|
|
|
|
*
|
|
|
|
* @param size the size of the new ptr array
|
|
|
|
* @return returns true if resizing was sucessful
|
|
|
|
*/
|
|
|
|
bool PuppetHolder::resizeHolder(int size) {
|
|
|
|
|
|
|
|
if (mPuppetArr.capacity() == size)
|
|
|
|
return true; // no need to resize if we're already at the same capacity
|
|
|
|
|
|
|
|
sead::Heap *seqHeap = sead::HeapMgr::instance()->findHeapByName("SequenceHeap", 0);
|
|
|
|
|
|
|
|
if (!mPuppetArr.isBufferReady())
|
|
|
|
return mPuppetArr.tryAllocBuffer(size, seqHeap);
|
|
|
|
|
|
|
|
sead::PtrArray<PuppetActor> newPuppets = sead::PtrArray<PuppetActor>();
|
|
|
|
|
|
|
|
if (newPuppets.tryAllocBuffer(size, seqHeap)) {
|
|
|
|
|
|
|
|
int curPupCount = mPuppetArr.size();
|
|
|
|
|
|
|
|
for (int i = 0; i < curPupCount > size ? size : curPupCount; i++) {
|
|
|
|
newPuppets.pushBack(mPuppetArr[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
mPuppetArr.freeBuffer();
|
|
|
|
|
|
|
|
mPuppetArr = newPuppets;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-06-16 21:33:18 +00:00
|
|
|
|
|
|
|
bool PuppetHolder::tryRegisterPuppet(PuppetActor *puppet) {
|
|
|
|
if(!mPuppetArr.isFull()) {
|
|
|
|
mPuppetArr.pushBack(puppet);
|
|
|
|
return true;
|
|
|
|
}else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PuppetHolder::tryRegisterDebugPuppet(PuppetActor *puppet) {
|
|
|
|
mDebugPuppet = puppet;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PuppetActor *PuppetHolder::getDebugPuppet() {
|
|
|
|
if(mDebugPuppet) {
|
|
|
|
return mDebugPuppet;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PuppetHolder::update() {
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mPuppetArr.size(); i++)
|
|
|
|
{
|
|
|
|
PuppetActor *curPuppet = mPuppetArr[i];
|
|
|
|
PuppetInfo *curInfo = curPuppet->getInfo();
|
|
|
|
|
|
|
|
curInfo->isInSameStage = checkInfoIsInStage(curInfo);
|
|
|
|
|
2022-07-08 22:09:04 +00:00
|
|
|
if(curInfo->isInSameStage && al::isDead(curPuppet)) {
|
2022-06-16 21:33:18 +00:00
|
|
|
curPuppet->makeActorAlive();
|
2022-07-08 22:09:04 +00:00
|
|
|
|
|
|
|
curPuppet->emitJoinEffect();
|
|
|
|
}else if(!curInfo->isInSameStage && !al::isDead(curPuppet)) {
|
2022-06-16 21:33:18 +00:00
|
|
|
curPuppet->makeActorDead();
|
2022-07-08 22:09:04 +00:00
|
|
|
|
|
|
|
curPuppet->emitJoinEffect();
|
2022-06-16 21:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PuppetHolder::checkInfoIsInStage(PuppetInfo *info) {
|
|
|
|
if (info->isConnected) {
|
|
|
|
if (info->scenarioNo < 15) {
|
|
|
|
return al::isEqualString(mStageName.cstr(), info->stageName);
|
|
|
|
} else {
|
|
|
|
return al::isEqualString(mStageName.cstr(), info->stageName) && info->scenarioNo == mScenarioNo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PuppetHolder::setStageInfo(const char *stageName, u8 scenarioNo) {
|
|
|
|
mStageName = stageName;
|
|
|
|
mScenarioNo = scenarioNo;
|
|
|
|
}
|