From 7885a22cadb27d31c5f1966181c29b264d4742a7 Mon Sep 17 00:00:00 2001 From: ZippeyKeys12 Date: Fri, 14 Sep 2018 21:57:07 -0500 Subject: [PATCH] Add NewGame to EventHandler https://forum.zdoom.org/viewtopic.php?t=61908 --- src/events.cpp | 22 ++++++++++++++++++++++ src/events.h | 6 ++++++ src/g_level.cpp | 4 ++++ wadsrc/static/zscript/events.txt | 3 +++ 4 files changed, 35 insertions(+) diff --git a/src/events.cpp b/src/events.cpp index 91e66b82b..1baa9b1d3 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -515,6 +515,14 @@ bool E_CheckReplacement( PClassActor *replacee, PClassActor **replacement ) return final; } +void E_NewGame() +{ + for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) + { + handler->NewGame(); + } +} + // normal event loopers (non-special, argument-less) DEFINE_EVENT_LOOPER(RenderFrame) DEFINE_EVENT_LOOPER(WorldLightning) @@ -668,6 +676,8 @@ DEFINE_EMPTY_HANDLER(DStaticEventHandler, NetworkProcess); DEFINE_EMPTY_HANDLER(DStaticEventHandler, CheckReplacement); +DEFINE_EMPTY_HANDLER(DStaticEventHandler, NewGame) + // =========================================== // // Event handlers @@ -1154,6 +1164,18 @@ void DStaticEventHandler::CheckReplacement( PClassActor *replacee, PClassActor * } } +void DStaticEventHandler::NewGame() +{ + IFVIRTUAL(DStaticEventHandler, NewGame) + { + // don't create excessive DObjects if not going to be processed anyway + if (func == DStaticEventHandler_NewGame_VMPtr) + return; + VMValue params[1] = { (DStaticEventHandler*)this }; + VMCall(func, params, 1, nullptr, 0); + } +} + // void DStaticEventHandler::OnDestroy() { diff --git a/src/events.h b/src/events.h index 54d975566..456db6c10 100755 --- a/src/events.h +++ b/src/events.h @@ -72,6 +72,9 @@ void E_Console(int player, FString name, int arg1, int arg2, int arg3, bool manu // called when looking up the replacement for an actor class bool E_CheckReplacement(PClassActor* replacee, PClassActor** replacement); +// called on new game +void E_NewGame(); + // send networked event. unified function. bool E_SendNetworkEvent(FString name, int arg1, int arg2, int arg3, bool manual); @@ -172,6 +175,9 @@ public: // void CheckReplacement(PClassActor* replacee, PClassActor** replacement, bool* final); + + // + void NewGame(); }; class DEventHandler : public DStaticEventHandler { diff --git a/src/g_level.cpp b/src/g_level.cpp index 86567ea84..36843919b 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -527,6 +527,10 @@ void G_InitNew (const char *mapname, bool bTitleLevel) gamestate = GS_LEVEL; } G_DoLoadLevel (0, false); + if(!savegamerestore) + { + E_NewGame(); + } } // diff --git a/wadsrc/static/zscript/events.txt b/wadsrc/static/zscript/events.txt index 9a908f060..d2d8ed324 100755 --- a/wadsrc/static/zscript/events.txt +++ b/wadsrc/static/zscript/events.txt @@ -339,6 +339,9 @@ class StaticEventHandler : Object native play version("2.4") // virtual native void CheckReplacement(ReplaceEvent e); + // + virtual native void NewGame(); + // this value will be queried on Register() to decide the relative order of this handler to every other. // this is most useful in UI systems. // default is 0.