Browse Source

Add `AcediaAdapter` class

`AcediaAdapter` is meant to be a data storage about which classes to use
as API for client- and server-globals.
pull/8/head
Anton Tarasenko 2 years ago
parent
commit
9e86c4c23b
  1. 1
      sources/ClientRealm/ClientGlobal.uc
  2. 56
      sources/CoreRealm/API/SideEffects/SideEffectAPI.uc
  3. 76
      sources/CoreRealm/API/SideEffects/SideEffectAPIBase.uc
  4. 30
      sources/CoreRealm/AcediaAdapter.uc
  5. 41
      sources/CoreRealm/CoreGlobal.uc
  6. 1
      sources/ServerRealm/ServerGlobal.uc

1
sources/ClientRealm/ClientGlobal.uc

@ -21,7 +21,6 @@
*/ */
class ClientGlobal extends CoreGlobal; class ClientGlobal extends CoreGlobal;
var protected bool initialized;
// `Global` is expected to behave like a singleton and will store it's // `Global` is expected to behave like a singleton and will store it's
// main instance in this variable's default value. // main instance in this variable's default value.
var protected ClientGlobal myself; var protected ClientGlobal myself;

56
sources/CoreRealm/API/SideEffects/SideEffectAPI.uc

@ -1,6 +1,6 @@
/** /**
* Simple API for managing a list of `SideEffect` info objects: can add, * Standard implementation for simple API for managing a list of
* remove, return all and by package. * `SideEffect` info objects: can add, remove, return all and by package.
* Copyright 2022 Anton Tarasenko * Copyright 2022 Anton Tarasenko
*------------------------------------------------------------------------------ *------------------------------------------------------------------------------
* This file is part of Acedia. * This file is part of Acedia.
@ -18,16 +18,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Acedia. If not, see <https://www.gnu.org/licenses/>. * along with Acedia. If not, see <https://www.gnu.org/licenses/>.
*/ */
class SideEffectAPI extends AcediaObject; class SideEffectAPI extends SideEffectAPIBase;
var private array<SideEffect> activeSideEffects; var private array<SideEffect> activeSideEffects;
/** public function array<SideEffect> GetAll()
* Returns all so far registered `SideEffect`s.
*
* @return Array of all registered `SideEffect`s.
*/
public final function array<SideEffect> GetAll()
{ {
local int i; local int i;
@ -37,17 +32,7 @@ public final function array<SideEffect> GetAll()
return activeSideEffects; return activeSideEffects;
} }
/** public function SideEffect GetClass(class<SideEffect> sideEffectClass)
* Returns active `SideEffect` instance of the specified class
* `sideEffectClass`.
*
* @param sideEffectClass Class of side effect to return active instance of.
* @return Active `SideEffect` instance of the specified class
* `sideEffectClass`.
* `none` if either `sideEffectClass` is `none` or side effect of such
* class is not currently active.
*/
public final function SideEffect GetClass(class<SideEffect> sideEffectClass)
{ {
local int i; local int i;
@ -65,16 +50,7 @@ public final function SideEffect GetClass(class<SideEffect> sideEffectClass)
return none; return none;
} }
/** public function array<SideEffect> GetFromPackage(BaseText packageName)
* Returns all so far registered `SideEffect`s from a package `packageName`
* (case insensitive).
*
* @param packageName Name opf the package, in `SideEffect`s from which we are
* interested. Must be not `none`.
* @return Array of all registered `SideEffect`s from a package `packageName`.
* If `none`, returns an empty array.
*/
public final function array<SideEffect> GetFromPackage(BaseText packageName)
{ {
local int i; local int i;
local Text nextPackage; local Text nextPackage;
@ -96,14 +72,7 @@ public final function array<SideEffect> GetFromPackage(BaseText packageName)
return result; return result;
} }
/** public function bool Add(SideEffect newSideEffect)
* Registers a new `SideEffect` object as active.
*
* @param newSideEffect Instance of some `SideEffect` class to register as
* active side effect. Must not be `none`.
* @return `true` if new side effect was added and `false` otherwise.
*/
public final function bool Add(SideEffect newSideEffect)
{ {
local int i; local int i;
@ -121,16 +90,7 @@ public final function bool Add(SideEffect newSideEffect)
return true; return true;
} }
/** public function bool RemoveClass(
* Removes `SideEffect` of the specified sub-class from the list of active
* side effects.
*
* @param sideEffectClass Class of the side effect to remove.
* @return `true` if some side effect was removed as a result of this operation
* and `false` otherise (even if there was no side effect of specified
* class to begin with).
*/
public final function bool RemoveClass(
class<SideEffect> sideEffectClass) class<SideEffect> sideEffectClass)
{ {
local int i; local int i;

76
sources/CoreRealm/API/SideEffects/SideEffectAPIBase.uc

@ -0,0 +1,76 @@
/**
* Base class for simple API for managing a list of `SideEffect` info
* objects: can add, remove, return all and by package.
* Copyright 2022 Anton Tarasenko
*------------------------------------------------------------------------------
* 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 SideEffectAPIBase extends AcediaObject
abstract;
/**
* Returns all so far registered `SideEffect`s.
*
* @return Array of all registered `SideEffect`s.
*/
public function array<SideEffect> GetAll();
/**
* Returns active `SideEffect` instance of the specified class
* `sideEffectClass`.
*
* @param sideEffectClass Class of side effect to return active instance of.
* @return Active `SideEffect` instance of the specified class
* `sideEffectClass`.
* `none` if either `sideEffectClass` is `none` or side effect of such
* class is not currently active.
*/
public function SideEffect GetClass(class<SideEffect> sideEffectClass);
/**
* Returns all so far registered `SideEffect`s from a package `packageName`
* (case insensitive).
*
* @param packageName Name of the package, in `SideEffect`s from which we are
* interested. Must be not `none`.
* @return Array of all registered `SideEffect`s from a package `packageName`.
* If `none`, returns an empty array.
*/
public function array<SideEffect> GetFromPackage(BaseText packageName);
/**
* Registers a new `SideEffect` object as active.
*
* @param newSideEffect Instance of some `SideEffect` class to register as
* active side effect. Must not be `none`.
* @return `true` if new side effect was added and `false` otherwise.
*/
public function bool Add(SideEffect newSideEffect);
/**
* Removes `SideEffect` of the specified sub-class from the list of active
* side effects.
*
* @param sideEffectClass Class of the side effect to remove.
* @return `true` if some side effect was removed as a result of this operation
* and `false` otherwise (even if there was no side effect of specified
* class to begin with).
*/
public function bool RemoveClass(class<SideEffect> sideEffectClass);
defaultproperties
{
}

30
sources/CoreRealm/AcediaAdapter.uc

@ -0,0 +1,30 @@
/**
* 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.
* Copyright 2022 Anton Tarasenko
*------------------------------------------------------------------------------
* 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 AcediaAdapter extends AcediaObject
abstract;
var public const class<SideEffectAPIBase> sideEffectAPIClass;
defaultproperties
{
SideEffectAPIClass = class'SideEffectAPI'
}

41
sources/CoreRealm/CoreGlobal.uc

@ -21,16 +21,53 @@
*/ */
class CoreGlobal extends Object; class CoreGlobal extends Object;
var public SideEffectAPI sideEffects; var protected bool initialized;
var protected class<AcediaAdapter> adapterClass;
var public SideEffectAPIBase sideEffects;
var private LoggerAPI.Definition fatNoAdapterClass;
/**
* This method must perform initialization of the caller `...Global` instance.
*
* It must only be executed once (execution should be marked using
* `initialized` flag).
*/
protected function Initialize() protected function Initialize()
{ {
local MemoryAPI api; local MemoryAPI api;
if (initialized) {
return;
}
initialized = true;
if (adapterClass == none)
{
class'Global'.static.GetInstance().logger
.Auto(fatNoAdapterClass)
.ArgClass(self.class);
return;
}
api = class'Global'.static.GetInstance().memory; api = class'Global'.static.GetInstance().memory;
sideEffects = SideEffectAPI(api.Allocate(class'SideEffectAPI')); sideEffects =
SideEffectAPI(api.Allocate(adapterClass.default.sideEffectAPIClass));
} }
/**
* 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);
defaultproperties defaultproperties
{ {
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.")
} }

1
sources/ServerRealm/ServerGlobal.uc

@ -21,7 +21,6 @@
*/ */
class ServerGlobal extends CoreGlobal; class ServerGlobal extends CoreGlobal;
var protected bool initialized;
// `Global` is expected to behave like a singleton and will store it's // `Global` is expected to behave like a singleton and will store it's
// main instance in this variable's default value. // main instance in this variable's default value.
var protected ServerGlobal myself; var protected ServerGlobal myself;

Loading…
Cancel
Save