Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
StateMachine.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Development Kit"
3 // For conditions of distribution and use, see copyright notice in Prerequesites.hpp
4 
5 #pragma once
6 
7 #ifndef NDK_STATEMACHINE_HPP
8 #define NDK_STATEMACHINE_HPP
9 
10 #include <NDK/Prerequesites.hpp>
11 #include <NDK/State.hpp>
12 #include <memory>
13 #include <vector>
14 
15 namespace Ndk
16 {
18  {
19  public:
20  inline StateMachine(std::shared_ptr<State> originalState);
21  StateMachine(const StateMachine&) = delete;
22  inline StateMachine(StateMachine&& fsm) = default;
23  inline ~StateMachine();
24 
25  inline void ChangeState(std::shared_ptr<State> state);
26 
27  inline const std::shared_ptr<State>& GetCurrentState() const;
28 
29  inline bool IsTopState(const State* state) const;
30 
31  inline std::shared_ptr<State> PopState();
32  inline bool PopStatesUntil(std::shared_ptr<State> state);
33  inline void PushState(std::shared_ptr<State> state);
34 
35  inline void SetState(std::shared_ptr<State> state);
36 
37  inline bool Update(float elapsedTime);
38 
39  inline StateMachine& operator=(StateMachine&& fsm) = default;
40  StateMachine& operator=(const StateMachine&) = delete;
41 
42  private:
43  std::vector<std::shared_ptr<State>> m_states;
44  };
45 }
46 
47 #include <NDK/StateMachine.inl>
48 
49 #endif // NDK_STATEMACHINE_HPP
TODO: For now is unable to display different color in the history, it needs a RichTextDrawer to do so...
Definition: Algorithm.hpp:12
bool Update(float elapsedTime)
Updates all the states.
Definition: StateMachine.inl:168
void SetState(std::shared_ptr< State > state)
Pops every states of the machine to put a new one.
Definition: StateMachine.inl:150
const std::shared_ptr< State > & GetCurrentState() const
Gets the current state on the top of the machine.
Definition: StateMachine.inl:67
~StateMachine()
Destructs the object.
Definition: StateMachine.inl:37
NDK class that represents a state machine, to represent the multiple states of your program as a stac...
Definition: StateMachine.hpp:17
NDK class that represents a state of your application.
Definition: State.hpp:16
void ChangeState(std::shared_ptr< State > state)
Replaces the current state on the top of the machine.
Definition: StateMachine.inl:49
bool PopStatesUntil(std::shared_ptr< State > state)
Pops all the states of the machine until a specific one is reached.
Definition: StateMachine.inl:114
std::shared_ptr< State > PopState()
Pops the state on the top of the machine.
Definition: StateMachine.inl:94
void PushState(std::shared_ptr< State > state)
Pushes a new state on the top of the machine.
Definition: StateMachine.inl:133
bool IsTopState(const State *state) const
Checks whether the state is on the top of the machine.
Definition: StateMachine.inl:79
StateMachine(std::shared_ptr< State > originalState)
Constructs a StateMachine object with an original state.
Definition: StateMachine.inl:25