Files
UnrealEngineUWP/Engine/Source/Runtime/UMG/Private/Animation/WidgetAnimation.cpp
Robert Manuszewski f9cdeb96cd Copying //UE4/Dev-Core to //UE4/Main
==========================
MAJOR FEATURES + CHANGES
==========================

Change 2717513 on 2015/10/06 by Robert.Manuszewski@Robert_Manuszewski_EGUK_M1

	GC and WeakObjectPtr performance optimizations.

	- Moved some of the EObjectFlags to EInternalObjectFlags and merged them with FUObjectArray
	- Moved WeakObjectPtr serial numbersto FUObjectArray
	- Added pre-allocated UObject array

Change 2716517 on 2015/10/05 by Robert.Manuszewski@Robert_Manuszewski_EGUK_M1

	Make SavePackage thread safe UObject-wise so that StaticFindObject etc can't run in parallel when packages are being saved.

Change 2721142 on 2015/10/08 by Mikolaj.Sieluzycki@Dev-Core_D0920

	UHT will now use makefiles to speed up iterative runs.

Change 2726320 on 2015/10/13 by Jaroslaw.Palczynski@jaroslaw.palczynski_D1732_2963

	Hot-reload performance optimizations:
	1. Got rid of redundant touched BPs optimization (which was necessary before major HR fixes submitted earlier).
	2. Parallelized search for old CDOs referencers.

Change 2759032 on 2015/11/09 by Graeme.Thornton@GThornton_DesktopMaster

	Dependency preloading improvements
	 - Asset registry dependencies now resolve asset redirectors
	 - Rearrange runtime loading to put dependency preloads within BeginLoad/EndLoad for the source package

Change 2754342 on 2015/11/04 by Robert.Manuszewski@Robert_Manuszewski_Stream1

	Allow UnfocusedVolumeMultiplier to be set programmatically

Change 2764008 on 2015/11/12 by Robert.Manuszewski@Robert_Manuszewski_Stream1

	When cooking, don't add imports that are outers of objects excluded from the current cook target.

Change 2755562 on 2015/11/05 by Steve.Robb@Dev-Core

	Inline storage for TFunction.
	Fix for delegate inline storage on Win64.
	Some build fixes.
	Visualizer fixes for new TFunction format.

Change 2735084 on 2015/10/20 by Jaroslaw.Surowiec@Stream.1.JarekSurowiec

	CrashReporter Web - Search by Platform
	Added initial support for streams (GetBranchesAsListItems, CopyToJira)

Change 2762387 on 2015/11/11 by Steve.Robb@Dev-Core

	Unnecessary allocation removed when loading empty files in FFileHelper::LoadFileToString.

Change 2762632 on 2015/11/11 by Steve.Robb@Dev-Core

	Some TSet function optimisations:

	Avoiding unnecessary hashing of function arguments if the container is empty (rather than the hash being empty, which is not necessarily equivalent).
	Taking local copies of HashSize during iterations.

Change 2762936 on 2015/11/11 by Steve.Robb@Dev-Core

	BulkData zero byte allocations are now handled by an RAII object which owns the memory.

Change 2765758 on 2015/11/13 by Steve.Robb@Dev-Core

	FName::operator== and != optimised to be a single comparison.

Change 2757195 on 2015/11/06 by Jaroslaw.Surowiec@Stream.1.JarekSurowiec

	PR #1305: Improvements in CrashReporter for Symbol Server usage (Contributed by bozaro)

Change 2760778 on 2015/11/10 by Jaroslaw.Surowiec@Stream.1.JarekSurowiec

	PR #1725: Fixed typos in ProfilerCommon.h; Added comments (Contributed by BGR360)

	Also fixed starting condition.

Change 2739804 on 2015/10/23 by Robert.Manuszewski@Robert_Manuszewski_Stream1

	PR #1470: [UObjectGlobals] Do not overwrite instanced subobjects with ones from CDO (Contributed by slonopotamus)

Change 2744733 on 2015/10/28 by Steve.Robb@Dev-Core

	PR #1540 - Specifying a different Saved folder at launch through a command line parameter

	Integrated and optimized.

#lockdown Nick.Penwarden

[CL 2772222 by Robert Manuszewski in Main branch]
2015-11-18 16:20:49 -05:00

