nomlib
Loading...
Searching...
No Matches
nom::IState Class Reference

Abstract interface for game states. More...

#include <IState.hpp>

Public Types

enum  Flags { OpaqueUpdate = 0x2 , BackUpdate = OpaqueUpdate , OpaqueRender = 0x4 , BackRender = OpaqueRender }
 Specialized control over state management. More...
enum  Type { Parent = 0 , Child }
 State type enumeration. More...
typedef std::unique_ptr< IState > unique_ptr

Public Member Functions

 IState (void)
 Default constructor; initializes class variables to zero.
virtual ~IState (void)
 Destructor; declared virtual for inheritance.
 IState (uint32 id)
 Constructor for user-defined initialization of the class variable fields.
 IState (uint32 id, uint32 flags, IState::Type type)
 Constructor for user-defined initialization of the class variable fields.
uint32 id (void) const
 Obtain the user-defined identifier of the state.
virtual StateSymbol symbol () const
 Obtain the stack symbol for this state.
uint32 timestamp (void) const
 Obtain the recorded time stamp of the state.
uint32 flags (void) const
 Obtain the user-defined flags of the state.
IState::Type type (void) const
 Get the type of state.
void set_type (IState::Type type)
 Set the type of state.
virtual std::string input_context () const
 The nom::InputStateMapper context key associated with this state.
virtual bool on_event (const nom::Event &ev)
 User-defined implementation of the state's event handling logic.
virtual void on_update (float)
 User-defined implementation of the state's update logic.
virtual void on_draw (RenderWindow &)
virtual void on_init (void_ptr)
 User-defined implementation of the state's initialization logic.
virtual void on_exit (void_ptr)
 User-defined implementation of the state's destruction logic.
virtual void on_pause (void_ptr)
 User-defined implementation of the state's paused state logic.
virtual void on_resume (void_ptr)
 User-defined implementation of the state's resume from pause state logic.

Private Attributes

uint32 id_
 Unique identifier for the state.
uint32 timestamp_
 Number of ticks recorded at the time of state's construction.
uint32 flags_
 Specialized state management.
Type type_
 The type of state.

Detailed Description

Abstract interface for game states.

Remarks
See also nom::StateMachine, nom::SDLApp

Definition at line 53 of file IState.hpp.

Member Typedef Documentation

◆ unique_ptr

typedef std::unique_ptr<IState> nom::IState::unique_ptr

Definition at line 56 of file IState.hpp.

Member Enumeration Documentation

◆ Flags

Specialized control over state management.

Remarks
Multiple flags can be combined via bit masks.
Enumerator
OpaqueUpdate 

Request to nom::StateMachine to let the previous state continue updating itself. The name "BackUpdate" is retained as a deprecated alias for source compatibility.

OpaqueRender 

Request to nom::StateMachine to let the previous state continue rendering itself. The name "BackRender" is retained as a deprecated alias for source compatibility.

Definition at line 61 of file IState.hpp.

◆ Type

State type enumeration.

Remarks
The type of state defines the placement of it on the stack.
Enumerator
Parent 

Top-level / top-most placement on the stack.

Definition at line 79 of file IState.hpp.

Constructor & Destructor Documentation

◆ IState() [1/2]

nom::IState::IState ( uint32 id)

Constructor for user-defined initialization of the class variable fields.

Parameters
idUnique identifier of the state

◆ IState() [2/2]

nom::IState::IState ( uint32 id,
uint32 flags,
IState::Type type )

Constructor for user-defined initialization of the class variable fields.

Parameters
idUnique identifier of the state
flagsOne or more of the nom::IState::StateFlags enumerations.
typeThe type of state; one of the IState::Type enumeration values.

Member Function Documentation

◆ flags()

uint32 nom::IState::flags ( void ) const

Obtain the user-defined flags of the state.

Returns
Bit masked enumeration of nom::IState::StateFlags.
Remarks
It is not required that the state has any flags set.

◆ id()

uint32 nom::IState::id ( void ) const

Obtain the user-defined identifier of the state.

