From 5350721ec512139f30840cd5f6f7f759f3c6d775 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 12 Apr 2017 09:55:27 +0200 Subject: [PATCH] - removed PClass::DeriveData because it is no longer needed. - fixed: IsVisibleToPlayer and optimized it a bit more. - moved SourceLumpName to PClass, so that it can also be used for non-actors (there's a lot of non-Actor classes already.) - separated the serializer for PClassPointer from PPointer. Even though not doable, a pointer to a class type is something entirely different than a class pointer with a restriction so each should handle its own case. --- src/dobject.cpp | 6 +-- src/dobjtype.cpp | 64 ++++++++++------------- src/dobjtype.h | 4 +- src/info.cpp | 12 ----- src/info.h | 4 +- src/p_mobj.cpp | 5 +- src/scripting/decorate/thingdef_parse.cpp | 2 +- src/scripting/zscript/zcc_compile.cpp | 5 +- 8 files changed, 40 insertions(+), 62 deletions(-) diff --git a/src/dobject.cpp b/src/dobject.cpp index f581091bde..95dc5980e7 100644 --- a/src/dobject.cpp +++ b/src/dobject.cpp @@ -91,7 +91,7 @@ CCMD (dumpactors) "25:DoomStrifeChex", "26:HereticStrifeChex", "27:NotHexen", "28:HexenStrifeChex", "29:NotHeretic", "30:NotDoom", "31:All", }; - Printf("%i object class types total\nActor\tEd Num\tSpawnID\tFilter\tSource\n", PClass::AllClasses.Size()); + Printf("%u object class types total\nActor\tEd Num\tSpawnID\tFilter\tSource\n", PClass::AllClasses.Size()); for (unsigned int i = 0; i < PClass::AllClasses.Size(); i++) { PClass *cls = PClass::AllClasses[i]; @@ -102,11 +102,11 @@ CCMD (dumpactors) Printf("%s\t%i\t%i\t%s\t%s\n", acls->TypeName.GetChars(), ainfo->DoomEdNum, ainfo->SpawnID, filters[ainfo->GameFilter & 31], - acls->ActorInfo()->SourceLumpName.GetChars()); + acls->SourceLumpName.GetChars()); } else if (cls != NULL) { - Printf("%s\tn/a\tn/a\tn/a\tEngine (not an actor type)\n", cls->TypeName.GetChars()); + Printf("%s\tn/a\tn/a\tn/a\tEngine (not an actor type)\tSource: %s\n", cls->TypeName.GetChars(), cls->SourceLumpName.GetChars()); } else { diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index c3932e068e..9f8b88debc 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -1421,16 +1421,7 @@ void PPointer::WriteValue(FSerializer &ar, const char *key,const void *addr) con { if (PointedType->IsKindOf(RUNTIME_CLASS(PClass))) { - auto pt = static_cast(PointedType); - - if (pt->IsDescendantOf(RUNTIME_CLASS(PClass))) - { - ar(key, *(PClass **)addr); - } - else - { - ar(key, *(DObject **)addr); - } + ar(key, *(DObject **)addr); } else if (writer != nullptr) { @@ -1452,17 +1443,8 @@ bool PPointer::ReadValue(FSerializer &ar, const char *key, void *addr) const { if (PointedType->IsKindOf(RUNTIME_CLASS(PClass))) { - auto pt = static_cast(PointedType); - bool res = true; - - if (pt->IsDescendantOf(RUNTIME_CLASS(PClass))) - { - ::Serialize(ar, key, *(PClass **)addr, (PClass**)nullptr); - } - else - { - ::Serialize(ar, key, *(DObject **)addr, nullptr, &res); - } + bool res; + ::Serialize(ar, key, *(DObject **)addr, nullptr, &res); return res; } else if (reader != nullptr) @@ -1550,13 +1532,34 @@ PClassPointer::PClassPointer(PClass *restrict) { if (restrict) mDescriptiveName.Format("ClassPointer<%s>", restrict->TypeName.GetChars()); else mDescriptiveName = "ClassPointer"; - // class pointers do not need write barriers because all classes are stored in the global type table and won't get collected. - // This means we can use the cheapoer non-barriered opcodes here. - loadOp = OP_LOS; + loadOp = OP_LP; storeOp = OP_SP; mVersion = restrict->mVersion; } +//========================================================================== +// +// PPointer :: WriteValue +// +//========================================================================== + +void PClassPointer::WriteValue(FSerializer &ar, const char *key, const void *addr) const +{ + ar(key, *(PClass **)addr); +} + +//========================================================================== +// +// PPointer :: ReadValue +// +//========================================================================== + +bool PClassPointer::ReadValue(FSerializer &ar, const char *key, void *addr) const +{ + ::Serialize(ar, key, *(PClass **)addr, (PClass**)nullptr); + return false; +} + //========================================================================== // // PClassPointer - isCompatible @@ -3304,18 +3307,6 @@ void PClass::InitializeDefaults() } } -//========================================================================== -// -// PClass :: DeriveData -// -// Copies inheritable data to the child class. -// -//========================================================================== - -void PClass::DeriveData(PClass *newclass) -{ -} - //========================================================================== // // PClass :: CreateDerivedClass @@ -3365,7 +3356,6 @@ PClass *PClass::CreateDerivedClass(FName name, unsigned int size) { type->InitializeDefaults(); type->Virtuals = Virtuals; - DeriveData(type); } else type->ObjectFlags &= OF_Transient; diff --git a/src/dobjtype.h b/src/dobjtype.h index de364c4f8f..7e485f1946 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -429,6 +429,8 @@ public: class PClass *ClassRestriction; bool isCompatible(PType *type); + void WriteValue(FSerializer &ar, const char *key, const void *addr) const override; + bool ReadValue(FSerializer &ar, const char *key, void *addr) const override; void SetPointer(void *base, unsigned offset, TArray *special = NULL) const override; virtual bool IsMatch(intptr_t id1, intptr_t id2) const; @@ -600,7 +602,6 @@ public: bool ReadAllFields(FSerializer &ar, void *addr) const; void InitializeDefaults(); int FindVirtualIndex(FName name, PPrototype *proto); - virtual void DeriveData(PClass *newclass); static void StaticInit(); static void StaticShutdown(); @@ -619,6 +620,7 @@ public: bool bExported; // This type has been declared in a script bool bDecorateClass; // may be subject to some idiosyncracies due to DECORATE backwards compatibility TArray Virtuals; // virtual function table + FName SourceLumpName; void (*ConstructNative)(void *); diff --git a/src/info.cpp b/src/info.cpp index ead6fa2d04..6f00609afc 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -307,18 +307,6 @@ PClassActor::~PClassActor() { } -//========================================================================== -// -// PClassActor :: Derive -// -//========================================================================== - -void PClassActor::DeriveData(PClass *newclass) -{ - assert(newclass->IsKindOf(RUNTIME_CLASS(PClassActor))); - PClassActor *newa = static_cast(newclass); -} - //========================================================================== // // PClassActor :: SetReplacement diff --git a/src/info.h b/src/info.h index dc1c26fa43..6be614aa73 100644 --- a/src/info.h +++ b/src/info.h @@ -247,8 +247,7 @@ struct FActorInfo uint8_t GameFilter = GAME_Any; uint16_t SpawnID = 0; uint16_t ConversationID = 0; - int16_t DoomEdNum = 0; - FString SourceLumpName; + int16_t DoomEdNum = -1; FStateLabels *StateList = nullptr; DmgFactors DamageFactors; @@ -294,7 +293,6 @@ protected: public: static void StaticInit (); static void StaticSetActorNums (); - virtual void DeriveData(PClass *newclass); PClassActor(); ~PClassActor(); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 70c7146501..30e462b101 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -1605,11 +1605,14 @@ bool AActor::IsVisibleToPlayer() const (signed)(VisibleToTeam-1) != players[consoleplayer].userinfo.GetTeam() ) return false; + auto &vis = GetInfo()->VisibleToPlayerClass; + if (vis.Size() == 0) return true; // early out for the most common case. + const player_t* pPlayer = players[consoleplayer].camera->player; if (pPlayer) { - for(auto cls : GetInfo()->VisibleToPlayerClass) + for(auto cls : vis) { if (cls && pPlayer->mo->GetClass()->IsDescendantOf(cls)) { diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index d13c869d12..8950a70670 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -1109,7 +1109,7 @@ static PClassActor *ParseActorHeader(FScanner &sc, Baggage *bag) { PClassActor *info = CreateNewActor(sc, typeName, parentName); info->ActorInfo()->DoomEdNum = DoomEdNum > 0 ? DoomEdNum : -1; - info->ActorInfo()->SourceLumpName = Wads.GetLumpFullPath(sc.LumpNum); + info->SourceLumpName = Wads.GetLumpFullPath(sc.LumpNum); if (!info->SetReplacement(replaceName)) { diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 94c54dc439..0feda59e69 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -625,8 +625,7 @@ void ZCCCompiler::CreateClassTypes() DPrintf(DMSG_SPAMMY, "Registered %s as native with parent %s\n", me->TypeName.GetChars(), parent->TypeName.GetChars()); } c->cls->Type = me; - auto ac = dyn_cast(me); - if (ac != nullptr) ac->ActorInfo()->SourceLumpName = *c->cls->SourceName; + me->SourceLumpName = *c->cls->SourceName; } else { @@ -2194,7 +2193,6 @@ void ZCCCompiler::InitDefaults() FString mename = ti->TypeName.GetChars(); ti->InitializeDefaults(); - ti->ParentClass->DeriveData(ti); } } else @@ -2215,7 +2213,6 @@ void ZCCCompiler::InitDefaults() auto ti = static_cast(c->Type()); ti->InitializeDefaults(); - ti->ParentClass->DeriveData(ti); // We need special treatment for this one field in AActor's defaults which cannot be made visible to DECORATE as a property. // It's better to do this here under controlled conditions than deeper down in the class type classes.