mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-03-22 02:41:07 +00:00
Improve Services
This commit is contained in:
parent
b0dfa06201
commit
590475a8e3
4 changed files with 48 additions and 36 deletions
|
@ -53,6 +53,8 @@
|
|||
#include "s_soundinternal.h"
|
||||
#include "i_time.h"
|
||||
|
||||
#include "maps.h"
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// status bar exports
|
||||
|
@ -1159,7 +1161,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)
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue