Skip to content

Commit

Permalink
- moved UDMF custom properties into FLevelLocals.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Jan 10, 2019
1 parent 229dde1 commit 439c36c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 39 deletions.
3 changes: 3 additions & 0 deletions src/g_levellocals.h
Expand Up @@ -60,6 +60,7 @@ class DSectorMarker;

typedef TMap<int, int> FDialogueIDMap; // maps dialogue IDs to dialogue array index (for ACS)
typedef TMap<FName, int> FDialogueMap; // maps actor class names to dialogue array index
typedef TMap<int, FUDMFKeys> FUDMFKeyMap;

struct FLevelData
{
Expand Down Expand Up @@ -121,6 +122,8 @@ struct FLevelData
int i_compatflags = 0;
int i_compatflags2 = 0;

FUDMFKeyMap UDMFKeys[4];

};


Expand Down
28 changes: 7 additions & 21 deletions src/maploader/udmf.cpp
Expand Up @@ -285,20 +285,6 @@ const char *UDMFParserBase::CheckString(const char *key)
//
//===========================================================================

typedef TMap<int, FUDMFKeys> 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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -459,7 +445,7 @@ class UDMFParser : public UDMFParserBase
}
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++)
{
Expand Down
12 changes: 6 additions & 6 deletions src/p_acs.cpp
Expand Up @@ -5311,26 +5311,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->tagManager.FindFirstSectorFromTag(args[0]), Level->Behaviors.LookupString(args[1]));
return GetUDMFInt(Level, UDMF_Sector, Level->tagManager.FindFirstSectorFromTag(args[0]), Level->Behaviors.LookupString(args[1]));

case ACSF_GetSectorUDMFFixed:
return DoubleToACS(GetUDMFFloat(UDMF_Sector, Level->tagManager.FindFirstSectorFromTag(args[0]), Level->Behaviors.LookupString(args[1])));
return DoubleToACS(GetUDMFFloat(Level, UDMF_Sector, Level->tagManager.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 = SingleActorFromTID(args[0], activator);
Expand Down
8 changes: 5 additions & 3 deletions src/p_setup.cpp
Expand Up @@ -73,8 +73,6 @@
#include "p_acs.h"
#include "fragglescript/t_script.h"

void P_ClearUDMFKeys();

extern unsigned int R_OldBlend;

static void P_Shutdown ();
Expand Down Expand Up @@ -261,6 +259,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);

Expand Down Expand Up @@ -352,7 +355,6 @@ void P_FreeLevelData ()
// [ZZ] delete per-map event handlers
E_Shutdown(true);
R_FreePastViewers();
P_ClearUDMFKeys();

level.ClearLevelData();
}
Expand Down
6 changes: 3 additions & 3 deletions src/p_setup.h
Expand Up @@ -160,9 +160,9 @@ void P_LoadTranslator(const char *lumpname);
void P_TranslateLineDef (line_t *ld, maplinedef_t *mld, int lineindexforid = -1);
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();
Expand Down
12 changes: 6 additions & 6 deletions src/scripting/vmthunks.cpp
Expand Up @@ -2534,7 +2534,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)
Expand All @@ -2543,12 +2543,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)
Expand All @@ -2557,12 +2557,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)
Expand All @@ -2571,7 +2571,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)
Expand Down

0 comments on commit 439c36c

Please sign in to comment.