- separation of static and map-local event handlers into separate lists.

Having everything lumped together made this a maintenance hassle because it affected how the level has to be stored.
This hasn't been tested yet, so it may not work as intended!
This commit is contained in:
Christoph Oelckers 2019-02-02 16:43:11 +01:00
parent d005e0b483
commit 66eb4e5048
29 changed files with 240 additions and 242 deletions

View file

@ -404,27 +404,27 @@ void FCajunMaster::RemoveAllBots (FLevelLocals *Level, bool fromlist)
for (i = 0; i < MAXPLAYERS; ++i) for (i = 0; i < MAXPLAYERS; ++i)
{ {
if (players[i].Bot != NULL) if (Level->Players[i]->Bot != nullptr)
{ {
// If a player is looking through this bot's eyes, make him // If a player is looking through this bot's eyes, make him
// look through his own eyes instead. // look through his own eyes instead.
for (j = 0; j < MAXPLAYERS; ++j) for (j = 0; j < MAXPLAYERS; ++j)
{ {
if (i != j && playeringame[j] && players[j].Bot == NULL) if (i != j && Level->PlayerInGame(j) && Level->Players[j]->Bot == nullptr)
{ {
if (players[j].camera == players[i].mo) if (Level->Players[j]->camera == Level->Players[i]->mo)
{ {
players[j].camera = players[j].mo; Level->Players[j]->camera = Level->Players[j]->mo;
if (j == consoleplayer) if (Level->isConsolePlayer(Level->Players[j]->mo))
{ {
StatusBar->AttachToPlayer (players + j); StatusBar->AttachToPlayer (Level->Players[j]);
} }
} }
} }
} }
// [ZZ] run event hook // [ZZ] run event hook
eventManager.PlayerDisconnected(i); Level->localEventManager->PlayerDisconnected(i);
Level->Behaviors.StartTypedScripts (SCRIPT_Disconnect, players[i].mo, true, i, true); Level->Behaviors.StartTypedScripts (SCRIPT_Disconnect, Level->Players[i]->mo, true, i, true);
ClearPlayer (i, !fromlist); ClearPlayer (i, !fromlist);
} }
} }

View file

