113 FORCEINLINE
void Process(
const uint16_t MaxThreshold = 0)
115 std::scoped_lock<std::mutex> ScopedLock(Mutex);
116 const std::size_t EventsToProcess = (MaxThreshold == 0) ? EventQueue.size() : MaxThreshold;
117 for (
int Idx = 0; Idx < EventsToProcess; Idx++)
119 auto Iter = EventQueue.begin();
121 EventQueue.erase(Iter);
134 std::unique_lock<std::mutex> ScopedLock(Mutex);
135 static_assert(!std::is_enum_v<FirstFilter>,
"Enum implementation not supported yet");
137 auto IsEntryCorrectType = [](
const EventElement& Entry) ->
bool
139 return (Entry.TypeHash ==
typeid(FirstFilter).hash_code());
142 EventContainer FilteredQueue;
144 EventQueue | std::views::filter(IsEntryCorrectType),
145 std::back_inserter(FilteredQueue)
147 if (FilteredQueue.empty())
152 const std::size_t MovedEvents = std::erase_if(EventQueue, IsEntryCorrectType);
155 const std::size_t EventsToProcess = (MaxThreshold == 0) ? FilteredQueue.size() : MaxThreshold;
156 for (
int Idx = 0; Idx < EventsToProcess; Idx++)
158 auto Iter = FilteredQueue.begin();
159 LK_CORE_ASSERT(Iter->Name !=
nullptr,
"Event indexed {} is invalid in queue {}", Idx, (QueueName ? QueueName :
"NULL"));
160 #if defined(LK_ENGINE_EVENTQUEUE_DEBUG)
161 LK_CORE_CONSOLE_DEBUG(
"[{}] Executing {}: {}", QueueName, Iter->Idx, (Iter->Name ? Iter->Name :
"NULL"));
164 FilteredQueue.erase(Iter);
168 if constexpr (
sizeof...(RemainingFilters) > 0)
182 FORCEINLINE
void Add(EventArgs&&... Args)
184 std::scoped_lock<std::mutex> ScopedLock(Mutex);
185 std::shared_ptr<EventType> Event = std::make_shared<EventType>(std::forward<EventArgs>(Args)...);
186 #if defined(LK_ENGINE_EVENTQUEUE_DEBUG)
187 LK_CORE_DEBUG_TAG(LK_FMT_LIB::format(
"{}", QueueName),
"Queuing: {}", Event->GetName());
189 EventQueue.emplace_back(Event->GetName(), Event->GetType(),
typeid(*Event), EventQueue.size(), [&, Event]()
191 LK_CORE_ASSERT(Handler,
"No event handler registered");
194 LK_CORE_TRACE_TAG(
"EventQueue",
"Handling: {}", Event->ToString());
198 if (!Event->IsHandled())
200 LK_CORE_ERROR_TAG(LK_FMT_LIB::format(
"{}", QueueName),
"{}: Failed", Event->GetName());