Apparatus Version 1.0.0
ECS-like data-driven workflow for Unreal Engine.
MechanicalGameMode.h
1 // Fill out your copyright notice in the Description page of Project Settings.
2 
3 #pragma once
4 
5 #include "CoreMinimal.h"
6 #include "GameFramework/GameMode.h"
7 
8 #include "ApparatusRuntime.h"
9 #include "Belt.h"
10 #include "Mechanical.h"
11 #include "SubjectiveActorComponent.h"
12 #include "SubjectiveUserWidget.h"
13 #include "Mechanical.h"
14 
15 #include "MechanicalGameMode.generated.h"
16 
20 UCLASS()
21 class APPARATUSRUNTIME_API AMechanicalGameMode final : public AGameMode, public IMechanical
22 {
23  GENERATED_BODY()
24 
25 
28  UPROPERTY(Transient)
29  mutable class UBelt* BufferingBelt = nullptr;
30 
34  UPROPERTY(EditAnywhere, Category = Mechanism,
35  Meta = (AllowPrivateAccess = "true"))
36  float SteadyDeltaTime = 1.0f / 30.0f;
37 
38  friend class UDetail;
39  friend class UBelt;
40  friend class ISubjective;
41 
42  public:
47 
52 
53  protected:
57  virtual void BeginPlay() override;
58 
62  virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
63 
64  virtual FORCEINLINE UBelt* GetBufferingBelt() const override
65  {
66  if (BufferingBelt == nullptr)
67  {
68  BufferingBelt = UBelt::NewBuffering(GetTransientPackage());
69  }
70  return BufferingBelt;
71  }
72 
73  public:
74 
75  virtual void Tick(float DeltaTime) override;
76 
80  UFUNCTION(BlueprintCallable, BlueprintPure)
81  FORCEINLINE float GetProcessedSteadyTime() const
82  {
83  return DoGetProcessedSteadyTime(SteadyDeltaTime);
84  }
85 
93  UFUNCTION(BlueprintCallable, BlueprintPure,
94  Category = "Apparatus|Mechanism",
95  Meta = (DisplayName = "Steady Frame Ratio", Keywords = "get"))
96  FORCEINLINE float CalcSteadyFrameRatio() const
97  {
98  return DoCalcSteadyFrameRatio(GetGameTimeSinceCreation(),
99  SteadyDeltaTime);
100  }
101 
108  UFUNCTION(BlueprintCallable, BlueprintPure,
109  Category = "Apparatus|Mechanism",
110  Meta = (DisplayName = "Steady Future Factor", Keywords = "get ratio"))
111  FORCEINLINE float CalcSteadyFutureFactor() const
112  {
113  return DoCalcSteadyFutureFactor(GetGameTimeSinceCreation(),
114  SteadyDeltaTime);
115  }
116 
120  UFUNCTION(BlueprintCallable, BlueprintPure,
121  Category = "Apparatus|Mechanism",
122  Meta = (DisplayName = "Steady Frame", Keywords = "get"))
123  FORCEINLINE int32 GetSteadyFrame() const
124  {
125  return SteadyFrame;
126  }
127 
131  UFUNCTION(BlueprintCallable, BlueprintPure,
132  Category = "Apparatus|Mechanism",
133  Meta = (DisplayName = "Steady Time", Keywords = "get"))
134  FORCEINLINE float GetSteadyTime() const
135  {
136  return GetSteadyFrame() * SteadyDeltaTime;
137  }
138 }; // class AMechanicalGameModeBase
139 
141 {
142  PrimaryActorTick.bCanEverTick = true;
143 }
144 
146 {
147 }
148 
150 {
151  Super::BeginPlay();
153 }
154 
155 FORCEINLINE void AMechanicalGameMode::EndPlay(const EEndPlayReason::Type EndPlayReason)
156 {
158  Super::EndPlay(EndPlayReason);
159 }
160 
161 FORCEINLINE void AMechanicalGameMode::Tick(float DeltaTime)
162 {
163  DoTick(GetGameTimeSinceCreation(),
164  DeltaTime,
165  SteadyDeltaTime);
166 }
The game mode mechanism facility.
Definition: MechanicalGameMode.h:22
virtual UBelt * GetBufferingBelt() const override
A special callback to process a newly created subjects boot process.
Definition: MechanicalGameMode.h:64
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
End executing the mechanism.
Definition: MechanicalGameMode.h:155
AMechanicalGameMode()
Construct a new mechanism.
Definition: MechanicalGameMode.h:140
virtual void Tick(float DeltaTime) override
Definition: MechanicalGameMode.h:161
virtual void BeginPlay() override
Begin executing the mechanism.
Definition: MechanicalGameMode.h:149
~AMechanicalGameMode()
Destroy the mechanism.
Definition: MechanicalGameMode.h:145
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