- allow defining native fields through scripts. Internally this only requires exporting the address, but not the entire field.

- added new VARF_Transient flag so that the decision whether to serialize a field does not depend solely on its native status. It may actually make a lot of sense to use the auto-serializer for native fields, too, as this would eliminate a lot of maintenance code.
- defined (u)int8/16 as aliases to the byte and short types (Can't we not just get rid of this naming convention already...?)
- exporting the fields of Actor revealed a few name clashes between them and some global types, so Actor.Sector was renamed to CurSector and Actor.Inventory was renamed to Actor.Inv.
This commit is contained in:
Christoph Oelckers 2016-11-22 19:20:31 +01:00
commit 980c986305
22 changed files with 520 additions and 202 deletions

View file

@ -46,6 +46,7 @@
static TArray<FPropertyInfo*> properties;
static TArray<AFuncDesc> AFTable;
static TArray<FieldDesc> FieldTable;
//==========================================================================
//
@ -613,6 +614,37 @@ AFuncDesc *FindFunction(PStruct *cls, const char * string)
return nullptr;
}
//==========================================================================
//
// Find a function by name using a binary search
//
//==========================================================================
FieldDesc *FindField(PStruct *cls, const char * string)
{
int min = 0, max = FieldTable.Size() - 1;
while (min <= max)
{
int mid = (min + max) / 2;
int lexval = stricmp(cls->TypeName.GetChars(), FieldTable[mid].ClassName + 1);
if (lexval == 0) lexval = stricmp(string, FieldTable[mid].FieldName);
if (lexval == 0)
{
return &FieldTable[mid];
}
else if (lexval > 0)
{
min = mid + 1;
}
else
{
max = mid - 1;
}
}
return nullptr;
}
//==========================================================================
//
@ -651,6 +683,14 @@ static int funccmp(const void * a, const void * b)
return res;
}
static int fieldcmp(const void * a, const void * b)
{
// +1 to get past the prefix letter of the native class name, which gets omitted by the FName for the class.
int res = stricmp(((FieldDesc*)a)->ClassName + 1, ((FieldDesc*)b)->ClassName + 1);
if (res == 0) res = stricmp(((FieldDesc*)a)->FieldName, ((FieldDesc*)b)->FieldName);
return res;
}
//==========================================================================
//
// Initialization
@ -716,4 +756,19 @@ void InitThingdef()
AFTable.ShrinkToFit();
qsort(&AFTable[0], AFTable.Size(), sizeof(AFTable[0]), funccmp);
}
FieldTable.Clear();
if (FieldTable.Size() == 0)
{
FAutoSegIterator probe(FRegHead, FRegTail);
while (*++probe != NULL)
{
FieldDesc *afield = (FieldDesc *)*probe;
FieldTable.Push(*afield);
}
FieldTable.ShrinkToFit();
qsort(&FieldTable[0], FieldTable.Size(), sizeof(FieldTable[0]), fieldcmp);
}
}