You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
4.3 KiB
152 lines
4.3 KiB
2 years ago
|
/**
|
||
|
* Acedia's interaction class that allows it access to drawing and user input.
|
||
|
* 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 <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
class AcediaInteraction extends Interaction;
|
||
|
|
||
|
var private Global _;
|
||
|
var private ClientGlobal _client;
|
||
|
var private AcediaInteraction myself;
|
||
|
|
||
2 years ago
|
var private Unreal_OnTick_Signal onTickSignal;
|
||
2 years ago
|
var private Interaction_OnRender_Signal onPreRenderSignal;
|
||
|
var private Interaction_OnRender_Signal onPostRenderSignal;
|
||
|
|
||
2 years ago
|
/**
|
||
|
* Signal that will be emitted every tick.
|
||
|
*
|
||
|
* [Signature]
|
||
|
* void <slot>(float delta, float dilationCoefficient)
|
||
|
*
|
||
|
* @param delta In-game time in seconds that has passed since
|
||
|
* the last tick. To obtain real time passed from the last tick divide
|
||
|
* `delta` by `dilationCoefficient`.
|
||
|
* @param dilationCoefficient How fast is in-game time flow compared to
|
||
|
* the real world's one? `2` means twice as fast and
|
||
|
* `0.5` means twice as slow.
|
||
|
*/
|
||
|
/* SIGNAL */
|
||
|
public function Unreal_OnTick_Slot OnTick(AcediaObject receiver)
|
||
|
{
|
||
|
return Unreal_OnTick_Slot(onTickSignal.NewSlot(receiver));
|
||
|
}
|
||
|
|
||
2 years ago
|
/**
|
||
|
* Called before rendering, when `Interaction`s receive their `PreRender()`
|
||
|
* events
|
||
|
*
|
||
|
* [Signature]
|
||
|
* <slot>(Canvas canvas)
|
||
|
*
|
||
|
* @param Canvas `Actor` that attempts to broadcast next text message.
|
||
|
*/
|
||
|
/* SIGNAL */
|
||
|
public function Interaction_OnRender_Slot OnPreRender(AcediaObject receiver)
|
||
|
{
|
||
|
return Interaction_OnRender_Slot(onPreRenderSignal.NewSlot(receiver));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Called before rendering, when `Interaction`s receive their `PreRender()`
|
||
|
* events
|
||
|
*
|
||
|
* [Signature]
|
||
|
* <slot>(Canvas canvas)
|
||
|
*
|
||
|
* @param Canvas `Actor` that attempts to broadcast next text message.
|
||
|
*/
|
||
|
/* SIGNAL */
|
||
|
public function Interaction_OnRender_Slot OnPostRender(AcediaObject receiver)
|
||
|
{
|
||
|
return Interaction_OnRender_Slot(onPostRenderSignal.NewSlot(receiver));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Initializes newly created `Interaction`.
|
||
|
*/
|
||
|
public final function InitializeInteraction()
|
||
|
{
|
||
|
if (default.myself != none) {
|
||
|
return;
|
||
|
}
|
||
|
default.myself = self;
|
||
|
_ = class'Global'.static.GetInstance();
|
||
|
_client = class'ClientGlobal'.static.GetInstance();
|
||
2 years ago
|
onTickSignal = Unreal_OnTick_Signal(
|
||
|
_.memory.Allocate(class'Unreal_OnTick_Signal'));
|
||
2 years ago
|
onPreRenderSignal = Interaction_OnRender_Signal(
|
||
|
_.memory.Allocate(class'Interaction_OnRender_Signal'));
|
||
|
onPostRenderSignal = Interaction_OnRender_Signal(
|
||
|
_.memory.Allocate(class'Interaction_OnRender_Signal'));
|
||
|
}
|
||
|
|
||
|
event NotifyLevelChange()
|
||
|
{
|
||
2 years ago
|
_.memory.Free(onTickSignal);
|
||
|
_.memory.Free(onPreRenderSignal);
|
||
|
_.memory.Free(onPostRenderSignal);
|
||
|
onTickSignal = none;
|
||
|
onPreRenderSignal = none;
|
||
|
onPostRenderSignal = none;
|
||
2 years ago
|
_.environment.ShutDown();
|
||
|
default.myself = none;
|
||
|
_ = none;
|
||
|
_client = none;
|
||
|
master.RemoveInteraction(self);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns instance to the added `AcediaInteraction`'s instance.
|
||
|
*
|
||
|
* @return Instance added to interaction master.
|
||
|
*/
|
||
|
public static function AcediaInteraction GetInstance()
|
||
|
{
|
||
|
return default.myself;
|
||
|
}
|
||
|
|
||
|
public function PreRender(Canvas canvas)
|
||
|
{
|
||
|
if (onPreRenderSignal != none) {
|
||
|
onPreRenderSignal.Emit(canvas);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function PostRender(Canvas canvas)
|
||
|
{
|
||
|
if (onPostRenderSignal != none) {
|
||
|
onPostRenderSignal.Emit(canvas);
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
public function Tick(float delta)
|
||
|
{
|
||
|
local float dilationCoefficient;
|
||
|
|
||
|
if (onTickSignal != none)
|
||
|
{
|
||
|
dilationCoefficient = _client.unreal.GetLevel().timeDilation / 1.1;
|
||
|
onTickSignal.Emit(delta, dilationCoefficient);
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
defaultproperties
|
||
|
{
|
||
2 years ago
|
bVisible = true
|
||
|
bRequiresTick = true
|
||
2 years ago
|
}
|