@ -273,7 +273,7 @@ void D_ProcessEvents (void)
if (M_Responder (ev)) if (M_Responder (ev))
continue; // menu ate the event continue; // menu ate the event
// check events // check events
if (ev->type != EV_Mouse && eventManager.Responder(ev)) // [ZZ] ZScript ate the event // update 07.03.17: mouse events are handled directly if (ev->type != EV_Mouse && primaryLevel->localEventManager->Responder(ev)) // [ZZ] ZScript ate the event // update 07.03.17: mouse events are handled directly
continue; continue;
G_Responder (ev); G_Responder (ev);
} }
@ -295,7 +295,7 @@ void D_PostEvent (const event_t *ev)
return; return;
} }
events[eventhead] = *ev; events[eventhead] = *ev;
if (ev->type == EV_Mouse && menuactive == MENU_Off && ConsoleState != c_down && ConsoleState != c_falling && !eventManager.Responder(ev) && !paused) if (ev->type == EV_Mouse && menuactive == MENU_Off && ConsoleState != c_down && ConsoleState != c_falling && !primaryLevel->localEventManager->Responder(ev) && !paused)
{ {
if (Button_Mlook.bDown || freelook) if (Button_Mlook.bDown || freelook)
{ {
@ -2730,7 +2730,7 @@ void D_DoomMain (void)
{ {
Level->Thinkers.DestroyThinkersInList(STAT_STATIC); Level->Thinkers.DestroyThinkersInList(STAT_STATIC);
} }
eventManager.Shutdown(false); staticEventManager.Shutdown();
P_FreeLevelData(); P_FreeLevelData();
M_SaveDefaults(NULL); // save config before the restart M_SaveDefaults(NULL); // save config before the restart

View file

@ -2561,7 +2561,7 @@ void Net_DoCommand (int type, uint8_t **stream, int player)
if (cls != NULL) if (cls != NULL)
{ {
killcount = primaryLevel->Massacre(false, cls->TypeName); killcount = primaryLevel->Massacre(false, cls->TypeName);
PClassActor *cls_rep = cls->GetReplacement(); PClassActor *cls_rep = cls->GetReplacement(primaryLevel);
if (cls != cls_rep) if (cls != cls_rep)
{ {
killcount += primaryLevel->Massacre(false, cls_rep->TypeName); killcount += primaryLevel->Massacre(false, cls_rep->TypeName);
@ -2583,7 +2583,7 @@ void Net_DoCommand (int type, uint8_t **stream, int player)
if (cls != NULL && cls->IsDescendantOf(RUNTIME_CLASS(AActor))) if (cls != NULL && cls->IsDescendantOf(RUNTIME_CLASS(AActor)))
{ {
removecount = RemoveClass(primaryLevel, cls); removecount = RemoveClass(primaryLevel, cls);
const PClass *cls_rep = cls->GetReplacement(); const PClass *cls_rep = cls->GetReplacement(primaryLevel);
if (cls != cls_rep) if (cls != cls_rep)
{ {
removecount += RemoveClass(primaryLevel, cls_rep); removecount += RemoveClass(primaryLevel, cls_rep);
@ -2671,7 +2671,7 @@ void Net_DoCommand (int type, uint8_t **stream, int player)
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
arg[i] = ReadLong(stream); arg[i] = ReadLong(stream);
bool manual = !!ReadByte(stream); bool manual = !!ReadByte(stream);
eventManager.Console(player, s, arg[0], arg[1], arg[2], manual); primaryLevel->localEventManager->Console(player, s, arg[0], arg[1], arg[2], manual);
} }
break; break;

View file

@ -282,8 +282,8 @@ static void MarkRoot()
Mark(StatusBar); Mark(StatusBar);
M_MarkMenus(); M_MarkMenus();
Mark(DIntermissionController::CurrentIntermission); Mark(DIntermissionController::CurrentIntermission);
Mark(eventManager.FirstEventHandler); Mark(staticEventManager.FirstEventHandler);
Mark(eventManager.LastEventHandler); Mark(staticEventManager.LastEventHandler);
for (auto Level : AllLevels()) for (auto Level : AllLevels())
Level->Mark(); Level->Mark();

View file

@ -42,6 +42,7 @@
#include "g_game.h" #include "g_game.h"
#include "info.h" #include "info.h"
EventManager staticEventManager;
EventManager eventManager; EventManager eventManager;
@ -53,6 +54,7 @@ bool EventManager::RegisterHandler(DStaticEventHandler* handler)
return false; return false;
handler->OnRegister(); handler->OnRegister();
handler->owner = this;
// link into normal list // link into normal list
// update: link at specific position based on order. // update: link at specific position based on order.
@ -66,11 +68,6 @@ bool EventManager::RegisterHandler(DStaticEventHandler* handler)
} }
} }
// 1. MyHandler2->1:
// eventManager.FirstEventHandler = MyHandler2, eventManager.LastEventHandler = MyHandler2
// 2. MyHandler3->2:
// eventManager.FirstEventHandler = MyHandler2, eventManager.LastEventHandler = MyHandler3
// (Yes, all those write barriers here are really needed!) // (Yes, all those write barriers here are really needed!)
if (before != nullptr) if (before != nullptr)
{ {
@ -186,58 +183,6 @@ bool EventManager::IsStaticType(PClass* type)
return !type->IsDescendantOf(RUNTIME_CLASS(DEventHandler)); return !type->IsDescendantOf(RUNTIME_CLASS(DEventHandler));
} }
void EventManager::SerializeEvents(FSerializer& arc)
{
// todo : stuff
if (arc.BeginArray("eventhandlers"))
{
int numlocalhandlers = 0;
TArray<DStaticEventHandler*> handlers;
if (arc.isReading())
{
numlocalhandlers = arc.ArraySize();
// delete all current local handlers, if any
for (DStaticEventHandler* lhandler = FirstEventHandler; lhandler; lhandler = lhandler->next)
if (!lhandler->IsStatic()) lhandler->Destroy();
}
else
{
for (DStaticEventHandler* lhandler = FirstEventHandler; lhandler; lhandler = lhandler->next)
{
if (lhandler->IsStatic()) continue;
numlocalhandlers++;
handlers.Push(lhandler);
}
}
for (int i = 0; i < numlocalhandlers; i++)
{
// serialize the object properly.
if (arc.isReading())
{
// get object and put it into the array
DStaticEventHandler* lhandler;
arc(nullptr, lhandler);
if (lhandler != nullptr)
handlers.Push(lhandler);
}
else
{
::Serialize<DStaticEventHandler>(arc, nullptr, handlers[i], nullptr);
}
}
if (arc.isReading())
{
// add all newly deserialized handlers into the list
for (int i = 0; i < numlocalhandlers; i++)
RegisterHandler(handlers[i]);
}
arc.EndArray();
}
}
static PClass* GetHandlerClass(const FString& typeName) static PClass* GetHandlerClass(const FString& typeName)
{ {
PClass* type = PClass::FindClass(typeName); PClass* type = PClass::FindClass(typeName);
@ -279,7 +224,7 @@ void EventManager::InitStaticHandlers(bool map)
return; return;
// just make sure // just make sure
Shutdown(map); Shutdown();
// initialize event handlers from gameinfo // initialize event handlers from gameinfo
for (const FString& typeName : gameinfo.EventHandlers) for (const FString& typeName : gameinfo.EventHandlers)
@ -305,22 +250,23 @@ void EventManager::InitStaticHandlers(bool map)
} }
} }
void EventManager::Shutdown(bool map) void EventManager::Shutdown()
{ {
// delete handlers. // delete handlers.
for (DStaticEventHandler* handler = LastEventHandler; handler; handler = handler->prev) for (DStaticEventHandler* handler = LastEventHandler; handler; handler = handler->prev)
{ {
if (handler->IsStatic() == !map)
handler->Destroy(); handler->Destroy();
} }
} }
#define DEFINE_EVENT_LOOPER(name) void EventManager::##name() \ #define DEFINE_EVENT_LOOPER(name, play) void EventManager::##name() \
{ \ { \
if (ShouldCallStatic(play)) staticEventManager.name(); \
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next) \ for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next) \
handler->name(); \ handler->name(); \
} }
// note for the functions below. // note for the functions below.
// *Unsafe is executed on EVERY map load/close, including savegame loading, etc. // *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. // 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.
@ -329,7 +275,6 @@ void EventManager::WorldLoaded()
{ {
for (DStaticEventHandler* handler = 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. if (savegamerestore) continue; // don't execute WorldLoaded for handlers loaded from the savegame.
handler->WorldLoaded(); handler->WorldLoaded();
} }
@ -337,29 +282,15 @@ void EventManager::WorldLoaded()
void EventManager::WorldUnloaded() void EventManager::WorldUnloaded()
{ {
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev) for (DStaticEventHandler* handler = LastEventHandler; handler; handler = handler->prev)
{ {
if (handler->IsStatic()) continue;
handler->WorldUnloaded(); handler->WorldUnloaded();
} }
} }
void EventManager::WorldLoadedUnsafe() bool EventManager::ShouldCallStatic(bool forplay)
{ {
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) return this != &staticEventManager && Level == primaryLevel;
{
if (!handler->IsStatic()) continue;
handler->WorldLoaded();
}
}
void EventManager::WorldUnloadedUnsafe()
{
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev)
{
if (!handler->IsStatic()) continue;
handler->WorldUnloaded();
}
} }
void EventManager::WorldThingSpawned(AActor* actor) void EventManager::WorldThingSpawned(AActor* actor)
@ -367,7 +298,10 @@ void EventManager::WorldThingSpawned(AActor* actor)
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever. // don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
if (actor->ObjectFlags & OF_EuthanizeMe) if (actor->ObjectFlags & OF_EuthanizeMe)
return; return;
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
if (ShouldCallStatic(true)) staticEventManager.WorldThingSpawned(actor);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->WorldThingSpawned(actor); handler->WorldThingSpawned(actor);
} }
@ -376,7 +310,10 @@ void EventManager::WorldThingDied(AActor* actor, AActor* inflictor)
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever. // don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
if (actor->ObjectFlags & OF_EuthanizeMe) if (actor->ObjectFlags & OF_EuthanizeMe)
return; return;
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
if (ShouldCallStatic(true)) staticEventManager.WorldThingDied(actor, inflictor);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->WorldThingDied(actor, inflictor); handler->WorldThingDied(actor, inflictor);
} }
@ -385,7 +322,10 @@ void EventManager::WorldThingRevived(AActor* actor)
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever. // don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
if (actor->ObjectFlags & OF_EuthanizeMe) if (actor->ObjectFlags & OF_EuthanizeMe)
return; return;
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
if (ShouldCallStatic(true)) staticEventManager.WorldThingRevived(actor);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->WorldThingRevived(actor); handler->WorldThingRevived(actor);
} }
@ -394,7 +334,10 @@ void EventManager::WorldThingDamaged(AActor* actor, AActor* inflictor, AActor* s
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever. // don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
if (actor->ObjectFlags & OF_EuthanizeMe) if (actor->ObjectFlags & OF_EuthanizeMe)
return; return;
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
if (ShouldCallStatic(true)) staticEventManager.WorldThingDamaged(actor, inflictor, source, damage, mod, flags, angle);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->WorldThingDamaged(actor, inflictor, source, damage, mod, flags, angle); handler->WorldThingDamaged(actor, inflictor, source, damage, mod, flags, angle);
} }
@ -407,32 +350,43 @@ void EventManager::WorldThingDestroyed(AActor* actor)
// this is because Destroyed should be reverse of Spawned. we don't want to catch random inventory give failures. // this is because Destroyed should be reverse of Spawned. we don't want to catch random inventory give failures.
if (!(actor->ObjectFlags & OF_Spawned)) if (!(actor->ObjectFlags & OF_Spawned))
return; return;
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev)
for (DStaticEventHandler* handler = LastEventHandler; handler; handler = handler->prev)
handler->WorldThingDestroyed(actor); handler->WorldThingDestroyed(actor);
if (ShouldCallStatic(true)) staticEventManager.WorldThingDestroyed(actor);
} }
void EventManager::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 = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(true)) staticEventManager.WorldLinePreActivated(line, actor, activationType, shouldactivate);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->WorldLinePreActivated(line, actor, activationType, shouldactivate); handler->WorldLinePreActivated(line, actor, activationType, shouldactivate);
} }
void EventManager::WorldLineActivated(line_t* line, AActor* actor, int activationType) void EventManager::WorldLineActivated(line_t* line, AActor* actor, int activationType)
{ {
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(true)) staticEventManager.WorldLineActivated(line, actor, activationType);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->WorldLineActivated(line, actor, activationType); handler->WorldLineActivated(line, actor, activationType);
} }
int EventManager::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 = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(true)) staticEventManager.WorldSectorDamaged(sector, source, damage, damagetype, part, position, isradius);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
damage = handler->WorldSectorDamaged(sector, source, damage, damagetype, part, position, isradius); damage = handler->WorldSectorDamaged(sector, source, damage, damagetype, part, position, isradius);
return damage; return damage;
} }
int EventManager::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 = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(true)) staticEventManager.WorldLineDamaged(line, source, damage, damagetype, side, position, isradius);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
damage = handler->WorldLineDamaged(line, source, damage, damagetype, side, position, isradius); damage = handler->WorldLineDamaged(line, source, damage, damagetype, side, position, isradius);
return damage; return damage;
} }
@ -444,26 +398,34 @@ void EventManager::PlayerEntered(int num, bool fromhub)
if (savegamerestore && !fromhub) if (savegamerestore && !fromhub)
return; return;
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(true)) staticEventManager.PlayerEntered(num, fromhub);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->PlayerEntered(num, fromhub); handler->PlayerEntered(num, fromhub);
} }
void EventManager::PlayerRespawned(int num) void EventManager::PlayerRespawned(int num)
{ {
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(true)) staticEventManager.PlayerRespawned(num);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->PlayerRespawned(num); handler->PlayerRespawned(num);
} }
void EventManager::PlayerDied(int num) void EventManager::PlayerDied(int num)
{ {
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(true)) staticEventManager.PlayerDied(num);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->PlayerDied(num); handler->PlayerDied(num);
} }
void EventManager::PlayerDisconnected(int num) void EventManager::PlayerDisconnected(int num)
{ {
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev) for (DStaticEventHandler* handler = LastEventHandler; handler; handler = handler->prev)
handler->PlayerDisconnected(num); handler->PlayerDisconnected(num);
if (ShouldCallStatic(true)) staticEventManager.PlayerDisconnected(num);
} }
bool EventManager::Responder(const event_t* ev) bool EventManager::Responder(const event_t* ev)
@ -473,7 +435,7 @@ bool EventManager::Responder(const event_t* ev)
if (ev->type == EV_GUI_Event) if (ev->type == EV_GUI_Event)
{ {
// iterate handlers back to front by order, and give them this event. // iterate handlers back to front by order, and give them this event.
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev) for (DStaticEventHandler* handler = LastEventHandler; handler; handler = handler->prev)
{ {
if (handler->IsUiProcessor) if (handler->IsUiProcessor)
{ {
@ -486,7 +448,7 @@ bool EventManager::Responder(const event_t* ev)
else else
{ {
// not sure if we want to handle device changes, but whatevs. // not sure if we want to handle device changes, but whatevs.
for (DStaticEventHandler* handler = eventManager.LastEventHandler; handler; handler = handler->prev) for (DStaticEventHandler* handler = LastEventHandler; handler; handler = handler->prev)
{ {
if (handler->IsUiProcessor) if (handler->IsUiProcessor)
uiProcessorsFound = true; uiProcessorsFound = true;
@ -494,25 +456,35 @@ bool EventManager::Responder(const event_t* ev)
return true; // event was processed return true; // event was processed
} }
} }
if (ShouldCallStatic(false)) uiProcessorsFound = staticEventManager.Responder(ev);
return (uiProcessorsFound && (ev->type == EV_Mouse)); // mouse events are eaten by the event system if there are any uiprocessors. return (uiProcessorsFound && (ev->type == EV_Mouse)); // mouse events are eaten by the event system if there are any uiprocessors.
} }
void EventManager::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 = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(false)) staticEventManager.Console(player, name, arg1, arg2, arg3, manual);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->ConsoleProcess(player, name, arg1, arg2, arg3, manual); handler->ConsoleProcess(player, name, arg1, arg2, arg3, manual);
} }
void EventManager::RenderOverlay(EHudState state) void EventManager::RenderOverlay(EHudState state)
{ {
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(false)) staticEventManager.RenderOverlay(state);
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
handler->RenderOverlay(state); handler->RenderOverlay(state);
} }
bool EventManager::CheckUiProcessors() bool EventManager::CheckUiProcessors()
{ {
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(false))
{
if (staticEventManager.CheckUiProcessors()) return true;
}
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
if (handler->IsUiProcessor) if (handler->IsUiProcessor)
return true; return true;
@ -521,7 +493,12 @@ bool EventManager::CheckUiProcessors()
bool EventManager::CheckRequireMouse() bool EventManager::CheckRequireMouse()
{ {
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(false))
{
if (staticEventManager.CheckRequireMouse()) return true;
}
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
if (handler->IsUiProcessor && handler->RequireMouse) if (handler->IsUiProcessor && handler->RequireMouse)
return true; return true;
@ -531,7 +508,11 @@ bool EventManager::CheckRequireMouse()
bool EventManager::CheckReplacement( PClassActor *replacee, PClassActor **replacement ) bool EventManager::CheckReplacement( PClassActor *replacee, PClassActor **replacement )
{ {
bool final = false; bool final = false;
for (DStaticEventHandler *handler = eventManager.FirstEventHandler; handler; handler = handler->next)
// This is play scope but unlike in-game events needs to be handled like UI by static handlers.
if (ShouldCallStatic(false)) final = staticEventManager.CheckReplacement(replacee, replacement);
for (DStaticEventHandler *handler = FirstEventHandler; handler; handler = handler->next)
handler->CheckReplacement(replacee,replacement,&final); handler->CheckReplacement(replacee,replacement,&final);
return final; return final;
} }
@ -539,32 +520,28 @@ bool EventManager::CheckReplacement( PClassActor *replacee, PClassActor **replac
bool EventManager::CheckReplacee(PClassActor **replacee, PClassActor *replacement) bool EventManager::CheckReplacee(PClassActor **replacee, PClassActor *replacement)
{ {
bool final = false; bool final = false;
for (DStaticEventHandler *handler = eventManager.FirstEventHandler; handler; handler = handler->next) if (ShouldCallStatic(false)) final = staticEventManager.CheckReplacee(replacee, replacement);
for (DStaticEventHandler *handler = FirstEventHandler; handler; handler = handler->next)
handler->CheckReplacee(replacee, replacement, &final); handler->CheckReplacee(replacee, replacement, &final);
return final; return final;
} }
void EventManager::NewGame(EventHandlerType handlerType) void EventManager::NewGame()
{ {
bool isStatic = handlerType == EventHandlerType::Global; //This is called separately for static and local handlers, so no forwarding here.
for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next)
// Shut down all per-map event handlers before static NewGame events.
if (isStatic)
EventManager::Shutdown(true);
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next)
{ {
if (handler->IsStatic() == isStatic)
handler->NewGame(); handler->NewGame();
} }
} }
// normal event loopers (non-special, argument-less) // normal event loopers (non-special, argument-less)
DEFINE_EVENT_LOOPER(RenderFrame) DEFINE_EVENT_LOOPER(RenderFrame, false)
DEFINE_EVENT_LOOPER(WorldLightning) DEFINE_EVENT_LOOPER(WorldLightning, true)
DEFINE_EVENT_LOOPER(WorldTick) DEFINE_EVENT_LOOPER(WorldTick, true)
DEFINE_EVENT_LOOPER(UiTick) DEFINE_EVENT_LOOPER(UiTick, false)
DEFINE_EVENT_LOOPER(PostUiTick) DEFINE_EVENT_LOOPER(PostUiTick, false)
// declarations // declarations
IMPLEMENT_CLASS(DStaticEventHandler, false, true); IMPLEMENT_CLASS(DStaticEventHandler, false, true);
@ -644,8 +621,10 @@ DEFINE_ACTION_FUNCTION(DStaticEventHandler, SetOrder)
PARAM_SELF_PROLOGUE(DStaticEventHandler); PARAM_SELF_PROLOGUE(DStaticEventHandler);
PARAM_INT(order); PARAM_INT(order);
/* not really needed - this is never checked again. To re-add, the handlers need a pointer to their manager but that's not worth it just for this check.
if (eventManager.CheckHandler(self)) if (eventManager.CheckHandler(self))
return 0; return 0;
*/
self->Order = order; self->Order = order;
return 0; return 0;
@ -660,14 +639,14 @@ DEFINE_ACTION_FUNCTION(DEventHandler, SendNetworkEvent)
PARAM_INT(arg3); PARAM_INT(arg3);
// //
ACTION_RETURN_BOOL(eventManager.SendNetworkEvent(name, arg1, arg2, arg3, false)); ACTION_RETURN_BOOL(currentVMLevel->localEventManager->SendNetworkEvent(name, arg1, arg2, arg3, false));
} }
DEFINE_ACTION_FUNCTION(DEventHandler, Find) DEFINE_ACTION_FUNCTION(DEventHandler, Find)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_CLASS(t, DStaticEventHandler); PARAM_CLASS(t, DStaticEventHandler);
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) for (DStaticEventHandler* handler = currentVMLevel->localEventManager->FirstEventHandler; handler; handler = handler->next)
if (handler->GetClass() == t) // check precise class if (handler->GetClass() == t) // check precise class
ACTION_RETURN_OBJECT(handler); ACTION_RETURN_OBJECT(handler);
ACTION_RETURN_OBJECT(nullptr); ACTION_RETURN_OBJECT(nullptr);
@ -678,7 +657,7 @@ DEFINE_ACTION_FUNCTION(DStaticEventHandler, Find)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_CLASS(t, DStaticEventHandler); PARAM_CLASS(t, DStaticEventHandler);
for (DStaticEventHandler* handler = eventManager.FirstEventHandler; handler; handler = handler->next) for (DStaticEventHandler* handler = staticEventManager.FirstEventHandler; handler; handler = handler->next)
if (handler->GetClass() == t) // check precise class if (handler->GetClass() == t) // check precise class
ACTION_RETURN_OBJECT(handler); ACTION_RETURN_OBJECT(handler);
ACTION_RETURN_OBJECT(nullptr); ACTION_RETURN_OBJECT(nullptr);
@ -730,7 +709,7 @@ FWorldEvent EventManager::SetupWorldEvent()
{ {
FWorldEvent e; FWorldEvent e;
e.IsSaveGame = savegamerestore; e.IsSaveGame = savegamerestore;
e.IsReopen = level.FromSnapshot && !savegamerestore; // each one by itself isnt helpful, but with hub load we have savegamerestore==0 and level.FromSnapshot==1. e.IsReopen = Level->FromSnapshot && !savegamerestore; // each one by itself isnt helpful, but with hub load we have savegamerestore==0 and level.FromSnapshot==1.
e.DamageAngle = 0.0; e.DamageAngle = 0.0;
return e; return e;
} }
@ -741,7 +720,7 @@ void DStaticEventHandler::WorldLoaded()
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
VMValue params[2] = { (DStaticEventHandler*)this, &e }; VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
} }
@ -753,7 +732,7 @@ void DStaticEventHandler::WorldUnloaded()
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
VMValue params[2] = { (DStaticEventHandler*)this, &e }; VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
} }
@ -765,7 +744,7 @@ void DStaticEventHandler::WorldThingSpawned(AActor* actor)
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
e.Thing = actor; e.Thing = actor;
VMValue params[2] = { (DStaticEventHandler*)this, &e }; VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
@ -778,7 +757,7 @@ void DStaticEventHandler::WorldThingDied(AActor* actor, AActor* inflictor)
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
e.Thing = actor; e.Thing = actor;
e.Inflictor = inflictor; e.Inflictor = inflictor;
VMValue params[2] = { (DStaticEventHandler*)this, &e }; VMValue params[2] = { (DStaticEventHandler*)this, &e };
@ -792,7 +771,7 @@ void DStaticEventHandler::WorldThingRevived(AActor* actor)
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
e.Thing = actor; e.Thing = actor;
VMValue params[2] = { (DStaticEventHandler*)this, &e }; VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
@ -805,7 +784,7 @@ void DStaticEventHandler::WorldThingDamaged(AActor* actor, AActor* inflictor, AA
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
e.Thing = actor; e.Thing = actor;
e.Inflictor = inflictor; e.Inflictor = inflictor;
e.Damage = damage; e.Damage = damage;
@ -824,7 +803,7 @@ void DStaticEventHandler::WorldThingDestroyed(AActor* actor)
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
e.Thing = actor; e.Thing = actor;
VMValue params[2] = { (DStaticEventHandler*)this, &e }; VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
@ -837,7 +816,7 @@ void DStaticEventHandler::WorldLinePreActivated(line_t* line, AActor* actor, int
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
e.Thing = actor; e.Thing = actor;
e.ActivatedLine = line; e.ActivatedLine = line;
e.ActivationType = activationType; e.ActivationType = activationType;
@ -854,7 +833,7 @@ void DStaticEventHandler::WorldLineActivated(line_t* line, AActor* actor, int ac
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
e.Thing = actor; e.Thing = actor;
e.ActivatedLine = line; e.ActivatedLine = line;
e.ActivationType = activationType; e.ActivationType = activationType;
@ -869,7 +848,7 @@ int DStaticEventHandler::WorldSectorDamaged(sector_t* sector, AActor* source, in
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return damage; if (isEmpty(func)) return damage;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
e.DamageSource = source; e.DamageSource = source;
e.DamageSector = sector; e.DamageSector = sector;
e.NewDamage = e.Damage = damage; e.NewDamage = e.Damage = damage;
@ -892,7 +871,7 @@ int DStaticEventHandler::WorldLineDamaged(line_t* line, AActor* source, int dama
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return damage; if (isEmpty(func)) return damage;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
e.DamageSource = source; e.DamageSource = source;
e.DamageLine = line; e.DamageLine = line;
e.NewDamage = e.Damage = damage; e.NewDamage = e.Damage = damage;
@ -915,7 +894,7 @@ void DStaticEventHandler::WorldLightning()
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FWorldEvent e = eventManager.SetupWorldEvent(); FWorldEvent e = owner->SetupWorldEvent();
VMValue params[2] = { (DStaticEventHandler*)this, &e }; VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
} }
@ -952,7 +931,7 @@ void DStaticEventHandler::RenderFrame()
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FRenderEvent e = eventManager.SetupRenderEvent(); FRenderEvent e = owner->SetupRenderEvent;
VMValue params[2] = { (DStaticEventHandler*)this, &e }; VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
} }
@ -965,7 +944,7 @@ void DStaticEventHandler::RenderOverlay(EHudState state)
{ {
// don't create excessive DObjects if not going to be processed anyway // don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return; if (isEmpty(func)) return;
FRenderEvent e = eventManager.SetupRenderEvent(); FRenderEvent e = owner->SetupRenderEvent();
e.HudState = int(state); e.HudState = int(state);
VMValue params[2] = { (DStaticEventHandler*)this, &e }; VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
@ -1255,7 +1234,7 @@ CCMD(event)
for (int i = 0; i < argn; i++) for (int i = 0; i < argn; i++)
arg[i] = atoi(argv[2 + i]); arg[i] = atoi(argv[2 + i]);
// call locally // call locally
eventManager.Console(-1, argv[1], arg[0], arg[1], arg[2], true); primaryLevel->localEventManager->Console(-1, argv[1], arg[0], arg[1], arg[2], true);
} }
} }
@ -1280,6 +1259,6 @@ CCMD(netevent)
for (int i = 0; i < argn; i++) for (int i = 0; i < argn; i++)
arg[i] = atoi(argv[2 + i]); arg[i] = atoi(argv[2 + i]);
// call networked // call networked
eventManager.SendNetworkEvent(argv[1], arg[0], arg[1], arg[2], true); primaryLevel->localEventManager->SendNetworkEvent(argv[1], arg[0], arg[1], arg[2], true);
} }
} }

