Skip to content

Commit

Permalink
Added OnEngineInitialize() for static event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Boondorl authored and madame-rachelle committed Jan 25, 2023
1 parent 4c7e9c6 commit 2d94321
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/d_main.cpp
Expand Up @@ -3512,6 +3512,8 @@ static int D_InitGame(const FIWADInfo* iwad_info, TArray<FString>& 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;
}
//==========================================================================
Expand Down
20 changes: 20 additions & 0 deletions src/events.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/events.h
Expand Up @@ -77,6 +77,7 @@ class DStaticEventHandler : public DObject // make it a part of normal GC proces
void OnUnregister();

//
void OnEngineInitialize();
void WorldLoaded();
void WorldUnloaded(const FString& nextmap);
void WorldThingSpawned(AActor* actor);
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions wadsrc/static/zscript/events.zs
Expand Up @@ -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) {}
Expand Down

0 comments on commit 2d94321

Please sign in to comment.