Files
BT411/engine/MUNGA/EVENT.h
T
arcattackandClaude Opus 4.8 7b3e76db38 Load-time attribution: the minute is the renderers' entity-make streams
Measured (loadphase markers + queue blocker dump): renderer LoadMission
31ms, model loads 0.2s -- the teal->green minute is the LoadingMission
ready-gate (IsPriorityEmpty counts timed events too) waiting out the
THREE renderers' entity-make streams: every entity/subsystem creation
posts message 3 to each Renderer receiver (classIDs 8/30/36 =
video/audio/gauge), hundreds deep per queue, draining across the whole
window (the audio renderer's share is why sound starts mid-load).

Instrumentation kept: [loadphase] markers (renderer span + busy-pass
counter) always on; GeneralEventQueue::DumpBlockers + the class-named
DumpData fallback behind BT_LOAD_DIAG=1 (hundreds of lines per load).
Optimizing the drain (batching/budget) is an open perf item --
deliberately untouched before the 8-player night.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 20:41:36 -05:00

348 lines
7.1 KiB
C++

#pragma once
#include "time.h"
#include "slot.h"
#include "network.h"
class GeneralEventQueue;
class EventQueue;
class DeferredEventQueue;
class Entity;
//##########################################################################
//######################## AbstractEvent #############################
//##########################################################################
class AbstractEvent:
public Node
{
friend class GeneralEventQueue;
friend class EventStatisticsManager;
//##########################################################################
// Event Functionality
//
protected:
AbstractEvent(
Receiver::Message *message,
Time time,
ClassID class_id
);
~AbstractEvent();
public:
virtual void
Process();
virtual void
DumpData();
protected:
Time alarmTime;
Receiver::Message* messageToSend;
};
//##########################################################################
//############################ Event #################################
//##########################################################################
class Event:
public AbstractEvent
{
friend class GeneralEventQueue;
friend class EventQueue;
friend class Receiver;
friend class DeferredEventQueue;
friend class Entity;
friend class EventStatisticsManager;
//##########################################################################
// Node Support
//
private:
void
ReleaseLinkHandler(
Socket *socket,
Plug *plug
);
//##########################################################################
// Memory Allocation Support
//
private:
static MemoryBlock* GetAllocatedMemory();
void* operator new(size_t) { return GetAllocatedMemory()->New(); }
void operator delete(void *where) { GetAllocatedMemory()->Delete(where); }
//##########################################################################
// Event Functionality
//
private:
Event(
Receiver *target,
Receiver::Message *message,
Time time
);
~Event();
public:
void
Repost(
EventQueue *queue,
int priority,
Time new_time=Time::Null
);
void
Defer();
void
Process();
void
DumpData();
private:
SlotOf<Receiver*> targetReceiver;
};
//##########################################################################
//######################## NetworkEvent ##############################
//##########################################################################
class NetworkEvent:
public AbstractEvent
{
friend class GeneralEventQueue;
//##########################################################################
// Event Functionality
//
private:
enum EventStyle
{
SendStyle,
BroadcastStyle,
ExclusiveBroadcastStyle
};
NetworkEvent(
HostID hostID,
NetworkManager::ClientID client_ID,
EventStyle event_style,
Receiver::Message *message,
Time time
);
~NetworkEvent();
public:
void
Process();
private:
HostID
hostID;
NetworkManager::ClientID
clientID;
EventStyle
eventStyle;
};
//##########################################################################
//#################### GeneralEventQueue ############################
//##########################################################################
//
// NOTE: Do not create any static event queues! new must be used to allocate
// all event queue objects
//
class GeneralEventQueue:
public Node
{
friend class Event;
//##########################################################################
// EventQueue Allocation
//
public:
GeneralEventQueue(ClassID class_ID);
GeneralEventQueue();
~GeneralEventQueue();
static GeneralEventQueue*
Make(
int priorities,
const char* trace_name=NULL
);
protected:
int
priorityLevels;
ChainOf<AbstractEvent*>
pendingEvents;
ChainOf<AbstractEvent*>
timedEvents;
int
eventCount;
#if defined(TRACE_EVENT_COUNT)
TraceOf<int>
*eventCountTrace;
#endif
//##########################################################################
// EventQueue Functionality
//
public:
void
Post(
int priority,
Receiver *target,
Receiver::Message *message,
Time when=Time::Null
);
void
SendEvent(
int priority,
HostID host_ID,
NetworkManager::ClientID client_id,
Receiver::Message *message,
Time when=Time::Null
);
void
BroadcastEvent(
int priority,
NetworkManager::ClientID client_id,
Receiver::Message *message,
Time when=Time::Null
);
void
ExclusiveBroadcastEvent(
int priority,
NetworkManager::ClientID client_id,
Receiver::Message *message,
Time when=Time::Null
);
int
GetEventCount()
{return eventCount;}
AbstractEvent*
PeekAtNextEvent(int min_priority=0);
Logical
IsPriorityEmpty(int priority);
// LOAD-ATTRIBUTION DIAG (2026-07-22): name every event holding a
// priority level non-empty (the LoadingMission ready-gate blocker hunt).
void
DumpBlockers(int priority);
Logical
ProcessOneEvent(int min_priority=0);
void
ProcessAllEvents(int min_priority=0);
void
FlushAllEvents(int max_priority=-1);
void
FlushMatchingEvents(
Receiver::MessageID target_message,
int max_priority=-1
);
void
Enqueue(
int priority,
AbstractEvent *event
);
//##########################################################################
// Testing Support
//
public:
void
DumpEventQueue();
};
//##########################################################################
//######################### EventQueue ###############################
//##########################################################################
class EventQueue:
public GeneralEventQueue
{
//##########################################################################
// EventQueue Allocation
//
public:
EventQueue();
static EventQueue*
Make(
int priorities,
const char* trace_name=NULL
);
~EventQueue();
//##########################################################################
// EventQueue Posting & Processing
//
public:
Event*
PeekAtNextEvent(int min_priority=0)
{
return
(Event*)GeneralEventQueue::PeekAtNextEvent(min_priority);
}
void
ProcessMatchingEvents(
Receiver *receiver,
Receiver::MessageID message_ID=Receiver::AnyMessageID
);
//##########################################################################
// Testing Support
//
public:
static Logical
TestClass();
};
//##########################################################################
//##################### DeferredEventQueue ###########################
//##########################################################################
//
// NOTE: Do not create any static event queues! new must be used to allocate
// all event queue objects
//
class DeferredEventQueue:
public Node
{
friend class Event;
//##########################################################################
// Node Support
//
private:
void
ReleaseLinkHandler(
Socket *socket,
Plug *plug
);
//##########################################################################
// Deferred Queue Functionality
//
public:
DeferredEventQueue(Receiver *target);
~DeferredEventQueue();
void
ProcessAllEvents()
{Check(this); deferredEvents->ProcessAllEvents();}
private:
EventQueue
*deferredEvents;
SlotOf<Receiver*>
waitingReceiver;
};