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() 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;
} }

49
sources/BaseRealm/Global.uc

@ -1,7 +1,7 @@
/** /**
* 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,25 +48,30 @@ 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';
@ -67,7 +82,7 @@ protected function Initialize()
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'));
@ -80,8 +95,9 @@ protected function Initialize()
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.
public function DropCoreAPI() {
memory = none; memory = none;
ref = none; ref = none;
box = none; box = none;
@ -99,3 +115,6 @@ public function DropCoreAPI()
avarice = none; avarice = none;
default.myself = none; default.myself = none;
} }
defaultproperties {
}
Loading…
Cancel
Save