- made the event manager an object so it can be instantiated multiple times.
This commit is contained in:
parent
8d83f03138
commit
484485f3cf
21 changed files with 257 additions and 246 deletions
236
src/events.cpp
236
src/events.cpp
|
|
@ -42,14 +42,14 @@
|
|||
#include "g_game.h"
|
||||
#include "info.h"
|
||||
|
||||
DStaticEventHandler* E_FirstEventHandler = nullptr;
|
||||
DStaticEventHandler* E_LastEventHandler = nullptr;
|
||||
EventManager eventManager;
|
||||
|
||||
bool E_RegisterHandler(DStaticEventHandler* handler)
|
||||
|
||||
bool EventManager::RegisterHandler(DStaticEventHandler* handler)
|
||||
{
|
||||
if (handler == nullptr || handler->ObjectFlags & OF_EuthanizeMe)
|
||||
return false;
|
||||
if (E_CheckHandler(handler))
|
||||
if (CheckHandler(handler))
|
||||
return false;
|
||||
|
||||
handler->OnRegister();
|
||||
|
|
@ -57,7 +57,7 @@ bool E_RegisterHandler(DStaticEventHandler* handler)
|
|||
// link into normal list
|
||||
// update: link at specific position based on order.
|
||||
DStaticEventHandler* before = nullptr;
|
||||
for (DStaticEventHandler* existinghandler = E_FirstEventHandler; existinghandler; existinghandler = existinghandler->next)
|
||||
for (DStaticEventHandler* existinghandler = FirstEventHandler; existinghandler; existinghandler = existinghandler->next)
|
||||
{
|
||||
if (existinghandler->Order > handler->Order)
|
||||
{
|
||||
|
|
@ -67,9 +67,9 @@ bool E_RegisterHandler(DStaticEventHandler* handler)
|
|||
}
|
||||
|
||||
// 1. MyHandler2->1:
|
||||
// E_FirstEventHandler = MyHandler2, E_LastEventHandler = MyHandler2
|
||||
// eventManager.FirstEventHandler = MyHandler2, eventManager.LastEventHandler = MyHandler2
|
||||
// 2. MyHandler3->2:
|
||||
// E_FirstEventHandler = MyHandler2, E_LastEventHandler = MyHandler3
|
||||
// eventManager.FirstEventHandler = MyHandler2, eventManager.LastEventHandler = MyHandler3
|
||||
|
||||
// (Yes, all those write barriers here are really needed!)
|
||||
if (before != nullptr)
|
||||
|
|
@ -87,9 +87,9 @@ bool E_RegisterHandler(DStaticEventHandler* handler)
|
|||
GC::WriteBarrier(handler, before->prev);
|
||||
before->prev = handler;
|
||||
GC::WriteBarrier(before, handler);
|
||||
if (before == E_FirstEventHandler)
|
||||
if (before == FirstEventHandler)
|
||||
{
|
||||
E_FirstEventHandler = handler;
|
||||
FirstEventHandler = handler;
|
||||
GC::WriteBarrier(handler);
|
||||
}
|
||||
}
|
||||
|
|
@ -97,11 +97,11 @@ bool E_RegisterHandler(DStaticEventHandler* handler)
|
|||
{
|
||||
// so if before is null, it means add last.
|
||||
// it can also mean that we have no handlers at all yet.
|
||||
handler->prev = E_LastEventHandler;
|
||||
GC::WriteBarrier(handler, E_LastEventHandler);
|
||||
handler->prev = LastEventHandler;
|
||||
GC::WriteBarrier(handler, LastEventHandler);
|
||||
handler->next = nullptr;
|
||||
if (E_FirstEventHandler == nullptr) E_FirstEventHandler = handler;
|
||||
E_LastEventHandler = handler;
|
||||
if (FirstEventHandler == nullptr) FirstEventHandler = handler;
|
||||
LastEventHandler = handler;
|
||||
GC::WriteBarrier(handler);
|
||||
if (handler->prev != nullptr)
|
||||
{
|
||||
|
|
@ -118,11 +118,11 @@ bool E_RegisterHandler(DStaticEventHandler* handler)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool E_UnregisterHandler(DStaticEventHandler* handler)
|
||||
bool EventManager::UnregisterHandler(DStaticEventHandler* handler)
|
||||
{
|
||||
if (handler == nullptr || handler->ObjectFlags & OF_EuthanizeMe)
|
||||
return false;
|
||||
if (!E_CheckHandler(handler))
|
||||
if (!CheckHandler(handler))
|
||||
return false;
|
||||
|
||||
handler->OnUnregister();
|
||||
|
|
@ -138,14 +138,14 @@ bool E_UnregisterHandler(DStaticEventHandler* handler)
|
|||
handler->next->prev = handler->prev;
|
||||
GC::WriteBarrier(handler->next, handler->prev);
|
||||
}
|
||||
if (handler == E_FirstEventHandler)
|
||||
if (handler == FirstEventHandler)
|
||||
{
|
||||
E_FirstEventHandler = handler->next;
|
||||
FirstEventHandler = handler->next;
|
||||
GC::WriteBarrier(handler->next);
|
||||
}
|
||||
if (handler == E_LastEventHandler)
|
||||
if (handler == LastEventHandler)
|
||||
{
|
||||
E_LastEventHandler = handler->prev;
|
||||
LastEventHandler = handler->prev;
|
||||
GC::WriteBarrier(handler->prev);
|
||||
}
|
||||
if (handler->IsStatic())
|
||||
|
|
@ -156,7 +156,7 @@ bool E_UnregisterHandler(DStaticEventHandler* handler)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool E_SendNetworkEvent(FString name, int arg1, int arg2, int arg3, bool manual)
|
||||
bool EventManager::SendNetworkEvent(FString name, int arg1, int arg2, int arg3, bool manual)
|
||||
{
|
||||
if (gamestate != GS_LEVEL)
|
||||
return false;
|
||||
|
|
@ -172,21 +172,21 @@ bool E_SendNetworkEvent(FString name, int arg1, int arg2, int arg3, bool manual)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool E_CheckHandler(DStaticEventHandler* handler)
|
||||
bool EventManager::CheckHandler(DStaticEventHandler* handler)
|
||||
{
|
||||
for (DStaticEventHandler* lhandler = E_FirstEventHandler; lhandler; lhandler = lhandler->next)
|
||||
for (DStaticEventHandler* lhandler = FirstEventHandler; lhandler; lhandler = lhandler->next)
|
||||
if (handler == lhandler) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool E_IsStaticType(PClass* type)
|
||||
bool EventManager::IsStaticType(PClass* type)
|
||||
{
|
||||
assert(type != nullptr);
|
||||
assert(type->IsDescendantOf(RUNTIME_CLASS(DStaticEventHandler)));
|
||||
return !type->IsDescendantOf(RUNTIME_CLASS(DEventHandler));
|
||||
}
|
||||
|
||||
void E_SerializeEvents(FSerializer& arc)
|
||||
void EventManager::SerializeEvents(FSerializer& arc)
|
||||
{
|
||||
// todo : stuff
|
||||
if (arc.BeginArray("eventhandlers"))
|
||||
|
|
@ -197,12 +197,12 @@ void E_SerializeEvents(FSerializer& arc)
|
|||
{
|
||||
numlocalhandlers = arc.ArraySize();
|
||||
// delete all current local handlers, if any
|
||||
for (DStaticEventHandler* lhandler = E_FirstEventHandler; lhandler; lhandler = lhandler->next)
|
||||
for (DStaticEventHandler* lhandler = FirstEventHandler; lhandler; lhandler = lhandler->next)
|
||||
if (!lhandler->IsStatic()) lhandler->Destroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (DStaticEventHandler* lhandler = E_FirstEventHandler; lhandler; lhandler = lhandler->next)
|
||||
for (DStaticEventHandler* lhandler = FirstEventHandler; lhandler; lhandler = lhandler->next)
|
||||
{
|
||||
if (lhandler->IsStatic()) continue;
|
||||
numlocalhandlers++;
|
||||
|
|
@ -231,14 +231,14 @@ void E_SerializeEvents(FSerializer& arc)
|
|||
{
|
||||
// add all newly deserialized handlers into the list
|
||||
for (int i = 0; i < numlocalhandlers; i++)
|
||||
E_RegisterHandler(handlers[i]);
|
||||
RegisterHandler(handlers[i]);
|
||||
}
|
||||
|
||||
arc.EndArray();
|
||||
}
|
||||
}
|
||||
|
||||
static PClass* E_GetHandlerClass(const FString& typeName)
|
||||
static PClass* GetHandlerClass(const FString& typeName)
|
||||
{
|
||||
PClass* type = PClass::FindClass(typeName);
|
||||
|
||||
|
|
@ -254,11 +254,11 @@ static PClass* E_GetHandlerClass(const FString& typeName)
|
|||
return type;
|
||||
}
|
||||
|
||||
static void E_InitHandler(PClass* type)
|
||||
void EventManager::InitHandler(PClass* type)
|
||||
{
|
||||
// check if type already exists, don't add twice.
|
||||
bool typeExists = false;
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
|
||||
{
|
||||
if (handler->IsA(type))
|
||||
{
|
||||
|
|
@ -269,27 +269,27 @@ static void E_InitHandler(PClass* type)
|
|||
|
||||
if (typeExists) return;
|
||||
DStaticEventHandler* handler = (DStaticEventHandler*)type->CreateNew();
|
||||
E_RegisterHandler(handler);
|
||||
RegisterHandler(handler);
|
||||
}
|
||||
|
||||
void E_InitStaticHandlers(bool map)
|
||||
void EventManager::InitStaticHandlers(bool map)
|
||||
{
|
||||
// don't initialize map handlers if restoring from savegame.
|
||||
if (savegamerestore)
|
||||
return;
|
||||
|
||||
// just make sure
|
||||
E_Shutdown(map);
|
||||
Shutdown(map);
|
||||
|
||||
// initialize event handlers from gameinfo
|
||||
for (const FString& typeName : gameinfo.EventHandlers)
|
||||
{
|
||||
PClass* type = E_GetHandlerClass(typeName);
|
||||
PClass* type = GetHandlerClass(typeName);
|
||||
// don't init the really global stuff here on startup initialization.
|
||||
// don't init map-local global stuff here on level setup.
|
||||
if (map == E_IsStaticType(type))
|
||||
if (map == IsStaticType(type))
|
||||
continue;
|
||||
E_InitHandler(type);
|
||||
InitHandler(type);
|
||||
}
|
||||
|
||||
if (!map)
|
||||
|
|
@ -298,26 +298,26 @@ void E_InitStaticHandlers(bool map)
|
|||
// initialize event handlers from mapinfo
|
||||
for (const FString& typeName : level.info->EventHandlers)
|
||||
{
|
||||
PClass* type = E_GetHandlerClass(typeName);
|
||||
if (E_IsStaticType(type))
|
||||
PClass* type = GetHandlerClass(typeName);
|
||||
if (IsStaticType(type))
|
||||
I_Error("Fatal: invalid event handler class %s in MAPINFO!\nMap-specific event handlers cannot be static.\n", typeName.GetChars());
|
||||
E_InitHandler(type);
|
||||
InitHandler(type);
|
||||
}
|
||||
}
|
||||
|
||||
void E_Shutdown(bool map)
|
||||
void EventManager::Shutdown(bool map)
|
||||
{
|
||||
// delete handlers.
|
||||
for (DStaticEventHandler* handler = E_LastEventHandler; handler; handler = handler->prev)
|
||||
for (DStaticEventHandler* handler = LastEventHandler; handler; handler = handler->prev)
|
||||
{
|
||||
if (handler->IsStatic() == !map)
|
||||
handler->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
#define DEFINE_EVENT_LOOPER(name) void E_##name() \
|
||||
#define DEFINE_EVENT_LOOPER(name) void EventManager::##name() \
|
||||
{ \
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) \
|
||||
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next) \
|
||||
handler->name(); \
|
||||
}
|
||||
|
||||
|
|
@ -325,9 +325,9 @@ void E_Shutdown(bool map)
|
|||
// *Unsafe is executed on EVERY map load/close, including savegame loading, etc.
|
||||
// There is no point in allowing non-static handlers to receive unsafe event separately, as there is no point in having static handlers receive safe event.
|
||||
// Because the main point of safe WorldLoaded/Unloading is that it will be preserved in savegames.
|
||||
void E_WorldLoaded()
|
||||
void EventManager::WorldLoaded()
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
|
||||
{
|
||||
if (handler->IsStatic()) continue;
|
||||
if (savegamerestore) continue; // don't execute WorldLoaded for handlers loaded from the savegame.
|
||||
|
|
@ -335,70 +335,70 @@ void E_WorldLoaded()
|
|||
}
|
||||
}
|
||||
|
||||
void E_WorldUnloaded()
|
||||
void EventManager::WorldUnloaded()
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_LastEventHandler; handler; handler = handler->prev)
|
||||
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev)
|
||||
{
|
||||
if (handler->IsStatic()) continue;
|
||||
handler->WorldUnloaded();
|
||||
}
|
||||
}
|
||||
|
||||
void E_WorldLoadedUnsafe()
|
||||
void EventManager::WorldLoadedUnsafe()
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
{
|
||||
if (!handler->IsStatic()) continue;
|
||||
handler->WorldLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
void E_WorldUnloadedUnsafe()
|
||||
void EventManager::WorldUnloadedUnsafe()
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_LastEventHandler; handler; handler = handler->prev)
|
||||
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev)
|
||||
{
|
||||
if (!handler->IsStatic()) continue;
|
||||
handler->WorldUnloaded();
|
||||
}
|
||||
}
|
||||
|
||||
void E_WorldThingSpawned(AActor* actor)
|
||||
void EventManager::WorldThingSpawned(AActor* actor)
|
||||
{
|
||||
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
|
||||
if (actor->ObjectFlags & OF_EuthanizeMe)
|
||||
return;
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->WorldThingSpawned(actor);
|
||||
}
|
||||
|
||||
void E_WorldThingDied(AActor* actor, AActor* inflictor)
|
||||
void EventManager::WorldThingDied(AActor* actor, AActor* inflictor)
|
||||
{
|
||||
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
|
||||
if (actor->ObjectFlags & OF_EuthanizeMe)
|
||||
return;
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->WorldThingDied(actor, inflictor);
|
||||
}
|
||||
|
||||
void E_WorldThingRevived(AActor* actor)
|
||||
void EventManager::WorldThingRevived(AActor* actor)
|
||||
{
|
||||
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
|
||||
if (actor->ObjectFlags & OF_EuthanizeMe)
|
||||
return;
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->WorldThingRevived(actor);
|
||||
}
|
||||
|
||||
void E_WorldThingDamaged(AActor* actor, AActor* inflictor, AActor* source, int damage, FName mod, int flags, DAngle angle)
|
||||
void EventManager::WorldThingDamaged(AActor* actor, AActor* inflictor, AActor* source, int damage, FName mod, int flags, DAngle angle)
|
||||
{
|
||||
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
|
||||
if (actor->ObjectFlags & OF_EuthanizeMe)
|
||||
return;
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->WorldThingDamaged(actor, inflictor, source, damage, mod, flags, angle);
|
||||
}
|
||||
|
||||
void E_WorldThingDestroyed(AActor* actor)
|
||||
void EventManager::WorldThingDestroyed(AActor* actor)
|
||||
{
|
||||
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
|
||||
if (actor->ObjectFlags & OF_EuthanizeMe)
|
||||
|
|
@ -407,73 +407,73 @@ void E_WorldThingDestroyed(AActor* actor)
|
|||
// this is because Destroyed should be reverse of Spawned. we don't want to catch random inventory give failures.
|
||||
if (!(actor->ObjectFlags & OF_Spawned))
|
||||
return;
|
||||
for (DStaticEventHandler* handler = E_LastEventHandler; handler; handler = handler->prev)
|
||||
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev)
|
||||
handler->WorldThingDestroyed(actor);
|
||||
}
|
||||
|
||||
void E_WorldLinePreActivated(line_t* line, AActor* actor, int activationType, bool* shouldactivate)
|
||||
void EventManager::WorldLinePreActivated(line_t* line, AActor* actor, int activationType, bool* shouldactivate)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->WorldLinePreActivated(line, actor, activationType, shouldactivate);
|
||||
}
|
||||
|
||||
void E_WorldLineActivated(line_t* line, AActor* actor, int activationType)
|
||||
void EventManager::WorldLineActivated(line_t* line, AActor* actor, int activationType)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->WorldLineActivated(line, actor, activationType);
|
||||
}
|
||||
|
||||
int E_WorldSectorDamaged(sector_t* sector, AActor* source, int damage, FName damagetype, int part, DVector3 position, bool isradius)
|
||||
int EventManager::WorldSectorDamaged(sector_t* sector, AActor* source, int damage, FName damagetype, int part, DVector3 position, bool isradius)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
damage = handler->WorldSectorDamaged(sector, source, damage, damagetype, part, position, isradius);
|
||||
return damage;
|
||||
}
|
||||
|
||||
int E_WorldLineDamaged(line_t* line, AActor* source, int damage, FName damagetype, int side, DVector3 position, bool isradius)
|
||||
int EventManager::WorldLineDamaged(line_t* line, AActor* source, int damage, FName damagetype, int side, DVector3 position, bool isradius)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
damage = handler->WorldLineDamaged(line, source, damage, damagetype, side, position, isradius);
|
||||
return damage;
|
||||
}
|
||||
|
||||
void E_PlayerEntered(int num, bool fromhub)
|
||||
void EventManager::PlayerEntered(int num, bool fromhub)
|
||||
{
|
||||
// this event can happen during savegamerestore. make sure that local handlers don't receive it.
|
||||
// actually, global handlers don't want it too.
|
||||
if (savegamerestore && !fromhub)
|
||||
return;
|
||||
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->PlayerEntered(num, fromhub);
|
||||
}
|
||||
|
||||
void E_PlayerRespawned(int num)
|
||||
void EventManager::PlayerRespawned(int num)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->PlayerRespawned(num);
|
||||
}
|
||||
|
||||
void E_PlayerDied(int num)
|
||||
void EventManager::PlayerDied(int num)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->PlayerDied(num);
|
||||
}
|
||||
|
||||
void E_PlayerDisconnected(int num)
|
||||
void EventManager::PlayerDisconnected(int num)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_LastEventHandler; handler; handler = handler->prev)
|
||||
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev)
|
||||
handler->PlayerDisconnected(num);
|
||||
}
|
||||
|
||||
bool E_Responder(const event_t* ev)
|
||||
bool EventManager::Responder(const event_t* ev)
|
||||
{
|
||||
bool uiProcessorsFound = false;
|
||||
|
||||
if (ev->type == EV_GUI_Event)
|
||||
{
|
||||
// iterate handlers back to front by order, and give them this event.
|
||||
for (DStaticEventHandler* handler = E_LastEventHandler; handler; handler = handler->prev)
|
||||
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev)
|
||||
{
|
||||
if (handler->IsUiProcessor)
|
||||
{
|
||||
|
|
@ -486,7 +486,7 @@ bool E_Responder(const event_t* ev)
|
|||
else
|
||||
{
|
||||
// not sure if we want to handle device changes, but whatevs.
|
||||
for (DStaticEventHandler* handler = E_LastEventHandler; handler; handler = handler->prev)
|
||||
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev)
|
||||
{
|
||||
if (handler->IsUiProcessor)
|
||||
uiProcessorsFound = true;
|
||||
|
|
@ -498,61 +498,61 @@ bool E_Responder(const event_t* ev)
|
|||
return (uiProcessorsFound && (ev->type == EV_Mouse)); // mouse events are eaten by the event system if there are any uiprocessors.
|
||||
}
|
||||
|
||||
void E_Console(int player, FString name, int arg1, int arg2, int arg3, bool manual)
|
||||
void EventManager::Console(int player, FString name, int arg1, int arg2, int arg3, bool manual)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->ConsoleProcess(player, name, arg1, arg2, arg3, manual);
|
||||
}
|
||||
|
||||
void E_RenderOverlay(EHudState state)
|
||||
void EventManager::RenderOverlay(EHudState state)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->RenderOverlay(state);
|
||||
}
|
||||
|
||||
bool E_CheckUiProcessors()
|
||||
bool EventManager::CheckUiProcessors()
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
if (handler->IsUiProcessor)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool E_CheckRequireMouse()
|
||||
bool EventManager::CheckRequireMouse()
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
if (handler->IsUiProcessor && handler->RequireMouse)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool E_CheckReplacement( PClassActor *replacee, PClassActor **replacement )
|
||||
bool EventManager::CheckReplacement( PClassActor *replacee, PClassActor **replacement )
|
||||
{
|
||||
bool final = false;
|
||||
for (DStaticEventHandler *handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler *handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->CheckReplacement(replacee,replacement,&final);
|
||||
return final;
|
||||
}
|
||||
|
||||
bool E_CheckReplacee(PClassActor **replacee, PClassActor *replacement)
|
||||
bool EventManager::CheckReplacee(PClassActor **replacee, PClassActor *replacement)
|
||||
{
|
||||
bool final = false;
|
||||
for (DStaticEventHandler *handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler *handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
handler->CheckReplacee(replacee, replacement, &final);
|
||||
return final;
|
||||
}
|
||||
|
||||
void E_NewGame(EventHandlerType handlerType)
|
||||
void EventManager::NewGame(EventHandlerType handlerType)
|
||||
{
|
||||
bool isStatic = handlerType == EventHandlerType::Global;
|
||||
|
||||
// Shut down all per-map event handlers before static NewGame events.
|
||||
if (isStatic)
|
||||
E_Shutdown(true);
|
||||
EventManager::Shutdown(true);
|
||||
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
{
|
||||
if (handler->IsStatic() == isStatic)
|
||||
handler->NewGame();
|
||||
|
|
@ -644,7 +644,7 @@ DEFINE_ACTION_FUNCTION(DStaticEventHandler, SetOrder)
|
|||
PARAM_SELF_PROLOGUE(DStaticEventHandler);
|
||||
PARAM_INT(order);
|
||||
|
||||
if (E_CheckHandler(self))
|
||||
if (eventManager.CheckHandler(self))
|
||||
return 0;
|
||||
|
||||
self->Order = order;
|
||||
|
|
@ -660,14 +660,14 @@ DEFINE_ACTION_FUNCTION(DEventHandler, SendNetworkEvent)
|
|||
PARAM_INT(arg3);
|
||||
//
|
||||
|
||||
ACTION_RETURN_BOOL(E_SendNetworkEvent(name, arg1, arg2, arg3, false));
|
||||
ACTION_RETURN_BOOL(eventManager.SendNetworkEvent(name, arg1, arg2, arg3, false));
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(DEventHandler, Find)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_CLASS(t, DStaticEventHandler);
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
if (handler->GetClass() == t) // check precise class
|
||||
ACTION_RETURN_OBJECT(handler);
|
||||
ACTION_RETURN_OBJECT(nullptr);
|
||||
|
|
@ -678,7 +678,7 @@ DEFINE_ACTION_FUNCTION(DStaticEventHandler, Find)
|
|||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_CLASS(t, DStaticEventHandler);
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
|
||||
if (handler->GetClass() == t) // check precise class
|
||||
ACTION_RETURN_OBJECT(handler);
|
||||
ACTION_RETURN_OBJECT(nullptr);
|
||||
|
|
@ -726,7 +726,7 @@ void DStaticEventHandler::OnUnregister()
|
|||
}
|
||||
}
|
||||
|
||||
static FWorldEvent E_SetupWorldEvent()
|
||||
FWorldEvent EventManager::SetupWorldEvent()
|
||||
{
|
||||
FWorldEvent e;
|
||||
e.IsSaveGame = savegamerestore;
|
||||
|
|
@ -741,7 +741,7 @@ void DStaticEventHandler::WorldLoaded()
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, &e };
|
||||
VMCall(func, params, 2, nullptr, 0);
|
||||
}
|
||||
|
|
@ -753,7 +753,7 @@ void DStaticEventHandler::WorldUnloaded()
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, &e };
|
||||
VMCall(func, params, 2, nullptr, 0);
|
||||
}
|
||||
|
|
@ -765,7 +765,7 @@ void DStaticEventHandler::WorldThingSpawned(AActor* actor)
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
e.Thing = actor;
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, &e };
|
||||
VMCall(func, params, 2, nullptr, 0);
|
||||
|
|
@ -778,7 +778,7 @@ void DStaticEventHandler::WorldThingDied(AActor* actor, AActor* inflictor)
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
e.Thing = actor;
|
||||
e.Inflictor = inflictor;
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, &e };
|
||||
|
|
@ -792,7 +792,7 @@ void DStaticEventHandler::WorldThingRevived(AActor* actor)
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
e.Thing = actor;
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, &e };
|
||||
VMCall(func, params, 2, nullptr, 0);
|
||||
|
|
@ -805,7 +805,7 @@ void DStaticEventHandler::WorldThingDamaged(AActor* actor, AActor* inflictor, AA
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
e.Thing = actor;
|
||||
e.Inflictor = inflictor;
|
||||
e.Damage = damage;
|
||||
|
|
@ -824,7 +824,7 @@ void DStaticEventHandler::WorldThingDestroyed(AActor* actor)
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
e.Thing = actor;
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, &e };
|
||||
VMCall(func, params, 2, nullptr, 0);
|
||||
|
|
@ -837,7 +837,7 @@ void DStaticEventHandler::WorldLinePreActivated(line_t* line, AActor* actor, int
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
e.Thing = actor;
|
||||
e.ActivatedLine = line;
|
||||
e.ActivationType = activationType;
|
||||
|
|
@ -854,7 +854,7 @@ void DStaticEventHandler::WorldLineActivated(line_t* line, AActor* actor, int ac
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
e.Thing = actor;
|
||||
e.ActivatedLine = line;
|
||||
e.ActivationType = activationType;
|
||||
|
|
@ -869,7 +869,7 @@ int DStaticEventHandler::WorldSectorDamaged(sector_t* sector, AActor* source, in
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return damage;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
e.DamageSource = source;
|
||||
e.DamageSector = sector;
|
||||
e.NewDamage = e.Damage = damage;
|
||||
|
|
@ -892,7 +892,7 @@ int DStaticEventHandler::WorldLineDamaged(line_t* line, AActor* source, int dama
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return damage;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
e.DamageSource = source;
|
||||
e.DamageLine = line;
|
||||
e.NewDamage = e.Damage = damage;
|
||||
|
|
@ -915,7 +915,7 @@ void DStaticEventHandler::WorldLightning()
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FWorldEvent e = E_SetupWorldEvent();
|
||||
FWorldEvent e = eventManager.SetupWorldEvent();
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, &e };
|
||||
VMCall(func, params, 2, nullptr, 0);
|
||||
}
|
||||
|
|
@ -932,7 +932,7 @@ void DStaticEventHandler::WorldTick()
|
|||
}
|
||||
}
|
||||
|
||||
static FRenderEvent E_SetupRenderEvent()
|
||||
FRenderEvent EventManager::SetupRenderEvent()
|
||||
{
|
||||
FRenderEvent e;
|
||||
auto &vp = r_viewpoint;
|
||||
|
|
@ -952,7 +952,7 @@ void DStaticEventHandler::RenderFrame()
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FRenderEvent e = E_SetupRenderEvent();
|
||||
FRenderEvent e = eventManager.SetupRenderEvent();
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, &e };
|
||||
VMCall(func, params, 2, nullptr, 0);
|
||||
}
|
||||
|
|
@ -965,7 +965,7 @@ void DStaticEventHandler::RenderOverlay(EHudState state)
|
|||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (isEmpty(func)) return;
|
||||
FRenderEvent e = E_SetupRenderEvent();
|
||||
FRenderEvent e = eventManager.SetupRenderEvent();
|
||||
e.HudState = int(state);
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, &e };
|
||||
VMCall(func, params, 2, nullptr, 0);
|
||||
|
|
@ -1234,7 +1234,7 @@ void DStaticEventHandler::NewGame()
|
|||
//
|
||||
void DStaticEventHandler::OnDestroy()
|
||||
{
|
||||
E_UnregisterHandler(this);
|
||||
eventManager.UnregisterHandler(this);
|
||||
Super::OnDestroy();
|
||||
}
|
||||
|
||||
|
|
@ -1255,7 +1255,7 @@ CCMD(event)
|
|||
for (int i = 0; i < argn; i++)
|
||||
arg[i] = atoi(argv[2 + i]);
|
||||
// call locally
|
||||
E_Console(-1, argv[1], arg[0], arg[1], arg[2], true);
|
||||
eventManager.Console(-1, argv[1], arg[0], arg[1], arg[2], true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1280,6 +1280,6 @@ CCMD(netevent)
|
|||
for (int i = 0; i < argn; i++)
|
||||
arg[i] = atoi(argv[2 + i]);
|
||||
// call networked
|
||||
E_SendNetworkEvent(argv[1], arg[0], arg[1], arg[2], true);
|
||||
eventManager.SendNetworkEvent(argv[1], arg[0], arg[1], arg[2], true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue