Files
UnrealEngineUWP/Engine/Source/Editor/SizeMap/SSizeMap.cpp
Matt Kuhlenschmidt 4fa92bfa50 Copying //UE4/Dev-Editor to //UE4/Dev-Main (Source: //UE4/Dev-Editor @ 3152045)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================

Change 3106449 on 2016/08/30 by Michael.Dupuis

	#jira UETOOL-229 Added generic command icons used in Edit Menu (including contextual menu)

Change 3133997 on 2016/09/21 by Alex.Delesky

	#jira UE-34079 - FSceneView parameter for FBatchedElements::Draw is no longer an optional parameter.

Change 3134132 on 2016/09/21 by Jamie.Dale

	Added the "unattended" flag when running the localzation commandlets via UAT

Change 3134147 on 2016/09/21 by Frank.Fella

	Core - Add multitouch support to windows.

Change 3134349 on 2016/09/21 by Michael.Dupuis

	#jira UE-36151 Update the title bar to display the branch also

Change 3134355 on 2016/09/21 by Michael.Dupuis

	#jira UE-36041 When initially creating a projet and trying to add everything to source control, also add the uproject file

Change 3134447 on 2016/09/21 by Alexis.Matte

	#jira UE-36064
	The SpriteComponent is now properly reused when duplicating a light.

Change 3134451 on 2016/09/21 by Alexis.Matte

	#jira UE-22782
	Make sure when we re-import we dont try to match the mesh name if the option bCombineToSingle is true

Change 3134457 on 2016/09/21 by Jamie.Dale

	FInternationalization::Leetify now deals with escape sequences correctly.

	This also changes it to mark all leetified text with the start and end marker, and the unit tests have been updated accordingly.

Change 3134685 on 2016/09/21 by Matt.Kuhlenschmidt

	Cleaned up some of the UI for the new material slot workflow (part 1)

Change 3134743 on 2016/09/21 by Matt.Kuhlenschmidt

	Fix crash clicking OK to the import mesh dialog in persona when a path is not selected.  The OK button is now disabled until a valid path is selected

Change 3134760 on 2016/09/21 by Matt.Kuhlenschmidt

	Guard against cascade crash if cascade was shutdown but there is an old cascade particle system component in the undo buffer that attempts to refresh cascade

Change 3134837 on 2016/09/21 by Matt.Kuhlenschmidt

	Fix static analysis warnings in this file

Change 3134939 on 2016/09/21 by Nick.Darnell

	Automation - Moving the functional testing hooks for the editor into a plugin, the goal is to make it so you don't have to see all the extra stuff automation adds to the editor until the game project needs it.  Refactoring the way automation messages are serialized, no longer relying on a comma delimited string to serialize automation data.  Improving the filter for automation window so it lets you put in a path, and find it that way.  Fixing RunTests from the commandline so that it properly finds the tests, instead of jumping out of the loop as soon as it finds any one match.

Change 3134941 on 2016/09/21 by Nick.Darnell

	Automation - Functional tests now support warnings as errors on a per test basis.  Continued itteration on screenshot comparison.

Change 3135051 on 2016/09/21 by Matt.Kuhlenschmidt

	Fixed size of material slots in persona details panel

Change 3135076 on 2016/09/21 by Nick.Darnell

	Automation - Adding a missing file.

Change 3135584 on 2016/09/22 by Gareth.Martin

	Removed unused ULandscapeInfo::BeginDestroy
	Slight cleanup to FLandscapeEditDataInterface::DeleteLayer

Change 3135585 on 2016/09/22 by Gareth.Martin

	New Count algo
	Const'd Copy/Accumulate/Transform

Change 3135599 on 2016/09/22 by Gareth.Martin

	Resolve crash if a Landscape Layer Info object is force deleted while it is in use :(
	#jira UE-35709

Change 3135724 on 2016/09/22 by Michael.Dupuis

	#jira UE-32662 Remove old migration code that was causing this side effect

Change 3135726 on 2016/09/22 by Nick.Darnell

	Slate - Removing the SLATE_PRE_MULTIPLY macro.

Change 3135730 on 2016/09/22 by Nick.Darnell

	UMG - Exposing the 2D hit location that the WidgetInteractionComponent hit on the WidgetComponent.

Change 3135738 on 2016/09/22 by Matt.Kuhlenschmidt

	Ensure any handles to the backbuffer are released before the backbuffer is resized

	https://jira.it.epicgames.net/browse/UE-30488

Change 3135810 on 2016/09/22 by Ben.Marsh

	Build: Compile tools before running automated tests.

Change 3135993 on 2016/09/22 by Matt.Kuhlenschmidt

	Ensure you can unpause after toggling play/pause with a keyboard shortcut.  We were processing the keybinding on key down AND up which caused the unpause to instantly pause again
	https://jira.it.epicgames.net/browse/UE-36276

Change 3136257 on 2016/09/22 by Matt.Kuhlenschmidt

	Fixed assign of materials to components not working if you multi-select multiple components of a blueprint and assign the material.  The construction script was running before all the material had been set on all components.

Change 3136318 on 2016/09/22 by Alex.Delesky

	#jira UE-7405 - Forcing the mouse cursor to show and then clicking inside the viewport will no longer cause the mouse to lose focus

Change 3136494 on 2016/09/22 by Matt.Kuhlenschmidt

	Fix crash restarting a mission in Odin

Change 3136741 on 2016/09/22 by Cody.Albert

	Fixed SButton and SWidget to not multiply color and opacity, since that's already being done by SCompoundWidget

	#jira UE-36322

Change 3137711 on 2016/09/23 by Matt.Kuhlenschmidt

	Added guard against slate rendering with deleted materials.  In this will now be caught with a looged with the deleted material name.

Change 3137713 on 2016/09/23 by Matt.Kuhlenschmidt

	Removed the pooled draw elements stuff which is not used

Change 3137791 on 2016/09/23 by Nick.Darnell

	MediaPlayer - Removing .png from one of the style files, as that's not required.  Was causing warnings to be logged on load.

Change 3137793 on 2016/09/23 by Nick.Darnell

	Localization - Adjusting some log statements to say with instead of w/

Change 3137796 on 2016/09/23 by Nick.Darnell

	Slate - Adding missing and replacing corrupted style files in the editor.

Change 3137864 on 2016/09/23 by Matt.Kuhlenschmidt

	Fixed "actors are referenced are you sure you want to delete" dialog appearing when you are copying a lot of actors to another level

Change 3137876 on 2016/09/23 by Jamie.Dale

	Added allocation tagging to MProf2

	This hooks into the existing FScopeCycleCounterUObject used by the stats system to track object tags (object, package, and class) when an allocation is made. Tags should be in the format "Category:Tag", and the "Tag" part may include "/" to create levels in the tag hierarchy (as shown in the MProf2 tool).

	#jira UETOOL-950

Change 3137982 on 2016/09/23 by Gareth.Martin

	Added Invoke() support to CopyIf

Change 3137983 on 2016/09/23 by Gareth.Martin

	Added ULandscapeInfo::ForAllLandscapeProxies to clean up a lot of horrible code
	- Removed some dependencies on ALandscape and ALandscapeStreamingProxy in the process :)
	Also made FLandscapeEditorLayerSettings's constructor explicit to clean up some other horrible code

