mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-17 09:42:04 +00:00
Add float user vars for DECORATE
- PClass::Extend now takes alignment into consideration.
This commit is contained in:
parent
a92de84cf7
commit
e2711a74e7
3 changed files with 15 additions and 13 deletions
|
@ -2403,22 +2403,23 @@ PClass *PClass::CreateDerivedClass(FName name, unsigned int size)
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// PClass:: Extend
|
// PClass :: Extend
|
||||||
//
|
//
|
||||||
// Add <extension> bytes to the end of this class. Returns the previous
|
// Add <extension> bytes to the end of this class and possibly more to meet
|
||||||
// size of the class.
|
// alignment restrictions. Returns the start of the extended block.
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
unsigned int PClass::Extend(unsigned int extension)
|
unsigned int PClass::Extend(unsigned int extension, unsigned int alignment)
|
||||||
{
|
{
|
||||||
assert(this->bRuntimeClass);
|
assert(this->bRuntimeClass);
|
||||||
|
|
||||||
unsigned int oldsize = Size;
|
unsigned int oldsize = Size;
|
||||||
Size += extension;
|
unsigned int padto = (oldsize + alignment - 1) & ~(alignment - 1);
|
||||||
|
Size = padto + extension;
|
||||||
Defaults = (BYTE *)M_Realloc(Defaults, Size);
|
Defaults = (BYTE *)M_Realloc(Defaults, Size);
|
||||||
memset(Defaults + oldsize, 0, extension);
|
memset(Defaults + oldsize, 0, Size - oldsize);
|
||||||
return oldsize;
|
return padto;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
|
@ -660,7 +660,8 @@ public:
|
||||||
void InsertIntoHash();
|
void InsertIntoHash();
|
||||||
DObject *CreateNew() const;
|
DObject *CreateNew() const;
|
||||||
PClass *CreateDerivedClass(FName name, unsigned int size);
|
PClass *CreateDerivedClass(FName name, unsigned int size);
|
||||||
unsigned int Extend(unsigned int extension);
|
unsigned int Extend(unsigned int extension, unsigned int alignment);
|
||||||
|
unsigned int Extend(const PType *type) { return Extend(type->Size, type->Align); }
|
||||||
void InitializeActorInfo();
|
void InitializeActorInfo();
|
||||||
void BuildFlatPointers();
|
void BuildFlatPointers();
|
||||||
const PClass *NativeClass() const;
|
const PClass *NativeClass() const;
|
||||||
|
|
|
@ -531,14 +531,14 @@ static void ParseUserVariable (FScanner &sc, PSymbolTable *symt, PClassActor *cl
|
||||||
sc.ScriptError("Native classes may not have user variables");
|
sc.ScriptError("Native classes may not have user variables");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the type and make sure it's int.
|
// Read the type and make sure it's acceptable.
|
||||||
sc.MustGetAnyToken();
|
sc.MustGetAnyToken();
|
||||||
if (sc.TokenType != TK_Int)
|
if (sc.TokenType != TK_Int && sc.TokenType != TK_Float)
|
||||||
{
|
{
|
||||||
sc.ScriptMessage("User variables must be of type int");
|
sc.ScriptMessage("User variables must be of type 'int' or 'float'");
|
||||||
FScriptPosition::ErrorCounter++;
|
FScriptPosition::ErrorCounter++;
|
||||||
}
|
}
|
||||||
type = TypeSInt32;
|
type = sc.TokenType == TK_Int ? (PType *)TypeSInt32 : (PType *)TypeFloat64;
|
||||||
|
|
||||||
sc.MustGetToken(TK_Identifier);
|
sc.MustGetToken(TK_Identifier);
|
||||||
// For now, restrict user variables to those that begin with "user_" to guarantee
|
// For now, restrict user variables to those that begin with "user_" to guarantee
|
||||||
|
@ -585,7 +585,7 @@ static void ParseUserVariable (FScanner &sc, PSymbolTable *symt, PClassActor *cl
|
||||||
sc.MustGetToken(';');
|
sc.MustGetToken(';');
|
||||||
|
|
||||||
PField *sym = new PField(symname, type, 0);
|
PField *sym = new PField(symname, type, 0);
|
||||||
sym->Offset = cls->Extend(sizeof(int) * maxelems);
|
sym->Offset = cls->Extend(type);
|
||||||
if (symt->AddSymbol(sym) == NULL)
|
if (symt->AddSymbol(sym) == NULL)
|
||||||
{
|
{
|
||||||
delete sym;
|
delete sym;
|
||||||
|
|
Loading…
Reference in a new issue