xyginext  0.2.0
Second generation of xygine game creation framework
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
xy::State Class Referenceabstract

Abstract base class for xygine states. More...

#include <State.hpp>

Classes

struct  Context
 Contains information about the current application context. More...
 

Public Types

using Ptr = std::unique_ptr< State >
 

Public Member Functions

 State (StateStack &stateStack, Context context)
 Constructor. More...
 
 State (const State &)=delete
 
 State (State &&)=delete
 
Stateoperator= (const State &)=delete
 
Stateoperator= (State &&)=delete
 
virtual bool handleEvent (const sf::Event &evt)=0
 Receives window events from the state stack to which the state belongs. More...
 
virtual void handleMessage (const Message &)=0
 Receives system messages from the message bus via the state stack to which the state belongs. More...
 
virtual bool update (float dt)=0
 Passes in the frame time once per frame. More...
 
virtual void draw ()=0
 Function to handle drawing. More...
 
virtual StateID stateID () const =0
 Returns the unique ID of this state.
 
void setContext (Context)
 Applies a new context for this state. More...
 

Protected Member Functions

void requestStackPush (StateID id)
 Request a new instance of a state with the given ID be pushed on top of the state stack to which this state belongs. More...
 
void requestStackPop ()
 Request that the state on top of the stack to which this state belongs is popped (and therefore destroyed)
 
void requestStackClear ()
 Request that all active states in the stack to which this state belongs are destroyed.
 
std::size_t getStackSize () const
 Returns the current number of states on the active state stack.
 
Context getContext () const
 Returns a copy of the state's current context.
 
void launchLoadingScreen ()
 
void quitLoadingScreen ()
 
virtual void updateLoadingScreen (float dt, sf::RenderWindow &)
 
std::size_t getStateCount () const
 Returns the number of active states on this state's stack.
 

Detailed Description

Abstract base class for xygine states.

States are used in conjunction with the StateStack to encapsulate the data required to display different states such as the main menu, pause screen, or game state

Constructor & Destructor Documentation

◆ State()

xy::State::State ( StateStack stateStack,
Context  context 
)

Constructor.

Parameters
stateStackState stack to which this state should be added
contextThe app's current context

Member Function Documentation

◆ draw()

virtual void xy::State::draw ( )
pure virtual

Function to handle drawing.

The App derived class should handle the clear() and display() functions outside of the state stack to which this state belongs so any drawing can be done here via getContext().renderWindow

◆ handleEvent()

virtual bool xy::State::handleEvent ( const sf::Event &  evt)
pure virtual

Receives window events from the state stack to which the state belongs.

Returns
true if events should continue to be passed up the stack, else false. For example when displaying a pause state over the top of a game state input events should be consumed so that they do not affect the running game state underneath

◆ handleMessage()

virtual void xy::State::handleMessage ( const Message )
pure virtual

Receives system messages from the message bus via the state stack to which the state belongs.

Messages can either be handle here, passed on to state members (such as a Scene) or both.

◆ launchLoadingScreen()

void xy::State::launchLoadingScreen ( )
protected

Optionally call these at the beginning and end of a state ctor which loads a lot of resources. Main game updates are suspended so you MUST call quitLoadingScreen() when finished.

◆ requestStackPush()

void xy::State::requestStackPush ( StateID  id)
protected

Request a new instance of a state with the given ID be pushed on top of the state stack to which this state belongs.

Parameters
idStateID of state to be pushed on to the stack

◆ setContext()

void xy::State::setContext ( Context  )

Applies a new context for this state.

Used by xygine to update the default view should the render window be resized or toggled between full screen

◆ update()

virtual bool xy::State::update ( float  dt)
pure virtual

Passes in the frame time once per frame.

Members of the state such as a Scene object can be updated here.

◆ updateLoadingScreen()

virtual void xy::State::updateLoadingScreen ( float  dt,
sf::RenderWindow &   
)
protectedvirtual

Optionally overload this to draw custom graphics during loading. As this runs in its own thread SYNCHRONISATION IS UP TO YOU.