Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
Flint::StateManager Class Reference

Manages a stack of States and applies queued transitions. More...

#include <flint/core/state.h>

+ Collaboration diagram for Flint::StateManager:

Classes

struct  PendingTransition
 Transition description queued for later application. More...
 

Public Types

enum class  TransitionType {
  PUSH , POP , REPLACE , CLEAR ,
  RESET
}
 Describes the kind of stack operation to perform on transition. More...
 

Public Member Functions

template<typename T >
void registerStateType ()
 
FLINT_API void handleInput (IWindow &window)
 
FLINT_API void update (float deltaTime)
 
FLINT_API void render (GPURenderer &renderer, IWindow &window)
 
FLINT_API void pushState (std::unique_ptr< State > state)
 Push a new state onto the stack and activate it.
 
FLINT_API void popState ()
 Pop the current state and resume the one beneath.
 
FLINT_API void replaceState (std::unique_ptr< State > state)
 Replace the current state with a new one.
 
FLINT_API State * currentState () const
 Get currently active (top) state.
 
FLINT_API bool empty () const
 Check if there are any states in the stack.
 
FLINT_API void queueTransition (TransitionType type, std::unique_ptr< State > newState)
 Enqueue a state transition to be applied on the next applyTransitions() call.
 
FLINT_API void applyTransitions ()
 Execute all pending transitions in FIFO order.
 
FLINT_API void clearStates ()
 Remove all states from the stack, calling onExit() on each.
 
FLINT_API void resetStates (std::unique_ptr< State > state)
 Clears all states from the stack and pushes a new root state.
 
FLINT_API const std::vector< std::unique_ptr< State > > & getStates () const
 Return read-only access to the full state deque.
 
FLINT_API void renderAllBelow (GPURenderer &gpuRenderer, IWindow &window, State *topState) const
 Render all states below topState in bottom-up order.
 
FLINT_API State * peekBelow (const State *top) const
 Return the state directly below top on the stack.
 
FLINT_API bool canInstallStateOps (const StateOps *operations, std::size_t count) const
 
FLINT_API void installStateOps (const StateOps *operations, std::size_t count)
 

Detailed Description

Manages a stack of States and applies queued transitions.

Transitions are deferred: call queueTransition() any time during a frame and the actual push/pop/replace will happen when applyTransitions() is called (typically once per frame before update/render).

Definition at line 77 of file state.h.

Member Enumeration Documentation

◆ TransitionType

Describes the kind of stack operation to perform on transition.

Enumerator
PUSH 

Push a new state on top; current state pauses (onExit).

POP 

Remove the top state; the state below resumes (onEnter).

REPLACE 

Replace the top state with a new one.

CLEAR 

Remove all states from the stack.

RESET 

Remove all states and push a new root state.

Definition at line 94 of file state.h.

Member Function Documentation

◆ applyTransitions()

FLINT_API void Flint::StateManager::applyTransitions ( )

Execute all pending transitions in FIFO order.

Should be called once per frame before update() and render(). Invokes onExit() on states being removed and onEnter() on states that become the new top.

◆ currentState()

FLINT_API State * Flint::StateManager::currentState ( ) const
nodiscard

Get currently active (top) state.

Returns
Pointer to the top State, or nullptr if the stack is empty.

◆ empty()

FLINT_API bool Flint::StateManager::empty ( ) const
nodiscard

Check if there are any states in the stack.

Returns
true if the stack is empty, false otherwise.

◆ getStates()

FLINT_API const std::vector< std::unique_ptr< State > > & Flint::StateManager::getStates ( ) const

Return read-only access to the full state deque.

Returns
Const reference to the underlying state container (bottom to top).

◆ peekBelow()

FLINT_API State * Flint::StateManager::peekBelow ( const State * top) const

Return the state directly below top on the stack.

Parameters
topThe reference state (must be in the stack).
Returns
Pointer to the state below top, or nullptr if none exists.

◆ popState()

FLINT_API void Flint::StateManager::popState ( )

Pop the current state and resume the one beneath.

Invokes onExit() on the removed state and onEnter() on the revealed one.

◆ pushState()

FLINT_API void Flint::StateManager::pushState ( std::unique_ptr< State > state)

Push a new state onto the stack and activate it.

Calls onExit() on the outgoing top (if any) and onEnter() on the new state.

Parameters
stateState instance to take ownership of and push.

◆ queueTransition()

FLINT_API void Flint::StateManager::queueTransition ( TransitionType type,
std::unique_ptr< State > newState )

Enqueue a state transition to be applied on the next applyTransitions() call.

Parameters
typeThe transition kind (PUSH, POP, or REPLACE).
newStateThe state to push or replace with (ignored for POP).

◆ registerStateType()

template<typename T >
void Flint::StateManager::registerStateType ( )
inline

Definition at line 83 of file state.h.

◆ renderAllBelow()

FLINT_API void Flint::StateManager::renderAllBelow ( GPURenderer & gpuRenderer,
IWindow & window,
State * topState ) const

Render all states below topState in bottom-up order.

Useful for transparent or overlay states that need the state beneath them to be visible.

Parameters
gpuRendererThe renderer passed to each state's render call.
windowActive window passed to each state's render call.
topStateThe state to stop at (it is not rendered by this call).

◆ replaceState()

FLINT_API void Flint::StateManager::replaceState ( std::unique_ptr< State > state)

Replace the current state with a new one.

Safely exits and removes the old top, then pushes the provided state and enters it.

Parameters
stateReplacement state; if null, the stack simply loses its top.

◆ resetStates()

FLINT_API void Flint::StateManager::resetStates ( std::unique_ptr< State > state)

Clears all states from the stack and pushes a new root state.

Parameters
stateThe new root state.

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