State

Pure virtual State class, used as base class for Photon’s state system.

Photon’s State system is extremely simple yet also very convenient.  Simply by creating classes that fulfill the State interface you can use Photon to manage the state that the game is in.

Implement as many or as few of the members of State as needed (the only necessary member being render) and make the state as current via Application::setState.  Once a state is made current it’s update and render methods will be called every frame until either a new state is made current or the application ends.

The active state is also notified of events as they occur, overloading any of the on* functions will result in the overloaded version being called when the particular event happens while the state is active.

Summary
Pure virtual State class, used as base class for Photon’s state system.
A State’s constructor is called whenever the state is made active via Application::setState.
A State’s destructor is called whenever the state is no longer the active state (the application ends, or a new state is made active).
All of a state’s logic should go in update, it is called every frame before the rendering process begins.
The only required member of State, anything that should be drawn to the screen while the State is active should be drawn in render.
If a state is executing and a new state is pushed onto the stack via Application::pushState the state will be paused until a time that it is either unpaused or popped from the stack itself.
If a state has been paused and is then made current again by the state(s) pushed on top of it being popped, the state management system will call onResume allowing the state to undo any work that had been done in onPause.
Called when a key is pressed.
Called when a key is released.
Called when a mouse button is pressed.
Called when a mouse button is released.
Called when the mouse is moved with the amount the mouse was moved by NOT with the new position.
Called when mouse wheel is scrolled.

(Con/ De)structors

State

State()

A State’s constructor is called whenever the state is made active via Application::setState.

~State

virtual ~State()

A State’s destructor is called whenever the state is no longer the active state (the application ends, or a new state is made active).

State Functions

update

virtual void update(scalar timeDelta)

All of a state’s logic should go in update, it is called every frame before the rendering process begins.  Nothing should be drawn to the screen within update because it will be cleared before it is shown.

render

virtual void render()=0

The only required member of State, anything that should be drawn to the screen while the State is active should be drawn in render.  Game logic inside of render should be kept to a minimum for optimum performance.

onPause

virtual void onPause()

If a state is executing and a new state is pushed onto the stack via Application::pushState the state will be paused until a time that it is either unpaused or popped from the stack itself.  When it is paused the state management system will call onPause which may perform any necessary work before the state goes idle.

onResume

virtual void onResume()

If a state has been paused and is then made current again by the state(s) pushed on top of it being popped, the state management system will call onResume allowing the state to undo any work that had been done in onPause.

Keyboard Actions

onKeyPress

virtual void onKeyPress(KeyCode key)

Called when a key is pressed.

Parameters

keyKeyCode of key that has been pressed.

onKeyRelease

virtual void onKeyRelease(KeyCode key)

Called when a key is released.

Parameters

keyKeyCode of key that has been released.

Mouse Actions

onMouseButtonPress

virtual void onMouseButtonPress(MouseButton button)

Called when a mouse button is pressed.

Parameters

buttonMouseButton that was pressed.

onMouseButtonRelease

virtual void onMouseButtonRelease(MouseButton button)

Called when a mouse button is released.

Parameters

buttonMouseButton that was released.

onMouseMove

virtual void onMouseMove(const math::Vector2 &delta)

Called when the mouse is moved with the amount the mouse was moved by NOT with the new position.

If the new position is needed it can be obtained via <getMouseX> and <getMouseY>.

Parameters

deltaChange in mouse position.

onMouseScroll

virtual void onMouseScroll(ScrollDir dir)

Called when mouse wheel is scrolled.

Parameters

dirScrollDir describing if mouse wheel was scrolled up or down.
State()
A State’s constructor is called whenever the state is made active via Application::setState.
template<class StateT> void setState()
Set the current Application State, removing all other States.
virtual ~State()
A State’s destructor is called whenever the state is no longer the active state (the application ends, or a new state is made active).
virtual void update(scalar timeDelta)
All of a state’s logic should go in update, it is called every frame before the rendering process begins.
virtual void render()=0
The only required member of State, anything that should be drawn to the screen while the State is active should be drawn in render.
virtual void onPause()
If a state is executing and a new state is pushed onto the stack via Application::pushState the state will be paused until a time that it is either unpaused or popped from the stack itself.
template<class StateT> void pushState()
Push a new State, does not remove old State.
virtual void onResume()
If a state has been paused and is then made current again by the state(s) pushed on top of it being popped, the state management system will call onResume allowing the state to undo any work that had been done in onPause.
virtual void onKeyPress(KeyCode key)
Called when a key is pressed.
virtual void onKeyRelease(KeyCode key)
Called when a key is released.
virtual void onMouseButtonPress(MouseButton button)
Called when a mouse button is pressed.
virtual void onMouseButtonRelease(MouseButton button)
Called when a mouse button is released.
virtual void onMouseMove(const math::Vector2 &delta)
Called when the mouse is moved with the amount the mouse was moved by NOT with the new position.
virtual void onMouseScroll(ScrollDir dir)
Called when mouse wheel is scrolled.
Enumeration defining keys, used in Application::keyPressed.
Enumeration defining buttons, used in Application::mouseButtonPressed.
Enumeration defining scroll direction of mouse wheel.