2021-11-18 14:37:34 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "SVirtualAssetsStatistics.h"
2022-01-24 09:12:04 -05:00
# include "Framework/Notifications/NotificationManager.h"
# include "Internationalization/FastDecimalFormat.h"
2021-11-18 14:37:34 -05:00
# include "Math/BasicMathExpressionEvaluator.h"
2022-01-24 09:12:04 -05:00
# include "Math/UnitConversion.h"
2021-11-18 14:37:34 -05:00
# include "Misc/ExpressionParser.h"
2022-04-27 09:21:42 -04:00
# include "Logging/MessageLog.h"
2021-11-18 14:37:34 -05:00
# include "Styling/StyleColors.h"
2022-01-24 09:12:04 -05:00
# include "VirtualizationManager.h"
2021-11-18 14:37:34 -05:00
# include "Widgets/Layout/SGridPanel.h"
2022-01-24 09:12:04 -05:00
# include "Widgets/Layout/SScrollBox.h"
2021-11-18 14:37:34 -05:00
# include "Widgets/SBoxPanel.h"
2022-01-24 09:12:04 -05:00
# include "Widgets/Text/STextBlock.h"
2022-05-09 13:31:58 -04:00
# include "Styling/AppStyle.h"
2021-11-18 14:37:34 -05:00
# define LOCTEXT_NAMESPACE "VirtualAssets"
extern FString SingleDecimalFormat ( double Value ) ;
using namespace UE : : Virtualization ;
2021-11-23 15:05:13 -05:00
SVirtualAssetsStatisticsDialog : : SVirtualAssetsStatisticsDialog ( )
{
// Register our VA notification delegate with the event
IVirtualizationSystem & System = IVirtualizationSystem : : Get ( ) ;
System . GetNotificationEvent ( ) . AddRaw ( this , & SVirtualAssetsStatisticsDialog : : OnNotificationEvent ) ;
}
SVirtualAssetsStatisticsDialog : : ~ SVirtualAssetsStatisticsDialog ( )
{
// Unregister our VA notification delegate with the event
IVirtualizationSystem & System = IVirtualizationSystem : : Get ( ) ;
System . GetNotificationEvent ( ) . RemoveAll ( this ) ;
}
2022-02-02 02:21:24 -05:00
void SVirtualAssetsStatisticsDialog : : OnNotificationEvent ( IVirtualizationSystem : : ENotification Notification , const FIoHash & PayloadId )
2021-11-23 15:05:13 -05:00
{
FScopeLock SocpeLock ( & NotificationCS ) ;
switch ( Notification )
{
case IVirtualizationSystem : : ENotification : : PullBegunNotification :
{
2021-12-01 11:49:50 -05:00
IsPulling = true ;
2021-11-23 15:05:13 -05:00
NumPullRequests + + ;
2021-12-01 11:49:50 -05:00
2021-11-23 15:05:13 -05:00
break ;
}
case IVirtualizationSystem : : ENotification : : PullEndedNotification :
{
2021-12-01 11:49:50 -05:00
if ( IsPulling = = true )
{
NumPullRequests - - ;
IsPulling = NumPullRequests ! = 0 ;
}
2021-11-23 15:05:13 -05:00
break ;
}
case IVirtualizationSystem : : ENotification : : PullFailedNotification :
{
2022-04-22 08:55:44 -04:00
NumPullRequestFailures + + ;
2021-11-23 15:05:13 -05:00
break ;
}
default :
break ;
}
}
2021-11-18 14:37:34 -05:00
void SVirtualAssetsStatisticsDialog : : Construct ( const FArguments & InArgs )
{
this - > ChildSlot
[
SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
2021-11-23 05:39:59 -05:00
. Padding ( 0 , 20 , 0 , 0 )
2021-11-18 14:37:34 -05:00
. Expose ( GridSlot )
[
2022-01-24 09:12:04 -05:00
SAssignNew ( ScrollBox , SScrollBox )
. Orientation ( EOrientation : : Orient_Horizontal )
. ScrollBarAlwaysVisible ( false )
+ SScrollBox : : Slot ( )
[
GetGridPanel ( )
]
2021-11-18 14:37:34 -05:00
]
] ;
2022-01-21 10:57:43 -05:00
RegisterActiveTimer ( 0.25f , FWidgetActiveTimerDelegate : : CreateSP ( this , & SVirtualAssetsStatisticsDialog : : UpdateGridPanels ) ) ;
2021-11-18 14:37:34 -05:00
}
EActiveTimerReturnType SVirtualAssetsStatisticsDialog : : UpdateGridPanels ( double InCurrentTime , float InDeltaTime )
{
2022-01-24 09:12:04 -05:00
ScrollBox - > ClearChildren ( ) ;
ScrollBox - > AddSlot ( )
2022-01-21 10:57:43 -05:00
[
GetGridPanel ( )
] ;
2022-01-24 09:12:04 -05:00
2021-11-18 14:37:34 -05:00
SlatePrepass ( GetPrepassLayoutScaleMultiplier ( ) ) ;
2022-01-21 10:57:43 -05:00
const float PullNotifactionTimeLimit = 1.0f ;
// Only show the pull notification if we have been pulling for more than a second..
if ( NumPullRequests ! = 0 )
{
PullNotificationTimer + = InDeltaTime ;
}
else
{
PullNotificationTimer = 0.0f ;
}
if ( PullNotificationTimer > PullNotifactionTimeLimit & & PullRequestNotificationItem . IsValid ( ) = = false )
2021-11-23 15:05:13 -05:00
{
// No existing notification or the existing one has finished
2022-04-22 08:55:44 -04:00
FNotificationInfo Info ( LOCTEXT ( " PayloadSyncNotifcation " , " Syncing Asset Payloads " ) ) ;
2021-11-23 15:05:13 -05:00
Info . bFireAndForget = false ;
2022-04-22 08:55:44 -04:00
Info . bUseLargeFont = false ;
Info . bUseThrobber = false ;
2021-11-23 15:05:13 -05:00
Info . FadeOutDuration = 0.5f ;
Info . ExpireDuration = 0.0f ;
PullRequestNotificationItem = FSlateNotificationManager : : Get ( ) . AddNotification ( Info ) ;
if ( PullRequestNotificationItem . IsValid ( ) )
{
PullRequestNotificationItem - > SetCompletionState ( SNotificationItem : : CS_Pending ) ;
}
}
2022-04-22 08:55:44 -04:00
if ( NumPullRequestFailures > 0 & & PullRequestFailedNotificationItem . IsValid ( ) = = false )
{
// No existing notification or the existing one has finished
FNotificationInfo Info ( LOCTEXT ( " PayloadFailedNotifcation " , " Failed to sync some Virtual Asset payloads from available backends. \n Some assets may no longer be usable.. " ) ) ;
Info . bFireAndForget = false ;
Info . bUseLargeFont = false ;
Info . bUseThrobber = false ;
Info . FadeOutDuration = 0.5f ;
Info . ExpireDuration = 0.0f ;
2022-05-09 13:31:58 -04:00
Info . Image = FAppStyle : : GetBrush ( TEXT ( " MessageLog.Warning " ) ) ;
2022-04-22 08:55:44 -04:00
Info . ButtonDetails . Add ( FNotificationButtonInfo ( LOCTEXT ( " PullFailedIgnore " , " Ignore " ) , LOCTEXT ( " PullFailedIgnoreToolTip " , " Ignore future warnings " ) , FSimpleDelegate : : CreateSP ( this , & SVirtualAssetsStatisticsDialog : : OnWarningReasonIgnore ) , SNotificationItem : : CS_None ) ) ;
Info . ButtonDetails . Add ( FNotificationButtonInfo ( LOCTEXT ( " PullFailedOK " , " Ok " ) , LOCTEXT ( " PullFailedOkToolTip " , " Notify future warnings " ) , FSimpleDelegate : : CreateSP ( this , & SVirtualAssetsStatisticsDialog : : OnWarningReasonOk ) , SNotificationItem : : CS_None ) ) ;
Info . HyperlinkText = LOCTEXT ( " PullFailed_ShowLog " , " Show Message Log " ) ;
Info . Hyperlink = FSimpleDelegate : : CreateStatic ( [ ] ( ) { FMessageLog ( " LogVirtualization " ) . Open ( EMessageSeverity : : Warning , true ) ; } ) ;
PullRequestFailedNotificationItem = FSlateNotificationManager : : Get ( ) . AddNotification ( Info ) ;
}
2021-11-23 15:05:13 -05:00
if ( NumPullRequests = = 0 & & PullRequestNotificationItem . IsValid ( ) = = true )
{
PullRequestNotificationItem - > SetCompletionState ( SNotificationItem : : CS_Success ) ;
PullRequestNotificationItem - > ExpireAndFadeout ( ) ;
PullRequestNotificationItem . Reset ( ) ;
}
2021-11-18 14:37:34 -05:00
return EActiveTimerReturnType : : Continue ;
}
2022-04-22 08:55:44 -04:00
void SVirtualAssetsStatisticsDialog : : OnWarningReasonOk ( )
{
if ( PullRequestFailedNotificationItem . IsValid ( ) = = true )
{
PullRequestFailedNotificationItem - > ExpireAndFadeout ( ) ;
PullRequestFailedNotificationItem . Reset ( ) ;
NumPullRequestFailures = 0 ;
}
}
void SVirtualAssetsStatisticsDialog : : OnWarningReasonIgnore ( )
{
if ( PullRequestFailedNotificationItem . IsValid ( ) = = true )
{
PullRequestFailedNotificationItem - > ExpireAndFadeout ( ) ;
}
}
2021-11-18 14:37:34 -05:00
TSharedRef < SWidget > SVirtualAssetsStatisticsDialog : : GetGridPanel ( )
{
2021-11-23 06:54:34 -05:00
IVirtualizationSystem & System = IVirtualizationSystem : : Get ( ) ;
TSharedRef < SGridPanel > Panel = SNew ( SGridPanel ) ;
2021-11-18 14:37:34 -05:00
const float RowMargin = 0.0f ;
const float TitleMargin = 10.0f ;
const float ColumnMargin = 10.0f ;
const FSlateColor TitleColor = FStyleColors : : AccentWhite ;
const FSlateFontInfo TitleFont = FCoreStyle : : GetDefaultFontStyle ( " Bold " , 10 ) ;
const double BytesToMegaBytes = 1.0 / ( 1024.0 * 1024.0 ) ;
2021-11-23 06:54:34 -05:00
if ( System . IsEnabled ( ) = = false )
2021-11-18 14:37:34 -05:00
{
2021-11-23 06:54:34 -05:00
Panel - > AddSlot ( 0 , 0 )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Disabled " , " Virtual Assets Are Disabled For This Project " ) )
] ;
}
else
{
int32 Row = 0 ;
2021-11-18 14:37:34 -05:00
Panel - > AddSlot ( 2 , Row )
2021-11-23 06:54:34 -05:00
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Read " , " Read " ) )
2021-11-23 06:54:34 -05:00
] ;
2021-11-18 14:37:34 -05:00
Panel - > AddSlot ( 5 , Row )
2021-11-23 06:54:34 -05:00
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Write " , " Write " ) )
2021-11-23 06:54:34 -05:00
] ;
2021-11-18 14:37:34 -05:00
Panel - > AddSlot ( 8 , Row )
2021-11-23 06:54:34 -05:00
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Cache " , " Cache " ) )
2021-11-23 06:54:34 -05:00
] ;
2021-11-18 14:37:34 -05:00
Row + + ;
2021-11-23 06:54:34 -05:00
Panel - > AddSlot ( 0 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Left )
. Text ( LOCTEXT ( " Backend " , " Backend " ) )
2021-11-23 06:54:34 -05:00
] ;
2021-11-18 14:37:34 -05:00
2021-11-23 06:54:34 -05:00
Panel - > AddSlot ( 1 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Count " , " Count " ) )
2021-11-23 06:54:34 -05:00
] ;
2021-11-23 05:39:59 -05:00
2021-11-23 06:54:34 -05:00
Panel - > AddSlot ( 2 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Time " , " Time (Sec) " ) )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 3 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Size " , " Size (MB) " ) )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 4 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Count " , " Count " ) )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 5 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Time " , " Time (Sec) " ) )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 6 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Size " , " Size (MB) " ) )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 7 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Count " , " Count " ) )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 8 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Time " , " Time (Sec) " ) )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 9 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin , 0.0f , TitleMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( TitleColor )
. Font ( TitleFont )
. Justification ( ETextJustify : : Center )
. Text ( LOCTEXT ( " Size " , " Size (MB) " ) )
2021-11-23 06:54:34 -05:00
] ;
Row + + ;
FPayloadActivityInfo AccumulatedPayloadAcitvityInfo = System . GetAccumualtedPayloadActivityInfo ( ) ;
FSlateColor Color = FStyleColors : : Foreground ;
FSlateFontInfo Font = FCoreStyle : : GetDefaultFontStyle ( " Regular " , 10 ) ;
2021-12-09 14:47:31 -05:00
auto DisplayPayloadActivityInfo = [ & ] ( const FString & DebugName , const FString & ConfigName , const FPayloadActivityInfo & PayloadActivityInfo )
2021-11-23 06:54:34 -05:00
{
Panel - > AddSlot ( 0 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Left )
. Text ( FText : : FromString ( DebugName ) )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 1 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Center )
. Text_Lambda ( [ PayloadActivityInfo ] { return FText : : FromString ( FString : : Printf ( TEXT ( " %u " ) , PayloadActivityInfo . Pull . PayloadCount ) ) ; } )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 2 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Center )
. Text_Lambda ( [ PayloadActivityInfo ] { return FText : : FromString ( SingleDecimalFormat ( ( double ) PayloadActivityInfo . Pull . CyclesSpent * FPlatformTime : : GetSecondsPerCycle ( ) ) ) ; } )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 3 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Center )
. Text_Lambda ( [ PayloadActivityInfo , BytesToMegaBytes ] { return FText : : FromString ( SingleDecimalFormat ( ( double ) PayloadActivityInfo . Pull . TotalBytes * BytesToMegaBytes ) ) ; } )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 4 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Center )
. Text_Lambda ( [ PayloadActivityInfo ] { return FText : : FromString ( FString : : Printf ( TEXT ( " %u " ) , PayloadActivityInfo . Push . PayloadCount ) ) ; } )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 5 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Center )
. Text_Lambda ( [ PayloadActivityInfo ] { return FText : : FromString ( SingleDecimalFormat ( ( double ) PayloadActivityInfo . Push . CyclesSpent * FPlatformTime : : GetSecondsPerCycle ( ) ) ) ; } )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 6 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Center )
. Text_Lambda ( [ PayloadActivityInfo , BytesToMegaBytes ] { return FText : : FromString ( SingleDecimalFormat ( ( double ) PayloadActivityInfo . Push . TotalBytes * BytesToMegaBytes ) ) ; } )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 7 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Center )
. Text_Lambda ( [ PayloadActivityInfo ] { return FText : : FromString ( FString : : Printf ( TEXT ( " %u " ) , PayloadActivityInfo . Cache . PayloadCount ) ) ; } )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 8 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Center )
. Text_Lambda ( [ PayloadActivityInfo ] { return FText : : FromString ( SingleDecimalFormat ( ( double ) PayloadActivityInfo . Cache . CyclesSpent * FPlatformTime : : GetSecondsPerCycle ( ) ) ) ; } )
2021-11-23 06:54:34 -05:00
] ;
Panel - > AddSlot ( 9 , Row )
[
SNew ( STextBlock )
. Margin ( FMargin ( ColumnMargin , RowMargin ) )
2021-12-09 14:47:31 -05:00
. ColorAndOpacity ( Color )
. Font ( Font )
. Justification ( ETextJustify : : Center )
. Text_Lambda ( [ PayloadActivityInfo , BytesToMegaBytes ] { return FText : : FromString ( SingleDecimalFormat ( ( double ) PayloadActivityInfo . Cache . TotalBytes * BytesToMegaBytes ) ) ; } )
2021-11-23 06:54:34 -05:00
] ;
Row + + ;
} ;
System . GetPayloadActivityInfo ( DisplayPayloadActivityInfo ) ;
Color = TitleColor ;
Font = TitleFont ;
DisplayPayloadActivityInfo ( FString ( " Total " ) , FString ( " Total " ) , AccumulatedPayloadAcitvityInfo ) ;
}
2021-11-18 14:37:34 -05:00
return Panel ;
}
# undef LOCTEXT_NAMESPACE