00001 #ifndef __STATE_H 00002 #define __STATE_H 00003 00004 class FSM; 00005 00006 // States are stored in the FSM class (Finite state machine) 00007 // The FSM only has one active state at a time and stores the state history stack 00008 // State data can be held in this class - however data which is used between states is best stored elsewhere. 00009 class State 00010 { 00011 public: 00012 State(); 00013 ~State(); 00014 // OnEnter is called when this state will not be the current state 00015 // loadResources true means this state is now in the history stack and was not there before 00016 virtual void OnEnter(const FSM *caller, bool loadResources); 00017 // OnLeave is called when this state is currently the current state and will no longer be the current state 00018 // unloadResources true means this state is no longer in the history stack and we will probably not be entering it again via the back button 00019 virtual void OnLeave(const FSM *caller, bool unloadResources); 00020 // Called once for every time this state is added to the FSM history stack 00021 virtual void FSMAddRef(const FSM *caller); 00022 // Called once for every time this state is removed from the FSM history stack. 00023 virtual void FSMRemoveRef(const FSM *caller); 00024 // The number of times this state is in the FSM history stack. 00025 unsigned FSMRefCount(void) const; 00026 protected: 00027 unsigned fsmRefCount; 00028 }; 00029 00030 // Same as State, but self-deletes when fsmRefCount==0 00031 class ManagedState : public State 00032 { 00033 public: 00034 virtual void FSMRemoveRef(const FSM *caller); 00035 }; 00036 00037 #endif
1.7.1