Add functionality to Service
Add ability to auto-launch and obtain instance of a `Service` with a single command. Add `Service`-specific events `Launch()` / `ShutDown()` Add ability to auto-register required listeners on launch.
This commit is contained in:
parent
b954c718aa
commit
341c4aaf89
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Parent class for all services used in Acedia.
|
* Parent class for all services used in Acedia.
|
||||||
* Currently simply makes itself server-only.
|
* Currently simply makes itself server-only.
|
||||||
* Copyright 2019 Anton Tarasenko
|
* Copyright 2020 Anton Tarasenko
|
||||||
*------------------------------------------------------------------------------
|
*------------------------------------------------------------------------------
|
||||||
* This file is part of Acedia.
|
* This file is part of Acedia.
|
||||||
*
|
*
|
||||||
@ -21,8 +21,61 @@
|
|||||||
class Service extends Singleton
|
class Service extends Singleton
|
||||||
abstract;
|
abstract;
|
||||||
|
|
||||||
|
// Listeners listed here will be automatically activated.
|
||||||
|
var public const array< class<Listener> > requiredListeners;
|
||||||
|
|
||||||
|
// Enables feature of given class.
|
||||||
|
public static final function Service Require()
|
||||||
|
{
|
||||||
|
local Service newInstance;
|
||||||
|
if (IsRunning())
|
||||||
|
{
|
||||||
|
return Service(GetInstance());
|
||||||
|
}
|
||||||
|
default.blockSpawning = false;
|
||||||
|
newInstance = class'Acedia'.static.GetInstance().Spawn(default.class);
|
||||||
|
default.blockSpawning = true;
|
||||||
|
return newInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whether service is currently running is determined by
|
||||||
|
public static final function bool IsRunning()
|
||||||
|
{
|
||||||
|
return (GetInstance() != none);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function OnLaunch(){}
|
||||||
|
protected function OnShutdown(){}
|
||||||
|
|
||||||
|
protected function OnCreated()
|
||||||
|
{
|
||||||
|
default.blockSpawning = true;
|
||||||
|
SetListenersActiveSatus(true);
|
||||||
|
OnLaunch();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function OnDestroyed()
|
||||||
|
{
|
||||||
|
SetListenersActiveSatus(false);
|
||||||
|
OnShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set listeners' status
|
||||||
|
private static function SetListenersActiveSatus(bool newStatus)
|
||||||
|
{
|
||||||
|
local int i;
|
||||||
|
for (i = 0; i < default.requiredListeners.length; i += 1)
|
||||||
|
{
|
||||||
|
if (default.requiredListeners[i] == none) continue;
|
||||||
|
default.requiredListeners[i].static.SetActive(newStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
defaultproperties
|
defaultproperties
|
||||||
{
|
{
|
||||||
remoteRole = ROLE_None
|
DrawType = DT_None
|
||||||
DrawType = DT_None
|
// Prevent spawning this feature by any other means than 'Launch()'.
|
||||||
|
blockSpawning = true
|
||||||
|
// Features are server-only actors
|
||||||
|
remoteRole = ROLE_None
|
||||||
}
|
}
|
Reference in New Issue
Block a user