Apparatus Version 1.0.0
ECS-like data-driven workflow for Unreal Engine.
MechanicalGameModeBase.h
1 /*
2  * ░▒▓ APPARATUS ▓▒░
3  *
4  * File: MechanicalGameModeBase.h
5  * Created: Friday, 23rd October 2020 7:00:48 pm
6  * Author: Vladislav Dmitrievich Turbanov (vladislav@turbanov.ru)
7  * ───────────────────────────────────────────────────────────────────
8  * Last Modified: Friday, 26th March 2021 1:36:17 pm
9  * Modified By: Vladislav Dmitrievich Turbanov (vladislav@turbanov.ru)
10  * ───────────────────────────────────────────────────────────────────
11  *
12  * The Apparatus source code is for your internal usage only.
13  * Redistribution of this file is strictly prohibited.
14  *
15  * Community forums: https://talk.turbanov.ru
16  *
17  * Copyright 2020 - 2021, SP Vladislav Dmitrievich Turbanov
18  * Made in Russia, Moscow City, Chekhov City
19  */
20 
21 #pragma once
22 
23 #include "CoreMinimal.h"
24 #include "GameFramework/Actor.h"
25 #include "UObject/WeakInterfacePtr.h"
26 
27 #include "ApparatusRuntime.h"
28 #include "Belt.h"
29 #include "Mechanical.h"
30 #include "SubjectiveActorComponent.h"
31 #include "SubjectiveUserWidget.h"
32 #include "Mechanical.h"
33 
34 #include "MechanicalGameModeBase.generated.h"
35 
36 
40 UCLASS()
41 class APPARATUSRUNTIME_API AMechanicalGameModeBase final : public AGameModeBase, public IMechanical
42 {
43  GENERATED_BODY()
44 
45 
48  UPROPERTY(Transient)
49  mutable class UBelt* BufferingBelt = nullptr;
50 
54  UPROPERTY(EditAnywhere, Category = Mechanism,
55  Meta = (AllowPrivateAccess = "true"))
56  float SteadyDeltaTime = 1.0f / 30.0f;
57 
58  friend class UDetail;
59  friend class UBelt;
60  friend class ISubjective;
61 
62  public:
67 
72 
73  protected:
77  virtual void BeginPlay() override;
78 
82  virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
83 
84  virtual FORCEINLINE UBelt* GetBufferingBelt() const override
85  {
86  if (BufferingBelt == nullptr)
87  {
88  BufferingBelt = UBelt::NewBuffering(GetTransientPackage());
89  }
90  return BufferingBelt;
91  }
92 
93  public:
94 
95  virtual void Tick(float DeltaTime) override;
96 
100  UFUNCTION(BlueprintCallable, BlueprintPure)
101  FORCEINLINE float GetProcessedSteadyTime() const
102  {
103  return DoGetProcessedSteadyTime(SteadyDeltaTime);
104  }
105 
113  UFUNCTION(BlueprintCallable, BlueprintPure,
114  Category = "Apparatus|Mechanism",
115  Meta = (DisplayName = "Steady Frame Ratio", Keywords = "get"))
116  FORCEINLINE float CalcSteadyFrameRatio() const
117  {
118  return DoCalcSteadyFrameRatio(GetGameTimeSinceCreation(),
119  SteadyDeltaTime);
120  }
121 
128  UFUNCTION(BlueprintCallable, BlueprintPure,
129  Category = "Apparatus|Mechanism",
130  Meta = (DisplayName = "Steady Future Factor", Keywords = "get ratio"))
131  FORCEINLINE float CalcSteadyFutureFactor() const
132  {
133  return DoCalcSteadyFutureFactor(GetGameTimeSinceCreation(),
134  SteadyDeltaTime);
135  }
136 
140  UFUNCTION(BlueprintCallable, BlueprintPure,
141  Category = "Apparatus|Mechanism",
142  Meta = (DisplayName = "Steady Frame", Keywords = "get"))
143  FORCEINLINE int32 GetSteadyFrame() const
144  {
145  return SteadyFrame;
146  }
147 
151  UFUNCTION(BlueprintCallable, BlueprintPure,
152  Category = "Apparatus|Mechanism",
153  Meta = (DisplayName = "Steady Time", Keywords = "get"))
154  FORCEINLINE float GetSteadyTime() const
155  {
156  return GetSteadyFrame() * SteadyDeltaTime;
157  }
158 }; // class AMechanicalGameModeBase
159 
161 {
162  PrimaryActorTick.bCanEverTick = true;
163 }
164 
166 {
167 }
168 
170 {
171  Super::BeginPlay();
173 }
174 
175 FORCEINLINE void AMechanicalGameModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason)
176 {
178  Super::EndPlay(EndPlayReason);
179 }
180 
181 FORCEINLINE void AMechanicalGameModeBase::Tick(float DeltaTime)
182 {
183  DoTick(GetGameTimeSinceCreation(),
184  DeltaTime,
185  SteadyDeltaTime);
186 }
The base game mode mechanism facility.
Definition: MechanicalGameModeBase.h:42
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
End executing the mechanism.
Definition: MechanicalGameModeBase.h:175
~AMechanicalGameModeBase()
Destroy the mechanism.
Definition: MechanicalGameModeBase.h:165
virtual UBelt * GetBufferingBelt() const override
A special callback to process a newly created subjects boot process.
Definition: MechanicalGameModeBase.h:84
AMechanicalGameModeBase()
Construct a new mechanism.
Definition: MechanicalGameModeBase.h:160
virtual void BeginPlay() override
Begin executing the mechanism.
Definition: MechanicalGameModeBase.h:169
virtual void Tick(float DeltaTime) override
Definition: MechanicalGameModeBase.h:181
A common interface for all mechanisms.
Definition: Mechanical.h:43
virtual void DoTick(float NewTime, float DeltaTime, float SteadyDeltaTime)
Perform a standard ticking routine.
Definition: Mechanical.h:230
An interface for all sorts of subjects.
Definition: Subjective.h:42
The conveyor belt consisting of subjects.
Definition: Belt.h:60
static class UBelt * NewBuffering(UObject *Owner)
Create a new buffering belt instance.
Definition: Belt.cpp:80
The base subject detail (component) class.
Definition: Detail.h:35
static void RegisterMechanical(TScriptInterface< IMechanical > Mechanical)
Register a mechanical within the mechanism.
Definition: Mechanism.h:384
static void UnregisterMechanical(TScriptInterface< IMechanical > Mechanical)
Unregister a mechanical from the mechanism.
Definition: Mechanism.h:266