View file

@ -1,5 +1,4 @@
#ifndef EVENTS_H #pragma once
#define EVENTS_H
#include "dobject.h" #include "dobject.h"
#include "serializer.h" #include "serializer.h"
@ -8,6 +7,7 @@
#include "sbar.h" #include "sbar.h"
class DStaticEventHandler; class DStaticEventHandler;
struct EventManager;
enum class EventHandlerType enum class EventHandlerType
{ {
@ -34,6 +34,7 @@ public:
IsUiProcessor = false; IsUiProcessor = false;
} }
EventManager *owner;
DStaticEventHandler* prev; DStaticEventHandler* prev;
DStaticEventHandler* next; DStaticEventHandler* next;
virtual bool IsStatic() { return true; } virtual bool IsStatic() { return true; }
@ -58,6 +59,8 @@ public:
} }
*/ */
arc("next", next);
arc("prev", prev);
arc("Order", Order); arc("Order", Order);
arc("IsUiProcessor", IsUiProcessor); arc("IsUiProcessor", IsUiProcessor);
arc("RequireMouse", RequireMouse); arc("RequireMouse", RequireMouse);
@ -228,9 +231,15 @@ struct FReplacedEvent
struct EventManager struct EventManager
{ {
FLevelLocals *Level = nullptr;
DStaticEventHandler* FirstEventHandler = nullptr; DStaticEventHandler* FirstEventHandler = nullptr;
DStaticEventHandler* LastEventHandler = nullptr; DStaticEventHandler* LastEventHandler = nullptr;
EventManager() = default;
EventManager(FLevelLocals *l) { Level = l; }
~EventManager() { Shutdown(); }
bool ShouldCallStatic(bool forplay);
// register // register
bool RegisterHandler(DStaticEventHandler* handler); bool RegisterHandler(DStaticEventHandler* handler);
// unregister // unregister
@ -242,16 +251,12 @@ struct EventManager
// init static handlers // init static handlers
void InitStaticHandlers(bool map); void InitStaticHandlers(bool map);
// shutdown handlers // shutdown handlers
void Shutdown(bool map); void Shutdown();
// called right after the map has loaded (approximately same time as OPEN ACS scripts) // called right after the map has loaded (approximately same time as OPEN ACS scripts)
void WorldLoaded(); void WorldLoaded();
// called when the map is about to unload (approximately same time as UNLOADING ACS scripts) // called when the map is about to unload (approximately same time as UNLOADING ACS scripts)
void WorldUnloaded(); void WorldUnloaded();
// called right after the map has loaded (every time, UNSAFE VERSION)
void WorldLoadedUnsafe();
// called right before the map is unloaded (every time, UNSAFE VERSION)
void WorldUnloadedUnsafe();
// called around PostBeginPlay of each actor. // called around PostBeginPlay of each actor.
void WorldThingSpawned(AActor* actor); void WorldThingSpawned(AActor* actor);
// called after AActor::Die of each actor. // called after AActor::Die of each actor.
@ -301,7 +306,7 @@ struct EventManager
bool CheckReplacee(PClassActor** replacee, PClassActor* replacement); bool CheckReplacee(PClassActor** replacee, PClassActor* replacement);
// called on new game // called on new game
void NewGame(EventHandlerType handlerType); void NewGame();
// send networked event. unified function. // send networked event. unified function.
bool SendNetworkEvent(FString name, int arg1, int arg2, int arg3, bool manual); bool SendNetworkEvent(FString name, int arg1, int arg2, int arg3, bool manual);
@ -311,15 +316,19 @@ struct EventManager
// check if we need native mouse due to UiProcessors // check if we need native mouse due to UiProcessors
bool CheckRequireMouse(); bool CheckRequireMouse();
// serialization stuff
void SerializeEvents(FSerializer& arc);
void InitHandler(PClass* type); void InitHandler(PClass* type);
FWorldEvent SetupWorldEvent(); FWorldEvent SetupWorldEvent();
FRenderEvent SetupRenderEvent(); FRenderEvent SetupRenderEvent();
void SetOwnerForHandlers()
{
for (DStaticEventHandler* existinghandler = FirstEventHandler; existinghandler; existinghandler = existinghandler->next)
{
existinghandler->owner = this;
}
}
}; };
extern EventManager eventManager; extern EventManager eventManager;
extern EventManager staticEventManager;
#endif

