|
Flint Engine
Modular C++20 2D game engine powered by SDL3
|
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) |
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).
|
strong |
Describes the kind of stack operation to perform on transition.
| 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.
|
nodiscard |
Get currently active (top) state.
|
nodiscard |
Check if there are any states in the stack.
| FLINT_API const std::vector< std::unique_ptr< State > > & Flint::StateManager::getStates | ( | ) | const |
Return read-only access to the full state deque.
Return the state directly below top on the stack.
| top | The reference state (must be in the stack). |
top, or nullptr if none exists. | 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.
| 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.
| state | State instance to take ownership of and push. |
| 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.
| type | The transition kind (PUSH, POP, or REPLACE). |
| newState | The state to push or replace with (ignored for POP). |
|
inline |
| 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.
| gpuRenderer | The renderer passed to each state's render call. |
| window | Active window passed to each state's render call. |
| topState | The state to stop at (it is not rendered by this call). |
| 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.
| state | Replacement state; if null, the stack simply loses its top. |
| FLINT_API void Flint::StateManager::resetStates | ( | std::unique_ptr< State > | state | ) |
Clears all states from the stack and pushes a new root state.
| state | The new root state. |