Files
UnrealEngineUWP/Engine/Source/Runtime/MovieScene/Private/EntitySystem/TrackInstance/MovieSceneTrackInstance.cpp
max chen 9bec93ff5b Sequencer: Fix FPreAnimatedTrackInstanceCaptureSources include
#preflight 61fafd0fc431b6aac045339a
#jira UE-141018
#rb andrew.rodham
#lockdown simon.tourangeau

#ROBOMERGE-AUTHOR: max.chen
#ROBOMERGE-SOURCE: CL 18838193 in //UE5/Release-5.0/... via CL 18838197 via CL 18838256
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v910-18824042)

[CL 18838261 by max chen in ue5-main branch]
2022-02-02 20:27:44 -05:00

155 lines
4.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "EntitySystem/TrackInstance/MovieSceneTrackInstance.h"
#include "EntitySystem/BuiltInComponentTypes.h"
#include "EntitySystem/MovieSceneEntitySystemLinker.h"
#include "Evaluation/PreAnimatedState/MovieScenePreAnimatedCaptureSource.h"
#include "Evaluation/PreAnimatedState/MovieScenePreAnimatedCaptureSources.inl"
#include "Algo/Sort.h"
void UMovieSceneTrackInstance::Initialize(UObject* InAnimatedObject, UMovieSceneEntitySystemLinker* InLinker)
{
// We make the difference between a master track instance, and a bound track instance that lost its binding,
// by remembering if this track instance was initialized with a valid bound object.
AnimatedObject = InAnimatedObject;
bIsMasterTrackInstance = (InAnimatedObject == nullptr);
PrivateLinker = InLinker;
OnInitialize();
}
void UMovieSceneTrackInstance::Animate()
{
OnAnimate();
}
void UMovieSceneTrackInstance::Destroy()
{
using namespace UE::MovieScene;
if (bIsMasterTrackInstance || !UE::MovieScene::FBuiltInComponentTypes::IsBoundObjectGarbage(AnimatedObject))
{
OnDestroyed();
}
FPreAnimatedTrackInstanceInputCaptureSources* InputMetaData = PrivateLinker->PreAnimatedState.GetTrackInstanceInputMetaData();
if (InputMetaData)
{
for (const FMovieSceneTrackInstanceInput& Input : Inputs)
{
InputMetaData->StopTrackingCaptureSource(Input);
}
}
FPreAnimatedTrackInstanceCaptureSources* TrackInstanceMetaData = PrivateLinker->PreAnimatedState.GetTrackInstanceMetaData();
if (TrackInstanceMetaData)
{
TrackInstanceMetaData->StopTrackingCaptureSource(this);
}
}
void UMovieSceneTrackInstance::UpdateInputs(TArray<FMovieSceneTrackInstanceInput>&& InNewInputs)
{
using namespace UE::MovieScene;
Algo::Sort(InNewInputs);
// Fast path if they are the same - this includes checking whether bInputHasBeenProcessed is the
// same on all pre/post inputs, which technically should never happen for us to have gotten this far
if (Inputs == InNewInputs)
{
// We still call OnBegin/EndUpdateInputs since some of them must have been invalidated for us to get this far
OnBeginUpdateInputs();
OnEndUpdateInputs();
return;
}
FPreAnimatedTrackInstanceInputCaptureSources* InputMetaData = PrivateLinker->PreAnimatedState.GetTrackInstanceInputMetaData();
// We know they are different in some way - now
OnBeginUpdateInputs();
int32 OldIndex = 0;
int32 NewIndex = 0;
const int32 OldNum = Inputs.Num();
const int32 NewNum = InNewInputs.Num();
for ( ; OldIndex < OldNum || NewIndex < NewNum; )
{
while (OldIndex < OldNum && NewIndex < NewNum && Inputs[OldIndex].IsSameInput(InNewInputs[NewIndex]))
{
if (!InNewInputs[NewIndex].bInputHasBeenProcessed)
{
// This input is the same as one already existing in the track instance
// But it is being reimported - remove it and add it again
OnInputRemoved(Inputs[OldIndex]);
if (InputMetaData)
{
InputMetaData->StopTrackingCaptureSource(Inputs[OldIndex]);
}
InNewInputs[NewIndex].bInputHasBeenProcessed = true;
OnInputAdded(InNewInputs[NewIndex]);
}
++OldIndex;
++NewIndex;
}
if (OldIndex >= OldNum && NewIndex >= NewNum)
{
break;
}
else if (OldIndex < OldNum && NewIndex < NewNum)
{
if (Inputs[OldIndex].Section < InNewInputs[NewIndex].Section)
{
// Out with the old
OnInputRemoved(Inputs[OldIndex]);
if (InputMetaData)
{
InputMetaData->StopTrackingCaptureSource(Inputs[OldIndex]);
}
++OldIndex;
}
else
{
// and in with the new
FScopedPreAnimatedCaptureSource CaptureSource(PrivateLinker, InNewInputs[NewIndex]);
InNewInputs[NewIndex].bInputHasBeenProcessed = true;
OnInputAdded(InNewInputs[NewIndex]);
++NewIndex;
}
}
else if (OldIndex < OldNum)
{
// Out with the old
OnInputRemoved(Inputs[OldIndex]);
if (InputMetaData)
{
InputMetaData->StopTrackingCaptureSource(Inputs[OldIndex]);
}
++OldIndex;
}
else if (ensure(NewIndex < NewNum))
{
// and in with the new
InNewInputs[NewIndex].bInputHasBeenProcessed = true;
OnInputAdded(InNewInputs[NewIndex]);
++NewIndex;
}
}
Swap(Inputs, InNewInputs);
OnEndUpdateInputs();
}
UWorld* UMovieSceneTrackInstance::GetWorld() const
{
return AnimatedObject ? AnimatedObject->GetWorld() : Super::GetWorld();
}