View file

@ -3615,7 +3615,7 @@ void FParser::SF_ThingCount(void)
pClass=T_GetMobjType(t_argv[0]); pClass=T_GetMobjType(t_argv[0]);
if (!pClass) return; if (!pClass) return;
// If we want to count map items we must consider actor replacement // If we want to count map items we must consider actor replacement
pClass = pClass->GetReplacement(); pClass = pClass->GetReplacement(Level);
again: again:
auto it = Level->GetThinkerIterator<AActor>(); auto it = Level->GetThinkerIterator<AActor>();
@ -3644,7 +3644,7 @@ void FParser::SF_ThingCount(void)
{ {
// Again, with decorate replacements // Again, with decorate replacements
replacemented = true; replacemented = true;
PClassActor *newkind = pClass->GetReplacement(); PClassActor *newkind = pClass->GetReplacement(Level);
if (newkind != pClass) if (newkind != pClass)
{ {
pClass = newkind; pClass = newkind;

View file

@ -1173,7 +1173,7 @@ void G_Ticker ()
} }
// [ZZ] also tick the UI part of the events // [ZZ] also tick the UI part of the events
eventManager.UiTick(); primaryLevel->localEventManager->UiTick();
C_RunDelayedCommands(); C_RunDelayedCommands();
// do main actions // do main actions
@ -1213,7 +1213,7 @@ void G_Ticker ()
} }
// [MK] Additional ticker for UI events right after all others // [MK] Additional ticker for UI events right after all others
eventManager.PostUiTick(); primaryLevel->localEventManager->PostUiTick();
} }
@ -1697,7 +1697,7 @@ void G_DoPlayerPop(int playernum)
auto mo = players[playernum].mo; auto mo = players[playernum].mo;
mo->Level->Behaviors.StopMyScripts(mo); mo->Level->Behaviors.StopMyScripts(mo);
// [ZZ] fire player disconnect hook // [ZZ] fire player disconnect hook
eventManager.PlayerDisconnected(playernum); mo->Level->localEventManager->PlayerDisconnected(playernum);
// [RH] Let the scripts know the player left // [RH] Let the scripts know the player left
mo->Level->Behaviors.StartTypedScripts(SCRIPT_Disconnect, mo, true, playernum, true); mo->Level->Behaviors.StartTypedScripts(SCRIPT_Disconnect, mo, true, playernum, true);
if (mo != NULL) if (mo != NULL)

