4#include <SFML/Window/Event.hpp>
20 virtual void handleInput(
const sf::Event::KeyEvent &keyPressed) = 0;
74 const unsigned int lives
111 [[nodiscard]]
bool empty()
const;
130 void swap(
const std::shared_ptr<State>& state);
136 void push(
const std::shared_ptr<State>& state);
150 void clear(
const std::shared_ptr<State>& state);
159 std::unique_ptr<GameContext> gameContext;
161 std::stack<std::shared_ptr<State>> states;
163 enum Command { NONE, SWAP, PUSH, POP, CLEAR };
164 struct PendingCommand {
165 Command command = Command::NONE;
166 std::shared_ptr<State> state =
nullptr;
169 PendingCommand pendingCommand;
Definition StateManager.h:13
virtual void handleInput(const sf::Event::KeyEvent &keyPressed)=0
Handler for KeyPressed events.
State(StateManager &ctx)
Creates the base State object.
Definition StateManager.cpp:4
virtual void render()=0
Render function that is called in the main Game loop.
virtual void resized()=0
Called when the window is resized.
StateManager & context
Definition StateManager.h:54
virtual void update(double dt)=0
Definition StateManager.h:96
State & top()
Returns the top of the manager stack.
Definition StateManager.cpp:16
StateManager()
Definition StateManager.cpp:7
void push(const std::shared_ptr< State > &state)
Pushes the state to the stack. Does this by updating pending command.
Definition StateManager.cpp:36
void executeCommand()
Applies any pending command, if there is any pending command.
Definition StateManager.cpp:50
GameContext & getGameContext() const
Returns the GameContext struct.
Definition StateManager.cpp:26
void swap(const std::shared_ptr< State > &state)
Helper function for swapping the top state with a new state. Does this by updating the pending comman...
Definition StateManager.cpp:31
void clear(const std::shared_ptr< State > &state)
Clears the state stack and pushes the new state. Does this by updating pending command.
Definition StateManager.cpp:45
void pop()
Pops the top state from the stack. Does this by updating pending command.
Definition StateManager.cpp:40
bool empty() const
Returns whether the manager stack is empty.
Definition StateManager.cpp:21
Definition StateManager.h:65
std::string username
Definition StateManager.h:68
unsigned int lives
Definition StateManager.h:69
std::shared_ptr< logic::Score > scoreSystem
Definition StateManager.h:66
std::shared_ptr< SoundManager > soundManager
Definition StateManager.h:67
GameContext(const std::shared_ptr< logic::Score > &scoreSystem, const std::shared_ptr< SoundManager > &soundManager, const unsigned int lives)
Definition StateManager.h:71