6#include <tracy/Tracy.hpp>
14void Event<T>::ensureRegistered() noexcept {
15 static const bool registered = [] {
16 EventSystem::registerEvent<T>();
23auto EventSystem::info() noexcept -> EventInfo& {
24 Event<T>::ensureRegistered();
27 return event_data.at(std::type_index(
typeid(T)));
33auto Event<T>::subscribe(
char priority, callback_t&& callback)
noexcept -> iterator_t {
36 auto cb =
new callback_t(std::move(callback));
37 auto& g = EventSystem::info<T>();
39 std::scoped_lock _(g.mutex);
41 return g.callbacks.emplace(priority,
static_cast<void*
>(cb));
46void Event<T>::unsubscribe(iterator_t it)
noexcept {
49 auto& g = EventSystem::info<T>();
52 auto deleter = [](
void* p) {
delete static_cast<std::move_only_function<
bool(T&)
>*>(p); };
56 std::scoped_lock _(g.mutex);
58 g.callbacks.erase(it);
63void Event<T>::notify() noexcept {
68 auto& g = EventSystem::info<T>();
73 std::scoped_lock _(g.mutex);
77 for (
auto& [priority, callback] : g.callbacks) {
78 g.processing.emplace_back(callback);
84 for (
auto& callback : g.processing) {
85 ZoneScopedN(
"Callback dispatch");
87 bool handled = (*
static_cast<callback_t*
>(callback))(
static_cast<T&
>(*
this));
94template<
typename T,
typename... Args>
95 requires std::is_base_of_v<_detail::IEvent, T>
96void send(Args&&... args)
noexcept {
99 static_assert(std::is_constructible_v<T, Args...>,
"Invalid Construtor For Type T");
101 !std::is_same_v<std::decay_t<T>, event::InspectorContent> && !std::is_same_v<std::decay_t<T>, event::InspectorLuaContent>
110 void* memory = _detail::allocate(
sizeof(T),
alignof(T));
Public logging interface for the engine.
@ cached
The node is loaded in memory but not in use.
Definition node.hpp:56
Per-type callback registry.
Definition event.hpp:120
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::vector< std::unique_ptr< void, void(*)(void *)> > deletion_queue
Definition event.hpp:147
Definition workspace_events.hpp:448
Definition workspace_events.hpp:473