Change 3138053 on 2016/09/23 by Matt.Kuhlenschmidt

	Fixed Child Actor Template properties not visible after changing Child Actor Class

Change 3138079 on 2016/09/23 by Jamie.Dale

	Fixing some Clang warnings

Change 3138087 on 2016/09/23 by Jamie.Dale

	Added GetResourceSizeEx and GetResourceSizeBytes, and deprecated GetResourceSize

	GetResourceSizeEx populates a struct which reports not only how much memory is allocated, but also which arenas the memory was allocated from. GetResourceSizeBytes just wraps a call to GetResourceSizeEx and returns the total size from all arenas (this has the same behavior as the now deprecated GetResourceSize).

	Classes that used to override GetResourceSize should instead override GetResourceSizeEx and report their allocations as appropriate.

	#jira UETOOL-952

Change 3138127 on 2016/09/23 by Gareth.Martin

	Fixed crash when merging levels containing landscape
	#jira UE-36267

Change 3138821 on 2016/09/23 by Stephan.Jiang

	Fixes "Select all input node" doesn't work properly on output node.

	#jira UE-36335

Change 3138915 on 2016/09/23 by Stephan.Jiang

	Disable "select all linked nodes" for output nodes in material editor

Change 3139341 on 2016/09/25 by Nick.Darnell

	Automation - Moving the Blueprint Compiler Tests into the RuntimeTests plugin, and making the context client only since that's the only valid place to runt these tests.

Change 3139342 on 2016/09/25 by Nick.Darnell

	Landscape - Fixing some compiler errors on mac.

Change 3139345 on 2016/09/25 by Nick.Darnell

	Automation - Spelling and cleanup.

Change 3139346 on 2016/09/25 by Nick.Darnell

	Engine - Changing a check to an ensure, there's no reason to crash if this happens.

Change 3139347 on 2016/09/25 by Nick.Darnell

	Automation  - Making EFunctionalTestResult a BlueprintType

Change 3139348 on 2016/09/25 by Nick.Darnell

	Automation - Adding another test map.

Change 3139676 on 2016/09/26 by Michael.Dupuis

	#jira UE-32335 If we are a config object simply permit the transaction for undo/redo

Change 3139702 on 2016/09/26 by Nick.Darnell

	UMG - Making GetLocalHitLocation on UWidgetComponent virtual.

Change 3139760 on 2016/09/26 by Alexis.Matte

	Make sure we remove override materials from the list when the mesh point by the component has less materials.
	#jira UE-28845

Change 3139761 on 2016/09/26 by Alex.Delesky

	Added additional validation code to FPropertyNode to now properly validate TMap value and key nodes.

	#jira none

Change 3139843 on 2016/09/26 by Alex.Delesky

	#jira UE-36066 - Clearing all options from a ComboBox String when selecting an option will now also clear out the selected text correctly.

Change 3139880 on 2016/09/26 by Frank.Fella

	QAGame - Update multitouch test with less crashy assets?

Change 3139908 on 2016/09/26 by Matt.Kuhlenschmidt

	Fix selections having the potential to be out of sync after undo/redo

Change 3139928 on 2016/09/26 by Nick.Darnell

	Automation - tweaking the test maps some more.

Change 3140646 on 2016/09/26 by Matt.Kuhlenschmidt

	Fix false positive with the test for vaild materials being rendered by slate.

Change 3140912 on 2016/09/26 by Frank.Fella

	Core - Fix multitouch ifdef which was preventing it from actually being enabled.Also update test level blueprint so that it's actually testable.

Change 3141218 on 2016/09/27 by Matt.Kuhlenschmidt

	PR #2798: BP open anim interferes with mouse movement (Contributed by projectgheist)

Change 3141223 on 2016/09/27 by Jamie.Dale

	Updated UTextProperty::Identical to no longer compare display strings all the time

	It was supposed to compare the identity at runtime as the display string can change at runtime. This was preventing FText properties from being used in TSet/TMap as the hash needs to be consistent.

	#jira UE-36456

