mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-24 13:01:48 +00:00
Implemented global EventHandlers in MAPINFO
This commit is contained in:
parent
e33a320544
commit
d5a0c29a68
6 changed files with 47 additions and 31 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "virtual.h"
|
||||
#include "r_utility.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "gi.h"
|
||||
#include "v_text.h"
|
||||
|
||||
DStaticEventHandler* E_FirstEventHandler = nullptr;
|
||||
|
@ -56,6 +57,37 @@ bool E_IsStaticType(PClass* type)
|
|||
!type->IsDescendantOf(RUNTIME_CLASS(DRenderEventHandler)));
|
||||
}
|
||||
|
||||
static void E_InitStaticHandler(PClass* type, FString typestring, bool map)
|
||||
{
|
||||
if (type == nullptr)
|
||||
{
|
||||
Printf("%cGWarning: unknown event handler class %s in MAPINFO!", TEXTCOLOR_ESCAPE, typestring.GetChars());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!E_IsStaticType(type))
|
||||
{
|
||||
Printf("%cGWarning: invalid event handler class %s in MAPINFO!\nMAPINFO event handlers should inherit Static* directly!", TEXTCOLOR_ESCAPE, typestring.GetChars());
|
||||
return;
|
||||
}
|
||||
|
||||
// check if type already exists, don't add twice.
|
||||
bool typeExists = false;
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
{
|
||||
if (handler->IsA(type))
|
||||
{
|
||||
typeExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeExists) return;
|
||||
DStaticEventHandler* handler = (DStaticEventHandler*)type->CreateNew();
|
||||
handler->isMapScope = map;
|
||||
E_RegisterHandler(handler);
|
||||
}
|
||||
|
||||
void E_InitStaticHandlers(bool map)
|
||||
{
|
||||
// remove existing
|
||||
|
@ -72,39 +104,17 @@ void E_InitStaticHandlers(bool map)
|
|||
{
|
||||
FString typestring = level.info->EventHandlers[i];
|
||||
PClass* type = PClass::FindClass(typestring);
|
||||
|
||||
if (type == nullptr)
|
||||
{
|
||||
Printf("%cGWarning: unknown event handler class %s in MAPINFO!", TEXTCOLOR_ESCAPE, typestring.GetChars());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!E_IsStaticType(type))
|
||||
{
|
||||
Printf("%cGWarning: invalid event handler class %s in MAPINFO!\nMAPINFO event handlers should inherit Static* directly!", TEXTCOLOR_ESCAPE, typestring.GetChars());
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if type already exists, don't add twice.
|
||||
bool typeExists = false;
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
{
|
||||
if (handler->IsA(type))
|
||||
{
|
||||
typeExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeExists) continue;
|
||||
DStaticEventHandler* handler = (DStaticEventHandler*)type->CreateNew();
|
||||
handler->isMapScope = true;
|
||||
E_RegisterHandler(handler);
|
||||
E_InitStaticHandler(type, typestring, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for (unsigned int i = 0; i < gameinfo.EventHandlers.Size(); i++)
|
||||
{
|
||||
FString typestring = gameinfo.EventHandlers[i];
|
||||
PClass* type = PClass::FindClass(typestring);
|
||||
E_InitStaticHandler(type, typestring, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1068,6 +1068,8 @@ void G_DoLoadLevel (int position, bool autosave)
|
|||
StatusBar->AttachToPlayer (&players[consoleplayer]);
|
||||
// [ZZ] init per-map static handlers
|
||||
E_InitStaticHandlers(true);
|
||||
// call map load hook
|
||||
E_MapLoaded();
|
||||
P_DoDeferedScripts (); // [RH] Do script actions that were triggered on another map.
|
||||
|
||||
if (demoplayback || oldgs == GS_STARTUP || oldgs == GS_TITLELEVEL)
|
||||
|
|
|
@ -317,6 +317,7 @@ void FMapInfoParser::ParseGameInfo()
|
|||
GAMEINFOKEY_STRINGARRAY(PrecachedClasses, "precacheclasses", 0, false)
|
||||
GAMEINFOKEY_STRINGARRAY(PrecachedTextures, "precachetextures", 0, false)
|
||||
GAMEINFOKEY_STRINGARRAY(PrecachedSounds, "precachesounds", 0, false)
|
||||
GAMEINFOKEY_STRINGARRAY(EventHandlers, "eventhandlers", 0, false)
|
||||
GAMEINFOKEY_STRING(PauseSign, "pausesign")
|
||||
GAMEINFOKEY_STRING(quitSound, "quitSound")
|
||||
GAMEINFOKEY_STRING(BorderFlat, "borderFlat")
|
||||
|
|
1
src/gi.h
1
src/gi.h
|
@ -124,6 +124,7 @@ struct gameinfo_t
|
|||
TArray<FName> PrecachedClasses;
|
||||
TArray<FString> PrecachedTextures;
|
||||
TArray<FSoundID> PrecachedSounds;
|
||||
TArray<FString> EventHandlers;
|
||||
|
||||
FString titleMusic;
|
||||
int titleOrder;
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include "thingdef.h"
|
||||
#include "d_player.h"
|
||||
#include "doomerrors.h"
|
||||
#include "events.h"
|
||||
|
||||
extern void LoadActors ();
|
||||
extern void InitBotStuff();
|
||||
|
@ -214,6 +215,9 @@ void PClassActor::StaticInit()
|
|||
ClearStrifeTypes();
|
||||
LoadActors ();
|
||||
InitBotStuff();
|
||||
|
||||
// reinit GLOBAL static stuff from gameinfo, once classes are loaded.
|
||||
E_InitStaticHandlers(false);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -1443,8 +1443,6 @@ void P_SpawnSpecials (void)
|
|||
break;
|
||||
}
|
||||
}
|
||||
// [ZZ] Loading event hook
|
||||
E_MapLoaded();
|
||||
// [RH] Start running any open scripts on this map
|
||||
FBehavior::StaticStartTypedScripts (SCRIPT_Open, NULL, false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue