diff --git a/BBGE/StateMachine.cpp b/BBGE/StateMachine.cpp index 682a480..88895ff 100644 --- a/BBGE/StateMachine.cpp +++ b/BBGE/StateMachine.cpp @@ -28,7 +28,6 @@ StateMachine::StateMachine () enqueuedState = nextState = prevState = currentState = STATE_NONE; stateCounter = 0; - currentStateData = enqueuedStateData = 0; } int StateMachine::getState() @@ -46,7 +45,7 @@ int StateMachine::getPrevState() return prevState; } -void StateMachine::perform(int state, float time, void *stateData) +void StateMachine::perform(int state, float time) { //debugLog("in perform"); stateExtraDT = 0; @@ -56,33 +55,30 @@ void StateMachine::perform(int state, float time, void *stateData) // do this to prevent scripts from repeating endlessly when running main loops enqueuedState = STATE_NONE; - enqueuedStateData = 0; onExitState(currentState); stateCounter = 0; stateTime = time; currentState = state; nextState = STATE_NONE; - this->currentStateData = stateData; //debugLog("onActionInit"); onEnterState(currentState); //debugLog("done"); } -void StateMachine::setState(int state, float time, bool force, void *stateData) +void StateMachine::setState(int state, float time, bool force) { if (canSetState(state)) { if (force) { - perform(state, time, stateData); + perform(state, time); } else { enqueuedState = state; enqueuedTime = time; - enqueuedStateData = stateData; } } } @@ -140,64 +136,9 @@ void StateMachine::onUpdate (float dt) } if (enqueuedState != STATE_NONE) { - perform(enqueuedState, enqueuedTime, enqueuedStateData); + perform(enqueuedState, enqueuedTime); enqueuedState = STATE_NONE; enqueuedTime = -1; } } -void StateMachine::addCooldown(int state, float time) -{ - Cooldown c; - c.state = state; - c.timer.start(time); - cooldowns.push_back(c); -} - -bool StateMachine::isCooldown(int state) -{ - for (Cooldowns::iterator i = cooldowns.begin(); i != cooldowns.end(); i++) - { - if ((*i).state == state && (*i).timer.isActive()) - { - return true; - } - } - return false; -} - -void StateMachine::removeCooldown(int state) -{ - for (Cooldowns::iterator i = cooldowns.begin(); i != cooldowns.end(); i++) - { - if ((*i).state == state) - { - cooldowns.erase(i); - break; - } - } -} - -void StateMachine::updateCooldowns(float dt) -{ - std::queue coolqueue; - - for (Cooldowns::iterator i = cooldowns.begin(); i != cooldowns.end(); i++) - { - Cooldown *c = &((*i)); - if (c->timer.updateCheck(dt)) { - coolqueue.push(c->state); - } - } - - while (!coolqueue.empty()) - { - removeCooldown(coolqueue.back()); - coolqueue.pop(); - } -} - -void StateMachine::clearCooldowns() -{ - cooldowns.clear(); -} diff --git a/BBGE/StateMachine.h b/BBGE/StateMachine.h index 207846b..b86ba93 100644 --- a/BBGE/StateMachine.h +++ b/BBGE/StateMachine.h @@ -23,20 +23,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Base.h" -struct Cooldown -{ - int state; - Timer timer; -}; -typedef std::list Cooldowns; - class StateMachine { public: StateMachine (); virtual ~StateMachine() {} - void setState(int state, float time = -1, bool force = false, void* stateData=0); + void setState(int state, float time = -1, bool force = false); void stopState(int state); bool isState(int state); int getState(); @@ -51,15 +44,8 @@ public: }; virtual bool canSetState(int state); - void addCooldown(int state, float time); - void removeCooldown(int state); - void updateCooldowns(float dt); - bool isCooldown(int state); - void clearCooldowns(); protected: - void *currentStateData; - void *enqueuedStateData; - void perform(int state, float time = -1, void *stateData=0); + void perform(int state, float time = -1); virtual void onEnterState(int state); virtual void onExitState(int state); @@ -71,7 +57,6 @@ protected: { stateCounter = 0; } private: - Cooldowns cooldowns; float stateCounter; };