Change 3141242 on 2016/09/27 by Richard.TalbotWatkin

	Fixed various issues where making changes to components in the Blueprint Editor could cause a crash if there is an active component in the component visualizer.
	#jira UE-36402 - Editor crash when adding a spline component after having deleted another spline component
	Duplicated CL 3139370 from //UE4/Release-4.13
	Duplicated CL 3139878 from //UE4/Release-4.13

Change 3141323 on 2016/09/27 by Michael.Dupuis

	#jira UE-35081 Enable bDisplayEngineVersionInBadge by default

Change 3141798 on 2016/09/27 by tim.gautier

	Added UMG_DisplayWidget

Change 3143038 on 2016/09/28 by Jamie.Dale

	Added extra context to FTableRowBase::OnPostDataImport

	It now takes the owning data table and the row name as parameters. This allows is to do more useful fix-up that depends on the context of where it's used (such as stabilized text keys).

Change 3143039 on 2016/09/28 by Jamie.Dale

	Optimized UTextProperty::Identical to use a pointer comparison rather than read out the identity

	Only texts which have the same display string pointer can have the same identity, so this is a much faster check.

Change 3143098 on 2016/09/28 by Gareth.Martin

	Fixed crash when loading duplicated landscape levels
	#jira UE-34890

Change 3143300 on 2016/09/28 by Gareth.Martin

	Fixed crash when duplicating a level containing a landscape through the content browser
	#jira UE-34890

Change 3143389 on 2016/09/28 by Jamie.Dale

	LastResort is no longer staged in shipping builds

	You can now use the Content/SlateDebug folder to store any Slate resources that shouldn't be used in a shipping build (either for the Engine or for a game).

	This also removes the old bUsesSlateEditorStyle hack as everything should have migrated away from that now.

Change 3143565 on 2016/09/28 by Matt.Kuhlenschmidt

	Fixed this file

Change 3143717 on 2016/09/28 by Michael.Dupuis

	Fixed lowercase

Change 3143798 on 2016/09/28 by Matt.Kuhlenschmidt

	Fixed StreamingPauseRendering code to not attempt to tick the scene viewport on the slate loading thread while where are blocked on level streaming.  The viewport is rendered once and the render target is passed to slate instead of the entire viewport

Change 3143820 on 2016/09/28 by Alexis.Matte

	Use the PersonaToolikit to get the mesh

Change 3143833 on 2016/09/28 by Matt.Kuhlenschmidt

	Added guard for UE-36499

Change 3144144 on 2016/09/28 by Matt.Kuhlenschmidt

	Fix constructor init order

Change 3144821 on 2016/09/29 by Jamie.Dale

	Fixed feedback loop in FSlateEditableTextLayout::ComputeDesiredSize

	If the wrapping width is less than the scrollbar width, the scrollbar could constantly re-appear and then disappear.

Change 3144867 on 2016/09/29 by Matt.Kuhlenschmidt

	Added a commandlet to allow command line importing of any asset type the engine supports.
	- Intermediate checkin

Change 3144875 on 2016/09/29 by Nick.Darnell

	Automation - Adding CornellBox example map, fixing some additional tests, removing the Movement Test.

Change 3144975 on 2016/09/29 by Matt.Kuhlenschmidt

	Disable auto-applying of scalability settings
	The user will still be asked if the settings should be applied but if they do nothing the notification will just go away without setting stuff.

Change 3145274 on 2016/09/29 by Jamie.Dale

	New asset menu no longer has a scrollbar on most displays

Change 3146004 on 2016/09/29 by Matt.Barnes

	Adding two FBX test files to help facilitate QA coverage on the new material/section workflow.

Change 3146377 on 2016/09/30 by Gareth.Martin

	Fixed landscape rendering errors after using the "change component size" tool
	- also affected initial import of a landscape+weightmaps
	#jira UE-34518

Change 3146455 on 2016/09/30 by Jamie.Dale

	Fixing more menus that had scrollbars due to only being able to use half the vertical resolution

Change 3146466 on 2016/09/30 by Gareth.Martin

	Fixed not being able to erase foliage attached to BSP
	#jira UE-36297

Change 3146471 on 2016/09/30 by Jamie.Dale

	Can no longer localize sequences via the Content Browser

Change 3146569 on 2016/09/30 by Jamie.Dale

	Fixed UGatherTextFromSourceCommandlet::ParseSourceText being able to underflow while parsing

Change 3147116 on 2016/09/30 by Michael.Dupuis

	#jira UE-33068 Update selection once after the bulk operation so the AssetContextMenu will have a proper selection, but only perform this if we're not in UserSearchingMode (which mean AssetPicker)

Change 3148091 on 2016/10/01 by Matt.Barnes

	Adding a map and relevant assets to facilitate testing around the new material blueprint nodes - GetMaterialSlotNames, GetMaterialIndex, and SetMaterialByName, respectively

Change 3148714 on 2016/10/03 by Nick.Darnell

	PR #2770: [Git plugin] Fix bug where history and merging do not work if the user has format.pretty settings in their gitconfig (Contributed by SRombauts)

	#jira UE-35568

Change 3148793 on 2016/10/03 by Nick.Darnell

	Automation - TPS for SM_Cornellbox

Change 3148801 on 2016/10/03 by Nick.Darnell

	PR #2820: [WidgetBlueprintLibrary] Throwing Essential-Functionality-Understanding PIE Errors when Player Controller ptr not supplied (Contributed by EverNewJoy)

	#jira UE-36711

Change 3148805 on 2016/10/03 by Nick.Darnell

	PR #2822: Add missing base includes and forward declarations for UProgressBar and UTextBlock (Contributed by error454)

	#jira UE-36715

Change 3148813 on 2016/10/03 by Nick.Darnell

	UMG - The retainer now contains the SVirtualWindow directly in the hierarchy.  This should now make it possible to reliably focus elements inside the retainer widget.

