Refactor Scripted Animations to provide an option for which clock to use
This commit is contained in:
@@ -1,59 +1,5 @@
|
||||
#include "ScriptedAnimation.h"
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Routines to calculate the current state of an FlxScriptedAnimation.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
double FlxScriptedAnimation::CalculateFade(double Offset, double Fade)
|
||||
{
|
||||
if (Offset < 0.0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
if (Fade > 0.001)
|
||||
{
|
||||
return FMath::Min(Offset / Fade, 1.0);
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
double FlxScriptedAnimation::UnclampedElapsedTime(double CurrentTime) const
|
||||
{
|
||||
return CurrentTime - StartTime;
|
||||
}
|
||||
|
||||
double FlxScriptedAnimation::UnclampedTimeLeft(double CurrentTime) const
|
||||
{
|
||||
return EndTime - CurrentTime;
|
||||
}
|
||||
|
||||
double FlxScriptedAnimation::ClampedElapsedTime(double CurrentTime) const
|
||||
{
|
||||
return FMath::Max(0.0, CurrentTime - StartTime);
|
||||
}
|
||||
|
||||
double FlxScriptedAnimation::ClampedTimeLeft(double CurrentTime) const
|
||||
{
|
||||
return FMath::Max(0.0, EndTime - CurrentTime);
|
||||
}
|
||||
|
||||
double FlxScriptedAnimation::CalcFadeInAlpha(double CurrentTime) const
|
||||
{
|
||||
return CalculateFade(UnclampedElapsedTime(CurrentTime), FadeInDuration);
|
||||
}
|
||||
|
||||
double FlxScriptedAnimation::CalcFadeOutAlpha(double CurrentTime) const
|
||||
{
|
||||
return CalculateFade(UnclampedTimeLeft(CurrentTime), FadeOutDuration);
|
||||
}
|
||||
|
||||
double FlxScriptedAnimation::CalcFadeInOutAlpha(double CurrentTime) const
|
||||
{
|
||||
return FMath::Min(CalcFadeInAlpha(CurrentTime), CalcFadeOutAlpha(CurrentTime));
|
||||
}
|
||||
#include "Engine/Engine.h"
|
||||
|
||||
void FlxScriptedAnimation::InitiateFadeOut(double CurrentTime, double AllowedFade)
|
||||
{
|
||||
@@ -81,43 +27,48 @@ void UlxScriptedAnimations::Keep(int n)
|
||||
}
|
||||
|
||||
void UlxScriptedAnimations::AddAnimation(
|
||||
UObject* WorldContextObject, UAnimSequenceBase* Sequence, double FadeInTime, double FadeOutTime, int64 AqHash)
|
||||
UObject* WorldContextObject, UAnimSequenceBase* Sequence, double FadeInTime, double FadeOutTime,
|
||||
int64 AnimationStepID, bool ContinueWhenPaused)
|
||||
{
|
||||
check(KeepCount >= 1);
|
||||
FlxScriptedAnimation Result;
|
||||
|
||||
// Get World Time
|
||||
UWorld* World = GEngine->GetWorldFromContextObjectChecked(WorldContextObject);
|
||||
double WorldTime = World ? World->GetTimeSeconds() : 0.0;
|
||||
FlxWorldClocks Clocks = UlxScriptedAnimationLibrary::GetAllWorldClocks(WorldContextObject);
|
||||
double CurrentTime = ContinueWhenPaused ? Clocks.RealTime : Clocks.WorldTime;
|
||||
|
||||
// Get the animation Length.
|
||||
double Length = (Sequence ? static_cast<double>(Sequence->GetPlayLength()) : 0.0);
|
||||
|
||||
// Fill the static setup fields
|
||||
Result.Sequence = Sequence;
|
||||
Result.AqHash = AqHash;
|
||||
Result.FadeInDuration = FadeInTime;
|
||||
Result.FadeOutDuration = FadeOutTime;
|
||||
Result.StartTime = WorldTime;
|
||||
Result.EndTime = WorldTime + Length;
|
||||
Result.Sequence = Sequence;
|
||||
Result.ContinueWhenPaused = ContinueWhenPaused;
|
||||
Result.AnimationStepID = AnimationStepID;
|
||||
Result.FadeInDuration = FadeInTime;
|
||||
Result.FadeOutDuration = FadeOutTime;
|
||||
Result.StartTime = CurrentTime;
|
||||
Result.EndTime = CurrentTime + Length;
|
||||
|
||||
Keep(KeepCount - 1);
|
||||
Animations.Insert(Result, 0);
|
||||
}
|
||||
|
||||
void UlxScriptedAnimations::FadeGarbage(TArray<int32> Hashes, double CurrentTime)
|
||||
void UlxScriptedAnimations::FadeGarbage(const UObject *WorldContextObject, TArray<int64> KeepIDs)
|
||||
{
|
||||
FlxWorldClocks Clocks = UlxScriptedAnimationLibrary::GetAllWorldClocks(WorldContextObject);
|
||||
for (int i = 0; i < Animations.Num(); i++)
|
||||
{
|
||||
FlxScriptedAnimation &Anim = Animations[i];
|
||||
if ((Anim.AqHash != 0) && (!Hashes.Contains(Anim.AqHash)))
|
||||
if ((Anim.AnimationStepID > 0) && (!KeepIDs.Contains(Anim.AnimationStepID)))
|
||||
{
|
||||
Anim.InitiateFadeOut(CurrentTime, 0.2);
|
||||
Anim.InitiateFadeOut(Anim.ChooseCorrectClock(Clocks), 0.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UlxScriptedAnimationLibrary::ScriptedAnimationEvaluatorData(const UlxScriptedAnimations *Animations, double CurrentTime,
|
||||
void UlxScriptedAnimationLibrary::ScriptedAnimationEvaluatorData(
|
||||
const UlxScriptedAnimations *Animations,
|
||||
const FlxWorldClocks &WorldClocks,
|
||||
UAnimSequenceBase *&Sequence0, float &ExplicitTime0,
|
||||
UAnimSequenceBase *&Sequence1, float &ExplicitTime1,
|
||||
UAnimSequenceBase *&Sequence2, float &ExplicitTime2,
|
||||
@@ -140,6 +91,7 @@ void UlxScriptedAnimationLibrary::ScriptedAnimationEvaluatorData(const UlxScript
|
||||
if (Anims.Num() > 0)
|
||||
{
|
||||
const FlxScriptedAnimation &Anim = Anims[0];
|
||||
double CurrentTime = Anim.ChooseCorrectClock(WorldClocks);
|
||||
Sequence0 = Anim.Sequence;
|
||||
ExplicitTime0 = Anim.ClampedElapsedTime(CurrentTime);
|
||||
Sequence0Alpha = Anim.CalcFadeInOutAlpha(CurrentTime);
|
||||
@@ -147,6 +99,7 @@ void UlxScriptedAnimationLibrary::ScriptedAnimationEvaluatorData(const UlxScript
|
||||
if (Anims.Num() > 1)
|
||||
{
|
||||
const FlxScriptedAnimation &Anim = Anims[1];
|
||||
double CurrentTime = Anim.ChooseCorrectClock(WorldClocks);
|
||||
Sequence1 = Anim.Sequence;
|
||||
ExplicitTime1 = Anim.ClampedElapsedTime(CurrentTime);
|
||||
Sequence1Alpha = Anim.CalcFadeInOutAlpha(CurrentTime);
|
||||
@@ -154,6 +107,7 @@ void UlxScriptedAnimationLibrary::ScriptedAnimationEvaluatorData(const UlxScript
|
||||
if (Anims.Num() > 2)
|
||||
{
|
||||
const FlxScriptedAnimation &Anim = Anims[2];
|
||||
double CurrentTime = Anim.ChooseCorrectClock(WorldClocks);
|
||||
Sequence2 = Anim.Sequence;
|
||||
ExplicitTime2 = Anim.ClampedElapsedTime(CurrentTime);
|
||||
Sequence2Alpha = Anim.CalcFadeInOutAlpha(CurrentTime);
|
||||
@@ -175,3 +129,14 @@ void UlxScriptedAnimationLibrary::ScriptedAnimationEvaluatorData(const UlxScript
|
||||
}
|
||||
}
|
||||
|
||||
FlxWorldClocks UlxScriptedAnimationLibrary::GetAllWorldClocks(const UObject *WorldContextObject)
|
||||
{
|
||||
UWorld* World = GEngine->GetWorldFromContextObjectChecked(WorldContextObject);
|
||||
FlxWorldClocks Result;
|
||||
if (World != nullptr)
|
||||
{
|
||||
Result.WorldTime = World->GetTimeSeconds();
|
||||
Result.RealTime = World->GetRealTimeSeconds();
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user