Files
Petari/source/Game/LiveActor/ActorStateKeeper.cpp
2024-01-15 15:57:14 -05:00

53 lines
1.4 KiB
C++

#include "Game/LiveActor/ActorStateKeeper.hpp"
#include "Game/LiveActor/Nerve.hpp"
ActorStateKeeper::ActorStateKeeper(int capacity)
: mStatesCapacity(capacity), mLength(0), mStates(NULL), mCurrentState(NULL) {
mStates = new State [capacity];
for(s32 i = 0; i < mStatesCapacity; i++) {
State& e = mStates[i];
e.mInterface = NULL;
e.mNerve = NULL;
e.mName = NULL;
}
}
bool ActorStateKeeper::updateCurrentState() {
return (!mCurrentState) ? false : (mCurrentState->mInterface)->update();
}
void ActorStateKeeper::startState(const Nerve *pNerve) {
mCurrentState = findStateInfo(pNerve);
if (mCurrentState) {
ActorStateBaseInterface* interface = mCurrentState->mInterface;
interface->appear();
}
}
void ActorStateKeeper::endState(const Nerve *pNerve) {
mCurrentState = findStateInfo(pNerve);
if (mCurrentState) {
ActorStateBaseInterface* interface = mCurrentState->mInterface;
if (!interface->mIsDead) {
interface->kill();
}
}
}
void ActorStateKeeper::addState(ActorStateBaseInterface* pInterface, const Nerve* pNerve, const char* pName) {
State& e = mStates[mLength];
e.mInterface = pInterface;
e.mNerve = pNerve;
e.mName = pName;
mLength += 1;
}
ActorStateKeeper::State* ActorStateKeeper::findStateInfo(const Nerve *pNerve) {
for(int i = 0; i < mLength; i++) {
if(mStates[i].mNerve == pNerve) return &mStates[i];
}
return NULL;
}