292 lines
7.1 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "UMGPrivatePCH.h"
#include "MovieScene.h"
#include "WidgetAnimation.h"
#include "WidgetTree.h"
#define LOCTEXT_NAMESPACE "UWidgetAnimation"
/* UWidgetAnimation structors
*****************************************************************************/
UWidgetAnimation::UWidgetAnimation(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, MovieScene(nullptr)
{ }
/* UWidgetAnimation interface
*****************************************************************************/
#if WITH_EDITOR
UWidgetAnimation* UWidgetAnimation::GetNullAnimation()
{
static UWidgetAnimation* NullAnimation = nullptr;
if (!NullAnimation)
{
NullAnimation = NewObject<UWidgetAnimation>(GetTransientPackage(), NAME_None);
NullAnimation->AddToRoot();
NullAnimation->MovieScene = NewObject<UMovieScene>(NullAnimation, FName("No Animation"));
NullAnimation->MovieScene->AddToRoot();
}
return NullAnimation;
}
#endif
float UWidgetAnimation::GetStartTime() const
{
return MovieScene->GetPlaybackRange().GetLowerBoundValue();
}
float UWidgetAnimation::GetEndTime() const
{
return MovieScene->GetPlaybackRange().GetUpperBoundValue();
}
void UWidgetAnimation::Initialize(UUserWidget* InPreviewWidget)
{
PreviewWidget = InPreviewWidget;
// clear object maps
PreviewObjectToIds.Empty();
IdToPreviewObjects.Empty();
IdToSlotContentPreviewObjects.Empty();
SlotContentPreviewObjectToIds.Empty();
if (PreviewWidget == nullptr)
{
return;
}
// populate object maps
UWidgetTree* WidgetTree = PreviewWidget->WidgetTree;
for (const FWidgetAnimationBinding& Binding : AnimationBindings)
{
UObject* FoundObject = Binding.FindRuntimeObject(*WidgetTree);
if (FoundObject == nullptr)
{
continue;
}
UPanelSlot* FoundSlot = Cast<UPanelSlot>(FoundObject);
if (FoundSlot == nullptr)
{
IdToPreviewObjects.Add(Binding.AnimationGuid, FoundObject);
PreviewObjectToIds.Add(FoundObject, Binding.AnimationGuid);
}
else
{
IdToSlotContentPreviewObjects.Add(Binding.AnimationGuid, FoundSlot->Content);
SlotContentPreviewObjectToIds.Add(FoundSlot->Content, Binding.AnimationGuid);
}
}
}
/* UMovieSceneAnimation overrides
*****************************************************************************/
void UWidgetAnimation::BindPossessableObject(const FGuid& ObjectId, UObject& PossessedObject)
{
UPanelSlot* PossessedSlot = Cast<UPanelSlot>(&PossessedObject);
if ((PossessedSlot != nullptr) && (PossessedSlot->Content != nullptr))
{
SlotContentPreviewObjectToIds.Add(PossessedSlot->Content, ObjectId);
IdToSlotContentPreviewObjects.Add(ObjectId, PossessedSlot->Content);
// Save the name of the widget containing the slots. This is the object
// to look up that contains the slot itself (the thing we are animating).
FWidgetAnimationBinding NewBinding;
{
NewBinding.AnimationGuid = ObjectId;
NewBinding.SlotWidgetName = PossessedSlot->GetFName();
NewBinding.WidgetName = PossessedSlot->Content->GetFName();
}
AnimationBindings.Add(NewBinding);
}
else if (PossessedSlot == nullptr)
{
PreviewObjectToIds.Add(&PossessedObject, ObjectId);
IdToPreviewObjects.Add(ObjectId, &PossessedObject);
FWidgetAnimationBinding NewBinding;
{
NewBinding.AnimationGuid = ObjectId;
NewBinding.WidgetName = PossessedObject.GetFName();
}
AnimationBindings.Add(NewBinding);
}
}
bool UWidgetAnimation::CanPossessObject(UObject& Object) const
{
UPanelSlot* Slot = Cast<UPanelSlot>(&Object);
if ((Slot != nullptr) && (Slot->Content == nullptr))
{
// can't possess empty slots.
return false;
}
return (Object.IsA<UVisual>() && Object.IsIn(PreviewWidget.Get()));
}
FGuid UWidgetAnimation::FindObjectId(UObject& Object) const
{
UPanelSlot* Slot = Cast<UPanelSlot>(&Object);
if (Slot != nullptr)
{
// slot guids are tracked by their content.
return SlotContentPreviewObjectToIds.FindRef(Slot->Content);
}
return PreviewObjectToIds.FindRef(&Object);
}
UObject* UWidgetAnimation::FindObject(const FGuid& ObjectId) const
{
TWeakObjectPtr<UObject> PreviewObject = IdToPreviewObjects.FindRef(ObjectId);
if (PreviewObject.IsValid())
{
return PreviewObject.Get();
}
TWeakObjectPtr<UObject> SlotContentPreviewObject = IdToSlotContentPreviewObjects.FindRef(ObjectId);
if (SlotContentPreviewObject.IsValid())
{
UWidget* Widget = Cast<UWidget>(SlotContentPreviewObject.Get());
if ( Widget != nullptr )
{
return Widget->Slot;
}
}
return nullptr;
}
UMovieScene* UWidgetAnimation::GetMovieScene() const
{
return MovieScene;
}
UObject* UWidgetAnimation::GetParentObject(UObject* Object) const
{
UPanelSlot* Slot = Cast<UPanelSlot>(Object);
if (Slot != nullptr)
{
// The slot is actually the child of the panel widget in the hierarchy,
// but we want it to show up as a sub-object of the widget it contains
// in the timeline so we return the content's GUID.
return Slot->Content;
}
return nullptr;
}
#if WITH_EDITOR
bool UWidgetAnimation::TryGetObjectDisplayName(const FGuid& ObjectId, FText& OutDisplayName) const
{
// TODO: This gets called every frame for every bound object and could
// be a potential performance issue for a really complicated animation.
TWeakObjectPtr<UObject> PreviewObject = IdToPreviewObjects.FindRef(ObjectId);
if (PreviewObject.IsValid())
{
OutDisplayName = FText::FromString(PreviewObject.Get()->GetName());
return true;
}
TWeakObjectPtr<UObject> SlotContentPreviewObject = IdToSlotContentPreviewObjects.FindRef(ObjectId);
if (SlotContentPreviewObject.IsValid())
{
UWidget* SlotContent = Cast<UWidget>(SlotContentPreviewObject.Get());
FText PanelName = SlotContent->Slot != nullptr && SlotContent->Slot->Parent != nullptr
? FText::FromString(SlotContent->Slot->Parent->GetName())
: LOCTEXT("InvalidPanel", "Invalid Panel");
FText ContentName = FText::FromString(SlotContent->GetName());
if ( PreviewObjectToIds.Contains( SlotContent ) )
{
OutDisplayName = FText::Format( LOCTEXT( "SlotObjectWithParent", "{0} Slot" ), PanelName );
}
else
{
OutDisplayName = FText::Format(LOCTEXT("SlotObject", "{0} ({1} Slot)"), ContentName, PanelName);
}
return true;
}
return false;
}
#endif
void UWidgetAnimation::UnbindPossessableObjects(const FGuid& ObjectId)
{
// unbind widgets
TArray<TWeakObjectPtr<UObject>> PreviewObjects;
{
IdToPreviewObjects.MultiFind(ObjectId, PreviewObjects);
for (TWeakObjectPtr<UObject>& PreviewObject : PreviewObjects)
{
PreviewObjectToIds.Remove(PreviewObject);
}
IdToPreviewObjects.Remove(ObjectId);
}
// unbind slots
TArray<TWeakObjectPtr<UObject>> SlotContentPreviewObjects;
{
IdToSlotContentPreviewObjects.MultiFind(ObjectId, SlotContentPreviewObjects);
for (TWeakObjectPtr<UObject>& SlotContentPreviewObject : SlotContentPreviewObjects)
{
SlotContentPreviewObjectToIds.Remove(SlotContentPreviewObject);
}
IdToSlotContentPreviewObjects.Remove(ObjectId);
}
// mark dirty
Modify();
// remove animation bindings
AnimationBindings.RemoveAll([&](const FWidgetAnimationBinding& Binding) {
return Binding.AnimationGuid == ObjectId;
});
}
#undef LOCTEXT_NAMESPACE