25 enum class operation :
unsigned int
35 void push_state(state::ID state_id)
noexcept;
36 void pop_state()
noexcept;
37 void clear_states()
noexcept;
54 m_factories.insert_or_assign(state_id, [
this]()
56 return std::make_unique<T>(runtime_context,
this);
61 template <
typename Po
inter>
64 auto reversed = m_states | std::views::reverse;
66 auto it = std::ranges::find_if(reversed, [](
const auto& sp)
68 return dynamic_cast<Pointer
>(sp.get()) !=
nullptr;
71 if (it != std::ranges::cend(reversed))
73 return dynamic_cast<Pointer
>(it->get());
82 explicit pending_change(operation action, state::ID
id = state::ID::TOTAL)
83 : action(action), state_id(id)
93 std::size_t operator()(state::ID
id)
const noexcept
95 return std::hash<unsigned int>{}(
static_cast<unsigned int>(id));
100 void apply_pending_changes() noexcept;
102 [[nodiscard]] std::unique_ptr<state> create_state(state::ID state_id)
104 if (
const auto& found = m_factories.find(state_id); found != m_factories.cend())
106 return found->second();
109 throw std::runtime_error(
"runtime_stack::create_state - No factory for state ID: " +
110 std::to_string(
static_cast<unsigned int>(state_id)));
113 std::vector<std::unique_ptr<state>> m_states;
114 std::vector<pending_change> m_pending;
115 runtime_app::context runtime_context;
116 std::unordered_map<state::ID,
117 std::function<std::unique_ptr<state>()>,
void register_state(state::ID state_id)
Register a factory for a concrete state type. The factory is called with (runtime_context,...
Definition runtime_stack.h:52
void visit_states(const std::optional< args > &args, double elapsed) noexcept
Visit each state top-to-bottom, calling update(args, elapsed) until one returns false....
struct representing the context passed to states in the runtime_app stack
Definition runtime_app.h:34