Made map-section handlers in MAPINFO not static. Static now unambiguously means 'global from GameInfo'.

This commit is contained in:
ZZYZX 2017-01-31 06:24:39 +02:00
parent 6ada9c0291
commit 765bc2db39
2 changed files with 7 additions and 12 deletions

View file

@ -23,7 +23,6 @@ bool E_RegisterHandler(DStaticEventHandler* handler)
if (handler->IsStatic()) if (handler->IsStatic())
{ {
handler->ObjectFlags |= OF_Fixed; handler->ObjectFlags |= OF_Fixed;
if (!handler->isMapScope) // global (GameInfo) handlers are not serialized.
handler->ObjectFlags |= OF_Transient; handler->ObjectFlags |= OF_Transient;
} }
return true; return true;
@ -149,7 +148,6 @@ static void E_InitStaticHandler(PClass* type, FString typestring, bool map)
if (typeExists) return; if (typeExists) return;
DStaticEventHandler* handler = (DStaticEventHandler*)type->CreateNew(); DStaticEventHandler* handler = (DStaticEventHandler*)type->CreateNew();
handler->isMapScope = map;
E_RegisterHandler(handler); E_RegisterHandler(handler);
} }
@ -189,7 +187,7 @@ void E_InitStaticHandlers(bool map)
// delete old static handlers if any. // delete old static handlers if any.
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{ {
if (handler->IsStatic() && !handler->isMapScope) if (handler->IsStatic())
handler->Destroy(); handler->Destroy();
} }
@ -218,8 +216,8 @@ void E_WorldLoaded()
{ {
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{ {
if (handler->IsStatic() && !handler->isMapScope) continue; if (handler->IsStatic()) continue;
if (handler->isMapScope && savegamerestore) continue; // don't execute WorldLoaded for handlers loaded from the savegame. if (savegamerestore) continue; // don't execute WorldLoaded for handlers loaded from the savegame.
handler->WorldLoaded(); handler->WorldLoaded();
} }
} }
@ -228,7 +226,7 @@ void E_WorldUnloaded()
{ {
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{ {
if (handler->IsStatic() && !handler->isMapScope) continue; if (handler->IsStatic()) continue;
handler->WorldUnloaded(); handler->WorldUnloaded();
} }
} }
@ -237,7 +235,7 @@ void E_WorldLoadedUnsafe()
{ {
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{ {
if (!handler->IsStatic() || handler->isMapScope) continue; if (!handler->IsStatic()) continue;
handler->WorldLoaded(); handler->WorldLoaded();
} }
} }
@ -246,7 +244,7 @@ void E_WorldUnloadedUnsafe()
{ {
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{ {
if (!handler->IsStatic() || handler->isMapScope) continue; if (!handler->IsStatic()) continue;
handler->WorldUnloaded(); handler->WorldUnloaded();
} }
} }

View file

@ -59,12 +59,10 @@ public:
{ {
prev = 0; prev = 0;
next = 0; next = 0;
isMapScope = false;
} }
DStaticEventHandler* prev; DStaticEventHandler* prev;
DStaticEventHandler* next; DStaticEventHandler* next;
bool isMapScope;
virtual bool IsStatic() { return true; } virtual bool IsStatic() { return true; }
// serialization handler. let's keep it here so that I don't get lost in serialized/not serialized fields // serialization handler. let's keep it here so that I don't get lost in serialized/not serialized fields
@ -74,7 +72,6 @@ public:
if (arc.isReading()) if (arc.isReading())
{ {
Printf("DStaticEventHandler::Serialize: reading object %s\n", GetClass()->TypeName.GetChars()); Printf("DStaticEventHandler::Serialize: reading object %s\n", GetClass()->TypeName.GetChars());
isMapScope = true; // unserialized static handler means map scope anyway. other handlers don't get serialized.
} }
else else
{ {