mirror of
https://github.com/encounter/Petari.git
synced 2026-03-30 11:34:15 -07:00
53 lines
1.4 KiB
C++
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;
|
|
}
|