From f9ae4b3c7c16b09118a069f9a70d21c2f454f652 Mon Sep 17 00:00:00 2001 From: "CVC\\jbelon" Date: Mon, 26 Feb 2018 19:03:18 +0100 Subject: [PATCH] Fix for Quality Settings apply function --- Docs/Example.CarlaSettings.ini | 7 ++- .../Source/Carla/Game/CarlaGameModeBase.cpp | 3 +- .../Source/Carla/Settings/CarlaSettings.cpp | 63 +++++++++---------- .../Source/Carla/Settings/CarlaSettings.h | 20 ++++-- 4 files changed, 51 insertions(+), 42 deletions(-) diff --git a/Docs/Example.CarlaSettings.ini b/Docs/Example.CarlaSettings.ini index 6b50d5628..54f3f9680 100644 --- a/Docs/Example.CarlaSettings.ini +++ b/Docs/Example.CarlaSettings.ini @@ -25,6 +25,9 @@ SynchronousMode=true ; performance. SendNonPlayerAgentsInfo=false +[CARLA/QualitySettings] +DefaultLevel=Epic + [CARLA/LevelSettings] ; Path of the vehicle class to be used for the player. Leave empty for default. ; Paths follow the pattern "/Game/Blueprints/Vehicles/Mustang/Mustang.Mustang_C" @@ -85,6 +88,7 @@ RotationYaw=0 ; depth map images instead. PostProcessing=Depth + [CARLA/Sensor/MyLidar] SensorType=LIDAR_RAY_TRACE ; Number of lasers. @@ -106,6 +110,3 @@ RotationPitch=0 RotationYaw=0 RotationRoll=0 - -[CARLA/QualitySettings] -DefaultLevel=Epic \ No newline at end of file diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp index 5efd1be63..1348b5264 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp @@ -131,7 +131,8 @@ void ACarlaGameModeBase::BeginPlay() Super::BeginPlay(); const auto &CarlaSettings = GameInstance->GetCarlaSettings(); - + CarlaSettings.ApplyQualitySettingsLevelPostRestart(); + // Setup semantic segmentation if necessary. if (CarlaSettings.bSemanticSegmentationEnabled) { TagActorsForSemanticSegmentation(); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp index 6e2b53603..02d808b96 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp @@ -118,9 +118,9 @@ static void LoadSettingsFromConfig( ConfigFile.GetString(S_CARLA_QUALITYSETTINGS, TEXT("DefaultLevel"), sDefaultLevel); if(!Settings.SetQualitySettingsLevel(FQualitySettings::FromString(sDefaultLevel))) { - //ERROR! @TODO : fix settings + ///apply pre-restart.... @todo } - + // Sensors. FString Sensors; @@ -179,14 +179,17 @@ bool UCarlaSettings::SetQualitySettingsLevel(EQualitySettingsLevel newDefaultLev return false; } - /*if(newDefaultLevel!=DefaultQualitySettingsLevel) - { - return true; - }*/ + DefaultQualitySettingsLevel = newDefaultLevel; + + return true; +} + +void UCarlaSettings::ApplyQualitySettingsLevelPostRestart() const +{ UWorld *world = GetWorld(); - + if(!world) return ; //set the quality settings now - switch(newDefaultLevel) + switch(DefaultQualitySettingsLevel) { case EQualitySettingsLevel::Low: {//r.SSR.qualitylaunch commands to lower quality settings world->Exec(world,TEXT("r.DefaultFeature.MotionBlur 0")); @@ -248,34 +251,31 @@ bool UCarlaSettings::SetQualitySettingsLevel(EQualitySettingsLevel newDefaultLev } }*/ - - //iterate all lights, deactivate shadows + + //iterate all directional lights, deactivate shadows UGameplayStatics::GetAllActorsOfClass(world, ALight::StaticClass(), actors); for(i=0;i(actors[i]); - if(light) + //tweak directional lights + ADirectionalLight* directionallight = Cast(actors[i]); + if(directionallight) { - //disable all lights shadows - light->SetCastShadows(false); - - //tweak directional lights - ADirectionalLight* directionallight = Cast(light); - if(directionallight) - { - directionallight->SetLightFunctionFadeDistance(LowLightFadeDistance); - } - - //disable point lights - APointLight* pointlight = Cast(light); - if(pointlight) - { - actors[i]->SetActorHiddenInGame(true); - } + directionallight->SetCastShadows(false); + directionallight->SetLightFunctionFadeDistance(LowLightFadeDistance); + continue; } - + //disable point lights + /* + APointLight* pointlight = Cast(actors[i]); + if(pointlight) + { + actors[i]->SetActorHiddenInGame(true); + } + */ + //disable any other type of light + actors[i]->SetActorHiddenInGame(true); } - + //Set all the roads the low quality material /*UGameplayStatics::GetAllActorsWithTag(world, FName("CARLA_ROAD"),actors); for(i=0; i RoadMaterials;