View file

@ -454,7 +454,7 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
// did we have any level before? // did we have any level before?
if (primaryLevel->info != nullptr) if (primaryLevel->info != nullptr)
eventManager.WorldUnloadedUnsafe(); staticEventManager.WorldUnloaded();
if (!savegamerestore) if (!savegamerestore)
{ {
@ -663,9 +663,13 @@ void FLevelLocals::ChangeLevel(const char *levelname, int position, int flags, i
unloading = true; unloading = true;
Behaviors.StartTypedScripts (SCRIPT_Unloading, NULL, false, 0, true); Behaviors.StartTypedScripts (SCRIPT_Unloading, NULL, false, 0, true);
// [ZZ] safe world unload // [ZZ] safe world unload
eventManager.WorldUnloaded(); for (auto Level : AllLevels())
{
// Todo: This must be exolicitly sandboxed!
Level->localEventManager->WorldUnloaded();
}
// [ZZ] unsafe world unload (changemap != map) // [ZZ] unsafe world unload (changemap != map)
eventManager.WorldUnloadedUnsafe(); staticEventManager.WorldUnloaded();
unloading = false; unloading = false;
STAT_ChangeLevel(nextlevel, this); STAT_ChangeLevel(nextlevel, this);
@ -1019,6 +1023,8 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au
if (flags2 & LEVEL2_FORCETEAMPLAYOFF) if (flags2 & LEVEL2_FORCETEAMPLAYOFF)
teamplay = false; teamplay = false;
if (isPrimaryLevel())
{
FString mapname = nextmapname; FString mapname = nextmapname;
mapname.ToLower(); mapname.ToLower();
Printf( Printf(
@ -1026,6 +1032,7 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au
"\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n" "\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n"
TEXTCOLOR_BOLD "%s - %s\n\n", TEXTCOLOR_BOLD "%s - %s\n\n",
mapname.GetChars(), LevelName.GetChars()); mapname.GetChars(), LevelName.GetChars());
}
// Set the sky map. // Set the sky map.
// First thing, we have a dummy sky texture name, // First thing, we have a dummy sky texture name,
@ -1063,7 +1070,7 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au
if (newGame) if (newGame)
{ {
eventManager.NewGame(EventHandlerType::Global); staticEventManager.NewGame();
} }
P_SetupLevel (this, position, newGame); P_SetupLevel (this, position, newGame);
@ -1118,7 +1125,7 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au
} }
const bool fromSnapshot = FromSnapshot; const bool fromSnapshot = FromSnapshot;
eventManager.PlayerEntered(ii, fromSnapshot && finishstate == FINISH_SameHub); localEventManager->PlayerEntered(ii, fromSnapshot && finishstate == FINISH_SameHub);
if (fromSnapshot) if (fromSnapshot)
{ {
@ -1136,9 +1143,9 @@ void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool au
StatusBar->AttachToPlayer (&players[consoleplayer]); StatusBar->AttachToPlayer (&players[consoleplayer]);
// unsafe world load // unsafe world load
eventManager.WorldLoadedUnsafe(); staticEventManager.WorldLoaded();
// regular world load (savegames are handled internally) // regular world load (savegames are handled internally)
eventManager.WorldLoaded(); localEventManager->WorldLoaded();
DoDeferedScripts (); // [RH] Do script actions that were triggered on another map. DoDeferedScripts (); // [RH] Do script actions that were triggered on another map.
@ -1484,6 +1491,7 @@ void FLevelLocals::Init()
P_InitParticles(this); P_InitParticles(this);
P_ClearParticles(this); P_ClearParticles(this);
BaseBlendA = 0.0f; // Remove underwater blend effect, if any BaseBlendA = 0.0f; // Remove underwater blend effect, if any
localEventManager = new EventManager;
gravity = sv_gravity * 35/TICRATE; gravity = sv_gravity * 35/TICRATE;
aircontrol = sv_aircontrol; aircontrol = sv_aircontrol;
@ -2121,6 +2129,8 @@ void FLevelLocals::Mark()
GC::Mark(BotInfo.firstthing); GC::Mark(BotInfo.firstthing);
GC::Mark(BotInfo.body1); GC::Mark(BotInfo.body1);
GC::Mark(BotInfo.body2); GC::Mark(BotInfo.body2);
GC::Mark(localEventManager->FirstEventHandler);
GC::Mark(localEventManager->LastEventHandler);
Thinkers.MarkRoots(); Thinkers.MarkRoots();
canvasTextureInfo.Mark(); canvasTextureInfo.Mark();
for (auto &c : CorpseQueue) for (auto &c : CorpseQueue)

View file

@ -96,6 +96,7 @@ class DAutomapBase;
struct wbstartstruct_t; struct wbstartstruct_t;
class DSectorMarker; class DSectorMarker;
struct FTranslator; struct FTranslator;
struct EventManager;
typedef TMap<int, int> FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS) typedef TMap<int, int> FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS)
typedef TMap<FName, int> FDialogueMap; // maps actor class names to dialogue array index typedef TMap<FName, int> FDialogueMap; // maps actor class names to dialogue array index
@ -442,6 +443,7 @@ public:
TArray<FLinePortalSpan> linePortalSpans; TArray<FLinePortalSpan> linePortalSpans;
FSectionContainer sections; FSectionContainer sections;
FCanvasTextureInfo canvasTextureInfo; FCanvasTextureInfo canvasTextureInfo;
EventManager *localEventManager = nullptr;
// [ZZ] Destructible geometry information // [ZZ] Destructible geometry information
TMap<int, FHealthGroup> healthGroups; TMap<int, FHealthGroup> healthGroups;

View file

@ -178,7 +178,7 @@ void DLightningThinker::LightningFlash ()
Level->flags |= LEVEL_SWAPSKIES; // set alternate sky Level->flags |= LEVEL_SWAPSKIES; // set alternate sky
S_Sound (CHAN_AUTO, "world/thunder", 1.0, ATTN_NONE); S_Sound (CHAN_AUTO, "world/thunder", 1.0, ATTN_NONE);
// [ZZ] just in case // [ZZ] just in case
eventManager.WorldLightning(); Level->localEventManager->WorldLightning();
// start LIGHTNING scripts // start LIGHTNING scripts
Level->Behaviors.StartTypedScripts (SCRIPT_Lightning, NULL, false); // [RH] Run lightning scripts Level->Behaviors.StartTypedScripts (SCRIPT_Lightning, NULL, false); // [RH] Run lightning scripts

View file

@ -1147,7 +1147,7 @@ void DBaseStatusBar::DrawTopStuff (EHudState state)
DrawMessages (HUDMSGLayer_OverMap, (state == HUD_StatusBar) ? GetTopOfStatusbar() : SCREENHEIGHT); DrawMessages (HUDMSGLayer_OverMap, (state == HUD_StatusBar) ? GetTopOfStatusbar() : SCREENHEIGHT);
} }
DrawMessages (HUDMSGLayer_OverHUD, (state == HUD_StatusBar) ? GetTopOfStatusbar() : SCREENHEIGHT); DrawMessages (HUDMSGLayer_OverHUD, (state == HUD_StatusBar) ? GetTopOfStatusbar() : SCREENHEIGHT);
eventManager.RenderOverlay(state); primaryLevel->localEventManager->RenderOverlay(state);
DrawConsistancy (); DrawConsistancy ();
DrawWaiting (); DrawWaiting ();

