Apparatus Version 1.0.0
ECS-like data-driven workflow for Unreal Engine.
MechanicalActor.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 
26 #include "Mechanism.h"
27 #include "Mechanical.h"
28 #include "Belt.h"
29 #include "ApparatusRuntime.h"
30 
31 #include "MechanicalActor.generated.h"
32 
33 
37 UCLASS()
38 class APPARATUSRUNTIME_API AMechanicalActor final : public AActor, public IMechanical
39 {
40  GENERATED_BODY()
41 
42 
45  UPROPERTY(Transient)
46  mutable class UBelt* BufferingBelt = nullptr;
47 
51  UPROPERTY(EditAnywhere, Category = Mechanism,
52  Meta = (AllowPrivateAccess = "true"))
53  float SteadyDeltaTime = 1.0f / 30.0f;
54 
55  public:
60 
65 
66  protected:
70  virtual void BeginPlay() override;
71 
75  virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
76 
77  virtual inline UBelt* GetBufferingBelt() const override
78  {
79  if (BufferingBelt == nullptr)
80  {
81  BufferingBelt = UBelt::NewBuffering(GetTransientPackage());
82  }
83  return BufferingBelt;
84  }
85 
86  public:
87 
88  virtual void Tick(float DeltaTime) override;
89 
93  UFUNCTION(BlueprintCallable, BlueprintPure,
94  Category = "Apparatus|Mechanism",
95  Meta = (DisplayName = "Processed Steady Time", Keywords = "get"))
96  FORCEINLINE float GetProcessedSteadyTime() const
97  {
98  return DoGetProcessedSteadyTime(SteadyDeltaTime);
99  }
100 
108  UFUNCTION(BlueprintCallable, BlueprintPure,
109  Category = "Apparatus|Mechanism",
110  Meta = (DisplayName = "Steady Frame Ratio", Keywords = "get"))
111  FORCEINLINE float CalcSteadyFrameRatio() const
112  {
113  return DoCalcSteadyFrameRatio(GetGameTimeSinceCreation(),
114  SteadyDeltaTime);
115  }
116 
123  UFUNCTION(BlueprintCallable, BlueprintPure,
124  Category = "Apparatus|Mechanism",
125  Meta = (DisplayName = "Steady Future Factor", Keywords = "get ratio"))
126  FORCEINLINE float CalcSteadyFutureFactor() const
127  {
128  return DoCalcSteadyFutureFactor(GetGameTimeSinceCreation(),
129  SteadyDeltaTime);
130  }
131 
135  UFUNCTION(BlueprintCallable, BlueprintPure,
136  Category = "Apparatus|Mechanism",
137  Meta = (DisplayName = "Steady Frame", Keywords = "get"))
138  FORCEINLINE int32 GetSteadyFrame() const
139  {
140  return SteadyFrame;
141  }
142 
146  UFUNCTION(BlueprintCallable, BlueprintPure,
147  Category = "Apparatus|Mechanism",
148  Meta = (DisplayName = "Steady Time", Keywords = "get"))
149  FORCEINLINE float GetSteadyTime() const
150  {
151  return GetSteadyFrame() * SteadyDeltaTime;
152  }
153 }; // class AMechanicalActor
154 
156 {
157  PrimaryActorTick.bCanEverTick = true;
158 }
159 
161 
162 
163 FORCEINLINE void AMechanicalActor::BeginPlay()
164 {
165  Super::BeginPlay();
167 }
168 
169 FORCEINLINE void AMechanicalActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
170 {
172  Super::EndPlay(EndPlayReason);
173 }
174 
175 FORCEINLINE void AMechanicalActor::Tick(float DeltaTime)
176 {
177  DoTick(GetGameTimeSinceCreation(),
178  DeltaTime,
179  SteadyDeltaTime);
180 }
The mechanical actor entity.
Definition: MechanicalActor.h:39
~AMechanicalActor()
Destroy the mechanism.
Definition: MechanicalActor.h:160
virtual void BeginPlay() override
Begin executing the mechanism.
Definition: MechanicalActor.h:163
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
End executing the mechanism.
Definition: MechanicalActor.h:169
AMechanicalActor()
Construct a new mechanism.
Definition: MechanicalActor.h:155
virtual void Tick(float DeltaTime) override
Definition: MechanicalActor.h:175
virtual UBelt * GetBufferingBelt() const override
A special callback to process a newly created subjects boot process.
Definition: MechanicalActor.h:77
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
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
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