Big refactor of ScriptedAnimations, moved into their own source file, lots of reorganization.

This commit is contained in:
2025-10-14 20:24:37 -04:00
parent 63dcbb7434
commit fbe2b7a45a
5 changed files with 363 additions and 226 deletions

View File

@@ -213,121 +213,6 @@ void UlxUtilityLibrary::GetPositionOfGridPanelMiddleCell(UGridPanel *GridPanel,
}
}
void UlxScriptedAnimations::Keep(int n)
{
if (n < 0) n = 0;
if (Animations.Num() > n)
{
Animations.SetNum(n);
}
}
void UlxScriptedAnimations::AddAnimation(
UObject* WorldContextObject, UAnimSequenceBase* Sequence, double FadeInTime, double FadeOutTime)
{
check(KeepCount >= 1);
FlxScriptedAnimation Result;
// Get World Time
UWorld* World = GEngine->GetWorldFromContextObjectChecked(WorldContextObject);
double WorldTime = World ? World->GetTimeSeconds() : 0.0;
// Fill the static setup fields
Result.Sequence = Sequence;
Result.FadeIn = FadeInTime;
Result.FadeOut = FadeOutTime;
Result.StartTime = WorldTime;
Result.AdjustedLength = (Result.Sequence ? static_cast<double>(Result.Sequence->GetPlayLength()) : 0.0);
Keep(KeepCount - 1);
Animations.Insert(Result, 0);
}
void UlxScriptedAnimations::FadeOutAll(UObject *WorldContextObject)
{
}
FlxScriptedAnimationProgress UlxUtilityLibrary::ScriptedAnimationProgress(const FlxScriptedAnimation &Animation, double CurrentTime)
{
FlxScriptedAnimationProgress Progress(Animation);
// Store the world time of the last update.
Progress.UpdateTime = CurrentTime;
// Compute time relationships
Progress.EndTime = Animation.StartTime + Progress.AdjustedLength;
Progress.ElapsedTime = FMath::Max(0.0, Progress.UpdateTime - Progress.StartTime);
Progress.TimeLeft = FMath::Max(0.0, Progress.EndTime - Progress.UpdateTime);
// Determine fade-in / fade-out blend
Progress.FadeInAlpha = 1.0;
Progress.FadeOutAlpha = 1.0;
if (Progress.FadeIn > 0.0) Progress.FadeInAlpha = FMath::Clamp(Progress.ElapsedTime / Progress.FadeIn, 0.0, 1.0);
if (Progress.FadeOut > 0.0) Progress.FadeOutAlpha = FMath::Clamp(Progress.TimeLeft / Progress.FadeOut, 0.0, 1.0);
Progress.FadeAlpha = FMath::Min(Progress.FadeInAlpha, Progress.FadeOutAlpha);
return Progress;
}
void UlxUtilityLibrary::ScriptedAnimationEvaluatorData(const UlxScriptedAnimations *Animations, double CurrentTime,
UAnimSequenceBase *&Sequence0, float &ExplicitTime0,
UAnimSequenceBase *&Sequence1, float &ExplicitTime1,
UAnimSequenceBase *&Sequence2, float &ExplicitTime2,
float &BaseAlpha, float &Sequence0Alpha, float &Sequence1Alpha, float &Sequence2Alpha)
{
Sequence0 = nullptr;
Sequence1 = nullptr;
Sequence2 = nullptr;
ExplicitTime0 = 0.0;
ExplicitTime1 = 0.0;
ExplicitTime2 = 0.0;
BaseAlpha = 0.0;
Sequence0Alpha = 0.0;
Sequence1Alpha = 0.0;
Sequence2Alpha = 0.0;
if (Animations != nullptr)
{
const TArray<FlxScriptedAnimation> &Anims = Animations->GetAnimations();
if (Anims.Num() > 0)
{
FlxScriptedAnimationProgress Progress = ScriptedAnimationProgress(Anims[0], CurrentTime);
Sequence0 = Progress.Sequence;
ExplicitTime0 = Progress.ElapsedTime;
Sequence0Alpha = Progress.FadeAlpha;
}
if (Anims.Num() > 1)
{
FlxScriptedAnimationProgress Progress = ScriptedAnimationProgress(Anims[1], CurrentTime);
Sequence1 = Progress.Sequence;
ExplicitTime1 = Progress.ElapsedTime;
Sequence1Alpha = Progress.FadeAlpha;
}
if (Anims.Num() > 2)
{
FlxScriptedAnimationProgress Progress = ScriptedAnimationProgress(Anims[2], CurrentTime);
Sequence2 = Progress.Sequence;
ExplicitTime2 = Progress.ElapsedTime;
Sequence2Alpha = Progress.FadeAlpha;
}
}
double AlphaTotal = Sequence0Alpha + Sequence1Alpha + Sequence2Alpha;
if (AlphaTotal > 1.0)
{
double Scale = 1.0 / AlphaTotal;
Sequence0Alpha *= Scale;
Sequence1Alpha *= Scale;
Sequence2Alpha *= Scale;
BaseAlpha = 0.0;
}
else
{
BaseAlpha = 1.0 - AlphaTotal;
}
}
ElxUsedOrNotUsed UlxUtilityLibrary::IsKeyUsedByMappingContext(const FKey &Key, const UInputMappingContext *MappingContext)
{
if (!MappingContext)