Files

53 lines
1.4 KiB
C++
Raw Permalink Normal View History

#include "Game/LiveActor/ActorStateKeeper.hpp"
#include "Game/LiveActor/Nerve.hpp"
2021-12-14 01:31:13 -05:00
2024-01-15 15:57:14 -05:00
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;
}
}
2021-12-14 01:31:13 -05:00
bool ActorStateKeeper::updateCurrentState() {
2024-01-15 15:57:14 -05:00
return (!mCurrentState) ? false : (mCurrentState->mInterface)->update();
2021-12-14 01:31:13 -05:00
}
void ActorStateKeeper::startState(const Nerve *pNerve) {
mCurrentState = findStateInfo(pNerve);
if (mCurrentState) {
2024-01-15 15:57:14 -05:00
ActorStateBaseInterface* interface = mCurrentState->mInterface;
2021-12-14 01:31:13 -05:00
interface->appear();
}
}
void ActorStateKeeper::endState(const Nerve *pNerve) {
mCurrentState = findStateInfo(pNerve);
if (mCurrentState) {
2024-01-15 15:57:14 -05:00
ActorStateBaseInterface* interface = mCurrentState->mInterface;
2021-12-14 01:31:13 -05:00
if (!interface->mIsDead) {
interface->kill();
}
}
}
2024-01-15 15:57:14 -05:00
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;
}