diff --git a/src/g_levellocals.h b/src/g_levellocals.h index d4e236b64..79f72c23f 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -96,6 +96,7 @@ class DSectorMarker; typedef TMap FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS) typedef TMap FDialogueMap; // maps actor class names to dialogue array index +typedef TMap FUDMFKeyMap; struct FLevelLocals { @@ -435,6 +436,7 @@ public: FBlockmap blockmap; TArray PolyBlockMap; + FUDMFKeyMap UDMFKeys[4]; // These are copies of the loaded map data that get used by the savegame code to skip unaltered fields // Without such a mechanism the savegame format would become too slow and large because more than 80-90% are normally still unaltered. @@ -464,7 +466,7 @@ public: uint8_t md5[16]; // for savegame validation. If the MD5 does not match the savegame won't be loaded. int time; // time in the hub - int maptime; // time in the map + int maptime; // time in the map int totaltime; // time in the game int starttime; int partime; diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index ea23dabb1..4a1688bf7 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -285,20 +285,6 @@ const char *UDMFParserBase::CheckString(const char *key) // //=========================================================================== -typedef TMap FUDMFKeyMap; - - -static FUDMFKeyMap UDMFKeys[4]; -// Things must be handled differently - -void P_ClearUDMFKeys() -{ - for(int i=0;i<4;i++) - { - UDMFKeys[i].Clear(); - } -} - static int udmfcmp(const void *a, const void *b) { FUDMFKey *A = (FUDMFKey*)a; @@ -346,11 +332,11 @@ FUDMFKey *FUDMFKeys::Find(FName key) // //=========================================================================== -int GetUDMFInt(int type, int index, FName key) +int GetUDMFInt(FLevelLocals *Level, int type, int index, FName key) { assert(type >=0 && type <=3); - FUDMFKeys *pKeys = UDMFKeys[type].CheckKey(index); + FUDMFKeys *pKeys = Level->UDMFKeys[type].CheckKey(index); if (pKeys != NULL) { @@ -363,11 +349,11 @@ int GetUDMFInt(int type, int index, FName key) return 0; } -double GetUDMFFloat(int type, int index, FName key) +double GetUDMFFloat(FLevelLocals *Level, int type, int index, FName key) { assert(type >=0 && type <=3); - FUDMFKeys *pKeys = UDMFKeys[type].CheckKey(index); + FUDMFKeys *pKeys = Level->UDMFKeys[type].CheckKey(index); if (pKeys != NULL) { @@ -380,11 +366,11 @@ double GetUDMFFloat(int type, int index, FName key) return 0; } -FString GetUDMFString(int type, int index, FName key) +FString GetUDMFString(FLevelLocals *Level, int type, int index, FName key) { assert(type >= 0 && type <= 3); - FUDMFKeys *pKeys = UDMFKeys[type].CheckKey(index); + FUDMFKeys *pKeys = Level->UDMFKeys[type].CheckKey(index); if (pKeys != NULL) { @@ -459,7 +445,7 @@ public: } void AddUserKey(FName key, int kind, int index) { - FUDMFKeys &keyarray = UDMFKeys[kind][index]; + FUDMFKeys &keyarray = Level->UDMFKeys[kind][index]; for(unsigned i=0; i < keyarray.Size(); i++) { diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 23d685677..6a45adb38 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -5277,26 +5277,26 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args) switch(funcIndex) { case ACSF_GetLineUDMFInt: - return GetUDMFInt(UDMF_Line, LineFromID(args[0]), Level->Behaviors.LookupString(args[1])); + return GetUDMFInt(Level, UDMF_Line, LineFromID(args[0]), Level->Behaviors.LookupString(args[1])); case ACSF_GetLineUDMFFixed: - return DoubleToACS(GetUDMFFloat(UDMF_Line, LineFromID(args[0]), Level->Behaviors.LookupString(args[1]))); + return DoubleToACS(GetUDMFFloat(Level, UDMF_Line, LineFromID(args[0]), Level->Behaviors.LookupString(args[1]))); case ACSF_GetThingUDMFInt: case ACSF_GetThingUDMFFixed: return 0; // Not implemented yet case ACSF_GetSectorUDMFInt: - return GetUDMFInt(UDMF_Sector, Level->FindFirstSectorFromTag(args[0]), Level->Behaviors.LookupString(args[1])); + return GetUDMFInt(Level, UDMF_Sector, Level->FindFirstSectorFromTag(args[0]), Level->Behaviors.LookupString(args[1])); case ACSF_GetSectorUDMFFixed: - return DoubleToACS(GetUDMFFloat(UDMF_Sector, Level->FindFirstSectorFromTag(args[0]), Level->Behaviors.LookupString(args[1]))); + return DoubleToACS(GetUDMFFloat(Level, UDMF_Sector, Level->FindFirstSectorFromTag(args[0]), Level->Behaviors.LookupString(args[1]))); case ACSF_GetSideUDMFInt: - return GetUDMFInt(UDMF_Side, SideFromID(args[0], args[1]), Level->Behaviors.LookupString(args[2])); + return GetUDMFInt(Level, UDMF_Side, SideFromID(args[0], args[1]), Level->Behaviors.LookupString(args[2])); case ACSF_GetSideUDMFFixed: - return DoubleToACS(GetUDMFFloat(UDMF_Side, SideFromID(args[0], args[1]), Level->Behaviors.LookupString(args[2]))); + return DoubleToACS(GetUDMFFloat(Level, UDMF_Side, SideFromID(args[0], args[1]), Level->Behaviors.LookupString(args[2]))); case ACSF_GetActorVelX: actor = Level->SingleActorFromTID(args[0], activator); @@ -10680,8 +10680,8 @@ void ACSProfile(FLevelLocals *Level, FCommandLine &argv) static const char *sort_names[] = { "total", "min", "max", "avg", "runs" }; static const uint8_t sort_match_len[] = { 1, 2, 2, 1, 1 }; - TArray ScriptProfiles, FuncProfiles; - long limit = 10; + TArray ScriptProfiles, FuncProfiles; + long limit = 10; int (*sorter)(const void *, const void *) = sort_by_total_instr; assert(countof(sort_names) == countof(sort_match_len)); diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 602adff56..83724cd21 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -74,8 +74,6 @@ #include "am_map.h" #include "fragglescript/t_script.h" -void P_ClearUDMFKeys(); - extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position); extern unsigned int R_OldBlend; @@ -260,6 +258,11 @@ void FLevelLocals::ClearLevelData() total_monsters = total_items = total_secrets = killed_monsters = found_items = found_secrets = wminfo.maxfrags = 0; + + for (int i = 0; i < 4; i++) + { + UDMFKeys[i].Clear(); + } SN_StopAllSequences(this); @@ -345,7 +348,6 @@ void P_FreeLevelData () // [ZZ] delete per-map event handlers E_Shutdown(true); R_FreePastViewers(); - P_ClearUDMFKeys(); DThinker::DestroyAllThinkers (); diff --git a/src/p_setup.h b/src/p_setup.h index 0ddc25fa3..12bffa6fb 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -153,9 +153,9 @@ struct maplinedef_t; void P_LoadTranslator(const char *lumpname); int P_TranslateSectorSpecial (int); -int GetUDMFInt(int type, int index, FName key); -double GetUDMFFloat(int type, int index, FName key); -FString GetUDMFString(int type, int index, FName key); +int GetUDMFInt(FLevelLocals *Level, int type, int index, FName key); +double GetUDMFFloat(FLevelLocals *Level, int type, int index, FName key); +FString GetUDMFString(FLevelLocals *Level, int type, int index, FName key); void FixMinisegReferences(); void FixHoles(); diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 74ecf1313..6e3705781 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -2554,7 +2554,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, GetAutomapPosition, GetAutomapPositi static int ZGetUDMFInt(FLevelLocals *self, int type, int index, int key) { - return GetUDMFInt(type, index, ENamedName(key)); + return GetUDMFInt(self,type, index, ENamedName(key)); } DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, GetUDMFInt, ZGetUDMFInt) @@ -2563,12 +2563,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, GetUDMFInt, ZGetUDMFInt) PARAM_INT(type); PARAM_INT(index); PARAM_NAME(key); - ACTION_RETURN_INT(GetUDMFInt(type, index, key)); + ACTION_RETURN_INT(GetUDMFInt(self, type, index, key)); } static double ZGetUDMFFloat(FLevelLocals *self, int type, int index, int key) { - return GetUDMFFloat(type, index, ENamedName(key)); + return GetUDMFFloat(self, type, index, ENamedName(key)); } DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, GetUDMFFloat, ZGetUDMFFloat) @@ -2577,12 +2577,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, GetUDMFFloat, ZGetUDMFFloat) PARAM_INT(type); PARAM_INT(index); PARAM_NAME(key); - ACTION_RETURN_FLOAT(GetUDMFFloat(type, index, key)); + ACTION_RETURN_FLOAT(GetUDMFFloat(self, type, index, key)); } static void ZGetUDMFString(FLevelLocals *self, int type, int index, int key, FString *result) { - *result = GetUDMFString(type, index, ENamedName(key)); + *result = GetUDMFString(self, type, index, ENamedName(key)); } DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, GetUDMFString, ZGetUDMFString) @@ -2591,7 +2591,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, GetUDMFString, ZGetUDMFString) PARAM_INT(type); PARAM_INT(index); PARAM_NAME(key); - ACTION_RETURN_STRING(GetUDMFString(type, index, key)); + ACTION_RETURN_STRING(GetUDMFString(self, type, index, key)); } DEFINE_ACTION_FUNCTION(FLevelLocals, GetChecksum)