9#include <unordered_map>
18 using StateTypeId = std::uint64_t;
20 [[nodiscard]]
constexpr StateTypeId hashStateTypeName(std::string_view name) {
21 StateTypeId hash = 14695981039346656037ull;
23 for (
const char character : name) {
24 hash ^=
static_cast<unsigned char>(character);
25 hash *= 1099511628211ull;
32 StateTypeId stateTypeId() {
33 return hashStateTypeName(
typeid(T).name());
40 std::size_t alignment;
43 void (*update)(
State *, float);
46 void (*onEnter)(
State *);
47 void (*onExit)(
State *);
53 .typeId = stateTypeId<T>(),
55 .alignment =
alignof(T),
57 .handleInput = [](
State *state,
58 IWindow &window) {
static_cast<T *
>(state)->T::handleInput(window); },
60 .update = [](State *state,
61 float deltaTime) {
static_cast<T *
>(state)->T::update(deltaTime); },
63 .render = [](State *state, GPURenderer &renderer,
64 IWindow &window) {
static_cast<T *
>(state)->T::render(renderer, window); },
66 .onEnter = [](State *state) {
static_cast<T *
>(state)->T::onEnter(); },
68 .onExit = [](State *state) {
static_cast<T *
>(state)->T::onExit(); },
75 m_registeredOperations[ops.typeId] = ops;
78 void replaceModuleOps(
const StateOps *operations, std::size_t count) {
79 std::unordered_map<StateTypeId, StateOps> next;
82 for (std::size_t i = 0; i < count; ++i) {
83 next[operations[i].typeId] = operations[i];
86 m_moduleOperations = std::move(next);
89 [[nodiscard]]
const StateOps *get(StateTypeId typeId)
const {
90 if (
const auto it = m_moduleOperations.find(typeId); it != m_moduleOperations.end()) {
94 if (
const auto it = m_registeredOperations.find(typeId);
95 it != m_registeredOperations.end()) {
102 [[nodiscard]]
bool hasModuleOps(StateTypeId typeId)
const {
103 return m_moduleOperations.contains(typeId);
107 std::unordered_map<StateTypeId, StateOps> m_registeredOperations;
108 std::unordered_map<StateTypeId, StateOps> m_moduleOperations;
High-level SDL GPU renderer managing pipeline state, batching, and frame presentation.
Abstract interface for a platform window.
Abstract base for a single game state (scene / screen).