9#include <unordered_map>
12namespace acheron::ecs {
41 auto& vec = subscribers[
typeid(T)];
42 vec.push_back([&world, callback](
const std::any& e) {
43 callback(world, std::any_cast<const T&>(e));
56 void Emit(
const T& event) {
57 events[
typeid(T)].push_back(event);
67 for (
auto& [type, vec] : events) {
68 auto& subs = subscribers[type];
70 for (
auto& sub : subs) {
79 std::unordered_map<std::type_index, std::vector<std::any>> events;
80 std::unordered_map<std::type_index, std::vector<std::function<void(
const std::any&)>>> subscribers;
Manages subscribing, dispatching, and creating events.
Definition event.hpp:22
void Dispatch()
Dispatch all queued events.
Definition event.hpp:66
std::function< void(World &, const T &)> Callback
Function signature for event callbacks.
Definition event.hpp:29
void Emit(const T &event)
Emit an event.
Definition event.hpp:56
void Subscribe(World &world, Callback< T > callback)
Subscribe to an event type.
Definition event.hpp:40
Central context for the ECS.
Definition world.hpp:20
Event emitted when a component is added to an entity.
Definition event.hpp:87
Event emitted when a component is removed from an entity.
Definition event.hpp:96
Event emitted when a component is set on en entity.
Definition event.hpp:105