Browse Source

Fix style for `Global`

core_refactor
Anton Tarasenko 2 years ago
parent
commit
863e440149
  1. 2
      sources/BaseRealm/AcediaEnvironment/AcediaEnvironment.uc
  2. 49
      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()
{
local LevelCore core;
if (acediaShutDown) {
return;
}
@ -171,6 +172,7 @@ public final function Shutdown()
if (core != none) {
core.Destroy();
}
_.DropCoreAPI();
acediaShutDown = true;
}

49
sources/BaseRealm/Global.uc

@ -1,7 +1,7 @@
/**
* Class for an object that will provide an access to a Acedia's functionality
* that is common for both clients and servers by giving a reference to this
* object to all Acedia's objects and actors, emulating a global API namespace.
* Author: dkanus
* Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore
* License: GPL
* Copyright 2020-2023 Anton Tarasenko
*------------------------------------------------------------------------------
* This file is part of Acedia.
@ -21,8 +21,18 @@
*/
class Global extends Object;
// `Global` is expected to behave like a singleton and will store it's
// main instance in this variable's default value.
//! Class singleton instance of an object that would hold references to any API that do not depend
//! 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 public RefAPI ref;
@ -38,25 +48,30 @@ var public ChatAPI chat;
var public ColorAPI color;
var public UserAPI users;
var public PlayersAPI players;
var public JSONAPI json;
var public JsonAPI json;
var public SchedulerAPI scheduler;
var public AvariceAPI avarice;
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) {
// `...Global`s are special and exist outside main Acedia's
// object infrastructure, so we allocate it without using API methods.
// `...Global`s are special and exist outside main Acedia's object infrastructure,
//so we allocate it without using [`MemoryAPI`] methods.
default.myself = new class'Global';
default.myself.Initialize();
}
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
// does not exist yet!
memory = new class'MemoryAPI';
@ -67,7 +82,7 @@ protected function Initialize()
text = TextAPI(memory.Allocate(class'TextAPI'));
math = MathAPI(memory.Allocate(class'MathAPI'));
collections = CollectionsAPI(memory.Allocate(class'CollectionsAPI'));
json = JSONAPI(memory.Allocate(class'JSONAPI'));
json = JsonAPI(memory.Allocate(class'JsonAPI'));
logger = LoggerAPI(memory.Allocate(class'LoggerAPI'));
color = ColorAPI(memory.Allocate(class'ColorAPI'));
alias = AliasesAPI(memory.Allocate(class'AliasesAPI'));
@ -80,8 +95,9 @@ protected function Initialize()
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.
public function DropCoreAPI() {
memory = none;
ref = none;
box = none;
@ -99,3 +115,6 @@ public function DropCoreAPI()
avarice = none;
default.myself = none;
}
defaultproperties {
}
Loading…
Cancel
Save