View file

@ -395,7 +395,7 @@ void PClassActor::StaticInit()
InitBotStuff(); InitBotStuff();
// reinit GLOBAL static stuff from gameinfo, once classes are loaded. // reinit GLOBAL static stuff from gameinfo, once classes are loaded.
eventManager.InitStaticHandlers(false); staticEventManager.InitStaticHandlers(false);
} }
//========================================================================== //==========================================================================
@ -517,7 +517,7 @@ void PClassActor::RegisterIDs()
// //
//========================================================================== //==========================================================================
PClassActor *PClassActor::GetReplacement(bool lookskill) PClassActor *PClassActor::GetReplacement(FLevelLocals *Level, bool lookskill)
{ {
FName skillrepname = NAME_None; FName skillrepname = NAME_None;
@ -538,7 +538,7 @@ PClassActor *PClassActor::GetReplacement(bool lookskill)
} }
// [MK] ZScript replacement through Event Handlers, has priority over others // [MK] ZScript replacement through Event Handlers, has priority over others
PClassActor *Replacement = ActorInfo()->Replacement; PClassActor *Replacement = ActorInfo()->Replacement;
if (eventManager.CheckReplacement(this,&Replacement) ) if (Level->localEventManager->CheckReplacement(this,&Replacement) )
{ {
// [MK] the replacement is final, so don't continue with the chain // [MK] the replacement is final, so don't continue with the chain
return Replacement ? Replacement : this; return Replacement ? Replacement : this;
@ -573,7 +573,7 @@ PClassActor *PClassActor::GetReplacement(bool lookskill)
// //
//========================================================================== //==========================================================================
PClassActor *PClassActor::GetReplacee(bool lookskill) PClassActor *PClassActor::GetReplacee(FLevelLocals *Level, bool lookskill)
{ {
FName skillrepname = NAME_None; FName skillrepname = NAME_None;
@ -598,7 +598,7 @@ PClassActor *PClassActor::GetReplacee(bool lookskill)
// showing up, one can assign an Arachnotron as the one being replaced // showing up, one can assign an Arachnotron as the one being replaced
// so functions like CheckReplacee and A_BossDeath can actually work, given // so functions like CheckReplacee and A_BossDeath can actually work, given
// modders set it up that way. // modders set it up that way.
if (eventManager.CheckReplacee(&savedrep, this)) if (Level->localEventManager->CheckReplacee(&savedrep, this))
{ {
// [MK] the replacement is final, so don't continue with the chain // [MK] the replacement is final, so don't continue with the chain
return savedrep ? savedrep : this; return savedrep ? savedrep : this;

View file

@ -350,8 +350,8 @@ public:
return i != nullptr && state >= i->OwnedStates && state < i->OwnedStates + i->NumOwnedStates; return i != nullptr && state >= i->OwnedStates && state < i->OwnedStates + i->NumOwnedStates;
} }
PClassActor *GetReplacement(bool lookskill=true); PClassActor *GetReplacement(FLevelLocals *Level, bool lookskill=true);
PClassActor *GetReplacee(bool lookskill=true); PClassActor *GetReplacee(FLevelLocals *Level, bool lookskill=true);
// For those times when being able to scan every kind of actor is convenient // For those times when being able to scan every kind of actor is convenient
static TArray<PClassActor *> AllActorClasses; static TArray<PClassActor *> AllActorClasses;

View file

@ -3639,7 +3639,7 @@ do_count:
{ {
// Again, with decorate replacements // Again, with decorate replacements
replacemented = true; replacemented = true;
PClassActor *newkind = kind->GetReplacement(); PClassActor *newkind = kind->GetReplacement(Level);
if (newkind != kind) if (newkind != kind)
{ {
kind = newkind; kind = newkind;
@ -3727,7 +3727,7 @@ int DLevelScript::DoSpawn (int type, const DVector3 &pos, int tid, DAngle angle,
if (info != NULL) if (info != NULL)
{ {
info = info->GetReplacement (); info = info->GetReplacement (Level);
if ((GetDefaultByType (info)->flags3 & MF3_ISMONSTER) && if ((GetDefaultByType (info)->flags3 & MF3_ISMONSTER) &&
((dmflags & DF_NO_MONSTERS) || (Level->flags2 & LEVEL2_NOMONSTERS))) ((dmflags & DF_NO_MONSTERS) || (Level->flags2 & LEVEL2_NOMONSTERS)))

View file

@ -3393,7 +3393,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_WolfAttack)
|| (self->target->flags2 & (MF2_INVULNERABLE|MF2_DORMANT))); || (self->target->flags2 & (MF2_INVULNERABLE|MF2_DORMANT)));
if (flags & WAF_USEPUFF && pufftype) if (flags & WAF_USEPUFF && pufftype)
{ {
AActor *dpuff = GetDefaultByType(pufftype->GetReplacement()); AActor *dpuff = GetDefaultByType(pufftype->GetReplacement(self->Level));
mod = dpuff->DamageType; mod = dpuff->DamageType;
if (dpuff->flags2 & MF2_THRUGHOST && self->target->flags3 & MF3_GHOST) if (dpuff->flags2 & MF2_THRUGHOST && self->target->flags3 & MF3_GHOST)

View file

@ -124,7 +124,7 @@ void P_DamageLinedef(line_t* line, AActor* source, int damage, FName damagetype,
if (dogroups) if (dogroups)
{ {
damage = eventManager.WorldLineDamaged(line, source, damage, damagetype, side, position, isradius); damage = line->GetLevel()->localEventManager->WorldLineDamaged(line, source, damage, damagetype, side, position, isradius);
if (damage < 0) damage = 0; if (damage < 0) damage = 0;
} }
@ -160,7 +160,7 @@ void P_DamageSector(sector_t* sector, AActor* source, int damage, FName damagety
if (dogroups) if (dogroups)
{ {
damage = eventManager.WorldSectorDamaged(sector, source, damage, damagetype, part, position, isradius); damage = sector->Level->localEventManager->WorldSectorDamaged(sector, source, damage, damagetype, part, position, isradius);
if (damage < 0) damage = 0; if (damage < 0) damage = 0;
} }

View file

@ -3073,7 +3073,7 @@ void A_BossDeath(AActor *self)
FName mytype = self->GetClass()->TypeName; FName mytype = self->GetClass()->TypeName;
// Ugh... // Ugh...
FName type = self->GetClass()->GetReplacee()->TypeName; FName type = self->GetClass()->GetReplacee(self->Level)->TypeName;
// Do generic special death actions first // Do generic special death actions first
bool checked = false; bool checked = false;

View file

@ -347,7 +347,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf
} }
// [ZZ] Fire WorldThingDied script hook. // [ZZ] Fire WorldThingDied script hook.
eventManager.WorldThingDied(this, inflictor); Level->localEventManager->WorldThingDied(this, inflictor);
// [JM] Fire KILL type scripts for actor. Not needed for players, since they have the "DEATH" script type. // [JM] Fire KILL type scripts for actor. Not needed for players, since they have the "DEATH" script type.
if (!player && !(flags7 & MF7_NOKILLSCRIPTS) && ((flags7 & MF7_USEKILLSCRIPTS) || gameinfo.forcekillscripts)) if (!player && !(flags7 & MF7_NOKILLSCRIPTS) && ((flags7 & MF7_USEKILLSCRIPTS) || gameinfo.forcekillscripts))
@ -560,7 +560,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf
ClientObituary (this, inflictor, source, dmgflags, MeansOfDeath); ClientObituary (this, inflictor, source, dmgflags, MeansOfDeath);
// [ZZ] fire player death hook // [ZZ] fire player death hook
eventManager.PlayerDied(Level->PlayerNum(player)); Level->localEventManager->PlayerDied(Level->PlayerNum(player));
// Death script execution, care of Skull Tag // Death script execution, care of Skull Tag
Level->Behaviors.StartTypedScripts (SCRIPT_Death, this, true); Level->Behaviors.StartTypedScripts (SCRIPT_Death, this, true);
@ -1460,7 +1460,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da
} }
const int realdamage = MAX(0, damage); const int realdamage = MAX(0, damage);
eventManager.WorldThingDamaged(target, inflictor, source, realdamage, mod, flags, angle); target->Level->localEventManager->WorldThingDamaged(target, inflictor, source, realdamage, mod, flags, angle);
needevent = false; needevent = false;
target->CallDie (source, inflictor, flags, MeansOfDeath); target->CallDie (source, inflictor, flags, MeansOfDeath);
@ -1481,7 +1481,7 @@ static int DoDamageMobj(AActor *target, AActor *inflictor, AActor *source, int d
if (realdamage > 0 && needevent) if (realdamage > 0 && needevent)
{ {
// [ZZ] event handlers only need the resultant damage (they can't do anything about it anyway) // [ZZ] event handlers only need the resultant damage (they can't do anything about it anyway)
eventManager.WorldThingDamaged(target, inflictor, source, realdamage, mod, flags, angle); target->Level->localEventManager->WorldThingDamaged(target, inflictor, source, realdamage, mod, flags, angle);
} }
return MAX(0, realdamage); return MAX(0, realdamage);

View file

@ -4415,7 +4415,7 @@ AActor *P_LineAttack(AActor *t1, DAngle angle, double distance,
shootz += sz; shootz += sz;
// We need to check the defaults of the replacement here // We need to check the defaults of the replacement here
AActor *puffDefaults = GetDefaultByType(pufftype->GetReplacement()); AActor *puffDefaults = GetDefaultByType(pufftype->GetReplacement(t1->Level));
TData.hitGhosts = (t1->player != NULL && TData.hitGhosts = (t1->player != NULL &&
t1->player->ReadyWeapon != NULL && t1->player->ReadyWeapon != NULL &&
@ -5161,7 +5161,7 @@ void P_RailAttack(FRailParams *p)
int flags; int flags;
assert(puffclass != NULL); // Because we set it to a default above assert(puffclass != NULL); // Because we set it to a default above
AActor *puffDefaults = GetDefaultByType(puffclass->GetReplacement()); //Contains all the flags such as FOILINVUL, etc. AActor *puffDefaults = GetDefaultByType(puffclass->GetReplacement(source->Level)); //Contains all the flags such as FOILINVUL, etc.
// disabled because not complete yet. // disabled because not complete yet.
flags = (puffDefaults->flags6 & MF6_NOTRIGGER) ? TRACE_ReportPortals : TRACE_PCross | TRACE_Impact | TRACE_ReportPortals; flags = (puffDefaults->flags6 & MF6_NOTRIGGER) ? TRACE_ReportPortals : TRACE_PCross | TRACE_Impact | TRACE_ReportPortals;

View file

@ -1208,7 +1208,7 @@ bool AActor::Grind(bool items)
if (i != NULL) if (i != NULL)
{ {
i = i->GetReplacement(); i = i->GetReplacement(Level);
const AActor *defaults = GetDefaultByType (i); const AActor *defaults = GetDefaultByType (i);
if (defaults->SpawnState == NULL || if (defaults->SpawnState == NULL ||
@ -4539,7 +4539,7 @@ AActor *AActor::StaticSpawn(FLevelLocals *Level, PClassActor *type, const DVecto
if (allowreplacement) if (allowreplacement)
{ {
type = type->GetReplacement(); type = type->GetReplacement(Level);
} }
AActor *actor; AActor *actor;
@ -4682,7 +4682,7 @@ void AActor::PostBeginPlay ()
void AActor::CallPostBeginPlay() void AActor::CallPostBeginPlay()
{ {
Super::CallPostBeginPlay(); Super::CallPostBeginPlay();
eventManager.WorldThingSpawned(this); Level->localEventManager->WorldThingSpawned(this);
} }
bool AActor::isFast() bool AActor::isFast()
@ -4800,7 +4800,7 @@ void AActor::OnDestroy ()
// note that this differs from ThingSpawned in that you can actually override OnDestroy to avoid calling the hook. // note that this differs from ThingSpawned in that you can actually override OnDestroy to avoid calling the hook.
// but you can't really do that without utterly breaking the game, so it's ok. // but you can't really do that without utterly breaking the game, so it's ok.
// note: if OnDestroy is ever made optional, E_WorldThingDestroyed should still be called for ANY thing. // note: if OnDestroy is ever made optional, E_WorldThingDestroyed should still be called for ANY thing.
eventManager.WorldThingDestroyed(this); Level->localEventManager->WorldThingDestroyed(this);
DeleteAttachedLights(); DeleteAttachedLights();
ClearRenderSectorList(); ClearRenderSectorList();
@ -5155,7 +5155,7 @@ AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flag
DObject::StaticPointerSubstitution (oldactor, p->mo); DObject::StaticPointerSubstitution (oldactor, p->mo);
eventManager.PlayerRespawned(PlayerNum(p)); localEventManager->PlayerRespawned(PlayerNum(p));
Behaviors.StartTypedScripts (SCRIPT_Respawn, p->mo, true); Behaviors.StartTypedScripts (SCRIPT_Respawn, p->mo, true);
} }
} }
@ -5363,7 +5363,7 @@ AActor *FLevelLocals::SpawnMapThing (FMapThing *mthing, int position)
// it to the unknown thing. // it to the unknown thing.
// Handle decorate replacements explicitly here // Handle decorate replacements explicitly here
// to check for missing frames in the replacement object. // to check for missing frames in the replacement object.
i = mentry->Type->GetReplacement(); i = mentry->Type->GetReplacement(this);
const AActor *defaults = GetDefaultByType (i); const AActor *defaults = GetDefaultByType (i);
if (defaults->SpawnState == NULL || if (defaults->SpawnState == NULL ||
@ -7137,7 +7137,7 @@ void AActor::Revive()
} }
// [ZZ] resurrect hook // [ZZ] resurrect hook
eventManager.WorldThingRevived(this); Level->localEventManager->WorldThingRevived(this);
} }
int AActor::GetGibHealth() const int AActor::GetGibHealth() const

View file

@ -1000,7 +1000,8 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload)
// [ZZ] serialize health groups // [ZZ] serialize health groups
P_SerializeHealthGroups(this, arc); P_SerializeHealthGroups(this, arc);
// [ZZ] serialize events // [ZZ] serialize events
eventManager.SerializeEvents(arc); arc("firstevent", localEventManager->FirstEventHandler)
("lastevent", localEventManager->LastEventHandler);
Thinkers.SerializeThinkers(arc, hubload); Thinkers.SerializeThinkers(arc, hubload);
arc("polyobjs", Polyobjects); arc("polyobjs", Polyobjects);
SerializeSubsectors(arc, "subsectors"); SerializeSubsectors(arc, "subsectors");
@ -1024,6 +1025,7 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload)
FWeaponSlots::SetupWeaponSlots(Players[i]->mo); FWeaponSlots::SetupWeaponSlots(Players[i]->mo);
} }
} }
localEventManager->SetOwnerForHandlers(); // This cannot be automated.
RecreateAllAttachedLights(); RecreateAllAttachedLights();
InitPortalGroups(this); InitPortalGroups(this);

View file

@ -338,6 +338,8 @@ void FLevelLocals::ClearLevelData()
Scrolls.Clear(); Scrolls.Clear();
if (automap) automap->Destroy(); if (automap) automap->Destroy();
Behaviors.UnloadModules(); Behaviors.UnloadModules();
delete localEventManager;
localEventManager = nullptr;
} }
//========================================================================== //==========================================================================
@ -348,9 +350,6 @@ void FLevelLocals::ClearLevelData()
void P_FreeLevelData () void P_FreeLevelData ()
{ {
// [ZZ] delete per-map event handlers
eventManager.Shutdown(true);
R_FreePastViewers(); R_FreePastViewers();
for (auto Level : AllLevels()) for (auto Level : AllLevels())
@ -425,7 +424,7 @@ void P_SetupLevel(FLevelLocals *Level, int position, bool newGame)
// [ZZ] init per-map static handlers. we need to call this before everything is set up because otherwise scripts don't receive PlayerEntered event // [ZZ] init per-map static handlers. we need to call this before everything is set up because otherwise scripts don't receive PlayerEntered event
// (which happens at god-knows-what stage in this function, but definitely not the last part, because otherwise it'd work to put E_InitStaticHandlers before the player spawning) // (which happens at god-knows-what stage in this function, but definitely not the last part, because otherwise it'd work to put E_InitStaticHandlers before the player spawning)
eventManager.InitStaticHandlers(true); Level->localEventManager->InitStaticHandlers(true);
// generate a checksum for the level, to be included and checked with savegames. // generate a checksum for the level, to be included and checked with savegames.
map->GetChecksum(Level->md5); map->GetChecksum(Level->md5);
@ -434,7 +433,7 @@ void P_SetupLevel(FLevelLocals *Level, int position, bool newGame)
if (newGame) if (newGame)
{ {
eventManager.NewGame(EventHandlerType::PerMap); Level->localEventManager->NewGame();
} }
MapLoader loader(Level); MapLoader loader(Level);
@ -587,7 +586,7 @@ static void P_Shutdown ()
} }
P_FreeLevelData (); P_FreeLevelData ();
// [ZZ] delete global event handlers // [ZZ] delete global event handlers
eventManager.Shutdown(false); staticEventManager.Shutdown(); // clear out the handlers before starting the engine shutdown
ST_Clear(); ST_Clear();
for (auto &p : players) for (auto &p : players)
{ {

View file

@ -168,7 +168,7 @@ bool P_ActivateLine (line_t *line, AActor *mo, int side, int activationType, DVe
// [MK] Use WorldLinePreActivated to decide if activation should continue // [MK] Use WorldLinePreActivated to decide if activation should continue
bool shouldactivate = true; bool shouldactivate = true;
eventManager.WorldLinePreActivated(line, mo, activationType, &shouldactivate); Level->localEventManager->WorldLinePreActivated(line, mo, activationType, &shouldactivate);
if ( !shouldactivate ) return false; if ( !shouldactivate ) return false;
bool remote = (line->special != 7 && line->special != 8 && (line->special < 11 || line->special > 14)); bool remote = (line->special != 7 && line->special != 8 && (line->special < 11 || line->special > 14));
@ -180,7 +180,7 @@ bool P_ActivateLine (line_t *line, AActor *mo, int side, int activationType, DVe
buttonSuccess = P_ExecuteSpecial(line->GetLevel(), line->special, line, mo, side == 1, line->args[0], line->args[1], line->args[2], line->args[3], line->args[4]); buttonSuccess = P_ExecuteSpecial(line->GetLevel(), line->special, line, mo, side == 1, line->args[0], line->args[1], line->args[2], line->args[3], line->args[4]);
// [MK] Fire up WorldLineActivated // [MK] Fire up WorldLineActivated
if ( buttonSuccess ) eventManager.WorldLineActivated(line, mo, activationType); if ( buttonSuccess ) Level->localEventManager->WorldLineActivated(line, mo, activationType);
special = line->special; special = line->special;
if (!repeat && buttonSuccess) if (!repeat && buttonSuccess)

View file

@ -62,7 +62,7 @@ bool FLevelLocals::EV_Thing_Spawn (int tid, AActor *source, int type, DAngle ang
return false; return false;
// Handle decorate replacements. // Handle decorate replacements.
kind = kind->GetReplacement(); kind = kind->GetReplacement(this);
if ((GetDefaultByType(kind)->flags3 & MF3_ISMONSTER) && if ((GetDefaultByType(kind)->flags3 & MF3_ISMONSTER) &&
((dmflags & DF_NO_MONSTERS) || (flags2 & LEVEL2_NOMONSTERS))) ((dmflags & DF_NO_MONSTERS) || (flags2 & LEVEL2_NOMONSTERS)))
@ -274,7 +274,7 @@ bool FLevelLocals::EV_Thing_Projectile (int tid, AActor *source, int type, const
} }
// Handle decorate replacements. // Handle decorate replacements.
kind = kind->GetReplacement(); kind = kind->GetReplacement(this);
defflags3 = GetDefaultByType(kind)->flags3; defflags3 = GetDefaultByType(kind)->flags3;
if ((defflags3 & MF3_ISMONSTER) && if ((defflags3 & MF3_ISMONSTER) &&

View file

@ -127,9 +127,14 @@ void P_Ticker (void)
P_ResetSightCounters (false); P_ResetSightCounters (false);
R_ClearInterpolationPath(); R_ClearInterpolationPath();
// Since things will be moving, it's okay to interpolate them in the renderer.
r_NoInterpolate = false;
// Reset all actor interpolations on all levels before the current thinking turn so that indirect actor movement gets properly interpolated. // Reset all actor interpolations on all levels before the current thinking turn so that indirect actor movement gets properly interpolated.
for (auto Level : AllLevels()) for (auto Level : AllLevels())
{ {
// todo: set up a sandbox for secondary levels here.
auto it = Level->GetThinkerIterator<AActor>(); auto it = Level->GetThinkerIterator<AActor>();
AActor *ac; AActor *ac;
@ -138,22 +143,13 @@ void P_Ticker (void)
ac->ClearInterpolation(); ac->ClearInterpolation();
} }
P_ThinkParticles(Level); // [RH] make the particles think P_ThinkParticles(Level); // [RH] make the particles think
}
// Since things will be moving, it's okay to interpolate them in the renderer.
r_NoInterpolate = false;
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i]) if (Level->PlayerInGame(i))
P_PlayerThink (&players[i]); P_PlayerThink(Level->Players[i]);
// [ZZ] call the WorldTick hook // [ZZ] call the WorldTick hook
eventManager.WorldTick(); Level->localEventManager->WorldTick();
StatusBar->CallTick (); // [RH] moved this here
for (auto Level : AllLevels())
{
// todo: set up a sandbox for secondary levels here.
Level->Tick(); // [RH] let the level tick Level->Tick(); // [RH] let the level tick
Level->Thinkers.RunThinkers(Level); Level->Thinkers.RunThinkers(Level);
@ -169,4 +165,5 @@ void P_Ticker (void)
Level->maptime++; Level->maptime++;
Level->totaltime++; Level->totaltime++;
} }
StatusBar->CallTick(); // Status bar should tick AFTER the thinkers to properly reflect the level's state at this time.
} }

View file

@ -654,8 +654,7 @@ bool player_t::Resurrect()
// player is now alive. // player is now alive.
// fire E_PlayerRespawned and start the ACS SCRIPT_Respawn. // fire E_PlayerRespawned and start the ACS SCRIPT_Respawn.
eventManager.PlayerRespawned(pnum); mo->Level->localEventManager->PlayerRespawned(pnum);
//
mo->Level->Behaviors.StartTypedScripts(SCRIPT_Respawn, mo, true); mo->Level->Behaviors.StartTypedScripts(SCRIPT_Respawn, mo, true);
return true; return true;
} }

View file

@ -1232,26 +1232,26 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetSpriteIndex, ZS_GetSpriteIndex)
static PClassActor *ZS_GetReplacement(PClassActor *c) static PClassActor *ZS_GetReplacement(PClassActor *c)
{ {
return c->GetReplacement(); return c->GetReplacement(currentVMLevel);
} }
DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetReplacement, ZS_GetReplacement) DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetReplacement, ZS_GetReplacement)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_POINTER(c, PClassActor); PARAM_POINTER(c, PClassActor);
ACTION_RETURN_POINTER(c->GetReplacement()); ACTION_RETURN_POINTER(ZS_GetReplacement(c));
} }
static PClassActor *ZS_GetReplacee(PClassActor *c) static PClassActor *ZS_GetReplacee(PClassActor *c)
{ {
return c->GetReplacee(); return c->GetReplacee(currentVMLevel);
} }
DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetReplacee, ZS_GetReplacee) DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetReplacee, ZS_GetReplacee)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_POINTER(c, PClassActor); PARAM_POINTER(c, PClassActor);
ACTION_RETURN_POINTER(c->GetReplacee()); ACTION_RETURN_POINTER(ZS_GetReplacee(c));
} }
static void DrawSplash(AActor *self, int count, double angle, int kind) static void DrawSplash(AActor *self, int count, double angle, int kind)

