A finite state machine.
More...
#include <StateMachine.hpp>
|
| StateMachine () noexcept |
| Constructor.
|
|
| StateMachine (StateMachine< Stored > &&) |
| Move constructor.
|
|
StateMachine< Stored > & | operator= (StateMachine< Stored > &&) |
| Move assignment operator.
|
|
virtual | ~StateMachine () |
| Destructor.
|
|
template<typename... Args> |
std::shared_ptr< Stored > | add (const std::string &key, Args &&... args) |
| Add a new state.
|
|
std::shared_ptr< Stored > | get (const std::string &key) noexcept |
| Get a specific state.
|
|
bool | has (const std::string &key) noexcept |
| Does a state exist.
|
|
void | remove (const std::string &key) |
| Remove a specific state.
|
|
void | push (const std::string &key) noexcept |
| Push a state onto the top of stack.
|
|
void | pop () noexcept |
| Remove state on top of stack.
|
|
void | pop_all () noexcept |
| Remove all states in stack.
|
|
std::shared_ptr< Stored > | top () const noexcept |
| Get top state in stack.
|
|
virtual void | update ()=0 |
| Process events and updates.
|
|
Stack & | stack () noexcept |
| Get stack.
|
|
Map & | storage () noexcept |
| Get storage.
|
|
|
using | Stack = std::vector<std::shared_ptr<Stored>> |
| We specifically use a std::vector for our stack.
|
|
using | Map = ankerl::unordered_dense::map<std::uint64_t, std::shared_ptr<Stored>> |
| Use a dense map for storage.
|
|
template<std::derived_from<
State > Stored>
class galaxy::StateMachine< Stored >
A finite state machine.
https://gameprogrammingpatterns.com/state.html
- Template Parameters
-
Stored | Object type being used in the state machine. |
Definition at line 27 of file StateMachine.hpp.
◆ Stack
template<std::derived_from<
State > Stored>
We specifically use a std::vector for our stack.
Definition at line 32 of file StateMachine.hpp.
◆ Map
template<std::derived_from<
State > Stored>
using galaxy::StateMachine< Stored >::Map = ankerl::unordered_dense::map<std::uint64_t, std::shared_ptr<Stored>> |
|
private |
◆ StateMachine() [1/3]
template<std::derived_from<
State > Stored>
◆ StateMachine() [2/3]
template<std::derived_from<
State > Stored>
◆ ~StateMachine()
template<std::derived_from<
State > Stored>
◆ StateMachine() [3/3]
template<std::derived_from<
State > Stored>
◆ operator=() [1/2]
template<std::derived_from<
State > Stored>
◆ add()
template<std::derived_from<
State > Stored>
template<typename... Args>
std::shared_ptr< Stored > galaxy::StateMachine< Stored >::add |
( |
const std::string & | key, |
|
|
Args &&... | args ) |
|
inline |
Add a new state.
- Template Parameters
-
Args | Constructor arguments for state. |
- Parameters
-
key | Name to assign to this state. |
args | Variable arguments for state constructor. |
- Returns
- Shared pointer to added scene.
Definition at line 207 of file StateMachine.hpp.
◆ get()
template<std::derived_from<
State > Stored>
Get a specific state.
- Parameters
-
- Returns
- Shared pointer to scene.
Definition at line 224 of file StateMachine.hpp.
◆ has()
template<std::derived_from<
State > Stored>
Does a state exist.
- Parameters
-
- Returns
- True if exists.
Definition at line 240 of file StateMachine.hpp.
◆ remove()
template<std::derived_from<
State > Stored>
Remove a specific state.
Will fail if state is in stack.
- Parameters
-
Definition at line 247 of file StateMachine.hpp.
◆ push()
template<std::derived_from<
State > Stored>
Push a state onto the top of stack.
- Parameters
-
Definition at line 263 of file StateMachine.hpp.
◆ pop()
template<std::derived_from<
State > Stored>
◆ pop_all()
template<std::derived_from<
State > Stored>
◆ top()
template<std::derived_from<
State > Stored>
Get top state in stack.
- Returns
- Shared pointer to top state.
Definition at line 301 of file StateMachine.hpp.
◆ update()
template<std::derived_from<
State > Stored>
◆ stack()
template<std::derived_from<
State > Stored>
◆ storage()
template<std::derived_from<
State > Stored>
◆ operator=() [2/2]
template<std::derived_from<
State > Stored>
Copy assignment operator.
◆ m_stack
template<std::derived_from<
State > Stored>
◆ m_storage
template<std::derived_from<
State > Stored>
The documentation for this class was generated from the following file: