5#include "flint/core/api.h"
6#include "flint/core/state-ops.h"
7#include "flint/graphics/renderer.h"
8#include "flint/window/IWindow.h"
12#include <unordered_map>
13#include <unordered_set>
27 virtual ~State() =
default;
40 virtual void update(
float deltaTime) = 0;
67 std::string m_contextName;
83 void registerStateType() {
84 m_stateOpsRegistry.registerOps(makeStateOps<T>());
87 FLINT_API
void handleInput(
IWindow &window);
88 FLINT_API
void update(
float deltaTime);
147 [[nodiscard]] FLINT_API
bool empty()
const;
183 FLINT_API
const std::vector<std::unique_ptr<State>> &
getStates()
const;
196 State *topState)
const;
206 FLINT_API
bool canInstallStateOps(
const StateOps *operations, std::size_t count)
const;
208 FLINT_API
void installStateOps(
const StateOps *operations, std::size_t count);
211 std::vector<std::unique_ptr<State>> m_states;
212 std::deque<PendingTransition> m_transitionQueue;
214 std::unordered_set<StateTypeId> collectRequiredTypeIds()
const;
215 [[nodiscard]]
const StateOps *getStateOps(
const State *state)
const;
217 void dispatchOnEnter(
State *state);
218 void dispatchOnExit(
State *state);
223 std::unordered_map<const State *, StateTypeId> m_stateTypes;
High-level SDL GPU renderer managing pipeline state, batching, and frame presentation.
Abstract interface for a platform window.
Manages a stack of States and applies queued transitions.
FLINT_API State * peekBelow(const State *top) const
Return the state directly below top on the stack.
FLINT_API void resetStates(std::unique_ptr< State > state)
Clears all states from the stack and pushes a new root state.
FLINT_API void pushState(std::unique_ptr< State > state)
Push a new state onto the stack and activate it.
FLINT_API bool empty() const
Check if there are any states in the stack.
FLINT_API void renderAllBelow(GPURenderer &gpuRenderer, IWindow &window, State *topState) const
Render all states below topState in bottom-up order.
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 popState()
Pop the current state and resume the one beneath.
FLINT_API void applyTransitions()
Execute all pending transitions in FIFO order.
FLINT_API const std::vector< std::unique_ptr< State > > & getStates() const
Return read-only access to the full state deque.
FLINT_API void replaceState(std::unique_ptr< State > state)
Replace the current state with a new one.
TransitionType
Describes the kind of stack operation to perform on transition.
FLINT_API State * currentState() const
Get currently active (top) state.
FLINT_API void clearStates()
Remove all states from the stack, calling onExit() on each.
Abstract base for a single game state (scene / screen).
virtual void update(float deltaTime)=0
Advance the simulation logic for this state by deltaTime seconds.
virtual void onExit()
Called immediately before this state is removed from the top of the stack.
virtual void onEnter()
Called immediately after this state becomes the top of the stack.
virtual void render(GPURenderer &gpuRenderer, IWindow &window)=0
Issue all draw calls necessary to visualize this state.
virtual void handleInput(IWindow &window)=0
Process raw input events and translate them into state-specific actions.
Transition description queued for later application.
std::unique_ptr< State > state