Returns
ID of the state
Remarks
It is not required that the state has an identifier set.

◆ input_context()

virtual std::string nom::IState::input_context ( ) const
virtual

The nom::InputStateMapper context key associated with this state.

When a nom::StateMachine has an input mapper installed (see nom::StateMachine::set_input_mapper) and this key is not empty, the machine activates the context after on_init and on_resume, disables it after on_pause, and erases it after on_exit. An empty key (the default) opts the state out of automatic context management.

Remarks
The context must be inserted into the mapper (e.g. in the state's constructor or on_init) before the machine activates it; activation happens after on_init returns.

◆ on_draw()

virtual void nom::IState::on_draw ( RenderWindow & )
virtual

User-defined implementation of the state's rendering logic

Parameters
IDrawable::RenderTargetRendering target (nom::RenderWindow).
Remarks
When not defined, a do-nothing implementation is provided.
Todo
Consider removing RenderTarget argument; I think we can get away with this.

◆ on_event()

virtual bool nom::IState::on_event ( const nom::Event & ev)
virtual

User-defined implementation of the state's event handling logic.

Parameters
evThe passed nom::Event object.
Returns
This method should return Boolean TRUE when the nom::Event object has been processed (think: consumed) by the user-implemented method, and boolean FALSE when the nom::Event object has not been processed (think: consumed). The default implementation returns false.
See also
StateMachine::on_event

◆ on_exit()

virtual void nom::IState::on_exit ( void_ptr )
virtual

User-defined implementation of the state's destruction logic.

Parameters
void_ptrA void pointer to user-defined data
Remarks
When not defined, a do-nothing implementation is provided.

◆ on_init()

virtual void nom::IState::on_init ( void_ptr )
virtual

User-defined implementation of the state's initialization logic.

Parameters
void_ptrA void pointer to user-defined data
Remarks
When not defined, a do-nothing implementation is provided.

◆ on_pause()

virtual void nom::IState::on_pause ( void_ptr )
virtual

User-defined implementation of the state's paused state logic.

Parameters
void_ptrA void pointer to user-defined data
Remarks
When not defined, a do-nothing implementation is provided.

◆ on_resume()

virtual void nom::IState::on_resume ( void_ptr )
virtual

User-defined implementation of the state's resume from pause state logic.

Parameters
void_ptrA void pointer to user-defined data
Remarks
When not defined, a do-nothing implementation is provided.

◆ on_update()

virtual void nom::IState::on_update ( float )
virtual

User-defined implementation of the state's update logic.

Parameters
floatUser-defined; typically a delta time (change in time).
Remarks
When not defined, a do-nothing implementation is provided.

◆ set_type()

void nom::IState::set_type ( IState::Type type)

Set the type of state.

Parameters
typeOne of the IState::Type enumeration values.

◆ symbol()

virtual StateSymbol nom::IState::symbol ( ) const
virtual

Obtain the stack symbol for this state.

Returns
The symbol used by nom::StateMachine to identify this state in its registered state table and transition table.
Remarks
Defaults to the state's id(). Override this in subclasses when the state identifier and stack symbol should differ.

◆ timestamp()

uint32 nom::IState::timestamp ( void ) const

Obtain the recorded time stamp of the state.

Returns
Number of ticks recorded at the time of construction
Remarks
Value recorded is from the return value of nom::ticks

◆ type()

IState::Type nom::IState::type ( void ) const

Get the type of state.

Returns
One of the IState::Type enumeration values.

Member Data Documentation

◆ flags_

uint32 nom::IState::flags_
private

Specialized state management.

Definition at line 226 of file IState.hpp.

◆ id_

uint32 nom::IState::id_
private

Unique identifier for the state.

Definition at line 220 of file IState.hpp.

◆ timestamp_

uint32 nom::IState::timestamp_
private

Number of ticks recorded at the time of state's construction.

Definition at line 223 of file IState.hpp.

◆ type_

Type nom::IState::type_
private

The type of state.

Definition at line 229 of file IState.hpp.


The documentation for this class was generated from the following file: