You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.1 KiB
128 lines
4.1 KiB
2 years ago
|
/**
|
||
|
* Base class for objects that will provide an access to a Acedia's client- and
|
||
|
* server-specific functionality by giving a reference to this object to all
|
||
|
* Acedia's objects and actors, emulating a global API namespace.
|
||
2 years ago
|
* Copyright 2022-2023 Anton Tarasenko
|
||
2 years ago
|
*------------------------------------------------------------------------------
|
||
|
* This file is part of Acedia.
|
||
|
*
|
||
|
* Acedia is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* Acedia is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with Acedia. If not, see <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
class CoreGlobal extends Object;
|
||
|
|
||
2 years ago
|
var protected bool initialized;
|
||
|
var protected class<AcediaAdapter> adapterClass;
|
||
2 years ago
|
|
||
2 years ago
|
var public SideEffectAPI sideEffects;
|
||
|
var public TimeAPI time;
|
||
2 years ago
|
var public DBAPI db;
|
||
2 years ago
|
|
||
|
var private LoggerAPI.Definition fatNoAdapterClass;
|
||
|
|
||
2 years ago
|
/**
|
||
|
* Accessor to the generic `UnrealAPI`.
|
||
|
*/
|
||
|
public function UnrealAPI unreal_api()
|
||
|
{
|
||
|
return none;
|
||
|
}
|
||
|
|
||
2 years ago
|
public final static function LevelCore GetLevelCore()
|
||
|
{
|
||
|
local LevelCore availableCore;
|
||
|
|
||
|
availableCore = class'ServerLevelCore'.static.GetInstance();
|
||
|
if (availableCore != none) {
|
||
|
return availableCore;
|
||
|
}
|
||
|
availableCore = class'ClientLevelCore'.static.GetInstance();
|
||
|
return availableCore;
|
||
|
}
|
||
|
|
||
2 years ago
|
public final static function CoreGlobal GetGenericInstance()
|
||
|
{
|
||
|
local ServerGlobal serverAPI;
|
||
|
local ClientGlobal clientAPI;
|
||
|
|
||
|
serverAPI = class'ServerGlobal'.static.GetInstance();
|
||
|
if (serverAPI != none && serverAPI.IsAvailable()) {
|
||
|
return serverAPI;
|
||
|
}
|
||
|
clientAPI = class'ClientGlobal'.static.GetInstance();
|
||
|
if (clientAPI != none && clientAPI.IsAvailable()) {
|
||
|
return clientAPI;
|
||
|
}
|
||
|
return none;
|
||
|
}
|
||
|
|
||
2 years ago
|
/**
|
||
|
* This method must perform initialization of the caller `...Global` instance.
|
||
|
*
|
||
|
* It must only be executed once (execution should be marked using
|
||
|
* `initialized` flag).
|
||
|
*/
|
||
2 years ago
|
protected function Initialize()
|
||
|
{
|
||
|
local MemoryAPI api;
|
||
|
|
||
2 years ago
|
if (initialized) {
|
||
|
return;
|
||
|
}
|
||
|
initialized = true;
|
||
|
if (adapterClass == none)
|
||
|
{
|
||
|
class'Global'.static.GetInstance().logger
|
||
|
.Auto(fatNoAdapterClass)
|
||
|
.ArgClass(self.class);
|
||
|
return;
|
||
|
}
|
||
2 years ago
|
api = class'Global'.static.GetInstance().memory;
|
||
2 years ago
|
sideEffects =
|
||
|
SideEffectAPI(api.Allocate(adapterClass.default.sideEffectAPIClass));
|
||
2 years ago
|
time = TimeAPI(api.Allocate(adapterClass.default.timeAPIClass));
|
||
|
db = DBAPI(api.Allocate(adapterClass.default.dbAPIClass));
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
/**
|
||
|
* Checks is caller `CoreGlobal` is available to be used.
|
||
|
*
|
||
|
* Server and client `CoreGlobal` instances are always created, so that they
|
||
|
* can be added to `AcediaObject`s and `AcediaActor`s at any time, even before
|
||
|
* they were initialized (whether they ever will be or not). This method
|
||
|
* allows one to check whether they were already initialized and can be used.
|
||
|
*
|
||
|
* @return `true` if caller `CoreGlobal` can be used and `false` otherwise.
|
||
|
*/
|
||
|
public function bool IsAvailable()
|
||
|
{
|
||
|
return initialized;
|
||
|
}
|
||
|
|
||
2 years ago
|
/**
|
||
|
* Changes adapter class for the caller `...Global` instance.
|
||
|
*
|
||
|
* Must not do anything when caller `...Global` instance was already
|
||
|
* initialized or when passed adapter class is `none`.
|
||
|
*
|
||
|
* @param newAdapter New adapter class to use in the caller `...Global`
|
||
|
* instance.
|
||
|
* @return `true` if new adapter was set and `false` otherwise.
|
||
|
*/
|
||
|
public function bool SetAdapter(class<AcediaAdapter> newAdapter);
|
||
|
|
||
2 years ago
|
defaultproperties
|
||
|
{
|
||
2 years ago
|
adapterClass = class'AcediaAdapter'
|
||
|
fatNoAdapterClass = (l=LOG_Fatal,m="`none` specified as an adapter for `%1` level core class. This should not have happened. AcediaCore cannot properly function.")
|
||
2 years ago
|
}
|