Change 3148855 on 2016/10/03 by Gareth.Martin

	Fixed performance regression when importing landscape heightmaps
	#jira UE-36659

Change 3149482 on 2016/10/03 by Cody.Albert

	Added link to Support landing page to Help menu

	#jira UE-36603

Change 3149520 on 2016/10/03 by tim.gautier

	Edited UMG_Behavior - Collapsed now has a toggleable state to demonstrate functionality.

Change 3149945 on 2016/10/04 by Gareth.Martin

	Fixed invisible landscape components when using tessellation on landscape material
	#jira UE-35494

Change 3149951 on 2016/10/04 by Gareth.Martin

	Reduced material update log spam when creating and editing landscapes
	- Some will remain, landscape fundementally manipulates a lot of material instances
	#jira UE-34440

Change 3150143 on 2016/10/04 by Matt.Kuhlenschmidt

	Fix not crashing when trying to clear objects which have a specific class filter in the property settings
	https://jira.it.epicgames.net/browse/UE-36692

Change 3150614 on 2016/10/04 by Nick.Darnell

	Git - Disabling some logging in non-debug builds of the git source control plugin.

Change 3151647 on 2016/10/05 by Matt.Kuhlenschmidt

	Fix loc warnings in these files (duplicate loc keys)

Change 3151679 on 2016/10/05 by Nick.Darnell

	Editor - Fixing the build, removing the VREditor module from the dynamically loaded list.

Change 3151722 on 2016/10/05 by Gareth.Martin

	Fix breakage to LandscapeEdModeSplineTools.cpp caused by Dev-VREditor from main integration

Change 3151816 on 2016/10/05 by Gareth.Martin

	Fixed more breakage to Landscape caused by Dev-VREditor from main integration

[CL 3152072 by Matt Kuhlenschmidt in Main branch]
2016-10-05 13:23:01 -04:00

