Dragonfly 4.19
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
11namespace df {
12
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:
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.
41
42 /// Set global state.
43 void setGlobalState(State *p_new_state);
44
45 /// Get global state.
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.
56};
57
58}
59#endif
Definition: Object.h:59
Definition: StateMachine.h:13
void setOwner(Object *p_new_owner)
Set owner of state machine.
State * m_p_state
Owner of this state machine.
Definition: StateMachine.h:17
void changeState(State *p_new_state)
Change current state.
void setGlobalState(State *p_new_state)
Set global state.
Object * getOwner() const
Get owner of state machine.
void setPreviousState(State *p_new_state)
Set previous state.
void setState(State *p_new_state)
Set current state.
State * getGlobalState() const
Get global state.
State * getState() const
Get current state.
State * getPreviousState() const
Get previous state.
State * m_p_previous_state
Current state.
Definition: StateMachine.h:18
void revertToPrevious()
Revert to previous state.
void Update()
Update state machine (calling Execute() for current state).
StateMachine()
Global state (reachable from any state).
State * m_p_global_state
Previous state.
Definition: StateMachine.h:19
Definition: State.h:14
An animation for a sprite.
Definition: Animation.h:15