From 6cc00e79a6dacc444cd0b6401d02b9d98abe1dd4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 21 Nov 2016 19:20:27 +0100 Subject: [PATCH] - made all internal struct types NativeStructs so that all variables of their types are made references. --- src/dobjtype.cpp | 20 ++++++++++++++++++++ src/dobjtype.h | 1 + src/g_level.cpp | 2 +- src/p_mobj.cpp | 4 ++-- src/p_user.cpp | 2 +- src/scripting/thingdef_data.cpp | 2 +- src/scripting/zscript/zcc_compile.cpp | 2 +- 7 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 4354e0885..09a3b1c94 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -2457,6 +2457,26 @@ PNativeStruct::PNativeStruct(FName name) HasNativeFields = true; } +//========================================================================== +// +// NewNativeStruct +// Returns a PNativeStruct for the given name and container, making sure not to +// create duplicates. +// +//========================================================================== + +PNativeStruct *NewNativeStruct(FName name, PTypeBase *outer) +{ + size_t bucket; + PType *stype = TypeTable.FindType(RUNTIME_CLASS(PNativeStruct), (intptr_t)outer, (intptr_t)name, &bucket); + if (stype == NULL) + { + stype = new PStruct(name, outer); + TypeTable.AddType(stype, RUNTIME_CLASS(PNativeStruct), (intptr_t)outer, (intptr_t)name, bucket); + } + return static_cast(stype); +} + /* PField *****************************************************************/ IMPLEMENT_CLASS(PField, false, false, false, false) diff --git a/src/dobjtype.h b/src/dobjtype.h index be192225b..6134bbf90 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -922,6 +922,7 @@ PPointer *NewPointer(PType *type, bool isconst = false); PClassPointer *NewClassPointer(PClass *restrict); PEnum *NewEnum(FName name, PTypeBase *outer); PStruct *NewStruct(FName name, PTypeBase *outer); +PNativeStruct *NewNativeStruct(FName name, PTypeBase *outer); PPrototype *NewPrototype(const TArray &rettypes, const TArray &argtypes); // Built-in types ----------------------------------------------------------- diff --git a/src/g_level.cpp b/src/g_level.cpp index 9a955a03e..8987aed6c 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1858,7 +1858,7 @@ void FLevelLocals::AddScroller (int secnum) void G_InitLevelLocalsForScript() { - PStruct *lstruct = NewStruct("LevelLocals", nullptr); + PStruct *lstruct = NewNativeStruct("LevelLocals", nullptr); PField *levelf = new PField("level", lstruct, VARF_Native | VARF_Static, (intptr_t)&level); GlobalSymbols.AddSymbol(levelf); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 1066d985a..a97ed61c5 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -161,8 +161,8 @@ void AActor::InitNativeFields() PType *TypeActor = NewPointer(RUNTIME_CLASS(AActor)); PType *TypeActorClass = NewClassPointer(RUNTIME_CLASS(AActor)); PType *TypeInventory = NewPointer(RUNTIME_CLASS(AInventory)); - PType *TypePlayer = NewPointer(NewStruct("Player", nullptr)); - auto TypeSector = NewPointer(NewStruct("Sector", nullptr)); + PType *TypePlayer = NewPointer(NewNativeStruct("Player", nullptr)); + auto TypeSector = NewPointer(NewNativeStruct("Sector", nullptr)); PType *array5 = NewArray(TypeSInt32, 5); auto meta = RUNTIME_CLASS(AActor); diff --git a/src/p_user.cpp b/src/p_user.cpp index ad0bb6ba4..6d34037f1 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -3137,7 +3137,7 @@ bool P_IsPlayerTotallyFrozen(const player_t *player) void P_InitPlayerForScript() { - PStruct *pstruct = NewStruct("Player", nullptr); + PStruct *pstruct = NewNativeStruct("Player", nullptr); pstruct->Size = sizeof(player_t); pstruct->Align = alignof(player_t); PArray *parray = NewArray(pstruct, MAXPLAYERS); diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index cdb896902..5e8338a27 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -663,7 +663,7 @@ void InitThingdef() { PType *TypeActor = NewPointer(RUNTIME_CLASS(AActor)); - PStruct *sstruct = NewStruct("Sector", nullptr); + PStruct *sstruct = NewNativeStruct("Sector", nullptr); auto sptr = NewPointer(sstruct); sstruct->AddNativeField("soundtarget", TypeActor, myoffsetof(sector_t, SoundTarget)); diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 9682066b9..81b1c5ef6 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -1533,7 +1533,7 @@ PType *ZCCCompiler::ResolveUserType(ZCC_BasicType *type, PSymbolTable *symt) { return TypeSInt32; // hack this to an integer until we can resolve the enum mess. } - if (ptype->IsKindOf(RUNTIME_CLASS(PClass))) + if (ptype->IsKindOf(RUNTIME_CLASS(PNativeStruct))) // native structs and classes cannot be instantiated, they always get used as reference. { return NewPointer(ptype, type->isconst); }