Browse Source

Fix style for `Global`

core_refactor
Anton Tarasenko 2 years ago
parent
commit
863e440149
  1. 2
      sources/BaseRealm/AcediaEnvironment/AcediaEnvironment.uc
  2. 105
      sources/BaseRealm/Global.uc

2
sources/BaseRealm/AcediaEnvironment/AcediaEnvironment.uc

@ -157,6 +157,7 @@ public final function Environment_FeatureDisabled_Slot OnFeatureDisabled(
public final function Shutdown() public final function Shutdown()
{ {
local LevelCore core; local LevelCore core;
if (acediaShutDown) { if (acediaShutDown) {
return; return;
} }
@ -171,6 +172,7 @@ public final function Shutdown()
if (core != none) { if (core != none) {
core.Destroy(); core.Destroy();
} }
_.DropCoreAPI();
acediaShutDown = true; acediaShutDown = true;
} }

105
sources/BaseRealm/Global.uc

@ -1,8 +1,8 @@
/** /**
* Class for an object that will provide an access to a Acedia's functionality * Author: dkanus
* that is common for both clients and servers by giving a reference to this * Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore
* object to all Acedia's objects and actors, emulating a global API namespace. * License: GPL
* Copyright 2020-2023 Anton Tarasenko * Copyright 2020-2023 Anton Tarasenko
*------------------------------------------------------------------------------ *------------------------------------------------------------------------------
* This file is part of Acedia. * This file is part of Acedia.
* *
@ -21,8 +21,18 @@
*/ */
class Global extends Object; class Global extends Object;
// `Global` is expected to behave like a singleton and will store it's //! Class singleton instance of an object that would hold references to any API that do not depend
// main instance in this variable's default value. //! on [`Actor`]s.
//!
//! To overcome cumbersome syntax of UnrealScript we gather all functions we want to be global into
//! special "API objects" and store their single references inside this one, [`Global`]'s instance.
//! Providing reference to properly initialized [`Global`] object to all [`AcediaObject`]s and
//! [`AcediaActor`]s will give them convenient accessors to all Acedia API.
//!
//! [`Global`] is expected to behave like a singleton and will store its main instance in this
//! variable's default value.
// For getting instance of [`Global`] from any object.
var protected Global myself; var protected Global myself;
var public RefAPI ref; var public RefAPI ref;
@ -38,64 +48,73 @@ var public ChatAPI chat;
var public ColorAPI color; var public ColorAPI color;
var public UserAPI users; var public UserAPI users;
var public PlayersAPI players; var public PlayersAPI players;
var public JSONAPI json; var public JsonAPI json;
var public SchedulerAPI scheduler; var public SchedulerAPI scheduler;
var public AvariceAPI avarice; var public AvariceAPI avarice;
var public AcediaEnvironment environment; var public AcediaEnvironment environment;
public final static function Global GetInstance() /// Returns instance of the [`Global`] object.
{ ///
/// [`Global`] is supposed to be used as a singleton, meaning that only one instance of it should be
/// created.
/// This method creates and returns such instance.
/// In case it was already created, that instance will be returned from now one.
public final static function Global GetInstance() {
if (default.myself == none) { if (default.myself == none) {
// `...Global`s are special and exist outside main Acedia's // `...Global`s are special and exist outside main Acedia's object infrastructure,
// object infrastructure, so we allocate it without using API methods. //so we allocate it without using [`MemoryAPI`] methods.
default.myself = new class'Global'; default.myself = new class'Global';
default.myself.Initialize(); default.myself.Initialize();
} }
return default.myself; return default.myself;
} }
protected function Initialize() /// Initializes [`Global`] by creating all API from base realm.
{ protected function Initialize() {
// Special case that we cannot spawn with memory API since it obviously // Special case that we cannot spawn with memory API since it obviously
// does not exist yet! // does not exist yet!
memory = new class'MemoryAPI'; memory = new class'MemoryAPI';
memory._constructor(); memory._constructor();
// `TextAPI` and `CollectionsAPI` need to be loaded before `LoggerAPI` // `TextAPI` and `CollectionsAPI` need to be loaded before `LoggerAPI`
ref = RefAPI(memory.Allocate(class'RefAPI')); ref = RefAPI(memory.Allocate(class'RefAPI'));
box = BoxAPI(memory.Allocate(class'BoxAPI')); box = BoxAPI(memory.Allocate(class'BoxAPI'));
text = TextAPI(memory.Allocate(class'TextAPI')); text = TextAPI(memory.Allocate(class'TextAPI'));
math = MathAPI(memory.Allocate(class'MathAPI')); math = MathAPI(memory.Allocate(class'MathAPI'));
collections = CollectionsAPI(memory.Allocate(class'CollectionsAPI')); collections = CollectionsAPI(memory.Allocate(class'CollectionsAPI'));
json = JSONAPI(memory.Allocate(class'JSONAPI')); json = JsonAPI(memory.Allocate(class'JsonAPI'));
logger = LoggerAPI(memory.Allocate(class'LoggerAPI')); logger = LoggerAPI(memory.Allocate(class'LoggerAPI'));
color = ColorAPI(memory.Allocate(class'ColorAPI')); color = ColorAPI(memory.Allocate(class'ColorAPI'));
alias = AliasesAPI(memory.Allocate(class'AliasesAPI')); alias = AliasesAPI(memory.Allocate(class'AliasesAPI'));
console = ConsoleAPI(memory.Allocate(class'ConsoleAPI')); console = ConsoleAPI(memory.Allocate(class'ConsoleAPI'));
chat = ChatAPI(memory.Allocate(class'ChatAPI')); chat = ChatAPI(memory.Allocate(class'ChatAPI'));
users = UserAPI(memory.Allocate(class'UserAPI')); users = UserAPI(memory.Allocate(class'UserAPI'));
players = PlayersAPI(memory.Allocate(class'PlayersAPI')); players = PlayersAPI(memory.Allocate(class'PlayersAPI'));
scheduler = SchedulerAPI(memory.Allocate(class'SchedulerAPI')); scheduler = SchedulerAPI(memory.Allocate(class'SchedulerAPI'));
avarice = AvariceAPI(memory.Allocate(class'AvariceAPI')); avarice = AvariceAPI(memory.Allocate(class'AvariceAPI'));
environment = AcediaEnvironment(memory.Allocate(class'AcediaEnvironment')); environment = AcediaEnvironment(memory.Allocate(class'AcediaEnvironment'));
} }
public function DropCoreAPI() /// Drops references to all API from base realm, including self-reference, previously returned by
{ /// [`Global::GetInstance()`] method.
memory = none; public function DropCoreAPI() {
ref = none; memory = none;
box = none; ref = none;
text = none; box = none;
text = none;
collections = none; collections = none;
logger = none; logger = none;
alias = none; alias = none;
console = none; console = none;
chat = none; chat = none;
color = none; color = none;
users = none; users = none;
players = none; players = none;
json = none; json = none;
scheduler = none; scheduler = none;
avarice = none; avarice = none;
default.myself = none; default.myself = none;
} }
defaultproperties {
}
Loading…
Cancel
Save