Browse Source

Refactor shutting down process

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
28895baa88
  1. 86
      sources/BaseRealm/AcediaEnvironment/AcediaEnvironment.uc
  2. 1
      sources/BaseRealm/Global.uc
  3. 16
      sources/ServerRealm/API/Unreal/ServerUnrealAPI.uc

86
sources/BaseRealm/AcediaEnvironment/AcediaEnvironment.uc

@ -44,6 +44,8 @@ class AcediaEnvironment extends AcediaObject;
* considered enabled at the same time. * considered enabled at the same time.
*/ */
var private bool acediaShutDown;
var private array< class<_manifest> > availablePackages; var private array< class<_manifest> > availablePackages;
var private array< class<_manifest> > loadedPackages; var private array< class<_manifest> > loadedPackages;
@ -58,9 +60,62 @@ var private LoggerAPI.Definition errNotRegistered, errFeatureAlreadyEnabled;
var private LoggerAPI.Definition warnFeatureAlreadyEnabled; var private LoggerAPI.Definition warnFeatureAlreadyEnabled;
var private LoggerAPI.Definition errFeatureClassAlreadyEnabled; var private LoggerAPI.Definition errFeatureClassAlreadyEnabled;
var private SimpleSignal onShutdownSignal;
var private SimpleSignal onShutdownSystemSignal;
var private Environment_FeatureEnabled_Signal onFeatureEnabledSignal; var private Environment_FeatureEnabled_Signal onFeatureEnabledSignal;
var private Environment_FeatureDisabled_Signal onFeatureDisabledSignal; var private Environment_FeatureDisabled_Signal onFeatureDisabledSignal;
protected function Constructor()
{
// Always register our core package
RegisterPackage_S("AcediaCore");
onShutdownSignal = SimpleSignal(
_.memory.Allocate(class'SimpleSignal'));
onShutdownSystemSignal = SimpleSignal(
_.memory.Allocate(class'SimpleSignal'));
onFeatureEnabledSignal = Environment_FeatureEnabled_Signal(
_.memory.Allocate(class'Environment_FeatureEnabled_Signal'));
onFeatureDisabledSignal = Environment_FeatureDisabled_Signal(
_.memory.Allocate(class'Environment_FeatureDisabled_Signal'));
}
protected function Finalizer()
{
_.memory.Free(onShutdownSignal);
_.memory.Free(onShutdownSystemSignal);
_.memory.Free(onFeatureEnabledSignal);
_.memory.Free(onFeatureDisabledSignal);
}
/**
* Signal that will be emitted before Acedia shuts down.
* At this point all APIs should still exist and function.
*
* [Signature]
* void <slot>()
*/
/* SIGNAL */
public final function SimpleSlot OnShutDown(AcediaObject receiver)
{
return SimpleSlot(onShutdownSignal.NewSlot(receiver));
}
/**
* Signal that will be emitted during Acedia shut down. System API use it to
* clean up after themselves, so one shouldn't rely on them.
*
* There is no reason to use this signal unless you're reimplementing one of
* the APIs. Otherwise you probably want to use `OnShutDown()` signal instead.
*
* [Signature]
* void <slot>()
*/
/* SIGNAL */
public final function SimpleSlot OnShutDownSystem(AcediaObject receiver)
{
return SimpleSlot(onShutdownSystemSignal.NewSlot(receiver));
}
/** /**
* Signal that will be emitted when new `Feature` is enabled. * Signal that will be emitted when new `Feature` is enabled.
* Emitted after `Feature`'s `OnEnabled()` method was called. * Emitted after `Feature`'s `OnEnabled()` method was called.
@ -96,20 +151,27 @@ public final function Environment_FeatureDisabled_Slot OnFeatureDisabled(
onFeatureEnabledSignal.NewSlot(receiver)); onFeatureEnabledSignal.NewSlot(receiver));
} }
protected function Constructor() /**
* Shuts AcediaCore down, performing all the necessary cleaning up.
*/
public final function Shutdown()
{ {
// Always register our core package local LevelCore core;
RegisterPackage_S("AcediaCore"); if (acediaShutDown) {
onFeatureEnabledSignal = Environment_FeatureEnabled_Signal( return;
_.memory.Allocate(class'Environment_FeatureEnabled_Signal'));
onFeatureDisabledSignal = Environment_FeatureDisabled_Signal(
_.memory.Allocate(class'Environment_FeatureDisabled_Signal'));
} }
DisableAllFeatures();
protected function Finalizer() onShutdownSignal.Emit();
{ onShutdownSystemSignal.Emit();
_.memory.Free(onFeatureEnabledSignal); core = class'ServerLevelCore'.static.GetInstance();
_.memory.Free(onFeatureDisabledSignal); if (core != none) {
core.Destroy();
}
core = class'ClientLevelCore'.static.GetInstance();
if (core != none) {
core.Destroy();
}
acediaShutDown = true;
} }
/** /**

1
sources/BaseRealm/Global.uc

@ -59,6 +59,7 @@ 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();
// `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'));

16
sources/ServerRealm/API/Unreal/ServerUnrealAPI.uc

@ -21,6 +21,22 @@ class ServerUnrealAPI extends ServerUnrealAPIBase;
var private LoggerAPI.Definition fatalNoStalker; var private LoggerAPI.Definition fatalNoStalker;
protected function Constructor()
{
_.environment.OnShutDownSystem(self).connect = HandleShutdown;
}
protected function HandleShutdown()
{
local UnrealService service;
service = UnrealService(class'UnrealService'.static.GetInstance());
// This has to clean up anything we've added
if (service != none) {
service.Destroy();
}
}
/* SIGNAL */ /* SIGNAL */
public function Unreal_OnTick_Slot OnTick( public function Unreal_OnTick_Slot OnTick(
AcediaObject receiver) AcediaObject receiver)

Loading…
Cancel
Save