From 7b26a144c23dd6ee1a2adf1bb93b5c87d9d66272 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Mar 2023 10:55:09 +0200 Subject: [PATCH] - moved all service code to 'common'. This needs to work on Raze as well! --- src/common/scripting/interface/vmnatives.cpp | 31 ++++++++++++++++++-- src/gamedata/info.cpp | 28 ++---------------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index d3c3a83f3..2c7df6fb7 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/common/scripting/interface/vmnatives.cpp @@ -55,6 +55,35 @@ #include "maps.h" +static ZSMap AllServices; + +static void MarkServices() { + + ZSMap::Iterator it(AllServices); + ZSMap::Pair* pair; + while (it.NextPair(pair)) + { + GC::Mark(pair->Value); + } +} + +void InitServices() +{ + PClass* cls = PClass::FindClass("Service"); + for (PClass* clss : PClass::AllClasses) + { + if (clss != cls && cls->IsAncestorOf(clss)) + { + DObject* obj = clss->CreateNew(); + obj->ObjectFlags |= OF_Transient; + AllServices.Insert(clss->TypeName, obj); + } + } + GC::AddMarkerFunc(&MarkServices); +} + + + //========================================================================== // // status bar exports @@ -1161,8 +1190,6 @@ DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, baseorder); DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, loop); DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, handle); -extern ZSMap AllServices; - DEFINE_GLOBAL_NAMED(PClass::AllClasses, AllClasses) DEFINE_GLOBAL(AllServices) diff --git a/src/gamedata/info.cpp b/src/gamedata/info.cpp index ed516a1cf..3736cb4d2 100644 --- a/src/gamedata/info.cpp +++ b/src/gamedata/info.cpp @@ -369,18 +369,7 @@ static void LoadAltHudStuff() // PClassActor :: StaticInit STATIC // //========================================================================== - -ZSMap AllServices; - -static void MarkServices(){ - - ZSMap::Iterator it(AllServices); - ZSMap::Pair *pair; - while (it.NextPair(pair)) - { - GC::Mark(pair->Value); - } -} +void InitServices(); void PClassActor::StaticInit() { @@ -407,6 +396,8 @@ void PClassActor::StaticInit() if (!batchrun) Printf ("LoadActors: Load actor definitions.\n"); ClearStrifeTypes(); LoadActors (); + InitServices(); + for (auto cls : AllClasses) { @@ -416,19 +407,6 @@ void PClassActor::StaticInit() } } - PClass * cls = PClass::FindClass("Service"); - for(PClass * clss : PClass::AllClasses) - { - if(clss != cls && cls->IsAncestorOf(clss)) - { - DObject * obj = clss->CreateNew(); - obj->ObjectFlags |= OF_Transient; - AllServices.Insert(clss->TypeName, obj); - } - } - - GC::AddMarkerFunc(&MarkServices); - LoadAltHudStuff(); InitBotStuff();