Dragonfly  4.3
A text-based game engine
StateMachine.h
1 ///
2 /// A finite state machine.
3 ///
4 
5 #ifndef STATEMACHINE_H
6 #define STATEMACHINE_H
7 
8 #include "Object.h"
9 #include "State.h"
10 
11 namespace df {
12 
13 class StateMachine {
14 
15  private:
16  Object *m_p_owner; /// Owner of this state machine.
17  State *m_p_state; /// Current state.
18  State *m_p_previous_state; /// Previous state.
19  State *m_p_global_state; /// Global state (reachable from any state).
20 
21  public:
22  StateMachine();
23 
24  /// Set owner of state machine.
25  void setOwner(Object *p_new_owner);
26 
27  /// Get owner of state machine.
28  Object *getOwner() const;
29 
30  /// Set current state.
31  void setState(State *p_new_state);
32 
33  /// Get current state.
34  State *getState() const;
35 
36  /// Set previous state.
37  void setPreviousState(State *p_new_state);
38 
39  /// Get previous state.
40  State *getPreviousState() const;
41 
42  /// Set global state.
43  void setGlobalState(State *p_new_state);
44 
45  /// Get global state.
46  State *getGlobalState() const;
47 
48  /// Update state machine (calling Execute() for current state).
49  void Update();
50 
51  /// Change current state.
52  void changeState(State *p_new_state);
53 
54  /// Revert to previous state.
55  void revertToPrevious();
56 };
57 
58 } // end of namespace df
59 #endif
Definition: StateMachine.h:13
void revertToPrevious()
Revert to previous state.
State * m_p_state
Owner of this state machine.
Definition: StateMachine.h:17
State * getState() const
Get current state.
A 2-d bounding box.
Definition: Box.h:10
void setOwner(Object *p_new_owner)
Set owner of state machine.
void setGlobalState(State *p_new_state)
Set global state.
Definition: State.h:14
void changeState(State *p_new_state)
Change current state.
void setState(State *p_new_state)
Set current state.
Definition: Object.h:59
State * getGlobalState() const
Get global state.
void setPreviousState(State *p_new_state)
Set previous state.
State * getPreviousState() const
Get previous state.
void Update()
Update state machine (calling Execute() for current state).
Object * getOwner() const
Get owner of state machine.
State * m_p_previous_state
Current state.
Definition: StateMachine.h:18
StateMachine()
Global state (reachable from any state).
State * m_p_global_state
Previous state.
Definition: StateMachine.h:19