Enable string & float user_ properties in UDMF things

This commit is contained in:
Jason Francis 2018-03-19 10:39:50 -04:00 committed by Christoph Oelckers
parent 2951476ce0
commit 4494b18e8a
4 changed files with 47 additions and 55 deletions

View file

@ -167,7 +167,7 @@ bool hasglnodes;
TArray<FMapThing> MapThingsConverted; TArray<FMapThing> MapThingsConverted;
TMap<unsigned,unsigned> MapThingsUserDataIndex; // from mapthing idx -> user data idx TMap<unsigned,unsigned> MapThingsUserDataIndex; // from mapthing idx -> user data idx
TArray<FMapThingUserData> MapThingsUserData; TArray<FUDMFKey> MapThingsUserData;
int sidecount; int sidecount;
sidei_t *sidetemp; sidei_t *sidetemp;
@ -1645,23 +1645,34 @@ static void SetMapThingUserData(AActor *actor, unsigned udi)
{ {
return; return;
} }
while (MapThingsUserData[udi].Property != NAME_None) while (MapThingsUserData[udi].Key != NAME_None)
{ {
FName varname = MapThingsUserData[udi].Property; FName varname = MapThingsUserData[udi].Key;
int value = MapThingsUserData[udi].Value;
PField *var = dyn_cast<PField>(actor->GetClass()->FindSymbol(varname, true)); PField *var = dyn_cast<PField>(actor->GetClass()->FindSymbol(varname, true));
udi++;
if (var == NULL || (var->Flags & (VARF_Native|VARF_Private|VARF_Protected|VARF_Static)) || !var->Type->isScalar()) if (var == NULL || (var->Flags & (VARF_Native|VARF_Private|VARF_Protected|VARF_Static)) || !var->Type->isScalar())
{ {
DPrintf(DMSG_WARNING, "%s is not a user variable in class %s\n", varname.GetChars(), DPrintf(DMSG_WARNING, "%s is not a writable user variable in class %s\n", varname.GetChars(),
actor->GetClass()->TypeName.GetChars()); actor->GetClass()->TypeName.GetChars());
} }
else else
{ // Set the value of the specified user variable. { // Set the value of the specified user variable.
var->Type->SetValue(reinterpret_cast<uint8_t *>(actor) + var->Offset, value); void *addr = reinterpret_cast<uint8_t *>(actor) + var->Offset;
if (var->Type->isString())
{
var->Type->InitializeValue(addr, &MapThingsUserData[udi].StringVal);
}
else if (var->Type->isFloat())
{
var->Type->SetValue(addr, MapThingsUserData[udi].FloatVal);
}
else if (var->Type->isIntCompatible())
{
var->Type->SetValue(addr, MapThingsUserData[udi].IntVal);
}
} }
udi++;
} }
} }

View file

@ -30,6 +30,7 @@
#include "resourcefiles/resourcefile.h" #include "resourcefiles/resourcefile.h"
#include "doomdata.h" #include "doomdata.h"
#include "r_defs.h"
struct MapData struct MapData
@ -180,14 +181,8 @@ struct FMissingCount
}; };
typedef TMap<FString,FMissingCount> FMissingTextureTracker; typedef TMap<FString,FMissingCount> FMissingTextureTracker;
// Record of user data for UDMF maps
struct FMapThingUserData
{
FName Property;
int Value;
};
extern TMap<unsigned,unsigned> MapThingsUserDataIndex; // from mapthing idx -> user data idx extern TMap<unsigned,unsigned> MapThingsUserDataIndex; // from mapthing idx -> user data idx
extern TArray<FMapThingUserData> MapThingsUserData; extern TArray<FUDMFKey> MapThingsUserData;
#endif #endif

View file

@ -476,38 +476,7 @@ public:
fogMap = normMap = NULL; fogMap = normMap = NULL;
} }
void AddUserKey(FName key, int kind, int index) void ReadUserKey(FUDMFKey &ukey) {
{
FUDMFKeys &keyarray = UDMFKeys[kind][index];
for(unsigned i=0; i < keyarray.Size(); i++)
{
if (keyarray[i].Key == key)
{
switch (sc.TokenType)
{
case TK_IntConst:
keyarray[i] = sc.Number;
break;
case TK_FloatConst:
keyarray[i] = sc.Float;
break;
default:
case TK_StringConst:
keyarray[i] = parsedString;
break;
case TK_True:
keyarray[i] = 1;
break;
case TK_False:
keyarray[i] = 0;
break;
}
return;
}
}
FUDMFKey ukey;
ukey.Key = key;
switch (sc.TokenType) switch (sc.TokenType)
{ {
case TK_IntConst: case TK_IntConst:
@ -527,6 +496,22 @@ public:
ukey = 0; ukey = 0;
break; break;
} }
}
void AddUserKey(FName key, int kind, int index)
{
FUDMFKeys &keyarray = UDMFKeys[kind][index];
for(unsigned i=0; i < keyarray.Size(); i++)
{
if (keyarray[i].Key == key)
{
ReadUserKey(keyarray[i]);
return;
}
}
FUDMFKey ukey;
ukey.Key = key;
ReadUserKey(ukey);
keyarray.Push(ukey); keyarray.Push(ukey);
} }
@ -809,10 +794,10 @@ public:
CHECK_N(Zd | Zdt) CHECK_N(Zd | Zdt)
if (0 == strnicmp("user_", key.GetChars(), 5)) if (0 == strnicmp("user_", key.GetChars(), 5))
{ // Custom user key - Sets an actor's user variable directly { // Custom user key - Sets an actor's user variable directly
FMapThingUserData ud; FUDMFKey ukey;
ud.Property = key; ukey.Key = key;
ud.Value = CheckInt(key); ReadUserKey(ukey);
MapThingsUserData.Push(ud); MapThingsUserData.Push(ukey);
} }
break; break;
} }
@ -2111,10 +2096,10 @@ public:
{ // User data added { // User data added
MapThingsUserDataIndex[MapThingsConverted.Size()-1] = userdatastart; MapThingsUserDataIndex[MapThingsConverted.Size()-1] = userdatastart;
// Mark end of the user data for this map thing // Mark end of the user data for this map thing
FMapThingUserData ud; FUDMFKey ukey;
ud.Property = NAME_None; ukey.Key = NAME_None;
ud.Value = 0; ukey = 0;
MapThingsUserData.Push(ud); MapThingsUserData.Push(ukey);
} }
} }
else if (sc.Compare("linedef")) else if (sc.Compare("linedef"))

View file

@ -200,6 +200,7 @@ public:
bool isStruct() const { return TypeTableType == NAME_Struct; } bool isStruct() const { return TypeTableType == NAME_Struct; }
bool isClass() const { return TypeTableType == NAME_Object; } bool isClass() const { return TypeTableType == NAME_Object; }
bool isPrototype() const { return TypeTableType == NAME_Prototype; } bool isPrototype() const { return TypeTableType == NAME_Prototype; }
bool isString() const { return TypeTableType == NAME_String; }
PContainerType *toContainer() { return isContainer() ? (PContainerType*)this : nullptr; } PContainerType *toContainer() { return isContainer() ? (PContainerType*)this : nullptr; }
PPointer *toPointer() { return isPointer() ? (PPointer*)this : nullptr; } PPointer *toPointer() { return isPointer() ? (PPointer*)this : nullptr; }