diff --git a/sources/ClientRealm/ClientGlobal.uc b/sources/ClientRealm/ClientGlobal.uc index 84236bd..c5e57e3 100644 --- a/sources/ClientRealm/ClientGlobal.uc +++ b/sources/ClientRealm/ClientGlobal.uc @@ -21,7 +21,6 @@ */ class ClientGlobal extends CoreGlobal; -var protected bool initialized; // `Global` is expected to behave like a singleton and will store it's // main instance in this variable's default value. var protected ClientGlobal myself; diff --git a/sources/CoreRealm/API/SideEffects/SideEffectAPI.uc b/sources/CoreRealm/API/SideEffects/SideEffectAPI.uc index 614bde1..540ff12 100644 --- a/sources/CoreRealm/API/SideEffects/SideEffectAPI.uc +++ b/sources/CoreRealm/API/SideEffects/SideEffectAPI.uc @@ -1,6 +1,6 @@ /** - * Simple API for managing a list of `SideEffect` info objects: can add, - * remove, return all and by package. + * Standard implementation 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. @@ -18,16 +18,11 @@ * You should have received a copy of the GNU General Public License * along with Acedia. If not, see . */ -class SideEffectAPI extends AcediaObject; +class SideEffectAPI extends SideEffectAPIBase; var private array activeSideEffects; -/** - * Returns all so far registered `SideEffect`s. - * - * @return Array of all registered `SideEffect`s. - */ -public final function array GetAll() +public function array GetAll() { local int i; @@ -37,17 +32,7 @@ public final function array GetAll() return activeSideEffects; } -/** - * 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 sideEffectClass) +public function SideEffect GetClass(class sideEffectClass) { local int i; @@ -65,16 +50,7 @@ public final function SideEffect GetClass(class sideEffectClass) return none; } -/** - * 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 GetFromPackage(BaseText packageName) +public function array GetFromPackage(BaseText packageName) { local int i; local Text nextPackage; @@ -96,14 +72,7 @@ public final function array GetFromPackage(BaseText packageName) return result; } -/** - * 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) +public function bool Add(SideEffect newSideEffect) { local int i; @@ -121,16 +90,7 @@ public final function bool Add(SideEffect newSideEffect) return true; } -/** - * 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( +public function bool RemoveClass( class sideEffectClass) { local int i; diff --git a/sources/CoreRealm/API/SideEffects/SideEffectAPIBase.uc b/sources/CoreRealm/API/SideEffects/SideEffectAPIBase.uc new file mode 100644 index 0000000..14718ea --- /dev/null +++ b/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 . + */ +class SideEffectAPIBase extends AcediaObject + abstract; + +/** + * Returns all so far registered `SideEffect`s. + * + * @return Array of all registered `SideEffect`s. + */ +public function array 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 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 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 sideEffectClass); + +defaultproperties +{ +} \ No newline at end of file diff --git a/sources/CoreRealm/AcediaAdapter.uc b/sources/CoreRealm/AcediaAdapter.uc new file mode 100644 index 0000000..683210b --- /dev/null +++ b/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 . + */ +class AcediaAdapter extends AcediaObject + abstract; + +var public const class sideEffectAPIClass; + +defaultproperties +{ + SideEffectAPIClass = class'SideEffectAPI' +} \ No newline at end of file diff --git a/sources/CoreRealm/CoreGlobal.uc b/sources/CoreRealm/CoreGlobal.uc index ffc8709..577aa40 100644 --- a/sources/CoreRealm/CoreGlobal.uc +++ b/sources/CoreRealm/CoreGlobal.uc @@ -21,16 +21,53 @@ */ class CoreGlobal extends Object; -var public SideEffectAPI sideEffects; +var protected bool initialized; +var protected class 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() { 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; - 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 newAdapter); + 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.") } \ No newline at end of file diff --git a/sources/ServerRealm/ServerGlobal.uc b/sources/ServerRealm/ServerGlobal.uc index 545db19..646be25 100644 --- a/sources/ServerRealm/ServerGlobal.uc +++ b/sources/ServerRealm/ServerGlobal.uc @@ -21,7 +21,6 @@ */ class ServerGlobal extends CoreGlobal; -var protected bool initialized; // `Global` is expected to behave like a singleton and will store it's // main instance in this variable's default value. var protected ServerGlobal myself;