Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions luth/source/luth/core/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ namespace Luth
m_FrameData.Shutdown();
IOThread::Shutdown();
JobSystem::Shutdown();
EventBus::FlushAll();
Memory::TaggedPageAllocator::Get().Shutdown();
Memory::MemoryTracker::Shutdown();
}
Expand Down
26 changes: 26 additions & 0 deletions luth/source/luth/events/EventBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ namespace Luth
GetBus(bus).ProcessEvents();
}

// Drop any queued events and subscribers without dispatching.
static void Flush(BusType bus) {
GetBus(bus).Flush();
}

// Drop all queued events and subscribers without dispatching.
static void FlushAll() {
for (size_t i = 0; i < static_cast<size_t>(BusType::COUNT); ++i) {
GetBus(static_cast<BusType>(i)).Flush();
}
}

class BusInstance {
public:
template<typename T, typename... Args>
Expand Down Expand Up @@ -151,6 +163,20 @@ namespace Luth
}
}

void Flush() {
std::queue<std::pair<EventPtr, EventTypeID>> pending;
{
std::lock_guard<std::mutex> lock(m_QueueLock);
pending.swap(m_EventQueue);
}

while (!pending.empty())
pending.pop();

m_Subscribers.clear();
m_NextSubId = 0;
}

template<typename T>
static EventTypeID GetEventTypeID() {
static EventTypeID typeID = NextEventTypeID();
Expand Down