diff --git a/src/d_main.cpp b/src/d_main.cpp index 5104b1aa0..ce49a75cb 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -3524,6 +3524,8 @@ static int D_InitGame(const FIWADInfo* iwad_info, TArray& allwads, TArr D_StartTitle (); // start up intro loop setmodeneeded = false; // This may be set to true here, but isn't needed for a restart } + + staticEventManager.OnEngineInitialize(); return 0; } //========================================================================== diff --git a/src/events.cpp b/src/events.cpp index 28caa1c38..d179ac50a 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -280,6 +280,14 @@ void EventManager::Shutdown() handler->name(); \ } +void EventManager::OnEngineInitialize() +{ + for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next) + { + if (handler->IsStatic()) + handler->OnEngineInitialize(); + } +} // note for the functions below. // *Unsafe is executed on EVERY map load/close, including savegame loading, etc. @@ -773,6 +781,18 @@ FWorldEvent EventManager::SetupWorldEvent() return e; } +void DStaticEventHandler::OnEngineInitialize() +{ + IFVIRTUAL(DStaticEventHandler, OnEngineInitialize) + { + // don't create excessive DObjects if not going to be processed anyway + if (isEmpty(func)) return; + VMValue params[1] = { (DStaticEventHandler*)this }; + VMCall(func, params, 1, nullptr, 0); + } +} + + void DStaticEventHandler::WorldLoaded() { IFVIRTUAL(DStaticEventHandler, WorldLoaded) diff --git a/src/events.h b/src/events.h index b6ca6f6a4..c97908b37 100755 --- a/src/events.h +++ b/src/events.h @@ -77,6 +77,7 @@ public: void OnUnregister(); // + void OnEngineInitialize(); void WorldLoaded(); void WorldUnloaded(const FString& nextmap); void WorldThingSpawned(AActor* actor); @@ -230,6 +231,8 @@ struct EventManager // shutdown handlers void Shutdown(); + // after the engine is done creating data + void OnEngineInitialize(); // called right after the map has loaded (approximately same time as OPEN ACS scripts) void WorldLoaded(); // called when the map is about to unload (approximately same time as UNLOADING ACS scripts) diff --git a/wadsrc/static/zscript/events.zs b/wadsrc/static/zscript/events.zs index 6da39d39f..c3c10129c 100644 --- a/wadsrc/static/zscript/events.zs +++ b/wadsrc/static/zscript/events.zs @@ -89,6 +89,7 @@ class StaticEventHandler : Object native play version("2.4") virtual void OnUnregister() {} // actual handlers are here + virtual void OnEngineInitialize() {} virtual void WorldLoaded(WorldEvent e) {} virtual void WorldUnloaded(WorldEvent e) {} virtual void WorldThingSpawned(WorldEvent e) {}