16#include <shared_mutex>
30void TOAST_API pollEvents() noexcept;
44 friend void TOAST_API event::pollEvents()
noexcept;
45 virtual void notify()
noexcept = 0;
49auto TOAST_API allocate(std::size_t size, std::size_t align)
noexcept ->
void*;
55template<
typename T,
typename... Args>
56 requires std::is_base_of_v<_detail::IEvent, T>
57void send(Args&&... args)
noexcept;
79 friend class Listener;
80 friend class ThreadListener;
81 friend struct EventSystem;
85 using iterator_t = std::multimap<char, void*, std::greater<>>::iterator;
90 static void ensureRegistered() noexcept;
95 static auto subscribe(
char priority,
callback_t&& callback) noexcept -> iterator_t;
99 static
void unsubscribe(iterator_t it) noexcept;
102 void notify() noexcept override;
122 std::multimap<char, void*, std::greater<>> callbacks;
123 std::vector<void*> processing;
128 static std::unordered_map<std::type_index, EventInfo>
event_data;
134 static void unsubscribeAny(std::type_index type,
const std::any& iterator);
137 static auto info() noexcept ->
EventInfo&;
143 static std::unordered_map<std::type_index, std::function<
void(std::any)>>
unsubscribe_map;
153 static
void registerEvent() {
154 static_assert(std::is_base_of_v<Event<T>, T>,
"CONTRACT VIOLATION: You Must Inhert as 'struct Derived : Event<Derived>'");
160 TOAST_INFO(
"Events",
"Registering Event Type: {}",
typeid(T).name());
162 std::piecewise_construct,
163 std::forward_as_tuple(
typeid(T)),
164 std::forward_as_tuple()
168 auto it = std::any_cast<typename Event<T>::iterator_t>(iter);
169 Event<T>::unsubscribe(it);
205void registerProtoEvents();
Satisfied when ProtoTraits<T> is fully specialized with both conversion functions.
Definition event.hpp:197
Public logging interface for the engine.
#define TOAST_INFO(sink,...)
logs an information message
Definition log.hpp:83
Per-type callback registry.
Definition event.hpp:120
Internal dispatch table for the event system.
Definition event.hpp:111
static std::mutex deletion_mutex
Protects the event queue memory pool during concurrent sends.
Definition event.hpp:150
static std::shared_mutex registration_mutex
Guards event_data and unsubscribe_map.
Definition event.hpp:131
static std::unordered_map< std::type_index, EventInfo > event_data
Dispatch table keyed by event type; one entry per registered event type.
Definition event.hpp:128
static std::mutex pool_mutex
Protects the event queue memory pool during concurrent sends.
Definition event.hpp:140
static std::unordered_map< std::type_index, std::function< void(std::any)> > unsubscribe_map
Type-erased unsubscribe functions keyed by event type; used by Listener to erase iterators without th...
Definition event.hpp:143
static std::vector< std::unique_ptr< void, void(*)(void *)> > deletion_queue
Definition event.hpp:147
static void unsubscribeAny(std::type_index type, const std::any &iterator)
Unsubscribes a callback of the given type.
Definition event.cpp:51
std::move_only_function< bool(T &)> callback_t
callbacks that return 'true' are consumed and do not propogate
Definition event.hpp:84
Specialization point that exposes a C++ event type over the C# FFI via protobuf.
Definition event.hpp:188