From 920f9a3f3f74202902975bdca0fc97ef59cb18bf Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 7 Apr 2020 00:35:53 +0200 Subject: [PATCH] - cleaned out all Doom dependencies from the DObject system. --- source/common/objects/dobjgc.cpp | 12 ++++++++-- source/common/objects/dobjgc.h | 4 ++++ source/common/objects/dobjtype.cpp | 38 +++--------------------------- source/common/objects/dobjtype.h | 5 ++-- 4 files changed, 19 insertions(+), 40 deletions(-) diff --git a/source/common/objects/dobjgc.cpp b/source/common/objects/dobjgc.cpp index 57cef407a..40b29a680 100644 --- a/source/common/objects/dobjgc.cpp +++ b/source/common/objects/dobjgc.cpp @@ -100,8 +100,6 @@ // EXTERNAL DATA DECLARATIONS ---------------------------------------------- -//extern DThinker *NextToThink; - // PUBLIC DATA DEFINITIONS ------------------------------------------------- namespace GC @@ -262,9 +260,19 @@ void MarkArray(DObject **obj, size_t count) // //========================================================================== +TArray markers; +void AddMarkerFunc(GCMarkerFunc func) +{ + if (markers.Find(func) == markers.Size()) + markers.Push(func); +} + static void MarkRoot() { Gray = NULL; + + for (auto func : markers) func(); + // Mark soft roots. if (SoftRoots != NULL) { diff --git a/source/common/objects/dobjgc.h b/source/common/objects/dobjgc.h index 5a181c736..de187db6c 100644 --- a/source/common/objects/dobjgc.h +++ b/source/common/objects/dobjgc.h @@ -154,6 +154,10 @@ namespace GC { MarkArray(&arr[0], arr.Size()); } + + using GCMarkerFunc = void(*)(); + void AddMarkerFunc(GCMarkerFunc func); + } // A template class to help with handling read barriers. It does not diff --git a/source/common/objects/dobjtype.cpp b/source/common/objects/dobjtype.cpp index 916f9ca4b..83653c20e 100644 --- a/source/common/objects/dobjtype.cpp +++ b/source/common/objects/dobjtype.cpp @@ -212,15 +212,6 @@ void PClass::StaticInit () ((ClassReg *)*probe)->RegisterClass (); } probe.Reset(); -#if 0 - for(auto cls : AllClasses) - { - if (cls->IsDescendantOf(RUNTIME_CLASS(AActor))) - { - PClassActor::AllActorClasses.Push(static_cast(cls)); - } - } -#endif // Keep built-in classes in consistant order. I did this before, though // I'm not sure if this is really necessary to maintain any sort of sync. @@ -252,7 +243,6 @@ void PClass::StaticShutdown () { *p = nullptr; } - //ScriptUtil::Clear(); FunctionPtrList.Clear(); VMFunction::DeleteAll(); @@ -264,13 +254,7 @@ void PClass::StaticShutdown () // This flags DObject::Destroy not to call any scripted OnDestroy methods anymore. bVMOperational = false; -#if 0 - for (auto &p : players) - { - p.PendingWeapon = nullptr; - } Namespaces.ReleaseSymbols(); -#endif // This must be done in two steps because the native classes are not ordered by inheritance, // so all meta data must be gone before deleting the actual class objects. @@ -281,7 +265,6 @@ void PClass::StaticShutdown () TypeTable.Clear(); ClassDataAllocator.FreeAllBlocks(); AllClasses.Clear(); - //PClassActor::AllActorClasses.Clear(); ClassMap.Clear(); FAutoSegIterator probe(CRegHead, CRegTail); @@ -392,12 +375,6 @@ void PClass::InsertIntoHash (bool native) { ClassMap[TypeName] = this; } -#if 0 - if (!native && IsDescendantOf(RUNTIME_CLASS(AActor))) - { - PClassActor::AllActorClasses.Push(static_cast(this)); - } -#endif } //========================================================================== @@ -549,16 +526,6 @@ void PClass::Derive(PClass *newclass, FName name) } -//========================================================================== -// -// PClassActor :: InitializeNativeDefaults -// -//========================================================================== - -void PClass::InitializeDefaults() -{ -} - //========================================================================== // // PClass :: CreateDerivedClass @@ -567,7 +534,7 @@ void PClass::InitializeDefaults() // //========================================================================== -PClass *PClass::CreateDerivedClass(FName name, unsigned int size) +PClass *PClass::CreateDerivedClass(FName name, unsigned int size, bool *newlycreated) { assert(size >= Size); PClass *type; @@ -575,6 +542,7 @@ PClass *PClass::CreateDerivedClass(FName name, unsigned int size) const PClass *existclass = FindClass(name); + if (newlycreated) *newlycreated = false; if (existclass != nullptr) { // This is a placeholder so fill it in @@ -607,7 +575,7 @@ PClass *PClass::CreateDerivedClass(FName name, unsigned int size) if (size != TentativeClass) { NewClassType(type); - type->InitializeDefaults(); + if (newlycreated) *newlycreated = true; type->Virtuals = Virtuals; } else diff --git a/source/common/objects/dobjtype.h b/source/common/objects/dobjtype.h index bd6fe1e6d..db0893b14 100644 --- a/source/common/objects/dobjtype.h +++ b/source/common/objects/dobjtype.h @@ -36,12 +36,11 @@ class PClass { protected: void Derive(PClass *newclass, FName name); - void InitializeSpecials(void *addr, void *defaults, TArray PClass::*Inits); void SetSuper(); public: + void InitializeSpecials(void* addr, void* defaults, TArray PClass::* Inits); void WriteAllFields(FSerializer &ar, const void *addr) const; bool ReadAllFields(FSerializer &ar, void *addr) const; - void InitializeDefaults(); int FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc); PSymbol *FindSymbol(FName symname, bool searchparents) const; PField *AddField(FName name, PType *type, uint32_t flags); @@ -77,7 +76,7 @@ public: ~PClass(); void InsertIntoHash(bool native); DObject *CreateNew(); - PClass *CreateDerivedClass(FName name, unsigned int size); + PClass *CreateDerivedClass(FName name, unsigned int size, bool *newlycreated = nullptr); void InitializeActorInfo(); void BuildFlatPointers();