Add PlayerSpawned() event (#1118)

* Add PlayerSpawned() event

* add playerspawned to DStaticEventHandler

* Define PlyerSpawned() correctly
This commit is contained in:
Sterling Parker 2020-08-25 09:54:20 -06:00 committed by GitHub
parent b5af2fc2eb
commit d2a9de0012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 0 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)
{

View File

@ -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) {}