2019-12-26 14:45:42 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2018-09-25 10:11:35 -04:00
# pragma once
# include "PreLoadScreen.h"
# include "CoreMinimal.h"
# include "Widgets/SVirtualWindow.h"
# include "Widgets/SWindow.h"
# include "TickableObjectRenderThread.h"
# include "Containers/Ticker.h"
# include "PreLoadSlateThreading.h"
2019-07-22 11:49:15 -04:00
2018-09-25 10:11:35 -04:00
// Class that handles storing all registered PreLoadScreens and Playing/Stopping them
class PRELOADSCREEN_API FPreLoadScreenManager
{
public :
//Gets the single instance of this settings object. Also creates it if needed
2020-06-23 18:40:00 -04:00
static FPreLoadScreenManager * Get ( ) ;
static void Create ( ) ;
static void Destroy ( ) ;
2018-09-25 10:11:35 -04:00
void Initialize ( FSlateRenderer & InSlateRenderer ) ;
2020-06-23 18:40:00 -04:00
void RegisterPreLoadScreen ( const TSharedPtr < IPreLoadScreen > & PreLoadScreen ) ;
void UnRegisterPreLoadScreen ( const TSharedPtr < IPreLoadScreen > & PreLoadScreen ) ;
2018-09-25 10:11:35 -04:00
2020-06-23 18:40:00 -04:00
/**
* Plays the first found PreLoadScreen that matches the bEarlyPreLoadScreen setting passed in .
* @ returns false if no PreLoadScreen with that type has been registered .
*/
bool PlayFirstPreLoadScreen ( EPreLoadScreenTypes PreLoadScreenTypeToPlay ) ;
2018-09-25 10:11:35 -04:00
2020-06-23 18:40:00 -04:00
/**
* Plays the PreLoadScreen with a tag that matches InTag
* @ returns false if no PreLoadScreen with that tag has been registered .
*/
2018-09-25 10:11:35 -04:00
bool PlayPreLoadScreenWithTag ( FName InTag ) ;
2020-06-23 18:40:00 -04:00
void StopPreLoadScreen ( ) ;
void WaitForEngineLoadingScreenToFinish ( ) ;
2018-09-25 10:11:35 -04:00
void PassPreLoadScreenWindowBackToGame ( ) const ;
bool IsUsingMainWindow ( ) const ;
TSharedPtr < SWindow > GetRenderWindow ( ) ;
bool HasRegisteredPreLoadScreenType ( EPreLoadScreenTypes PreLoadScreenTypeToCheck ) const ;
bool HasActivePreLoadScreenType ( EPreLoadScreenTypes PreLoadScreenTypeToCheck ) const ;
bool HasValidActivePreLoadScreen ( ) const ;
void SetEngineLoadingComplete ( bool IsEngineLoadingFinished = true ) ;
bool IsEngineLoadingComplete ( ) const { return bIsEngineLoadingComplete ; }
2019-01-08 11:38:48 -05:00
static void EnableRendering ( bool bEnabled ) ;
2018-09-25 10:11:35 -04:00
static bool ArePreLoadScreensEnabled ( ) ;
// Callback for handling cleaning up any resources you would like to remove after the PreLoadScreenManager cleans up
2020-06-23 18:40:00 -04:00
// Not needed for PreLoadScreens as those have a separate CleanUp method called.
2018-09-25 10:11:35 -04:00
DECLARE_MULTICAST_DELEGATE ( FOnPreLoadScreenManagerCleanUp ) ;
FOnPreLoadScreenManagerCleanUp OnPreLoadScreenManagerCleanUp ;
2020-06-23 18:40:00 -04:00
DECLARE_MULTICAST_DELEGATE_OneParam ( FIsPreloadScreenResponsibleForRenderingMultiDelegate , bool ) ;
FIsPreloadScreenResponsibleForRenderingMultiDelegate IsResponsibleForRenderingDelegate ;
2018-09-25 10:11:35 -04:00
protected :
//Default constructor. We don't want other classes to make these. Should just rely on Get()
2020-06-23 18:40:00 -04:00
FPreLoadScreenManager ( ) ;
2018-09-25 10:11:35 -04:00
2020-06-23 18:40:00 -04:00
~ FPreLoadScreenManager ( ) = default ;
2018-09-25 10:11:35 -04:00
2020-06-23 18:40:00 -04:00
void PlayPreLoadScreenAtIndex ( int32 Index ) ;
2018-09-25 10:11:35 -04:00
void BeginPlay ( ) ;
/*** These functions describe the flow for an EarlyPreLoadScreen where everything is blocking waiting on a call to StopPreLoadScreen ***/
void HandleEarlyStartupPlay ( ) ;
//Separate tick that handles
void EarlyPlayFrameTick ( ) ;
void GameLogicFrameTick ( ) ;
void EarlyPlayRenderFrameTick ( ) ;
2020-06-23 18:40:00 -04:00
bool HasActivePreLoadScreenTypeForEarlyStartup ( ) const ;
2018-09-25 10:11:35 -04:00
2019-04-17 22:56:58 -04:00
void PlatformSpecificGameLogicFrameTick ( ) ;
2020-06-23 18:40:00 -04:00
//Creates a tick on the Render Thread that we run every
static void StaticRenderTick_RenderThread ( ) ;
void RenderTick_RenderThread ( ) ;
2018-09-25 10:11:35 -04:00
/*** These functions describe how everything is handled during an non-Early PreLoadPlay. Everything is handled asynchronously in this case with a standalone renderer ***/
2019-10-03 08:46:18 -04:00
void HandleEngineLoadingPlay ( ) ;
/*** These functions describe the flow for showing an CustomSplashScreen ***/
void HandleCustomSplashScreenPlay ( ) ;
2018-09-25 10:11:35 -04:00
IPreLoadScreen * GetActivePreLoadScreen ( ) ;
const IPreLoadScreen * GetActivePreLoadScreen ( ) const ;
2020-06-23 18:40:00 -04:00
void HandleStopPreLoadScreen ( ) ;
void CleanUpResources ( ) ;
//Singleton Instance
struct FPreLoadScreenManagerDelete
{
void operator ( ) ( FPreLoadScreenManager * Ptr ) const
{
delete Ptr ;
}
} ;
static TUniquePtr < FPreLoadScreenManager , FPreLoadScreenManagerDelete > Instance ;
static FCriticalSection AcquireCriticalSection ;
static TAtomic < bool > bRenderingEnabled ;
TArray < TSharedPtr < IPreLoadScreen > > PreLoadScreens ;
int32 ActivePreLoadScreenIndex ;
2018-09-25 10:11:35 -04:00
double LastTickTime ;
/** Widget renderer used to tick and paint windows in a thread safe way */
TSharedPtr < FPreLoadSlateWidgetRenderer , ESPMode : : ThreadSafe > WidgetRenderer ;
/** The window that the loading screen resides in */
TWeakPtr < class SWindow > MainWindow ;
/** Virtual window that we render to instead of the main slate window (for thread safety). Shares only the same backbuffer as the main window */
TSharedPtr < class SVirtualWindow > VirtualRenderWindow ;
bool bInitialized ;
/** The threading mechanism with which we handle running slate on another thread */
2020-06-23 18:40:00 -04:00
FPreLoadScreenSlateSynchMechanism * SyncMechanism ;
friend FPreLoadScreenSlateSynchMechanism ;
2018-09-25 10:11:35 -04:00
2020-06-23 18:40:00 -04:00
bool bIsResponsibleForRendering ;
2020-08-11 01:36:57 -04:00
bool bHasRenderPreLoadScreenFrame_RenderThread ;
2019-07-22 11:49:15 -04:00
2018-09-25 10:11:35 -04:00
double LastRenderTickTime ;
float OriginalSlateSleepVariableValue ;
bool bIsEngineLoadingComplete ;
2019-04-17 22:56:58 -04:00
private :
# if PLATFORM_ANDROID
void Android_PlatformSpecificGameLogicFrameTick ( ) ;
# endif //PLATFORM_ANDROID
# if PLATFORM_IOS
void IOS_PlatformSpecificGameLogicFrameTick ( ) ;
# endif //PLATFORM_IOS
2018-09-25 10:11:35 -04:00
} ;