From d2a9de0012c63725e3e3e6fd5727fb49192505b9 Mon Sep 17 00:00:00 2001 From: Sterling Parker Date: Tue, 25 Aug 2020 09:54:20 -0600 Subject: [PATCH] Add PlayerSpawned() event (#1118) * Add PlayerSpawned() event * add playerspawned to DStaticEventHandler * Define PlyerSpawned() correctly --- src/events.cpp | 20 ++++++++++++++++++++ src/events.h | 3 +++ src/playsim/p_mobj.cpp | 1 + wadsrc/static/zscript/events.zs | 1 + 4 files changed, 25 insertions(+) diff --git a/src/events.cpp b/src/events.cpp index 08b713068..d07bfefe8 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -418,6 +418,14 @@ void EventManager::PlayerEntered(int num, bool fromhub) handler->PlayerEntered(num, fromhub); } +void EventManager::PlayerSpawned(int num) +{ + if (ShouldCallStatic(true)) staticEventManager.PlayerSpawned(num); + + for (DStaticEventHandler* handler = FirstEventHandler; handler; handler = handler->next) + handler->PlayerSpawned(num); +} + void EventManager::PlayerRespawned(int num) { if (ShouldCallStatic(true)) staticEventManager.PlayerRespawned(num); @@ -998,6 +1006,18 @@ void DStaticEventHandler::PlayerEntered(int num, bool fromhub) } } +void DStaticEventHandler::PlayerSpawned(int num) +{ + IFVIRTUAL(DStaticEventHandler, PlayerSpawned) + { + // don't create excessive DObjects if not going to be processed anyway + if (isEmpty(func)) return; + FPlayerEvent e = { num, false }; + VMValue params[2] = { (DStaticEventHandler*)this, &e }; + VMCall(func, params, 2, nullptr, 0); + } +} + void DStaticEventHandler::PlayerRespawned(int num) { IFVIRTUAL(DStaticEventHandler, PlayerRespawned) diff --git a/src/events.h b/src/events.h index 6690b16cd..816615823 100755 --- a/src/events.h +++ b/src/events.h @@ -97,6 +97,7 @@ public: // void PlayerEntered(int num, bool fromhub); + void PlayerSpawned(int num); void PlayerRespawned(int num); void PlayerDied(int num); void PlayerDisconnected(int num); @@ -263,6 +264,8 @@ struct EventManager void RenderUnderlay(EHudState state); // this executes when a player enters the level (once). PlayerEnter+inhub = RETURN void PlayerEntered(int num, bool fromhub); + // this executes at the same time as ENTER scripts + void PlayerSpawned(int num); // this executes when a player respawns. includes resurrect cheat. void PlayerRespawned(int num); // this executes when a player dies (partially duplicating worldthingdied, but whatever) diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index 9f64cd986..233e4e798 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -5260,6 +5260,7 @@ AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flag if (state == PST_ENTER || (state == PST_LIVE && !savegamerestore)) { Behaviors.StartTypedScripts (SCRIPT_Enter, p->mo, true); + localEventManager->PlayerSpawned(PlayerNum(p)); } else if (state == PST_REBORN) { diff --git a/wadsrc/static/zscript/events.zs b/wadsrc/static/zscript/events.zs index 6f85bc188..aa4d620ec 100644 --- a/wadsrc/static/zscript/events.zs +++ b/wadsrc/static/zscript/events.zs @@ -340,6 +340,7 @@ class StaticEventHandler : Object native play version("2.4") // virtual void PlayerEntered(PlayerEvent e) {} + virtual void PlayerSpawned(PlayerEvent e) {} virtual void PlayerRespawned(PlayerEvent e) {} virtual void PlayerDied(PlayerEvent e) {} virtual void PlayerDisconnected(PlayerEvent e) {}