overlaytopleft/games-fps/gzdoom/files/0035-Improve-Services.patch

192 lines
5.3 KiB
Diff

From ab19c639264fca169dac6f0052dce38bc1c2dab5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= <ricolvs123@gmail.com>
Date: Sat, 18 Feb 2023 23:28:54 -0300
Subject: [PATCH 35/51] Improve Services
---
src/common/scripting/interface/vmnatives.cpp | 7 +++
src/gamedata/info.cpp | 27 +++++++++++
wadsrc/static/zscript/engine/base.zs | 1 +
wadsrc/static/zscript/engine/service.zs | 49 ++++++--------------
4 files changed, 48 insertions(+), 36 deletions(-)
diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp
index a29a6b711..f268b6e07 100644
--- a/src/common/scripting/interface/vmnatives.cpp
+++ b/src/common/scripting/interface/vmnatives.cpp
@@ -53,6 +53,8 @@
#include "s_soundinternal.h"
#include "i_time.h"
+#include "maps.h"
+
//==========================================================================
//
// status bar exports
@@ -1114,7 +1116,12 @@ DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, baseorder);
DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, loop);
DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, handle);
+extern ZSMap<FName, DObject* > AllServices;
+
DEFINE_GLOBAL_NAMED(PClass::AllClasses, AllClasses)
+
+DEFINE_GLOBAL(AllServices)
+
DEFINE_GLOBAL(Bindings)
DEFINE_GLOBAL(AutomapBindings)
DEFINE_GLOBAL(generic_ui)
diff --git a/src/gamedata/info.cpp b/src/gamedata/info.cpp
index 22ad8d42b..ed516a1cf 100644
--- a/src/gamedata/info.cpp
+++ b/src/gamedata/info.cpp
@@ -54,6 +54,7 @@
#include "g_levellocals.h"
#include "texturemanager.h"
#include "d_main.h"
+#include "maps.h"
extern void LoadActors ();
extern void InitBotStuff();
@@ -64,6 +65,7 @@ FRandom FState::pr_statetics("StateTics");
cycle_t ActionCycles;
+void InitServices();
//==========================================================================
//
@@ -368,6 +370,18 @@ static void LoadAltHudStuff()
//
//==========================================================================
+ZSMap<FName, DObject*> AllServices;
+
+static void MarkServices(){
+
+ ZSMap<FName, DObject*>::Iterator it(AllServices);
+ ZSMap<FName, DObject*>::Pair *pair;
+ while (it.NextPair(pair))
+ {
+ GC::Mark<DObject>(pair->Value);
+ }
+}
+
void PClassActor::StaticInit()
{
sprites.Clear();
@@ -402,6 +416,19 @@ 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();
diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs
index cd2269661..43b998541 100644
--- a/wadsrc/static/zscript/engine/base.zs
+++ b/wadsrc/static/zscript/engine/base.zs
@@ -181,6 +181,7 @@ struct Vector3
struct _ native // These are the global variables, the struct is only here to avoid extending the parser for this.
{
native readonly Array<class> AllClasses;
+ native internal readonly Map<Name , Service> AllServices;
native readonly bool multiplayer;
native @KeyBindings Bindings;
native @KeyBindings AutomapBindings;
diff --git a/wadsrc/static/zscript/engine/service.zs b/wadsrc/static/zscript/engine/service.zs
index 5f834a809..50981ad80 100644
--- a/wadsrc/static/zscript/engine/service.zs
+++ b/wadsrc/static/zscript/engine/service.zs
@@ -54,6 +54,10 @@ class Service abstract
{
return null;
}
+
+ static Service Find(class<Service> serviceName){
+ return AllServices.GetIfExists(serviceName.GetClassName());
+ }
}
/**
@@ -88,54 +92,27 @@ class ServiceIterator
static ServiceIterator Find(String serviceName)
{
let result = new("ServiceIterator");
-
- result.mServiceName = serviceName;
- result.mClassIndex = 0;
- result.FindNextService();
-
+ result.mServiceName = serviceName.MakeLower();
+ result.it.Init(AllServices);
return result;
}
/**
* Gets the service and advances the iterator.
*
- * @returns service instance, or NULL if no more servers found.
- *
- * @note Each ServiceIterator will return new instances of services.
+ * @returns service instance, or NULL if no more services found.
*/
Service Next()
{
- uint classesNumber = AllClasses.Size();
- Service result = (mClassIndex == classesNumber)
- ? NULL
- : Service(new(AllClasses[mClassIndex]));
-
- ++mClassIndex;
- FindNextService();
-
- return result;
- }
-
- private void FindNextService()
- {
- uint classesNumber = AllClasses.size();
- while (mClassIndex < classesNumber && !ServiceNameContains(AllClasses[mClassIndex], mServiceName))
+ while(it.Next())
{
- ++mClassIndex;
+ String cName = it.GetKey();
+ if(cName.MakeLower().IndexOf(mServiceName) != -1);
+ return it.GetValue();
}
+ return null;
}
- private static bool ServiceNameContains(class aClass, String substring)
- {
- if (!(aClass is "Service")) return false;
-
- String className = aClass.GetClassName();
- String lowerClassName = className.MakeLower();
- String lowerSubstring = substring.MakeLower();
- bool result = lowerClassName.IndexOf(lowerSubstring) != -1;
- return result;
- }
-
+ private MapIterator<Name, Service> it;
private String mServiceName;
- private uint mClassIndex;
}
--
2.39.3