601 lines
25 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "SizeMapModule.h"
#include "STreeMap.h"
#include "SSizeMap.h"
#include "AssetRegistryModule.h"
#include "AssetThumbnail.h"
#include "ClassIconFinder.h"
#include "UnitConversion.h"
#define LOCTEXT_NAMESPACE "SizeMap"
SSizeMap::SSizeMap()
: TreeMapWidget( nullptr ),
RootAssetPackageNames(),
RootTreeMapNode( new FTreeMapNodeData() ),
// @todo sizemap: Hard-coded thumbnail pool size. Not a big deal, but ideally move the constants elsewhere
AssetThumbnailPool( new FAssetThumbnailPool(1024) )
{
}
SSizeMap::~SSizeMap()
{
if( AssetThumbnailPool.IsValid() )
{
AssetThumbnailPool->ReleaseResources();
AssetThumbnailPool.Reset();
}
}
void SSizeMap::Construct( const FArguments& InArgs )
{
ChildSlot
[
SAssignNew( TreeMapWidget, STreeMap, RootTreeMapNode.ToSharedRef(), nullptr )
.OnTreeMapNodeDoubleClicked( this, &SSizeMap::OnTreeMapNodeDoubleClicked )
];
}
void SSizeMap::SetRootAssetPackageNames( const TArray<FName>& NewRootAssetPackageNames )
{
RootAssetPackageNames = NewRootAssetPackageNames;
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
if ( AssetRegistryModule.Get().IsLoadingAssets() )
{
// We are still discovering assets, listen for the completion delegate before building the graph
if (!AssetRegistryModule.Get().OnFilesLoaded().IsBoundToObject(this))
{
AssetRegistryModule.Get().OnFilesLoaded().AddSP( this, &SSizeMap::OnInitialAssetRegistrySearchComplete );
}
}
else
{
// All assets are already discovered, build the graph now.
RefreshMap();
}
}
namespace SizeMapInternals
{
/** Serialization archive that discovers assets referenced by a specific Unreal object */
class FAssetReferenceFinder : public FArchiveUObject
{
public:
FAssetReferenceFinder( UObject* Object )
{
ArIsObjectReferenceCollector = true;
ArIgnoreOuterRef = true;
check( Object != nullptr );
AllVisitedObjects.Add( Object );
Object->Serialize( *this );
}
FArchive& operator<<( UObject*& Object )
{
// Only look at objects which are valid
const bool bIsValidObject =
Object != nullptr && // Object should not be null
!Object->HasAnyFlags(RF_Transient) && // Should not be transient
!Object->IsPendingKill(); // Should not be pending kill
if( bIsValidObject )
{
// Skip objects that we've already processed
if( !AllVisitedObjects.Contains( Object ) )
{
AllVisitedObjects.Add( Object );
const bool bIsAsset =
Object->GetOuter() != nullptr && // Not a package itself (such as a script package like '/Script/Engine')
Object->GetOuter()->IsA( UPackage::StaticClass() ) && // Only want outer assets (these should be the only public assets, anyway)
Object->HasAllFlags( RF_Public ); // Assets should be public
if( bIsAsset )
{
ReferencedAssets.Add( Object );
}
else
{
// It's probably an inner object. Recursively serialize.
Object->Serialize( *this );
// Make sure the object's class is serialized too, so that we catch any assets referenced from the class defaults
AllVisitedObjects.Add( Object->GetClass() );
Object->GetClass()->Serialize( *this ); // @todo sizemap urgent: Doesn't really seem to be needed
}
}
}
return *this;
}
TSet< UObject* >& GetReferencedAssets()
{
return ReferencedAssets;
}
protected:
/** The set of referenced assets */
TSet< UObject* > ReferencedAssets;
/** Set of all objects we've visited, so we don't follow cycles */
TSet< UObject* > AllVisitedObjects;
};
/** Given a size in bytes and a boolean that indicates whether the size is actually known to be correct, returns a pretty
string to represent that size, such as "256.0 MB", or "unknown size" */
static FString MakeBestSizeString( const SIZE_T SizeInBytes, const bool bHasKnownSize )
{
FString BestSizeString;
const FNumericUnit<double> BestUnit = FUnitConversion::QuantizeUnitsToBestFit( (double)SizeInBytes, EUnit::Bytes );
if( BestUnit.Units == EUnit::Bytes )
{
// We ended up with bytes, so show a decimal number
BestSizeString = FString::Printf( TEXT( "%s %s" ),
*FText::AsNumber( static_cast<uint64>(SizeInBytes) ).ToString(),
*LOCTEXT( "Bytes", "bytes" ).ToString() );
}
else
{
// Show a fractional number with the best possible units
FNumberFormattingOptions NumberFormattingOptions;
NumberFormattingOptions.MaximumFractionalDigits = 1; // @todo sizemap: We could make the number of digits customizable in the UI
NumberFormattingOptions.MinimumFractionalDigits = 0;
NumberFormattingOptions.MinimumIntegralDigits = 1;
BestSizeString = FString::Printf( TEXT( "%s %s" ),
*FText::AsNumber( BestUnit.Value, &NumberFormattingOptions ).ToString(),
FUnitConversion::GetUnitDisplayString( BestUnit.Units ) );
}
if( !bHasKnownSize )
{
if( SizeInBytes == 0 )
{
BestSizeString = LOCTEXT( "UnknownSize", "unknown size" ).ToString();
}
else
{
BestSizeString = FString::Printf( TEXT( "%s %s" ),
*LOCTEXT( "UnknownSizeButAtLeastThisBig", "at least" ).ToString(),
*BestSizeString );
}
}
return BestSizeString;
}
}
void SSizeMap::GatherDependenciesRecursively( FAssetRegistryModule& AssetRegistryModule, TSharedPtr<FAssetThumbnailPool>& InAssetThumbnailPool, TMap<FName, TSharedPtr<FTreeMapNodeData>>& VisitedAssetPackageNames, const TArray<FName>& AssetPackageNames, const TSharedPtr<FTreeMapNodeData>& Node, TSharedPtr<FTreeMapNodeData>& SharedRootNode, int32& NumAssetsWhichFailedToLoad )
{
for( const FName AssetPackageName : AssetPackageNames )
{
// Have we already added this asset to the tree? If so, we'll either move it to a "shared" group or (if it's referenced again by the same
// root-level asset) ignore it
if( VisitedAssetPackageNames.Contains( AssetPackageName ) )
{
// OK, we've determined that this asset has already been referenced by something else in our tree. We'll move it to a "shared" group
// so all of the assets that are referenced in multiple places can be seen together.
TSharedPtr<FTreeMapNodeData> ExistingNode = VisitedAssetPackageNames[ AssetPackageName ];
// Is the existing node not already under the "shared" group? Note that it might still be (indirectly) under
// the "shared" group, in which case we'll still want to move it up to the root since we've figured out that it is
// actually shared between multiple assets which themselves may be shared
if( ExistingNode->Parent != SharedRootNode.Get() )
{
// Don't bother moving any of the assets at the root level into a "shared" bucket. We're only trying to best
// represent the memory used when all of the root-level assets have become loaded. It's OK if root-level assets
// are referenced by other assets in the set -- we don't need to indicate they are shared explicitly
FTreeMapNodeData* ExistingNodeParent = ExistingNode->Parent;
check( ExistingNodeParent != nullptr );
const bool bExistingNodeIsAtRootLevel = ExistingNodeParent->Parent == nullptr || RootAssetPackageNames.Contains( AssetPackageName );
if( !bExistingNodeIsAtRootLevel )
{
// OK, the current asset (AssetPackageName) is definitely not a root level asset, but its already in the tree
// somewhere as a non-shared, non-root level asset. We need to make sure that this Node's reference is not from the
// same root-level asset as the ExistingNodeInTree. Otherwise, there's no need to move it to a 'shared' group.
FTreeMapNodeData* MyParentNode = Node.Get();
check( MyParentNode != nullptr );
FTreeMapNodeData* MyRootLevelAssetNode = MyParentNode;
while( MyRootLevelAssetNode->Parent != nullptr && MyRootLevelAssetNode->Parent->Parent != nullptr )
{
MyRootLevelAssetNode = MyRootLevelAssetNode->Parent;
}
if( MyRootLevelAssetNode->Parent == nullptr )
{
// No root asset (Node must be a root level asset itself!)
MyRootLevelAssetNode = nullptr;
}
// Find the existing node's root level asset node
FTreeMapNodeData* ExistingNodeRootLevelAssetNode = ExistingNodeParent;
while( ExistingNodeRootLevelAssetNode->Parent->Parent != nullptr )
{
ExistingNodeRootLevelAssetNode = ExistingNodeRootLevelAssetNode->Parent;
}
// If we're being referenced by another node within the same asset, no need to move it to a 'shared' group.
if( MyRootLevelAssetNode != ExistingNodeRootLevelAssetNode )
{
// This asset was already referenced by something else (or was in our top level list of assets to display sizes for)
if( !SharedRootNode.IsValid() )
{
// Find the root-most tree node
FTreeMapNodeData* RootNode = MyParentNode;
while( RootNode->Parent != nullptr )
{
RootNode = RootNode->Parent;
}
SharedRootNode = MakeShareable( new FTreeMapNodeData() );
RootNode->Children.Add( SharedRootNode );
SharedRootNode->Parent = RootNode; // Keep back-pointer to parent node
}
// Reparent the node that we've now determined to be shared
ExistingNode->Parent->Children.Remove( ExistingNode );
SharedRootNode->Children.Add( ExistingNode );
ExistingNode->Parent = SharedRootNode.Get();
}
}
}
}
else
{
// This asset is new to us so far! Let's add it to the tree. Later as we descend through references, we might find that the
// asset is referenced by something else as well, in which case we'll pull it out and move it to a "shared" top-level box
// Don't bother showing code references
const FString AssetPackageNameString = AssetPackageName.ToString();
if( !AssetPackageNameString.StartsWith( TEXT( "/Script/" ) ) )
{
FTreeMapNodeDataRef ChildTreeMapNode = MakeShareable( new FTreeMapNodeData() );
Node->Children.Add( ChildTreeMapNode );
ChildTreeMapNode->Parent = Node.Get(); // Keep back-pointer to parent node
VisitedAssetPackageNames.Add( AssetPackageName, ChildTreeMapNode );
FNodeSizeMapData& NodeSizeMapData = NodeSizeMapDataMap.Add( ChildTreeMapNode );
// Set some defaults for this node. These will be used if we can't actually locate the asset.
// @todo sizemap urgent: We need a better indication in the UI when there are one or more missing assets. Because missing assets have a size
// of zero, they are nearly impossible to zoom into. At the least, we should have some Output Log spew when assets cannot be loaded
NodeSizeMapData.AssetData.AssetName = AssetPackageName;
NodeSizeMapData.AssetData.AssetClass = FName( *LOCTEXT( "MissingAsset", "MISSING!" ).ToString() );
NodeSizeMapData.AssetSize = 0;
NodeSizeMapData.bHasKnownSize = false;
// Find the asset using the asset registry
// @todo sizemap: Asset registry-based reference gathering is faster but possibly not as exhaustive (no PostLoad created references, etc.) Maybe should be optional?
// @todo sizemap: With AR-based reference gathering, sometimes the size map is missing root level dependencies until you reopen it a few times (Buggy BP)
// @todo sizemap: With AR-based reference gathering, reference changes at editor-time do not appear in the Size Map until you restart
// @todo sizemap: With AR-based reference gathering, opening the size map for all engine content caused the window to not respond until a restart
// @todo sizemap: We don't really need the asset registry given we need to load the objects to figure out their size, unless we make that AR-searchable.
// ---> This would allow us to not have to wait for AR initialization. But if we made size AR-searchable, we could run very quickly for large data sets!
const bool bUseAssetRegistryForDependencies = false;
const FString AssetPathString = AssetPackageNameString + TEXT(".") + FPackageName::GetLongPackageAssetName( AssetPackageNameString );
const FAssetData FoundAssetData = AssetRegistryModule.Get().GetAssetByObjectPath( FName( *AssetPathString ) );
if( FoundAssetData.IsValid() )
{
NodeSizeMapData.AssetData = FoundAssetData;
// Now actually load up the asset. We need it in memory in order to accurately determine its size.
// @todo sizemap: We could async load these packages to make the editor experience a bit nicer (smoother progress)
UObject* Asset = StaticLoadObject( UObject::StaticClass(), nullptr, *AssetPathString );
if( Asset != nullptr )
{
TArray<FName> ReferencedAssetPackageNames;
if( bUseAssetRegistryForDependencies )
{
AssetRegistryModule.Get().GetDependencies( AssetPackageName, ReferencedAssetPackageNames );
}
else
{
SizeMapInternals::FAssetReferenceFinder References( Asset );
for( UObject* Object : References.GetReferencedAssets() )
{
ReferencedAssetPackageNames.Add( FName( *Object->GetOutermost()->GetPathName() ) );
}
}
// For textures, make sure we're getting the worst case size, not the size of the currently loaded set of mips
// @todo sizemap: We should instead have a special EResourceSizeMode that asks for the worst case size. Some assets (like UTextureCube) currently always report resident mip size, even when asked for inclusive size
if( Asset->IsA( UTexture2D::StaticClass() ) )
{
NodeSizeMapData.AssetSize = Asset->GetResourceSizeBytes( EResourceSizeMode::Inclusive );
}
else
{
NodeSizeMapData.AssetSize = Asset->GetResourceSizeBytes( EResourceSizeMode::Exclusive );
}
NodeSizeMapData.bHasKnownSize = (NodeSizeMapData.AssetSize != 0);
if( !NodeSizeMapData.bHasKnownSize )
{
// @todo sizemap urgent: Try to serialize to figure out how big it is (not into sub-assets though!)
// FObjectMemoryAnalyzer ObjectMemoryAnalyzer( Asset );
}
// Now visit all of the assets that we are referencing
GatherDependenciesRecursively( AssetRegistryModule, InAssetThumbnailPool, VisitedAssetPackageNames, ReferencedAssetPackageNames, ChildTreeMapNode, SharedRootNode, NumAssetsWhichFailedToLoad );
}
else
{
++NumAssetsWhichFailedToLoad;
}
}
else
{
++NumAssetsWhichFailedToLoad;
}
}
}
}
}
void SSizeMap::FinalizeNodesRecursively( TSharedPtr<FTreeMapNodeData>& Node, const TSharedPtr<FTreeMapNodeData>& SharedRootNode, int32& TotalAssetCount, SIZE_T& TotalSize, bool& bAnyUnknownSizes )
{
// Process children first, so we can get the totals for the root node and shared nodes
int32 SubtreeAssetCount = 0;
SIZE_T SubtreeSize = 0;
bool bAnyUnknownSizesInSubtree = false;
{
for( TSharedPtr<FTreeMapNodeData> ChildNode : Node->Children )
{
FinalizeNodesRecursively( ChildNode, SharedRootNode, SubtreeAssetCount, SubtreeSize, bAnyUnknownSizesInSubtree );
}
TotalAssetCount += SubtreeAssetCount;
TotalSize += SubtreeSize;
if( bAnyUnknownSizesInSubtree )
{
bAnyUnknownSizes = true;
}
}
if( Node == SharedRootNode )
{
// @todo sizemap: Should we indicate in a non-shared parent node how many if its dependents ended up being in the "shared" bucket? Probably
// not that important, because the user can choose to view that asset in isolation to see the full tree.
Node->Name = FString::Printf( TEXT( "%s (%s)" ),
*LOCTEXT( "SharedGroupName", "*SHARED*" ).ToString(),
*SizeMapInternals::MakeBestSizeString( SubtreeSize, !bAnyUnknownSizes ) );
// Container nodes are always auto-sized
Node->Size = 0.0f;
}
else if( Node->Parent == nullptr )
{
// Tree root is always auto-sized
Node->Size = 0.0f;
}
else
{
const FNodeSizeMapData& NodeSizeMapData = NodeSizeMapDataMap.FindChecked( Node.ToSharedRef() );
++TotalAssetCount;
TotalSize += NodeSizeMapData.AssetSize;
if( !NodeSizeMapData.bHasKnownSize )
{
bAnyUnknownSizes = true;
}
// Setup a thumbnail
const FSlateBrush* DefaultThumbnailSlateBrush;
{
// For non-class types, use the default based upon the actual asset class
// This has the side effect of not showing a class icon for assets that don't have a proper thumbnail image available
bool bIsClassType = false;
const UClass* ThumbnailClass = FClassIconFinder::GetIconClassForAssetData( NodeSizeMapData.AssetData, &bIsClassType );
const FName DefaultThumbnail = (bIsClassType) ? NAME_None : FName(*FString::Printf(TEXT("ClassThumbnail.%s"), *NodeSizeMapData.AssetData.AssetClass.ToString()));
DefaultThumbnailSlateBrush = FClassIconFinder::FindThumbnailForClass(ThumbnailClass, DefaultThumbnail);
// @todo sizemap urgent: Actually implement rendered thumbnail support, not just class-based background images
// const int32 ThumbnailSize = 128; // @todo sizemap: Hard-coded thumbnail size. Move this elsewhere
// TSharedRef<FAssetThumbnail> AssetThumbnail( new FAssetThumbnail( NodeSizeMapData.AssetData, ThumbnailSize, ThumbnailSize, AssetThumbnailPool ) );
// ChildTreeMapNode->AssetThumbnail = AssetThumbnail->MakeThumbnailImage();
}
if( Node->IsLeafNode() )
{
Node->CenterText = SizeMapInternals::MakeBestSizeString( NodeSizeMapData.AssetSize, NodeSizeMapData.bHasKnownSize );
Node->Size = NodeSizeMapData.AssetSize;
// The STreeMap widget is not expecting zero-sized leaf nodes. So we make them very small instead.
if( Node->Size == 0 )
{
Node->Size = 1;
}
// Leaf nodes get a background picture
Node->BackgroundBrush = DefaultThumbnailSlateBrush;
// "Asset name"
// "Asset type"
Node->Name = NodeSizeMapData.AssetData.AssetName.ToString();
Node->Name2 = NodeSizeMapData.AssetData.AssetClass.ToString();
}
else
{
// Container nodes are always auto-sized
Node->Size = 0.0f;
// "Asset name (asset type, size)"
Node->Name = FString::Printf( TEXT( "%s (%s, %s)" ),
*NodeSizeMapData.AssetData.AssetName.ToString(),
*NodeSizeMapData.AssetData.AssetClass.ToString(),
*SizeMapInternals::MakeBestSizeString( SubtreeSize + NodeSizeMapData.AssetSize, !bAnyUnknownSizesInSubtree && NodeSizeMapData.bHasKnownSize ) );
const bool bNeedsSelfNode = NodeSizeMapData.AssetSize > 0;
if( bNeedsSelfNode )
{
// We have children, so make some space for our own asset's size within our box
FTreeMapNodeDataRef ChildSelfTreeMapNode = MakeShareable( new FTreeMapNodeData() );
Node->Children.Add( ChildSelfTreeMapNode );
ChildSelfTreeMapNode->Parent = Node.Get(); // Keep back-pointer to parent node
// Map the "self" node to the same node data as its parent
NodeSizeMapDataMap.Add( ChildSelfTreeMapNode, NodeSizeMapData );
// "*SELF*"
// "Asset type"
ChildSelfTreeMapNode->Name = LOCTEXT( "SelfNodeLabel", "*SELF*" ).ToString();
ChildSelfTreeMapNode->Name2 = NodeSizeMapData.AssetData.AssetClass.ToString();
ChildSelfTreeMapNode->CenterText = SizeMapInternals::MakeBestSizeString( NodeSizeMapData.AssetSize, NodeSizeMapData.bHasKnownSize );
ChildSelfTreeMapNode->Size = NodeSizeMapData.AssetSize;
// Leaf nodes get a background picture
ChildSelfTreeMapNode->BackgroundBrush = DefaultThumbnailSlateBrush;
}
}
}
// Sort all of my child nodes alphabetically. This is just so that we get deterministic results when viewing the
// same sets of assets.
Node->Children.StableSort(
[]( const FTreeMapNodeDataPtr& A, const FTreeMapNodeDataPtr& B )
{
return A->Name < B->Name;
}
);
}
void SSizeMap::RefreshMap()
{
// Wipe the current tree out
RootTreeMapNode->Children.Empty();
NodeSizeMapDataMap.Empty();
// First, do a pass to gather asset dependencies and build up a tree
TMap<FName, TSharedPtr<FTreeMapNodeData>> VisitedAssetPackageNames;
TSharedPtr<FTreeMapNodeData> SharedRootNode;
int32 NumAssetsWhichFailedToLoad = 0;
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
GatherDependenciesRecursively( AssetRegistryModule, AssetThumbnailPool, VisitedAssetPackageNames, RootAssetPackageNames, RootTreeMapNode, SharedRootNode, NumAssetsWhichFailedToLoad );
// Next, do another pass over our tree to and count how big the assets are and to set the node labels. Also in this pass, we may
// create some additional "self" nodes for assets that have children but also take up size themselves.
int32 TotalAssetCount = 0;
SIZE_T TotalSize = 0;
bool bAnyUnknownSizes = false;
FinalizeNodesRecursively( RootTreeMapNode, SharedRootNode, TotalAssetCount, TotalSize, bAnyUnknownSizes );
// Create a nice name for the tree!
if( NumAssetsWhichFailedToLoad > 0 )
{
RootTreeMapNode->Name = FString::Printf( TEXT( "%s %i %s" ),
*LOCTEXT( "RootNode_WarningPrefix", "WARNING:" ).ToString(),
NumAssetsWhichFailedToLoad,
*LOCTEXT( "RootNode_NAssetsFailedToLoad", "assets were missing! Only partial results shown." ).ToString() );
}
else if( RootAssetPackageNames.Num() == 1 && !SharedRootNode.IsValid() )
{
// @todo sizemap: When zoomed right into one asset, can we use the Class color for the node instead of grey?
FString OnlyAssetName = RootAssetPackageNames[ 0 ].ToString();
if( RootTreeMapNode->Children.Num() > 0 )
{
// The root will only have one child, so go ahead and use that child as the actual root
FTreeMapNodeDataPtr OnlyChild = RootTreeMapNode->Children[ 0 ];
OnlyChild->CopyNodeInto( *RootTreeMapNode );
RootTreeMapNode->Children = OnlyChild->Children;
RootTreeMapNode->Parent = nullptr;
for( const auto& ChildNode : RootTreeMapNode->Children )
{
ChildNode->Parent = RootTreeMapNode.Get();
}
OnlyAssetName = OnlyChild->Name;
}
// Use a more descriptive name for the root level node
RootTreeMapNode->Name = FString::Printf( TEXT( "%s %s (%i %s)" ),
*LOCTEXT( "RootNode_SizeMapForOneAsset", "Size map for" ).ToString(),
*OnlyAssetName,
TotalAssetCount,
*LOCTEXT( "RootNode_References", "total assets" ).ToString() );
}
else
{
// Multiple assets (or at least some shared assets) at the root level
RootTreeMapNode->BackgroundBrush = nullptr;
RootTreeMapNode->Size = 0.0f;
RootTreeMapNode->Parent = nullptr;
RootTreeMapNode->Name = FString::Printf( TEXT( "%s %i %s (%i %s, %s)" ),
*LOCTEXT( "RootNode_SizeMapForMultiple", "Size map for" ).ToString(),
RootAssetPackageNames.Num(),
*LOCTEXT( "RootNode_Assets", "assets" ).ToString(),
TotalAssetCount,
*LOCTEXT( "RootNode_References", "total assets" ).ToString(),
*SizeMapInternals::MakeBestSizeString( TotalSize, !bAnyUnknownSizes ) );
}
// OK, now refresh the actual tree map widget so our new tree will be displayed.
const bool bShouldPlayTransition = false;
TreeMapWidget->RebuildTreeMap( bShouldPlayTransition );
}
void SSizeMap::OnInitialAssetRegistrySearchComplete()
{
RefreshMap();
}
void SSizeMap::OnTreeMapNodeDoubleClicked( FTreeMapNodeData& TreeMapNodeData )
{
const FNodeSizeMapData* NodeSizeMapData = NodeSizeMapDataMap.Find( TreeMapNodeData.AsShared() );
if( NodeSizeMapData != nullptr )
{
TArray<FAssetData> Assets;
Assets.Add( NodeSizeMapData->AssetData );
GEditor->SyncBrowserToObjects( Assets );
}
}
// @todo sizemap urgent: We should add a spinner while we discover and load assets
// @todo sizemap urgent: Audit common asset types and make sure they have a useful GetResourceSize() implementation
// -> Some implementations are including the size of editor-only data (Static Mesh). This should be configurable!
// @todo sizemap urgent: It would be great to be able to see 0-sized/unknown-sized/tiny-sized nodes somehow, or at least a count of them
// - You'd almost want a way to zoom in super small. Or a little laserpointer effect that shows labels for super-tiny nodes
// @todo sizemap urgent: Need inline help to figure out mousewheel? Single click currently does nothing.
// @todo sizemap urgent: When an asset is not reporting a size, this tool should help to escalate that by making it very obvious that its missing (no GetResourceSize function)
// @todo sizemap: Can "zoom into" <Self> nodes which is a bit weird. (Asset name no longer draws). Maybe disallow zooming all the way in?
// --> Double-click current zooms directly into a single asset. Not super useful. Maybe only allow zooming down to the deepest nodes, not leaves
// @todo sizemap: When the tab is restored from layout, it will be totally empty. Instead it should probably have instructions for how to show the sizes for assets. (Same with Reference Viewer)
// @todo sizemap: We ideally want to replace the SReferenceTree code with SSizeMap
// @todo sizemap: Add a tree view that shows all of the references along with their sizes (so you can see Very Small references)
// @todo sizemap: It would be useful to be able to preview the sizes for specific platforms? (option in the UI)
// @todo sizemap: Should we show the percentage of total size as an option in the UI (though, the size of the boxes show this pretty well.)
// @todo sizemap: Should we show the folder part of the asset name as a tool-tip?
// @todo sizemap: It might be nice to unload assets that were loaded by us after the size map is built up
// @todo sizemap: Add a Refresh button. (Also, try to detect when objects change and auto-refresh, optionally)
#undef LOCTEXT_NAMESPACE