From 27c5e21a1dbc4a57c6bedb5caa6d46e69e3c3b4e Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Fri, 3 Feb 2017 09:04:01 +0200 Subject: [PATCH] Moved E_InitStaticHandlers(true) a bit higher in the initialization so that local scripts receive PlayerEntered properly --- src/events.cpp | 4 ++++ src/g_level.cpp | 4 ++-- src/p_setup.cpp | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/events.cpp b/src/events.cpp index 02f269db4..141db3fdf 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -197,6 +197,8 @@ void E_InitStaticHandlers(bool map) if (map) // don't initialize map handlers if restoring from savegame. { + Printf("Initializing map handlers\n"); + // delete old handlers if any. for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) { @@ -211,6 +213,7 @@ void E_InitStaticHandlers(bool map) PClass* type = PClass::FindClass(typestring); if (!type || E_IsStaticType(type)) // don't init the really global stuff here. continue; + Printf("global -> %s\n", typestring.GetChars()); E_InitStaticHandler(type, typestring, false); } @@ -218,6 +221,7 @@ void E_InitStaticHandlers(bool map) { FString typestring = level.info->EventHandlers[i]; PClass* type = PClass::FindClass(typestring); + Printf("level -> %s\n", typestring.GetChars()); E_InitStaticHandler(type, typestring, true); } } diff --git a/src/g_level.cpp b/src/g_level.cpp index db6254063..8b9e8d37e 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1021,6 +1021,7 @@ void G_DoLoadLevel (int position, bool autosave) } level.maptime = 0; + P_SetupLevel (level.MapName, position); AM_LevelInit(); @@ -1062,6 +1063,7 @@ void G_DoLoadLevel (int position, bool autosave) } level.starttime = gametic; + G_UnSnapshotLevel (!savegamerestore); // [RH] Restore the state of the level. G_FinishTravel (); // For each player, if they are viewing through a player, make sure it is themselves. @@ -1073,8 +1075,6 @@ void G_DoLoadLevel (int position, bool autosave) } } StatusBar->AttachToPlayer (&players[consoleplayer]); - // [ZZ] init per-map static handlers - E_InitStaticHandlers(true); // unsafe world load E_WorldLoadedUnsafe(); // regular world load (savegames are handled internally) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index df41345f4..066fba6d4 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -78,6 +78,7 @@ #ifndef NO_EDATA #include "edata.h" #endif +#include "events.h" #include "fragglescript/t_fs.h" @@ -3627,6 +3628,10 @@ void P_SetupLevel (const char *lumpname, int position) I_Error("Unable to open map '%s'\n", lumpname); } + // [ZZ] init per-map static handlers. we need to call this before everything is set up because otherwise scripts don't receive PlayerEntered event + // (which happens at god-knows-what stage in this function, but definitely not the last part, because otherwise it'd work to put E_InitStaticHandlers before the player spawning) + E_InitStaticHandlers(true); + // generate a checksum for the level, to be included and checked with savegames. map->GetChecksum(level.md5); // find map num