View file

@ -91,6 +91,7 @@
#include "events.h" #include "events.h"
#include "doomerrors.h" #include "doomerrors.h"
#include "i_system.h" #include "i_system.h"
#include "g_levellocals.h"
// Prototypes and declarations. // Prototypes and declarations.
#include "rawinput.h" #include "rawinput.h"
@ -177,7 +178,7 @@ static void I_CheckGUICapture ()
} }
// [ZZ] check active event handlers that want the UI processing // [ZZ] check active event handlers that want the UI processing
if (!wantCapt && eventManager.CheckUiProcessors()) if (!wantCapt && primaryLevel->localEventManager->CheckUiProcessors())
wantCapt = true; wantCapt = true;
if (wantCapt != GUICapture) if (wantCapt != GUICapture)
@ -781,7 +782,7 @@ void I_StartTic ()
BlockMouseMove--; BlockMouseMove--;
ResetButtonTriggers (); ResetButtonTriggers ();
I_CheckGUICapture (); I_CheckGUICapture ();
EventHandlerResultForNativeMouse = eventManager.CheckRequireMouse(); EventHandlerResultForNativeMouse = primaryLevel->localEventManager->CheckRequireMouse();
I_CheckNativeMouse (false, EventHandlerResultForNativeMouse); I_CheckNativeMouse (false, EventHandlerResultForNativeMouse);
I_GetEvent (); I_GetEvent ();
} }