LEAP Documentation 40220
Documentation for the LEAP project
Interpolator.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2017. All Rights Reserved.
2
3#pragma once
4
5#include "GameFramework/Actor.h"
6#include "Kismet/KismetMathLibrary.h"
7#include "Interpolator.generated.h"
8
9DECLARE_DYNAMIC_DELEGATE_OneParam(FInterpolationSignature, float, Value);
10DECLARE_DELEGATE_OneParam(FInterpolationDelegate, struct FInterpolationEntry&);
11
12USTRUCT(Blueprintable)
14{
15 GENERATED_USTRUCT_BODY()
16
18
19 FInterpolationEntry(UObject* Object, FInterpolationDelegate Event, FInterpolationSignature DynamicEvent, FInterpolationDelegate OnCompleteEvent, FInterpolationSignature OnCompleteDynamicEvent, float TE, float TT, float S, float E, EEasingFunc::Type Ease, UCurveFloat* C)
20 : DynamicDelegate(DynamicEvent), CompleteDynamicDelegate(OnCompleteDynamicEvent), Delegate(Event), CompleteDelegate(OnCompleteEvent), TimeElapsed(TE), TimeTotal(TT), Start(S), End(E), EaseType(Ease), Curve(C), CallingObject(Object)
21 {
22 Counter++;
23 ID = Counter;
24 bIsValid = true;
25 }
26
27 FInterpolationSignature DynamicDelegate;
28 FInterpolationSignature CompleteDynamicDelegate;
29 FInterpolationDelegate Delegate;
30 FInterpolationDelegate CompleteDelegate;
31
32 float TimeElapsed = 0.f;
33 float TimeTotal = 0.f;
34 float DeltaTime = 0.0f;
35 float Start = 0.f;
36 float End = 0.f;
37 float PercentCompleted = 0.0f;
38 float Value = 0.0f;
39 bool bInverted = false;
40 bool bIsValid = false;
41 EEasingFunc::Type EaseType;
42 UCurveFloat* Curve = nullptr;
43
44 bool bReplicated = false;
45
46 UPROPERTY()
47 uint32 ID = 0;
48
49 static uint32 Counter;
50
51 UPROPERTY()
52 UObject* CallingObject = nullptr;
53
54 bool bCompleted = false;
55
56 bool operator==(const FInterpolationEntry& rhs) const
57 {
58 return ID == rhs.ID;
59 }
60};
61
62UCLASS()
63class PROJECTX_API AInterpolator : public AActor
64{
65 GENERATED_UCLASS_BODY()
66
67public:
68 virtual void Tick(float DeltaTime) override;
69 virtual void BeginPlay() override;
70 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason);
71
72 /* Interpolates a value from 0 to 1 over the specified amount of time, using a selected curve.
73 @param TimeTotal - the amount of time for the value to go from 0 to 1
74 @param EaseType - Select from a number of simple curves which affect how the value interpolates
75 @param Event - calls back each time the value interpolates towards 1
76 @param On Complete Event - calls back once the value has fully interpolated towards 1
77 @return Interpolation ID */
78 UFUNCTION(BlueprintCallable, Category = "Interpolation", meta = (WorldContext = "WorldContextObject", AutoCreateRefTerm = "OnCompleteEvent"))
79 static int32 InterpolateOverTimeSimple(UObject* WorldContextObject, float TimeTotal, EEasingFunc::Type EaseType, const FInterpolationSignature& Event, const FInterpolationSignature& OnCompleteEvent);
80 static uint32 InterpolateOverTimeSimple(UObject* WorldContextObject, float TimeTotal, EEasingFunc::Type EaseType, const FInterpolationDelegate& Event, const FInterpolationDelegate& OnCompleteEvent);
81 static uint32 InterpolateOverTimeSimple(UObject* WorldContextObject, float TimeTotal, EEasingFunc::Type EaseType, const FInterpolationDelegate& Event);
82
83 /* Interpolates a value from Start to End over the specified amount of time with an optional starting point and custom curve.
84 @return Interpolation ID */
85 UFUNCTION(BlueprintCallable, Category = "Interpolation", meta = (WorldContext = "WorldContextObject", AutoCreateRefTerm = "OnCompleteEvent"))
86 static int32 InterpolateOverTimeCustomCurve(UObject* WorldContextObject, float TimeElapsed, float TimeTotal, float Start, float End, UCurveFloat* Curve, const FInterpolationSignature& Event, const FInterpolationSignature& OnCompleteEvent);
87 static int32 InterpolateOverTimeCustomCurve(UObject* WorldContextObject, float TimeElapsed, float TimeTotal, float Start, float End, UCurveFloat* Curve, const FInterpolationSignature& Event);
88 static int32 InterpolateOverTimeCustomCurve(UObject* WorldContextObject, float TimeElapsed, float TimeTotal, float Start, float End, UCurveFloat* Curve, const FInterpolationDelegate& Event);
89 static int32 InterpolateOverTimeCustomCurve(UObject* WorldContextObject, float TimeElapsed, float TimeTotal, float Start, float End, UCurveFloat* Curve, const FInterpolationDelegate& Event, const FInterpolationDelegate& OnCompleteEvent);
90
91 /* Interpolates a value from Start to End over the specified amount of time with an optional starting point and selection of stock curves.
92 @return Interpolation ID */
93 UFUNCTION(BlueprintCallable, Category = "Interpolation", meta = (WorldContext = "WorldContextObject", AutoCreateRefTerm = "OnCompleteEvent"))
94 static int32 InterpolateOverTime(UObject* WorldContextObject, float TimeElapsed, float TimeTotal, float Start, float End, EEasingFunc::Type EaseType, const FInterpolationSignature& Event, const FInterpolationSignature& OnCompleteEvent);
95 static uint32 InterpolateOverTime(UObject* WorldContextObject, float TimeElapsed, float TimeTotal, float Start, float End, EEasingFunc::Type EaseType, const FInterpolationDelegate &Event, const FInterpolationDelegate& OnCompleteEvent);
96 static uint32 InterpolateOverTime(UObject* WorldContextObject, float TimeElapsed, float TimeTotal, float Start, float End, EEasingFunc::Type EaseType, const FInterpolationDelegate &Event);
97 static uint32 InterpolateOverTime(UObject* WorldContextObject, float TimeElapsed, float TimeTotal, float Start, float End, const FInterpolationDelegate& Event, const FInterpolationSignature& DynamicEvent, const FInterpolationDelegate& OnCompleteEvent, const FInterpolationSignature& OnCompleteDynamicEvent, EEasingFunc::Type EaseType = EEasingFunc::Linear, UCurveFloat* Curve = nullptr, bool bReplicated = false);
98
99 static uint32 InterpolateOverTimeReplicated(UObject* WorldContextObject, float StartTime, float EndTime, float Start, float End, EEasingFunc::Type EaseType, const FInterpolationDelegate& Event);
100
101 static FInterpolationEntry* GetInterpolationEntry(const FInterpolationDelegate& Event);
102 static FInterpolationEntry* GetInterpolationEntry(const FInterpolationSignature& Event);
103
104 /* Stops the execution of this interpolation and clears it. */
105 UFUNCTION(BlueprintCallable, Category = "Interpolation")
106 static void ClearInterpolation(const UObject* Caller, const int32 ID);
107
108 /* Checks if the interpolation ID is currently executing */
109 UFUNCTION(BlueprintPure, Category = "Interpolation")
110 static bool IsInterpolationActive(const UObject* Caller, const int32 ID) { return GetInterpolationEntryByID(Caller, ID) != nullptr; };
111
112 /* Completes the interpolation by calling the final interpolation frame as well as the oncomplete event. */
113 UFUNCTION(BlueprintCallable, Category = "Interpolation")
114 static void CompleteInterpolation(const UObject* Caller, const int32 ID);
115
116 /* Grabs an interpolation by id so that it can be modified while running. */
117 static FInterpolationEntry* GetInterpolationEntryByID(const UObject* Caller, const uint32 ID);
118
119 /* Stops the execution of all interpolations on this object. */
120 UFUNCTION(BlueprintCallable, Category = "Interpolation")
121 static void ClearInterpolatorsForObject(const UObject* Object);
122
123 /* Completes and clears all interpolators. */
124 static void NotifyLevelTravel();
125
126 /* Inverts the playback of an interpolator */
127 UFUNCTION(BlueprintCallable, Category = "Interpolation")
128 static void InvertInterpolator(const UObject* Caller, const int32 ID);
129
130public:
131 static AInterpolator* GetInterpolator(UObject* WorldContextObject);
132
133private:
134 static void CalculateEntryValue(FInterpolationEntry* Entry, bool bFromTick = false);
135
136private:
138 static TArray<FInterpolationEntry> InterpolationList;
139 static TWeakObjectPtr<AInterpolator> Singleton;
140};
DECLARE_DELEGATE_OneParam(FInterpolationDelegate, struct FInterpolationEntry &)
DECLARE_DYNAMIC_DELEGATE_OneParam(FInterpolationSignature, float, Value)
Definition: Interpolator.h:64
Definition: ProjectXGameInstance.h:507
Definition: Interpolator.h:14
FInterpolationSignature DynamicDelegate
Definition: Interpolator.h:27
EEasingFunc::Type EaseType
Definition: Interpolator.h:41
FInterpolationDelegate Delegate
Definition: Interpolator.h:29
FInterpolationEntry(UObject *Object, FInterpolationDelegate Event, FInterpolationSignature DynamicEvent, FInterpolationDelegate OnCompleteEvent, FInterpolationSignature OnCompleteDynamicEvent, float TE, float TT, float S, float E, EEasingFunc::Type Ease, UCurveFloat *C)
Definition: Interpolator.h:19
FInterpolationSignature CompleteDynamicDelegate
Definition: Interpolator.h:28
FInterpolationDelegate CompleteDelegate
Definition: Interpolator.h:30