Moved E_InitStaticHandlers(true) a bit higher in the initialization so that local scripts receive PlayerEntered properly

This commit is contained in:
ZZYZX 2017-02-03 09:04:01 +02:00
parent 490159f6df
commit 27c5e21a1d
3 changed files with 11 additions and 2 deletions

View file

@ -197,6 +197,8 @@ void E_InitStaticHandlers(bool map)
if (map) // don't initialize map handlers if restoring from savegame. if (map) // don't initialize map handlers if restoring from savegame.
{ {
Printf("Initializing map handlers\n");
// delete old handlers if any. // delete old handlers if any.
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{ {
@ -211,6 +213,7 @@ void E_InitStaticHandlers(bool map)
PClass* type = PClass::FindClass(typestring); PClass* type = PClass::FindClass(typestring);
if (!type || E_IsStaticType(type)) // don't init the really global stuff here. if (!type || E_IsStaticType(type)) // don't init the really global stuff here.
continue; continue;
Printf("global -> %s\n", typestring.GetChars());
E_InitStaticHandler(type, typestring, false); E_InitStaticHandler(type, typestring, false);
} }
@ -218,6 +221,7 @@ void E_InitStaticHandlers(bool map)
{ {
FString typestring = level.info->EventHandlers[i]; FString typestring = level.info->EventHandlers[i];
PClass* type = PClass::FindClass(typestring); PClass* type = PClass::FindClass(typestring);
Printf("level -> %s\n", typestring.GetChars());
E_InitStaticHandler(type, typestring, true); E_InitStaticHandler(type, typestring, true);
} }
} }

View file

@ -1021,6 +1021,7 @@ void G_DoLoadLevel (int position, bool autosave)
} }
level.maptime = 0; level.maptime = 0;
P_SetupLevel (level.MapName, position); P_SetupLevel (level.MapName, position);
AM_LevelInit(); AM_LevelInit();
@ -1062,6 +1063,7 @@ void G_DoLoadLevel (int position, bool autosave)
} }
level.starttime = gametic; level.starttime = gametic;
G_UnSnapshotLevel (!savegamerestore); // [RH] Restore the state of the level. G_UnSnapshotLevel (!savegamerestore); // [RH] Restore the state of the level.
G_FinishTravel (); G_FinishTravel ();
// For each player, if they are viewing through a player, make sure it is themselves. // 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]); StatusBar->AttachToPlayer (&players[consoleplayer]);
// [ZZ] init per-map static handlers
E_InitStaticHandlers(true);
// unsafe world load // unsafe world load
E_WorldLoadedUnsafe(); E_WorldLoadedUnsafe();
// regular world load (savegames are handled internally) // regular world load (savegames are handled internally)

View file

@ -78,6 +78,7 @@
#ifndef NO_EDATA #ifndef NO_EDATA
#include "edata.h" #include "edata.h"
#endif #endif
#include "events.h"
#include "fragglescript/t_fs.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); 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. // generate a checksum for the level, to be included and checked with savegames.
map->GetChecksum(level.md5); map->GetChecksum(level.md5);
// find map num // find map num