Files
UnrealEngineUWP/Engine/Source/Editor/StatsViewer/Private/StatsPages/CookerStatsPage.cpp

245 lines
6.5 KiB
C++
Raw Normal View History

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "StatsPages/CookerStatsPage.h"
#include "GenericPlatform/GenericPlatformFile.h"
#include "HAL/PlatformFilemanager.h"
#include "HAL/FileManager.h"
#include "Modules/ModuleManager.h"
#include "Textures/SlateIcon.h"
#include "Framework/Commands/UIAction.h"
#include "Widgets/Text/STextBlock.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
#include "Widgets/Input/SComboButton.h"
#include "AssetRegistryModule.h"
#define LOCTEXT_NAMESPACE "FCookerStatsPage"
/* FCookerStatsPage static functions
*****************************************************************************/
FCookerStatsPage& FCookerStatsPage::Get()
{
static FCookerStatsPage* Instance = nullptr;
if (Instance == nullptr)
{
Instance = new FCookerStatsPage;
}
return *Instance;
}
/* IStatsPage interface
*****************************************************************************/
void FCookerStatsPage::Generate( TArray<TWeakObjectPtr<UObject>>& OutObjects ) const
{
// visitor for the directory enumerator
class FPlatformDirectoryVisitor
: public IPlatformFile::FDirectoryVisitor
{
public:
FPlatformDirectoryVisitor( IAssetRegistry& InAssetRegistry, TArray<TWeakObjectPtr<UObject>>& InOutObjects, const FString& InPlatformName )
: AssetRegistry(InAssetRegistry)
, OutObjects(InOutObjects)
, PlatformName(InPlatformName)
{ }
virtual bool Visit( const TCHAR* FilenameOrDirectory, bool bIsDirectory ) override
{
if (!bIsDirectory)
{
FString OriginalFileName = FString(FilenameOrDirectory).Replace(*(FPaths::GameSavedDir() / TEXT("Cooked") / PlatformName), *FPaths::RootDir());
if (OriginalFileName.EndsWith(TEXT(".uasset")) || OriginalFileName.EndsWith(TEXT(".umap")))
{
UCookerStats* Entry = NewObject<UCookerStats>();
Entry->AddToRoot();
Entry->Path = FilenameOrDirectory;
Entry->SizeAfter = (int32)IFileManager::Get().FileSize(FilenameOrDirectory) / 1024.0f;
Entry->SizeBefore = FMath::Max(0.0f, (int32)IFileManager::Get().FileSize(*OriginalFileName) / 1024.0f);
FString PackageName;
if (FPackageName::TryConvertFilenameToLongPackageName(OriginalFileName, PackageName))
{
TArray<FAssetData> Assets;
AssetRegistry.GetAssetsByPackageName(FName(*PackageName), Assets);
for (auto Asset : Assets)
{
Entry->Assets.Add(Asset.GetAsset());
}
}
OutObjects.Add(Entry);
}
}
return true;
}
private:
IAssetRegistry& AssetRegistry;
TArray<TWeakObjectPtr<UObject>>& OutObjects;
FString PlatformName;
};
if (SelectedPlatformName.IsEmpty())
{
return;
}
// create data objects for each cooked asset
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
FPlatformDirectoryVisitor PlatformDirectoryVisitor(AssetRegistryModule.Get(), OutObjects, SelectedPlatformName);
FPlatformFileManager::Get().GetPlatformFile().IterateDirectoryRecursively(*(FPaths::GameSavedDir() / TEXT("Cooked") / SelectedPlatformName), PlatformDirectoryVisitor);
}
void FCookerStatsPage::GenerateTotals( const TArray<TWeakObjectPtr<UObject>>& InObjects, TMap<FString, FText>& OutTotals ) const
{
if (InObjects.Num() == 0)
{
return;
}
UCookerStats* TotalEntry = NewObject<UCookerStats>();
{
for (auto It = InObjects.CreateConstIterator(); It; ++It)
{
UCookerStats* StatsEntry = Cast<UCookerStats>(It->Get());
TotalEntry->SizeBefore += StatsEntry->SizeBefore;
TotalEntry->SizeAfter += StatsEntry->SizeAfter;
}
OutTotals.Add(TEXT("SizeBefore"), FText::AsNumber(TotalEntry->SizeBefore));
OutTotals.Add(TEXT("SizeAfter"), FText::AsNumber(TotalEntry->SizeAfter));
}
}
TSharedPtr<SWidget> FCookerStatsPage::GetCustomFilter( TWeakPtr<IStatsViewer> InParentStatsViewer )
{
return SNew(SComboButton)
.ContentPadding(2.0f)
.Visibility_Raw(this, &FCookerStatsPage::HandleFilterComboButtonVisibility)
.OnGetMenuContent_Raw(this, &FCookerStatsPage::HandleFilterComboButtonGetMenuContent)
.ButtonContent()
[
SNew(STextBlock)
.Text_Raw(this, &FCookerStatsPage::HandleFilterComboButtonText)
.ToolTipText(LOCTEXT("FilterColumnToUse_Tooltip", "Choose the target platform to filter when searching"))
];
}
void FCookerStatsPage::OnShow( TWeakPtr<class IStatsViewer> InParentStatsViewer )
{
}
void FCookerStatsPage::OnHide( )
{
}
/* FCookerStatsPage callback
*****************************************************************************/
TSharedRef<SWidget> FCookerStatsPage::HandleFilterComboButtonGetMenuContent( ) const
{
// visitor for the directory enumerator
class FCookedDirectoryVisitor
: public IPlatformFile::FDirectoryVisitor
{
public:
FCookedDirectoryVisitor( const FCookerStatsPage& InCookerStatsPage, FMenuBuilder& InMenuBuilder )
: CookerStatsPage(InCookerStatsPage)
, MenuBuilder(InMenuBuilder)
{ }
virtual bool Visit( const TCHAR* FilenameOrDirectory, bool bIsDirectory ) override
{
if (bIsDirectory)
{
FString PlatformName = FPaths::GetBaseFilename(FilenameOrDirectory);
MenuBuilder.AddMenuEntry(
FText::FromString(PlatformName),
FText::FromString(PlatformName),
FSlateIcon(),
FUIAction(
FExecuteAction::CreateRaw(&CookerStatsPage, &FCookerStatsPage::HandleFilterMenuEntryExecute, PlatformName),
FCanExecuteAction(),
FIsActionChecked::CreateRaw(&CookerStatsPage, &FCookerStatsPage::HandleFilterMenuEntryIsChecked, PlatformName)
),
NAME_None,
EUserInterfaceActionType::RadioButton
);
}
return true;
}
private:
const FCookerStatsPage& CookerStatsPage;
FMenuBuilder& MenuBuilder;
};
// create menu entries for each cooked directory
FMenuBuilder MenuBuilder(true, nullptr);
{
FCookedDirectoryVisitor CookedDirectoryVisitor(*this, MenuBuilder);
FPlatformFileManager::Get().GetPlatformFile().IterateDirectory(*(FPaths::GameSavedDir() / TEXT("Cooked")), CookedDirectoryVisitor);
}
return MenuBuilder.MakeWidget();
}
FText FCookerStatsPage::HandleFilterComboButtonText( ) const
{
if (SelectedPlatformName.IsEmpty())
{
return LOCTEXT("SelectPlatformLabel", "Select platform...");
}
return FText::FromString(SelectedPlatformName);
}
EVisibility FCookerStatsPage::HandleFilterComboButtonVisibility( ) const
{
return EVisibility::Visible;
}
void FCookerStatsPage::HandleFilterMenuEntryExecute( FString PlatformName )
{
SelectedPlatformName = PlatformName;
Refresh();
}
bool FCookerStatsPage::HandleFilterMenuEntryIsChecked( FString PlatformName ) const
{
return (PlatformName == SelectedPlatformName);
}
#undef LOCTEXT_NAMESPACE