Performance settings changes are now delayed until the load screen is fully faded in, so that the 3D renderer is disabled only after we can't see it any more anyway.

This commit is contained in:
Jamie Greunbaum 2023-05-30 01:04:53 -04:00
parent af66792d04
commit d4f5bbd834
2 changed files with 13 additions and 10 deletions

View File

@ -163,7 +163,10 @@ ULoadingScreenWidget *ULoadingScreenManager::ShowLoadingScreen()
UGameViewportClient *GameViewportClient = LocalGameInstance->GetGameViewportClient(); UGameViewportClient *GameViewportClient = LocalGameInstance->GetGameViewportClient();
GameViewportClient->AddViewportWidgetContent(this->LoadingScreenWidget.ToSharedRef(), Settings->LoadingScreenZOrder); GameViewportClient->AddViewportWidgetContent(this->LoadingScreenWidget.ToSharedRef(), Settings->LoadingScreenZOrder);
this->ChangePerformanceSettings(/*bEnableLoadingScreen=*/ true); // After the load screen is fully loaded in, change the performance settings. We delay
// this because one of the performance settings disables 3D rendering, which we don't
// want to do until the load screen is completely obscuring that fact.
this->LoadingScreenUMGWidget->OnLoadScreenOpened.AddLambda([this]{ this->ChangePerformanceSettings(/*bEnableLoadingScreen=*/ true); });
if (!GIsEditor || Settings->ForceTickLoadingScreenEvenInEditor) if (!GIsEditor || Settings->ForceTickLoadingScreenEvenInEditor)
{ {
@ -196,7 +199,7 @@ void ULoadingScreenManager::HideLoadingScreen_Private()
{ {
this->ChangePerformanceSettings(/*bEnableLoadingScreen=*/ false); this->ChangePerformanceSettings(/*bEnableLoadingScreen=*/ false);
this->LoadingScreenUMGWidget->OnLoadScreenClosed.BindUObject(this, &ULoadingScreenManager::RemoveLoadingScreen); this->LoadingScreenUMGWidget->OnLoadScreenClosed.AddUObject(this, &ULoadingScreenManager::RemoveLoadingScreen);
this->LoadingScreenUMGWidget->BeginFadeOut(); this->LoadingScreenUMGWidget->BeginFadeOut();
} }
} }
@ -211,8 +214,8 @@ void ULoadingScreenManager::RemoveLoadingScreen()
this->StopBlockingInput(); this->StopBlockingInput();
this->RemoveWidgetFromViewport(); this->RemoveWidgetFromViewport();
this->LoadingScreenUMGWidget->OnLoadScreenOpened.Unbind(); this->LoadingScreenUMGWidget->OnLoadScreenOpened.Clear();
this->LoadingScreenUMGWidget->OnLoadScreenClosed.Unbind(); this->LoadingScreenUMGWidget->OnLoadScreenClosed.Clear();
// Let observers know that the loading screen is done // Let observers know that the loading screen is done
this->LoadingScreenVisibilityChanged.Broadcast(/*bIsVisible=*/ false); this->LoadingScreenVisibilityChanged.Broadcast(/*bIsVisible=*/ false);
@ -256,26 +259,26 @@ void ULoadingScreenManager::StopBlockingInput()
} }
} }
void ULoadingScreenManager::ChangePerformanceSettings(bool bEnabingLoadingScreen) void ULoadingScreenManager::ChangePerformanceSettings(bool bEnableLoadingScreen)
{ {
UGameInstance *LocalGameInstance = this->GetGameInstance(); UGameInstance *LocalGameInstance = this->GetGameInstance();
UGameViewportClient *GameViewportClient = LocalGameInstance->GetGameViewportClient(); UGameViewportClient *GameViewportClient = LocalGameInstance->GetGameViewportClient();
FShaderPipelineCache::SetBatchMode(bEnabingLoadingScreen ? FShaderPipelineCache::BatchMode::Fast : FShaderPipelineCache::BatchMode::Background); FShaderPipelineCache::SetBatchMode(bEnableLoadingScreen ? FShaderPipelineCache::BatchMode::Fast : FShaderPipelineCache::BatchMode::Background);
// Don't bother drawing the 3D world while we're loading // Don't bother drawing the 3D world while we're loading
GameViewportClient->bDisableWorldRendering = bEnabingLoadingScreen; GameViewportClient->bDisableWorldRendering = bEnableLoadingScreen;
// Make sure to prioritize streaming in levels if the loading screen is up // Make sure to prioritize streaming in levels if the loading screen is up
if (UWorld* ViewportWorld = GameViewportClient->GetWorld()) if (UWorld* ViewportWorld = GameViewportClient->GetWorld())
{ {
if (AWorldSettings *WorldSettings = ViewportWorld->GetWorldSettings(false, false)) if (AWorldSettings *WorldSettings = ViewportWorld->GetWorldSettings(false, false))
{ {
WorldSettings->bHighPriorityLoadingLocal = bEnabingLoadingScreen; WorldSettings->bHighPriorityLoadingLocal = bEnableLoadingScreen;
} }
} }
if (bEnabingLoadingScreen) if (bEnableLoadingScreen)
{ {
// Set a new hang detector timeout multiplier when the loading screen is visible. // Set a new hang detector timeout multiplier when the loading screen is visible.
double HangDurationMultiplier; double HangDurationMultiplier;

View File

@ -61,7 +61,7 @@ private:
/** Resumes in-game input, if blocking */ /** Resumes in-game input, if blocking */
void StopBlockingInput(); void StopBlockingInput();
void ChangePerformanceSettings(bool bEnabingLoadingScreen); void ChangePerformanceSettings(bool bEnableLoadingScreen);
private: private:
/** Delegate broadcast when the loading screen visibility changes */ /** Delegate broadcast when the loading screen visibility changes */