![]() |
xyginext
0.2.0
Second generation of xygine game creation framework
|
Maintains a stack of active states. More...
#include <StateStack.hpp>
Public Types | |
enum | Action { Push, Pop, Clear } |
Public Member Functions | |
StateStack (State::Context context) | |
Constructor. More... | |
StateStack (const StateStack &)=delete | |
StateStack (StateStack &&)=delete | |
StateStack & | operator= (const StateStack &)=delete |
StateStack & | operator= (StateStack &&)=delete |
template<typename T > | |
void | registerState (StateID id) |
Registers a custom state with its ID. More... | |
template<typename T , typename... Args> | |
void | registerState (StateID id, Args &&... args) |
Overload for registering states which have custom construction parameters. More... | |
void | unregisterState (StateID id) |
Unregisters a State with the given ID. | |
void | update (float dt) |
Updates each currently active state. More... | |
void | draw () |
Draws each of the active states on the stack. More... | |
void | handleEvent (const sf::Event &evt) |
Passes the current window event down to all active states, as long as the state's event handler returns true. | |
void | handleMessage (const Message &) |
Passes the current system message down to all active states. | |
void | pushState (StateID id) |
Push a new instance of a state with the given ID to the stack. More... | |
void | popState () |
Pops the top most state from the stack. | |
void | clearStates () |
Clears all states from the state stack. | |
bool | empty () const |
Returns true if there are no active states on the stack. | |
sf::View | updateView () |
Forces the stack to reevaluate the current view in relation to the resolution of the render window. More... | |
void | applyPendingChanges () |
Applies any changes requested by states active on the stack. | |
std::size_t | getStackSize () const |
Returns the number of actives states on the stack. | |
Maintains a stack of active states.
States are used to encapsulate different parts of an application or game, such as menus or the game state. States can be stacked upon each other, for example a pause state may be pushed on top of the game state so that it consumes events and input (in a pause menu) but makes sure the game state is not updated - hence paused - without losing its state altogether.
A game or app derived from the App class usually has just one state stack to manage any customs states which are created by inheriting the abstract base class State. Custom states should be assigned a unique 32 bit ID and registered with the state stack.
|
explicit |
Constructor.
context | State context containing the application state |
void xy::StateStack::draw | ( | ) |
Draws each of the active states on the stack.
This should happen between the render window clear() and display() calls.
void xy::StateStack::pushState | ( | StateID | id | ) |
Push a new instance of a state with the given ID to the stack.
id | Integer representing the ID of t he state to push on the stack |
|
inline |
Registers a custom state with its ID.
When creating new states an ID should be assigned so that when a state is requested it can be correctly constructed
|
inline |
Overload for registering states which have custom construction parameters.
id | Value to register with state |
args | List of arguments to be passed to the state constructor |
void xy::StateStack::update | ( | float | dt | ) |
Updates each currently active state.
This should be called from the App::update function so that the current frame time is passed down to each active state on the stack.
sf::View xy::StateStack::updateView | ( | ) |
Forces the stack to reevaluate the current view in relation to the resolution of the render window.
The stack then correctly calculates the letterboxing and aspect ratio before updating the context of existing states to reflect the change