mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-11 07:11:54 +00:00
Add support for Name and String types to ACS's GetUserVariable
- Reading one of these types will copy its value into the global ACS string table and return the index.
This commit is contained in:
parent
b37ef48e99
commit
1648a71e45
1 changed files with 18 additions and 5 deletions
|
@ -4529,12 +4529,12 @@ int DLevelScript::LineFromID(int id)
|
|||
}
|
||||
}
|
||||
|
||||
bool GetVarAddrType(AActor *self, FName varname, int index, void *&addr, PType *&type, bool allownative)
|
||||
bool GetVarAddrType(AActor *self, FName varname, int index, void *&addr, PType *&type, bool readonly)
|
||||
{
|
||||
PField *var = dyn_cast<PField>(self->GetClass()->Symbols.FindSymbol(varname, true));
|
||||
PArray *arraytype;
|
||||
|
||||
if (var == NULL || (!allownative && (var->Flags & VARF_Native)))
|
||||
if (var == NULL || (!readonly && (var->Flags & VARF_Native)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -4561,6 +4561,11 @@ bool GetVarAddrType(AActor *self, FName varname, int index, void *&addr, PType *
|
|||
// but we do want to support Float subclasses like Fixed.
|
||||
if (!type->IsA(RUNTIME_CLASS(PInt)) || !type->IsKindOf(RUNTIME_CLASS(PFloat)))
|
||||
{
|
||||
// For reading, we also support Name and String types.
|
||||
if (readonly && (type->IsA(RUNTIME_CLASS(PName)) || type->IsA(RUNTIME_CLASS(PString))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -4591,13 +4596,21 @@ static int GetUserVariable(AActor *self, FName varname, int index)
|
|||
|
||||
if (GetVarAddrType(self, varname, index, addr, type, true))
|
||||
{
|
||||
if (!type->IsKindOf(RUNTIME_CLASS(PFloat)))
|
||||
if (type->IsKindOf(RUNTIME_CLASS(PFloat)))
|
||||
{
|
||||
return type->GetValueInt(addr);
|
||||
return FLOAT2FIXED(type->GetValueFloat(addr));
|
||||
}
|
||||
else if (type->IsA(RUNTIME_CLASS(PName)))
|
||||
{
|
||||
return GlobalACSStrings.AddString(FName(ENamedName(type->GetValueInt(addr))).GetChars());
|
||||
}
|
||||
else if (type->IsA(RUNTIME_CLASS(PString)))
|
||||
{
|
||||
return GlobalACSStrings.AddString(*(FString *)addr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FLOAT2FIXED(type->GetValueFloat(addr));
|
||||
return type->GetValueInt(addr);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue