From d2f2c3c65059f4431af7a050ea3371699aa54e7c Mon Sep 17 00:00:00 2001 From: nsubiron Date: Mon, 15 Oct 2018 14:37:58 +0200 Subject: [PATCH] Use new quality level enum and uncrustify related files --- .../Source/Carla/Game/CarlaGameModeBase.cpp | 4 +- .../Carla/Sensor/SceneCaptureSensor.cpp | 4 +- .../Source/Carla/Settings/CarlaSettings.cpp | 102 +-- .../Source/Carla/Settings/CarlaSettings.h | 211 +++---- .../Carla/Settings/CarlaSettingsDelegate.cpp | 585 ++++++++++-------- .../Carla/Settings/CarlaSettingsDelegate.h | 76 +-- 6 files changed, 521 insertions(+), 461 deletions(-) mode change 100755 => 100644 Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp index 9b03e55c2..be0492895 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp @@ -104,7 +104,7 @@ void ACarlaGameModeBase::InitGame( if(CarlaSettingsDelegate!=nullptr) { //apply quality settings - CarlaSettingsDelegate->ApplyQualitySettingsLevelPostRestart(); + CarlaSettingsDelegate->ApplyQualityLevelPostRestart(); //assign settings delegate for every new actor from now on CarlaSettingsDelegate->RegisterSpawnHandler(world); @@ -159,7 +159,7 @@ void ACarlaGameModeBase::RestartPlayer(AController* NewPlayer) } if(CarlaSettingsDelegate != nullptr) { - CarlaSettingsDelegate->ApplyQualitySettingsLevelPreRestart(); + CarlaSettingsDelegate->ApplyQualityLevelPreRestart(); } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.cpp index a2dacae84..ffd50270d 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.cpp @@ -31,7 +31,7 @@ namespace SceneCaptureSensor_local_ns { check(World != nullptr); const auto *GameInstance = Cast(World->GetGameInstance()); check(GameInstance != nullptr); - return GameInstance->GetCarlaSettings().GetQualitySettingsLevel(); + return GameInstance->GetCarlaSettings().GetQualityLevel(); } } // namespace SceneCaptureSensor_local_ns @@ -147,7 +147,7 @@ void ASceneCaptureSensor::BeginPlay() SetUpSceneCaptureComponent(*CaptureComponent2D); if (bEnablePostProcessingEffects && - (SceneCaptureSensor_local_ns::GetQualitySettings(GetWorld()) == EQualitySettingsLevel::Low)) + (SceneCaptureSensor_local_ns::GetQualitySettings(GetWorld()) == EQualityLevel::Low)) { CaptureComponent2D->CaptureSource = ESceneCaptureSource::SCS_SceneColorHDRNoAlpha; } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp old mode 100755 new mode 100644 index 5f5371dfa..cf9476a24 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.cpp @@ -20,10 +20,10 @@ #include "Materials/MaterialInstance.h" // INI file sections. -#define S_CARLA_SERVER TEXT("CARLA/Server") -#define S_CARLA_LEVELSETTINGS TEXT("CARLA/LevelSettings") -#define S_CARLA_SENSOR TEXT("CARLA/Sensor") -#define S_CARLA_QUALITYSETTINGS TEXT("CARLA/QualitySettings") +#define S_CARLA_SERVER TEXT("CARLA/Server") +#define S_CARLA_LEVELSETTINGS TEXT("CARLA/LevelSettings") +#define S_CARLA_SENSOR TEXT("CARLA/Sensor") +#define S_CARLA_QUALITYSETTINGS TEXT("CARLA/QualitySettings") // ============================================================================= // -- Static variables & constants --------------------------------------------- @@ -44,7 +44,8 @@ static void ForEachSectionInName(const FString &SensorName, T &&Callback) check(SubSections.Num() > 0); FString Section = S_CARLA_SENSOR; Callback(Section); - for (FString &SubSection : SubSections) { + for (FString &SubSection : SubSections) + { Section += TEXT("/"); Section += SubSection; Callback(Section); @@ -56,19 +57,43 @@ static FString GetSensorType( const FString &SensorName) { FString SensorType; - ForEachSectionInName(SensorName, [&](const auto &Section){ + ForEachSectionInName(SensorName, [&](const auto &Section) { ConfigFile.GetString(*Section, TEXT("SensorType"), SensorType); }); return SensorType; } +static EQualityLevel QualityLevelFromString(const FString &SQualitySettingsLevel) +{ + if (SQualitySettingsLevel.Equals("Low")) + { + return EQualityLevel::Low; + } + if (SQualitySettingsLevel.Equals("Epic")) + { + return EQualityLevel::Epic; + } + return EQualityLevel::INVALID; +} + +FString QualityLevelToString(EQualityLevel QualitySettingsLevel) +{ + const UEnum *ptr = FindObject(ANY_PACKAGE, TEXT("EQualityLevel"), true); + if (!ptr) + { + return FString("Invalid"); + } + return ptr->GetNameStringByIndex(static_cast(QualitySettingsLevel)); +} + static void LoadSettingsFromConfig( const FIniFile &ConfigFile, UCarlaSettings &Settings, const bool bLoadCarlaServerSection) { // CarlaServer. - if (bLoadCarlaServerSection) { + if (bLoadCarlaServerSection) + { ConfigFile.GetBool(S_CARLA_SERVER, TEXT("UseNetworking"), Settings.bUseNetworking); ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WorldPort"), Settings.WorldPort); ConfigFile.GetInt(S_CARLA_SERVER, TEXT("ServerTimeOut"), Settings.ServerTimeOut); @@ -83,18 +108,22 @@ static void LoadSettingsFromConfig( ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("WeatherId"), Settings.WeatherId); ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("SeedVehicles"), Settings.SeedVehicles); ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("SeedPedestrians"), Settings.SeedPedestrians); - ConfigFile.GetBool(S_CARLA_LEVELSETTINGS, TEXT("DisableTwoWheeledVehicles"), Settings.bDisableTwoWheeledVehicles); + ConfigFile.GetBool(S_CARLA_LEVELSETTINGS, + TEXT("DisableTwoWheeledVehicles"), + Settings.bDisableTwoWheeledVehicles); // QualitySettings. FString sQualityLevel; ConfigFile.GetString(S_CARLA_QUALITYSETTINGS, TEXT("QualityLevel"), sQualityLevel); - Settings.SetQualitySettingsLevel(UQualitySettings::FromString(sQualityLevel)); + Settings.SetQualityLevel(QualityLevelFromString(sQualityLevel)); } static bool GetSettingsFilePathFromCommandLine(FString &Value) { - if (FParse::Value(FCommandLine::Get(), TEXT("-carla-settings="), Value)) { - if (FPaths::IsRelative(Value)) { + if (FParse::Value(FCommandLine::Get(), TEXT("-carla-settings="), Value)) + { + if (FPaths::IsRelative(Value)) + { Value = FPaths::ConvertRelativePathToFull(FPaths::LaunchDir(), Value); return true; } @@ -106,29 +135,6 @@ static bool GetSettingsFilePathFromCommandLine(FString &Value) // -- UCarlaSettings ----------------------------------------------------------- // ============================================================================= -EQualitySettingsLevel UQualitySettings::FromString(const FString& SQualitySettingsLevel) -{ - if(SQualitySettingsLevel.Equals("Low")) return EQualitySettingsLevel::Low; - if(SQualitySettingsLevel.Equals("Medium")) return EQualitySettingsLevel::Medium; - if(SQualitySettingsLevel.Equals("High")) return EQualitySettingsLevel::High; - if(SQualitySettingsLevel.Equals("Epic")) return EQualitySettingsLevel::Epic; - - return EQualitySettingsLevel::None; -} - -FString UQualitySettings::ToString(EQualitySettingsLevel QualitySettingsLevel) -{ - const UEnum* ptr = FindObject(ANY_PACKAGE, TEXT("EQualitySettingsLevel"), true); - if(!ptr) - return FString("Invalid"); - return ptr->GetNameStringByIndex(static_cast(QualitySettingsLevel)); -} - -void UCarlaSettings::SetQualitySettingsLevel(EQualitySettingsLevel newQualityLevel) -{ - QualitySettingsLevel = newQualityLevel; -} - void UCarlaSettings::LoadSettings() { CurrentFileName = TEXT(""); @@ -182,7 +188,8 @@ void UCarlaSettings::LoadWeatherDescriptions() void UCarlaSettings::ValidateWeatherId() { - if (WeatherId >= WeatherDescriptions.Num()) { + if (WeatherId >= WeatherDescriptions.Num()) + { UE_LOG(LogCarla, Error, TEXT("Provided weather id %d cannot be found"), WeatherId); WeatherId = -1; } @@ -191,7 +198,8 @@ void UCarlaSettings::ValidateWeatherId() void UCarlaSettings::LogSettings() const { auto EnabledDisabled = [](bool bValue) { return (bValue ? TEXT("Enabled") : TEXT("Disabled")); }; - UE_LOG(LogCarla, Log, TEXT("== CARLA Settings ==============================================================")); + UE_LOG(LogCarla, Log, + TEXT("== CARLA Settings ==============================================================")); UE_LOG(LogCarla, Log, TEXT("Last settings file loaded: %s"), *CurrentFileName); UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_SERVER); UE_LOG(LogCarla, Log, TEXT("Networking = %s"), EnabledDisabled(bUseNetworking)); @@ -201,7 +209,8 @@ void UCarlaSettings::LogSettings() const UE_LOG(LogCarla, Log, TEXT("Send Non-Player Agents Info = %s"), EnabledDisabled(bSendNonPlayerAgentsInfo)); UE_LOG(LogCarla, Log, TEXT("Rendering = %s"), EnabledDisabled(!bDisableRendering)); UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_LEVELSETTINGS); - UE_LOG(LogCarla, Log, TEXT("Player Vehicle = %s"), (PlayerVehicle.IsEmpty() ? TEXT("Default") : *PlayerVehicle)); + UE_LOG(LogCarla, Log, TEXT("Player Vehicle = %s"), + (PlayerVehicle.IsEmpty() ? TEXT("Default") : *PlayerVehicle)); UE_LOG(LogCarla, Log, TEXT("Number Of Vehicles = %d"), NumberOfVehicles); UE_LOG(LogCarla, Log, TEXT("Number Of Pedestrians = %d"), NumberOfPedestrians); UE_LOG(LogCarla, Log, TEXT("Weather Id = %d"), WeatherId); @@ -214,11 +223,12 @@ void UCarlaSettings::LogSettings() const UE_LOG(LogCarla, Log, TEXT(" * %d - %s"), i, *WeatherDescriptions[i].Name); } UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_QUALITYSETTINGS); - UE_LOG(LogCarla, Log, TEXT("Quality Settings = %s"), *UQualitySettings::ToString(QualitySettingsLevel)); + UE_LOG(LogCarla, Log, TEXT("Quality Level = %s"), *QualityLevelToString(QualityLevel)); UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_SENSOR); UE_LOG(LogCarla, Log, TEXT("Semantic Segmentation = %s"), EnabledDisabled(bSemanticSegmentationEnabled)); - UE_LOG(LogCarla, Log, TEXT("================================================================================")); + UE_LOG(LogCarla, Log, + TEXT("================================================================================")); } #undef S_CARLA_SERVER @@ -230,10 +240,13 @@ void UCarlaSettings::GetActiveWeatherDescription( FWeatherDescription &WeatherDescription) const { auto WeatherPtr = GetActiveWeatherDescription(); - if (WeatherPtr != nullptr) { + if (WeatherPtr != nullptr) + { WeatherDescription = *WeatherPtr; bWeatherWasChanged = true; - } else { + } + else + { bWeatherWasChanged = false; } } @@ -247,13 +260,16 @@ const FWeatherDescription &UCarlaSettings::GetWeatherDescriptionByIndex(int32 In void UCarlaSettings::LoadSettingsFromFile(const FString &FilePath, const bool bLogOnFailure) { - if (FPaths::FileExists(FilePath)) { + if (FPaths::FileExists(FilePath)) + { UE_LOG(LogCarla, Log, TEXT("Loading CARLA settings from \"%s\""), *FilePath); const FIniFile ConfigFile(FilePath); constexpr bool bLoadCarlaServerSection = true; LoadSettingsFromConfig(ConfigFile, *this, bLoadCarlaServerSection); CurrentFileName = FilePath; - } else if (bLogOnFailure) { + } + else if (bLogOnFailure) + { UE_LOG(LogCarla, Error, TEXT("Unable to find settings file \"%s\""), *FilePath); } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.h index 1259818dd..42a1cea6d 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettings.h @@ -5,44 +5,19 @@ // For a copy, see . #pragma once + #include "Engine/StaticMesh.h" -#include "WeatherDescription.h" + +#include "Carla/Settings/QualityLevel.h" +#include "Carla/Settings/WeatherDescription.h" + #include "CarlaSettings.generated.h" -UENUM(BlueprintType) -enum class EQualitySettingsLevel : uint8 -{ - None UMETA(DisplayName = "Not set"), - Low UMETA(DisplayName = "Low"), - Medium UMETA(DisplayName = "Medium"), - High UMETA(DisplayName = "High"), - Epic UMETA(DisplayName = "Epic") -}; - -UCLASS(BlueprintType) -class CARLA_API UQualitySettings : public UObject -{ - GENERATED_BODY() - -public: - - using uint_type = typename std::underlying_type::type; - UFUNCTION(BlueprintCallable) - static EQualitySettingsLevel FromString(const FString &SQualitySettingsLevel); - UFUNCTION(BlueprintCallable) - static FString ToString(EQualitySettingsLevel QualitySettingsLevel); - - static constexpr uint_type ToUInt(EQualitySettingsLevel quality_settings_level) - { - return static_cast(quality_settings_level); - } -}; - -/** Global settings for CARLA. - * Setting object used to hold both config settings and editable ones in one place - * To ensure the settings are saved to the specified config file make sure to add - * props using the globalconfig or config meta. - */ +/// Global settings for CARLA. +/// +/// Setting object used to hold both config settings and editable ones in one +/// place. To ensure the settings are saved to the specified config file make +/// sure to add props using the globalconfig or config meta. UCLASS(BlueprintType, Blueprintable, config = Game, defaultconfig) class CARLA_API UCarlaSettings : public UObject { @@ -50,44 +25,54 @@ class CARLA_API UCarlaSettings : public UObject public: - /** - * Sets the new quality settings level and make changes in the game related to it. - * @note This will not apply the quality settings. Use ApplyQualitySettings functions instead - * @param newQualityLevel Store the new quality - */ - UFUNCTION(BlueprintCallable, Category="CARLA Settings") - void SetQualitySettingsLevel(EQualitySettingsLevel newQualityLevel); + /// Sets the new quality settings level and make changes in the game related + /// to it. + /// + /// @note This will not apply the quality settings. Use ApplyQualitySettings + /// functions instead + /// @param InQualityLevel Store the new quality. + UFUNCTION(BlueprintCallable, Category = "CARLA Settings") + void SetQualityLevel(EQualityLevel InQualityLevel) + { + QualityLevel = InQualityLevel; + } - /** @return current quality settings level (could not be applied yet) */ - UFUNCTION(BlueprintCallable, Category="CARLA Settings") - EQualitySettingsLevel GetQualitySettingsLevel() const { return QualitySettingsLevel; } + /// @return current quality settings level (could not have been applied yet). + UFUNCTION(BlueprintCallable, Category = "CARLA Settings") + EQualityLevel GetQualityLevel() const + { + return QualityLevel; + } - /** Load the settings based on the command-line arguments and the INI file if provided. */ + /// Load the settings based on the command-line arguments and the INI file if + /// provided. void LoadSettings(); - /** Load the settings from the given string (formatted as INI). CarlaServer section is ignored. */ + /// Load the settings from the given string (formatted as INI). CarlaServer + /// section is ignored. void LoadSettingsFromString(const FString &INIFileContents); - /** Load weather description from config files. (There may be overrides for each map). */ + /// Load weather description from config files. (There may be overrides for + /// each map). void LoadWeatherDescriptions(); - /** Check if requested weather id is present in WeatherDescriptions. */ + /// Check if requested weather id is present in WeatherDescriptions. void ValidateWeatherId(); - /** Log settings values. */ + /// Log settings values. void LogSettings() const; const FWeatherDescription *GetActiveWeatherDescription() const { - if ((WeatherId >= 0) && (WeatherId < WeatherDescriptions.Num())) { + if ((WeatherId >= 0) && (WeatherId < WeatherDescriptions.Num())) + { return &WeatherDescriptions[WeatherId]; } return nullptr; } - // Special overload for blueprints. - UFUNCTION(BlueprintCallable, Category="CARLA Settings") + UFUNCTION(BlueprintCallable, Category = "CARLA Settings") void GetActiveWeatherDescription( bool &bWeatherWasChanged, FWeatherDescription &WeatherDescription) const; @@ -95,56 +80,55 @@ public: UFUNCTION(BlueprintCallable) const FWeatherDescription &GetWeatherDescriptionByIndex(int32 Index); - ///----------- constants ------------------ + /// ----------- constants ------------------ + public: - /** - * CARLA_ROAD name to tag road mesh actors - */ + + /// CARLA_ROAD name to tag road mesh actors. static const FName CARLA_ROAD_TAG; - /** - * CARLA_SKY name to tag the sky sphere (BPS) actors in the scenes - */ + + /// CARLA_SKY name to tag the sky sphere (BPS) actors in the scenes. static const FName CARLA_SKY_TAG; private: - /***/ void LoadSettingsFromFile(const FString &FilePath, bool bLogOnFailure); - /** File name of the settings file used to load this settings. Empty if none used. */ + /// File name of the settings file used to load this settings. Empty if none + /// used. UPROPERTY(Category = "CARLA Settings|Debug", VisibleAnywhere) FString CurrentFileName; - // =========================================================================== /// @name CARLA Server // =========================================================================== /// @{ + public: - /** If active, wait for the client to connect and control the pawn. */ + /// If active, wait for the client to connect and control the pawn. UPROPERTY(Category = "CARLA Server", VisibleAnywhere) bool bUseNetworking = false; - /** World port to listen for client connections. */ + /// World port to listen for client connections. UPROPERTY(Category = "CARLA Server", VisibleAnywhere, meta = (EditCondition = bUseNetworking)) uint32 WorldPort = 2000u; - /** Time-out in milliseconds for the networking operations. */ + /// Time-out in milliseconds for the networking operations. UPROPERTY(Category = "CARLA Server", VisibleAnywhere, meta = (EditCondition = bUseNetworking)) uint32 ServerTimeOut = 10000u; - /** In synchronous mode, CARLA waits every tick until the control from the - * client is received. - */ + /// In synchronous mode, CARLA waits every tick until the control from the + /// client is received. UPROPERTY(Category = "CARLA Server", VisibleAnywhere, meta = (EditCondition = bUseNetworking)) bool bSynchronousMode = true; - /** Send info about every non-player agent in the scene every frame. */ + /// Send info about every non-player agent in the scene every frame. UPROPERTY(Category = "CARLA Server", VisibleAnywhere, meta = (EditCondition = bUseNetworking)) bool bSendNonPlayerAgentsInfo = false; - /** Enable or disable the viewport rendering of the world. Disabled by default */ + /// Enable or disable the viewport rendering of the world. Disabled by + /// default. UPROPERTY(Category = "CARLA Server", VisibleAnywhere) bool bDisableRendering = false; @@ -153,41 +137,43 @@ public: /// @name Level Settings // =========================================================================== /// @{ + public: - /** Display name of the current map. */ + /// Display name of the current map. UPROPERTY(Category = "Level Settings", VisibleAnywhere) FString MapName; - /** Path to the pawn class of the player. */ + /// Path to the pawn class of the player. UPROPERTY(Category = "Level Settings", VisibleAnywhere) FString PlayerVehicle; - /** Number of NPC vehicles to be spawned into the level. */ + /// Number of NPC vehicles to be spawned into the level. UPROPERTY(Category = "Level Settings", VisibleAnywhere) uint32 NumberOfVehicles = 5u; - /** Number of NPC pedestrians to be spawned into the level. */ + /// Number of NPC pedestrians to be spawned into the level. UPROPERTY(Category = "Level Settings", VisibleAnywhere) uint32 NumberOfPedestrians = 15u; - /** Index of the weather setting to use. If negative, weather won't be changed. */ + /// Index of the weather setting to use. If negative, weather won't be + /// changed. UPROPERTY(Category = "Level Settings", VisibleAnywhere) int32 WeatherId = -1; - /** Available weather settings. */ + /// Available weather settings. UPROPERTY(Category = "Level Settings", VisibleAnywhere) TArray WeatherDescriptions; - /** Random seed for the pedestrian spawner. */ + /// Random seed for the pedestrian spawner. UPROPERTY(Category = "Level Settings", VisibleAnywhere) int32 SeedPedestrians = 123456789; - /** Random seed for the vehicle spawner. */ + /// Random seed for the vehicle spawner. UPROPERTY(Category = "Level Settings", VisibleAnywhere) int32 SeedVehicles = 123456789; - /** Disable bikes and motorbikes. */ + /// Disable bikes and motorbikes. UPROPERTY(Category = "Level Settings", BlueprintReadOnly, VisibleAnywhere) bool bDisableTwoWheeledVehicles = false; @@ -197,47 +183,50 @@ public: /// @name Quality Settings // =========================================================================== /// @{ + private: - /** Quality Settings level. */ - UPROPERTY(Category = "Quality Settings", VisibleAnywhere, meta =(AllowPrivateAccess="true")) - EQualitySettingsLevel QualitySettingsLevel = EQualitySettingsLevel::Epic; + /// Quality Settings level. + UPROPERTY(Category = "Quality Settings", VisibleAnywhere, meta = (AllowPrivateAccess = "true")) + EQualityLevel QualityLevel = EQualityLevel::Epic; public: - /** @TODO : Move Low quality vars to a generic map of structs with the quality level as key*/ - - /** Low quality Road Materials. - * Uses slots name to set material for each part of the road for low quality - */ - UPROPERTY(Category = "Quality Settings/Low", BlueprintReadOnly, EditAnywhere, config, DisplayName="Road Materials List for Low Quality") + /// Low quality Road Materials. Uses slots name to set material for each part + /// of the road for low quality. + /// + /// @todo Move Low quality vars to a generic map of structs with the quality + /// level as key. + UPROPERTY(Category = "Quality Settings/Low", + BlueprintReadOnly, + EditAnywhere, + config, + DisplayName = "Road Materials List for Low Quality") TArray LowRoadMaterials; - //distances - /** - * Distance at which the light function should be completely faded to DisabledBrightness. - * This is useful for hiding aliasing from light functions applied in the distance. - */ + /// Distance at which the light function should be completely faded to + /// DisabledBrightness. This is useful for hiding aliasing from light + /// functions applied in the distance. UPROPERTY(Category = "Quality Settings/Low", BlueprintReadOnly, EditAnywhere, config) float LowLightFadeDistance = 1000.0f; - /** - * Default low distance for all primitive components - */ - UPROPERTY(Category = "Quality Settings/Low", BlueprintReadOnly, EditAnywhere, config, meta = (ClampMin = "5000.0", ClampMax = "20000.0", UIMin = "5000.0", UIMax = "20000.0")) + /// Default low distance for all primitive components. + UPROPERTY(Category = "Quality Settings/Low", BlueprintReadOnly, EditAnywhere, config, + meta = (ClampMin = "5000.0", ClampMax = "20000.0", UIMin = "5000.0", UIMax = "20000.0")) float LowStaticMeshMaxDrawDistance = 10000.0f; - /** - * Default low distance for roads meshes - */ - UPROPERTY(Category = "Quality Settings/Low", BlueprintReadOnly, EditAnywhere, config, meta = (ClampMin = "5000.0", ClampMax = "20000.0", UIMin = "5000.0", UIMax = "20000.0")) + /// Default low distance for roads meshes. + UPROPERTY(Category = "Quality Settings/Low", BlueprintReadOnly, EditAnywhere, config, + meta = (ClampMin = "5000.0", ClampMax = "20000.0", UIMin = "5000.0", UIMax = "20000.0")) float LowRoadPieceMeshMaxDrawDistance = 15000.0f; - - /** EPIC quality Road Materials. - * Uses slots name to set material for each part of the road for Epic quality - */ - UPROPERTY(Category = "Quality Settings/Epic", BlueprintReadOnly, EditAnywhere, config, DisplayName="Road Materials List for EPIC Quality") + /// EPIC quality Road Materials. Uses slots name to set material for each part + /// of the road for Epic quality. + UPROPERTY(Category = "Quality Settings/Epic", + BlueprintReadOnly, + EditAnywhere, + config, + DisplayName = "Road Materials List for EPIC Quality") TArray EpicRoadMaterials; /// @} @@ -246,12 +235,12 @@ public: /// @name Sensors // =========================================================================== /// @{ + public: - /** Whether semantic segmentation should be activated. The mechanisms for - * semantic segmentation impose some performance penalties even if it is not - * used, we only enable it if necessary. - */ + /// Whether semantic segmentation should be activated. The mechanisms for + /// semantic segmentation impose some performance penalties even if it is not + /// used, we only enable it if necessary. UPROPERTY(Category = "Sensors", BlueprintReadOnly, VisibleAnywhere) bool bSemanticSegmentationEnabled = true; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.cpp index 236a5b03b..94c103daf 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.cpp @@ -15,17 +15,19 @@ #include "Engine/LocalPlayer.h" #include "GameFramework/HUD.h" -///quality settings configuration between runs -EQualitySettingsLevel UCarlaSettingsDelegate::AppliedLowPostResetQualitySettingsLevel = EQualitySettingsLevel::Epic; +static constexpr float CARLA_SETTINGS_MAX_SCALE_SIZE = 50.0f; -UCarlaSettingsDelegate::UCarlaSettingsDelegate() : - ActorSpawnedDelegate(FOnActorSpawned::FDelegate::CreateUObject(this, &UCarlaSettingsDelegate::OnActorSpawned)) -{ -} +/// quality settings configuration between runs +EQualityLevel UCarlaSettingsDelegate::AppliedLowPostResetQualityLevel = EQualityLevel::Epic; + +UCarlaSettingsDelegate::UCarlaSettingsDelegate() + : ActorSpawnedDelegate(FOnActorSpawned::FDelegate::CreateUObject( + this, + &UCarlaSettingsDelegate::OnActorSpawned)) {} void UCarlaSettingsDelegate::Reset() { - AppliedLowPostResetQualitySettingsLevel = EQualitySettingsLevel::None; + AppliedLowPostResetQualityLevel = EQualityLevel::Epic; } void UCarlaSettingsDelegate::RegisterSpawnHandler(UWorld *InWorld) @@ -34,265 +36,295 @@ void UCarlaSettingsDelegate::RegisterSpawnHandler(UWorld *InWorld) InWorld->AddOnActorSpawnedHandler(ActorSpawnedDelegate); } -void UCarlaSettingsDelegate::OnActorSpawned(AActor* InActor) +void UCarlaSettingsDelegate::OnActorSpawned(AActor *InActor) { - check(CarlaSettings!=nullptr); + check(CarlaSettings != nullptr); if (InActor != nullptr && IsValid(InActor) && !InActor->IsPendingKill() && - !InActor->IsA() && //foliage culling is controlled per instance - !InActor->IsA() && //dont touch landscapes nor roads - !InActor->ActorHasTag(UCarlaSettings::CARLA_ROAD_TAG) && - !InActor->ActorHasTag(UCarlaSettings::CARLA_SKY_TAG) - ){ - TArray components = InActor->GetComponentsByClass(UPrimitiveComponent::StaticClass()); - switch(CarlaSettings->GetQualitySettingsLevel()) - { - case EQualitySettingsLevel::Low:{ - //apply settings for this actor for the current quality level - #define _MAX_SCALE_SIZE 50.0f - float dist = CarlaSettings->LowStaticMeshMaxDrawDistance; - const float maxscale = InActor->GetActorScale().GetMax(); - if(maxscale>_MAX_SCALE_SIZE) { - dist *= 100.0f; - } - SetActorComponentsDrawDistance(InActor, dist); - break; - } - default: break; - } + !InActor->IsA() && // foliage culling is + // controlled per instance + !InActor->IsA() && // dont touch landscapes nor roads + !InActor->ActorHasTag(UCarlaSettings::CARLA_ROAD_TAG) && + !InActor->ActorHasTag(UCarlaSettings::CARLA_SKY_TAG)) + { + TArray components = InActor->GetComponentsByClass(UPrimitiveComponent::StaticClass()); + switch (CarlaSettings->GetQualityLevel()) + { + case EQualityLevel::Low: { + // apply settings for this actor for the current quality level + float dist = CarlaSettings->LowStaticMeshMaxDrawDistance; + const float maxscale = InActor->GetActorScale().GetMax(); + if (maxscale > CARLA_SETTINGS_MAX_SCALE_SIZE) + { + dist *= 100.0f; + } + SetActorComponentsDrawDistance(InActor, dist); + break; + } + default: break; + } } } - -void UCarlaSettingsDelegate::ApplyQualitySettingsLevelPostRestart() +void UCarlaSettingsDelegate::ApplyQualityLevelPostRestart() { - CheckCarlaSettings(nullptr); - UWorld *InWorld = CarlaSettings->GetWorld(); - - const EQualitySettingsLevel QualitySettingsLevel = CarlaSettings->GetQualitySettingsLevel(); - if(AppliedLowPostResetQualitySettingsLevel==QualitySettingsLevel) return; - - switch(QualitySettingsLevel) - { - case EQualitySettingsLevel::Low: - { - //execute tweaks for quality - LaunchLowQualityCommands(InWorld); - //iterate all directional lights, deactivate shadows - SetAllLights(InWorld,CarlaSettings->LowLightFadeDistance,false,true); - //Set all the roads the low quality materials - SetAllRoads(InWorld, CarlaSettings->LowRoadPieceMeshMaxDrawDistance, CarlaSettings->LowRoadMaterials); - //Set all actors with static meshes a max disntace configured in the global settings for the low quality - SetAllActorsDrawDistance(InWorld, CarlaSettings->LowStaticMeshMaxDrawDistance); - //Disable all post process volumes - SetPostProcessEffectsEnabled(InWorld, false); - } - break; - case EQualitySettingsLevel::Medium: - UE_LOG(LogCarla, Warning, TEXT("Medium Quality Settings level is not implemented yet and will have no effect.")); - break; - case EQualitySettingsLevel::High: - UE_LOG(LogCarla, Warning, TEXT("High Quality Settings level is not implemented yet and will have no effect.")); - break; - case EQualitySettingsLevel::None: - /** No changes */ - UE_LOG(LogCarla, Warning, TEXT("No Quality Settings level set. No changes applied.")); - break; - default: case EQualitySettingsLevel::Epic: - { - LaunchEpicQualityCommands(InWorld); - SetAllLights(InWorld,0.0f,true,false); - SetAllRoads(InWorld, 0, CarlaSettings->EpicRoadMaterials); - SetAllActorsDrawDistance(InWorld, 0); - SetPostProcessEffectsEnabled(InWorld,true); - } - break; - } - AppliedLowPostResetQualitySettingsLevel = QualitySettingsLevel; + CheckCarlaSettings(nullptr); + UWorld *InWorld = CarlaSettings->GetWorld(); + + const EQualityLevel QualityLevel = CarlaSettings->GetQualityLevel(); + if (AppliedLowPostResetQualityLevel == QualityLevel) + { + return; + } + + switch (QualityLevel) + { + case EQualityLevel::Low: + { + // execute tweaks for quality + LaunchLowQualityCommands(InWorld); + // iterate all directional lights, deactivate shadows + SetAllLights(InWorld, CarlaSettings->LowLightFadeDistance, false, true); + // Set all the roads the low quality materials + SetAllRoads(InWorld, CarlaSettings->LowRoadPieceMeshMaxDrawDistance, CarlaSettings->LowRoadMaterials); + // Set all actors with static meshes a max disntace configured in the + // global settings for the low quality + SetAllActorsDrawDistance(InWorld, CarlaSettings->LowStaticMeshMaxDrawDistance); + // Disable all post process volumes + SetPostProcessEffectsEnabled(InWorld, false); + break; + } + default: + UE_LOG(LogCarla, Warning, TEXT("Unknown quality level, falling back to default.")); + case EQualityLevel::Epic: + { + LaunchEpicQualityCommands(InWorld); + SetAllLights(InWorld, 0.0f, true, false); + SetAllRoads(InWorld, 0, CarlaSettings->EpicRoadMaterials); + SetAllActorsDrawDistance(InWorld, 0); + SetPostProcessEffectsEnabled(InWorld, true); + break; + } + } + AppliedLowPostResetQualityLevel = QualityLevel; } -void UCarlaSettingsDelegate::ApplyQualitySettingsLevelPreRestart() +void UCarlaSettingsDelegate::ApplyQualityLevelPreRestart() { - CheckCarlaSettings(nullptr); + CheckCarlaSettings(nullptr); UWorld *InWorld = CarlaSettings->GetWorld(); - if(!IsValid(InWorld)||InWorld->IsPendingKill()) return; - //enable or disable world and hud rendering - APlayerController* playercontroller = UGameplayStatics::GetPlayerController(InWorld,0); - if(playercontroller) + if (!IsValid(InWorld) || InWorld->IsPendingKill()) { - ULocalPlayer* player = playercontroller->GetLocalPlayer(); - if(player) + return; + } + // enable or disable world and hud rendering + APlayerController *playercontroller = UGameplayStatics::GetPlayerController(InWorld, 0); + if (playercontroller) + { + ULocalPlayer *player = playercontroller->GetLocalPlayer(); + if (player) { player->ViewportClient->bDisableWorldRendering = CarlaSettings->bDisableRendering; } - //if we already have a hud class: - AHUD* hud = playercontroller->GetHUD(); - if(hud) + // if we already have a hud class: + AHUD *hud = playercontroller->GetHUD(); + if (hud) { hud->bShowHUD = !CarlaSettings->bDisableRendering; } - //toggle hud: @TODO: find a better solution - /*if(CarlaSettings->bDisableRendering) - { - GEngine->Exec(InWorld,TEXT("showhud")); - }*/ } - + } -UWorld* UCarlaSettingsDelegate::GetLocalWorld() +UWorld *UCarlaSettingsDelegate::GetLocalWorld() { - return GEngine->GetWorldFromContextObjectChecked(this); + return GEngine->GetWorldFromContextObjectChecked(this); } - -void UCarlaSettingsDelegate::CheckCarlaSettings(UWorld* world) +void UCarlaSettingsDelegate::CheckCarlaSettings(UWorld *world) { - if(IsValid(CarlaSettings)) return; - if(world==nullptr||!IsValid(world)||world->IsPendingKill()) world = GetLocalWorld(); - check(world!=nullptr); + if (IsValid(CarlaSettings)) + { + return; + } + if (world == nullptr || !IsValid(world) || world->IsPendingKill()) + { + world = GetLocalWorld(); + } + check(world != nullptr); auto GameInstance = Cast(world->GetGameInstance()); - check(GameInstance!=nullptr); + check(GameInstance != nullptr); CarlaSettings = &GameInstance->GetCarlaSettings(); - check(CarlaSettings!=nullptr); + check(CarlaSettings != nullptr); } -void UCarlaSettingsDelegate::LaunchLowQualityCommands(UWorld * world) const +void UCarlaSettingsDelegate::LaunchLowQualityCommands(UWorld *world) const { - //launch commands to lower quality settings - GEngine->Exec(world,TEXT("r.DefaultFeature.MotionBlur 0")); - GEngine->Exec(world,TEXT("r.DefaultFeature.Bloom 0")); - GEngine->Exec(world,TEXT("r.DefaultFeature.AmbientOcclusion 0")); - GEngine->Exec(world,TEXT("r.AmbientOcclusionLevels 0")); - GEngine->Exec(world,TEXT("r.DefaultFeature.AmbientOcclusionStaticFraction 0")); - GEngine->Exec(world,TEXT("r.DefaultFeature.AutoExposure 0")); - GEngine->Exec(world,TEXT("r.RHICmdBypass 0")); - GEngine->Exec(world,TEXT("r.DefaultFeature.AntiAliasing 2")); - GEngine->Exec(world,TEXT("r.Streaming.PoolSize 2000")); - GEngine->Exec(world,TEXT("r.HZBOcclusion 0")); - GEngine->Exec(world,TEXT("r.MinScreenRadiusForLights 0.01")); - GEngine->Exec(world,TEXT("r.SeparateTranslucency 0")); - GEngine->Exec(world,TEXT("r.FinishCurrentFrame 0")); - GEngine->Exec(world,TEXT("r.MotionBlurQuality 0")); - GEngine->Exec(world,TEXT("r.PostProcessAAQuality 0")); - GEngine->Exec(world,TEXT("r.BloomQuality 1")); - GEngine->Exec(world,TEXT("r.SSR.Quality 0")); - GEngine->Exec(world,TEXT("r.DepthOfFieldQuality 0")); - GEngine->Exec(world,TEXT("r.SceneColorFormat 2")); - GEngine->Exec(world,TEXT("r.TranslucencyVolumeBlur 0")); - GEngine->Exec(world,TEXT("r.TranslucencyLightingVolumeDim 4")); - GEngine->Exec(world,TEXT("r.MaxAnisotropy 8")); - GEngine->Exec(world,TEXT("r.LensFlareQuality 0")); - GEngine->Exec(world,TEXT("r.SceneColorFringeQuality 0")); - GEngine->Exec(world,TEXT("r.FastBlurThreshold 0")); - GEngine->Exec(world,TEXT("r.SSR.MaxRoughness 0.1")); - GEngine->Exec(world,TEXT("r.AllowOcclusionQueries 1")); - GEngine->Exec(world,TEXT("r.SSR 0")); - //GEngine->Exec(world,TEXT("r.StencilForLODDither 1")); //readonly - GEngine->Exec(world,TEXT("r.EarlyZPass 2")); //transparent before opaque - GEngine->Exec(world,TEXT("r.EarlyZPassMovable 1")); - GEngine->Exec(world,TEXT("Foliage.DitheredLOD 0")); - //GEngine->Exec(world,TEXT("r.ForwardShading 0")); //readonly - GEngine->Exec(world,TEXT("sg.PostProcessQuality 0")); - //GEngine->Exec(world,TEXT("r.ViewDistanceScale 0.1")); //--> too extreme (far clip too short) - GEngine->Exec(world,TEXT("sg.ShadowQuality 0")); - GEngine->Exec(world,TEXT("sg.TextureQuality 0")); - GEngine->Exec(world,TEXT("sg.EffectsQuality 0")); - GEngine->Exec(world,TEXT("sg.FoliageQuality 0")); - GEngine->Exec(world,TEXT("foliage.DensityScale 0")); - GEngine->Exec(world,TEXT("grass.DensityScale 0")); - GEngine->Exec(world,TEXT("r.TranslucentLightingVolume 0")); - GEngine->Exec(world,TEXT("r.LightShaftDownSampleFactor 4")); - GEngine->Exec(world,TEXT("r.OcclusionQueryLocation 1")); - //GEngine->Exec(world,TEXT("r.BasePassOutputsVelocity 0")); //--> readonly - //GEngine->Exec(world,TEXT("r.DetailMode 0")); //-->will change to lods 0 + // launch commands to lower quality settings + GEngine->Exec(world, TEXT("r.DefaultFeature.MotionBlur 0")); + GEngine->Exec(world, TEXT("r.DefaultFeature.Bloom 0")); + GEngine->Exec(world, TEXT("r.DefaultFeature.AmbientOcclusion 0")); + GEngine->Exec(world, TEXT("r.AmbientOcclusionLevels 0")); + GEngine->Exec(world, TEXT("r.DefaultFeature.AmbientOcclusionStaticFraction 0")); + GEngine->Exec(world, TEXT("r.DefaultFeature.AutoExposure 0")); + GEngine->Exec(world, TEXT("r.RHICmdBypass 0")); + GEngine->Exec(world, TEXT("r.DefaultFeature.AntiAliasing 2")); + GEngine->Exec(world, TEXT("r.Streaming.PoolSize 2000")); + GEngine->Exec(world, TEXT("r.HZBOcclusion 0")); + GEngine->Exec(world, TEXT("r.MinScreenRadiusForLights 0.01")); + GEngine->Exec(world, TEXT("r.SeparateTranslucency 0")); + GEngine->Exec(world, TEXT("r.FinishCurrentFrame 0")); + GEngine->Exec(world, TEXT("r.MotionBlurQuality 0")); + GEngine->Exec(world, TEXT("r.PostProcessAAQuality 0")); + GEngine->Exec(world, TEXT("r.BloomQuality 1")); + GEngine->Exec(world, TEXT("r.SSR.Quality 0")); + GEngine->Exec(world, TEXT("r.DepthOfFieldQuality 0")); + GEngine->Exec(world, TEXT("r.SceneColorFormat 2")); + GEngine->Exec(world, TEXT("r.TranslucencyVolumeBlur 0")); + GEngine->Exec(world, TEXT("r.TranslucencyLightingVolumeDim 4")); + GEngine->Exec(world, TEXT("r.MaxAnisotropy 8")); + GEngine->Exec(world, TEXT("r.LensFlareQuality 0")); + GEngine->Exec(world, TEXT("r.SceneColorFringeQuality 0")); + GEngine->Exec(world, TEXT("r.FastBlurThreshold 0")); + GEngine->Exec(world, TEXT("r.SSR.MaxRoughness 0.1")); + GEngine->Exec(world, TEXT("r.AllowOcclusionQueries 1")); + GEngine->Exec(world, TEXT("r.SSR 0")); + // GEngine->Exec(world,TEXT("r.StencilForLODDither 1")); //readonly + GEngine->Exec(world, TEXT("r.EarlyZPass 2")); // transparent before opaque + GEngine->Exec(world, TEXT("r.EarlyZPassMovable 1")); + GEngine->Exec(world, TEXT("Foliage.DitheredLOD 0")); + // GEngine->Exec(world,TEXT("r.ForwardShading 0")); //readonly + GEngine->Exec(world, TEXT("sg.PostProcessQuality 0")); + // GEngine->Exec(world,TEXT("r.ViewDistanceScale 0.1")); //--> too extreme + // (far clip too short) + GEngine->Exec(world, TEXT("sg.ShadowQuality 0")); + GEngine->Exec(world, TEXT("sg.TextureQuality 0")); + GEngine->Exec(world, TEXT("sg.EffectsQuality 0")); + GEngine->Exec(world, TEXT("sg.FoliageQuality 0")); + GEngine->Exec(world, TEXT("foliage.DensityScale 0")); + GEngine->Exec(world, TEXT("grass.DensityScale 0")); + GEngine->Exec(world, TEXT("r.TranslucentLightingVolume 0")); + GEngine->Exec(world, TEXT("r.LightShaftDownSampleFactor 4")); + GEngine->Exec(world, TEXT("r.OcclusionQueryLocation 1")); + // GEngine->Exec(world,TEXT("r.BasePassOutputsVelocity 0")); //--> readonly + // GEngine->Exec(world,TEXT("r.DetailMode 0")); //-->will change to lods 0 } - -void UCarlaSettingsDelegate::SetAllRoads(UWorld* world, const float max_draw_distance, const TArray &road_pieces_materials) const +void UCarlaSettingsDelegate::SetAllRoads( + UWorld *world, + const float max_draw_distance, + const TArray &road_pieces_materials) const { - if(!world||!IsValid(world)||world->IsPendingKill()) return; - AsyncTask(ENamedThreads::GameThread, [=](){ - if(!world||!IsValid(world)||world->IsPendingKill()) return; - TArray actors; - UGameplayStatics::GetAllActorsWithTag(world, UCarlaSettings::CARLA_ROAD_TAG,actors); - - for(int32 i=0; iIsPendingKill()) + { + return; + } + AsyncTask(ENamedThreads::GameThread, [=]() { + if (!world || !IsValid(world) || world->IsPendingKill()) { - AActor* actor = actors[i]; - if(!IsValid(actor) || actor->IsPendingKill()) continue; - TArray components = actor->GetComponentsByClass(UStaticMeshComponent::StaticClass()); - for(int32 j=0; j actors; + UGameplayStatics::GetAllActorsWithTag(world, UCarlaSettings::CARLA_ROAD_TAG, actors); + + for (int32 i = 0; i < actors.Num(); i++) + { + AActor *actor = actors[i]; + if (!IsValid(actor) || actor->IsPendingKill()) { - UStaticMeshComponent* staticmeshcomponent = Cast(components[j]); - if(staticmeshcomponent) + continue; + } + TArray components = actor->GetComponentsByClass(UStaticMeshComponent::StaticClass()); + for (int32 j = 0; j < components.Num(); j++) + { + UStaticMeshComponent *staticmeshcomponent = Cast(components[j]); + if (staticmeshcomponent) { - staticmeshcomponent->bAllowCullDistanceVolume = (max_draw_distance>0); + staticmeshcomponent->bAllowCullDistanceVolume = (max_draw_distance > 0); staticmeshcomponent->bUseAsOccluder = false; - staticmeshcomponent->LDMaxDrawDistance = max_draw_distance; - staticmeshcomponent->CastShadow = (max_draw_distance==0); - if(road_pieces_materials.Num()>0) + staticmeshcomponent->LDMaxDrawDistance = max_draw_distance; + staticmeshcomponent->CastShadow = (max_draw_distance == 0); + if (road_pieces_materials.Num() > 0) { TArray meshslotsnames = staticmeshcomponent->GetMaterialSlotNames(); - for(int32 k=0; kSetMaterial( - staticmeshcomponent->GetMaterialIndex(slotname), - material.MaterialInterface - ); + staticmeshcomponent->GetMaterialIndex(slotname), + material.MaterialInterface); return true; - } else return false; + } + else + { + return false; + } }); } } } } } - }); //,DELAY_TIME_TO_SET_ALL_ROADS, false); + }); // ,DELAY_TIME_TO_SET_ALL_ROADS, false); } -void UCarlaSettingsDelegate::SetActorComponentsDrawDistance(AActor* actor, const float max_draw_distance) const +void UCarlaSettingsDelegate::SetActorComponentsDrawDistance( + AActor *actor, + const float max_draw_distance) const { - if(!actor) return; - TArray components = actor->GetComponentsByClass(UPrimitiveComponent::StaticClass()); - float dist = max_draw_distance; - const float maxscale = actor->GetActorScale().GetMax(); - if(maxscale>_MAX_SCALE_SIZE) dist *= 100.0f; - for(int32 j=0; j(components[j]); - if(IsValid(primitivecomponent)) + if (!actor) + { + return; + } + TArray components = actor->GetComponentsByClass(UPrimitiveComponent::StaticClass()); + float dist = max_draw_distance; + const float maxscale = actor->GetActorScale().GetMax(); + if (maxscale > CARLA_SETTINGS_MAX_SCALE_SIZE) + { + dist *= 100.0f; + } + for (int32 j = 0; j < components.Num(); j++) + { + UPrimitiveComponent *primitivecomponent = Cast(components[j]); + if (IsValid(primitivecomponent)) { primitivecomponent->SetCullDistance(dist); - primitivecomponent->bAllowCullDistanceVolume = dist>0; + primitivecomponent->bAllowCullDistanceVolume = dist > 0; } - } + } } -void UCarlaSettingsDelegate::SetAllActorsDrawDistance(UWorld* world, const float max_draw_distance) const +void UCarlaSettingsDelegate::SetAllActorsDrawDistance(UWorld *world, const float max_draw_distance) const { - ///@TODO: use semantics to grab all actors by type (vehicles,ground,people,props) and set different distances configured in the global properties - if(!world||!IsValid(world)||world->IsPendingKill()) return; - AsyncTask(ENamedThreads::GameThread, [=](){ - if(!world||!IsValid(world)||world->IsPendingKill()) return; - TArray actors; - #define _MAX_SCALE_SIZE 50.0f - //set the lower quality - max draw distance - UGameplayStatics::GetAllActorsOfClass(world, AActor::StaticClass(),actors); - for(int32 i=0; iIsPendingKill()) + { + return; + } + AsyncTask(ENamedThreads::GameThread, [=]() { + if (!world || !IsValid(world) || world->IsPendingKill()) { - AActor* actor = actors[i]; - if(!IsValid(actor) || actor->IsPendingKill() || - actor->IsA() || //foliage culling is controlled per instance - actor->IsA() || //dont touch landscapes nor roads - actor->ActorHasTag(UCarlaSettings::CARLA_ROAD_TAG) || - actor->ActorHasTag(UCarlaSettings::CARLA_SKY_TAG) - ){ + return; + } + TArray actors; + // set the lower quality - max draw distance + UGameplayStatics::GetAllActorsOfClass(world, AActor::StaticClass(), actors); + for (int32 i = 0; i < actors.Num(); i++) + { + AActor *actor = actors[i]; + if (!IsValid(actor) || actor->IsPendingKill() || + actor->IsA() || // foliage culling is controlled + // per instance + actor->IsA() || // dont touch landscapes nor roads + actor->ActorHasTag(UCarlaSettings::CARLA_ROAD_TAG) || + actor->ActorHasTag(UCarlaSettings::CARLA_SKY_TAG)) + { continue; } SetActorComponentsDrawDistance(actor, max_draw_distance); @@ -300,86 +332,103 @@ void UCarlaSettingsDelegate::SetAllActorsDrawDistance(UWorld* world, const float }); } - -void UCarlaSettingsDelegate::SetPostProcessEffectsEnabled(UWorld* world, const bool enabled) const +void UCarlaSettingsDelegate::SetPostProcessEffectsEnabled(UWorld *world, const bool enabled) const { - TArray actors; + TArray actors; UGameplayStatics::GetAllActorsOfClass(world, APostProcessVolume::StaticClass(), actors); - for(int32 i=0; iIsPendingKill()) continue; - APostProcessVolume* postprocessvolume = Cast(actor); - if(postprocessvolume) - { - postprocessvolume->bEnabled = enabled; - } + AActor *actor = actors[i]; + if (!IsValid(actor) || actor->IsPendingKill()) + { + continue; + } + APostProcessVolume *postprocessvolume = Cast(actor); + if (postprocessvolume) + { + postprocessvolume->bEnabled = enabled; + } } } - -void UCarlaSettingsDelegate::LaunchEpicQualityCommands(UWorld* world) const +void UCarlaSettingsDelegate::LaunchEpicQualityCommands(UWorld *world) const { - if(!world) return ; - GEngine->Exec(world,TEXT("r.AmbientOcclusionLevels -1")); - GEngine->Exec(world,TEXT("r.RHICmdBypass 1")); - GEngine->Exec(world,TEXT("r.DefaultFeature.AntiAliasing 2")); - GEngine->Exec(world,TEXT("r.Streaming.PoolSize 2000")); - GEngine->Exec(world,TEXT("r.MinScreenRadiusForLights 0.03")); - GEngine->Exec(world,TEXT("r.SeparateTranslucency 1")); - GEngine->Exec(world,TEXT("r.PostProcessAAQuality 4")); - GEngine->Exec(world,TEXT("r.BloomQuality 5")); - GEngine->Exec(world,TEXT("r.SSR.Quality 3")); - GEngine->Exec(world,TEXT("r.DepthOfFieldQuality 2")); - GEngine->Exec(world,TEXT("r.SceneColorFormat 4")); - GEngine->Exec(world,TEXT("r.TranslucencyVolumeBlur 1")); - GEngine->Exec(world,TEXT("r.TranslucencyLightingVolumeDim 64")); - GEngine->Exec(world,TEXT("r.MaxAnisotropy 8")); - GEngine->Exec(world,TEXT("r.LensFlareQuality 2")); - GEngine->Exec(world,TEXT("r.SceneColorFringeQuality 1")); - GEngine->Exec(world,TEXT("r.FastBlurThreshold 100")); - GEngine->Exec(world,TEXT("r.SSR.MaxRoughness -1")); - //GEngine->Exec(world,TEXT("r.StencilForLODDither 0")); //readonly - GEngine->Exec(world,TEXT("r.EarlyZPass 3")); - GEngine->Exec(world,TEXT("r.EarlyZPassMovable 1")); - GEngine->Exec(world,TEXT("Foliage.DitheredLOD 1")); - GEngine->Exec(world,TEXT("sg.PostProcessQuality 3")); - GEngine->Exec(world,TEXT("r.ViewDistanceScale 1")); //--> too extreme (far clip too short) - GEngine->Exec(world,TEXT("sg.ShadowQuality 3")); - GEngine->Exec(world,TEXT("sg.TextureQuality 3")); - GEngine->Exec(world,TEXT("sg.EffectsQuality 3")); - GEngine->Exec(world,TEXT("sg.FoliageQuality 3")); - GEngine->Exec(world,TEXT("foliage.DensityScale 1")); - GEngine->Exec(world,TEXT("grass.DensityScale 1")); - GEngine->Exec(world,TEXT("r.TranslucentLightingVolume 1")); - GEngine->Exec(world,TEXT("r.LightShaftDownSampleFactor 2")); - //GEngine->Exec(world,TEXT("r.OcclusionQueryLocation 0")); - //GEngine->Exec(world,TEXT("r.BasePassOutputsVelocity 0")); //readonly - GEngine->Exec(world,TEXT("r.DetailMode 2")); + if (!world) + { + return; + } + GEngine->Exec(world, TEXT("r.AmbientOcclusionLevels -1")); + GEngine->Exec(world, TEXT("r.RHICmdBypass 1")); + GEngine->Exec(world, TEXT("r.DefaultFeature.AntiAliasing 2")); + GEngine->Exec(world, TEXT("r.Streaming.PoolSize 2000")); + GEngine->Exec(world, TEXT("r.MinScreenRadiusForLights 0.03")); + GEngine->Exec(world, TEXT("r.SeparateTranslucency 1")); + GEngine->Exec(world, TEXT("r.PostProcessAAQuality 4")); + GEngine->Exec(world, TEXT("r.BloomQuality 5")); + GEngine->Exec(world, TEXT("r.SSR.Quality 3")); + GEngine->Exec(world, TEXT("r.DepthOfFieldQuality 2")); + GEngine->Exec(world, TEXT("r.SceneColorFormat 4")); + GEngine->Exec(world, TEXT("r.TranslucencyVolumeBlur 1")); + GEngine->Exec(world, TEXT("r.TranslucencyLightingVolumeDim 64")); + GEngine->Exec(world, TEXT("r.MaxAnisotropy 8")); + GEngine->Exec(world, TEXT("r.LensFlareQuality 2")); + GEngine->Exec(world, TEXT("r.SceneColorFringeQuality 1")); + GEngine->Exec(world, TEXT("r.FastBlurThreshold 100")); + GEngine->Exec(world, TEXT("r.SSR.MaxRoughness -1")); + // GEngine->Exec(world,TEXT("r.StencilForLODDither 0")); //readonly + GEngine->Exec(world, TEXT("r.EarlyZPass 3")); + GEngine->Exec(world, TEXT("r.EarlyZPassMovable 1")); + GEngine->Exec(world, TEXT("Foliage.DitheredLOD 1")); + GEngine->Exec(world, TEXT("sg.PostProcessQuality 3")); + GEngine->Exec(world, TEXT("r.ViewDistanceScale 1")); // --> too extreme (far + // clip too short) + GEngine->Exec(world, TEXT("sg.ShadowQuality 3")); + GEngine->Exec(world, TEXT("sg.TextureQuality 3")); + GEngine->Exec(world, TEXT("sg.EffectsQuality 3")); + GEngine->Exec(world, TEXT("sg.FoliageQuality 3")); + GEngine->Exec(world, TEXT("foliage.DensityScale 1")); + GEngine->Exec(world, TEXT("grass.DensityScale 1")); + GEngine->Exec(world, TEXT("r.TranslucentLightingVolume 1")); + GEngine->Exec(world, TEXT("r.LightShaftDownSampleFactor 2")); + // GEngine->Exec(world,TEXT("r.OcclusionQueryLocation 0")); + // GEngine->Exec(world,TEXT("r.BasePassOutputsVelocity 0")); //readonly + GEngine->Exec(world, TEXT("r.DetailMode 2")); } -void UCarlaSettingsDelegate::SetAllLights(UWorld* world, const float max_distance_fade, const bool cast_shadows, const bool hide_non_directional) const +void UCarlaSettingsDelegate::SetAllLights( + UWorld *world, + const float max_distance_fade, + const bool cast_shadows, + const bool hide_non_directional) const { - if(!world||!IsValid(world)||world->IsPendingKill()) return; - AsyncTask(ENamedThreads::GameThread, [=](){ - if(!world||!IsValid(world)||world->IsPendingKill()) return; - TArray actors; - UGameplayStatics::GetAllActorsOfClass(world, ALight::StaticClass(), actors); - for(int32 i=0;iIsPendingKill()) + { + return; + } + AsyncTask(ENamedThreads::GameThread, [=]() { + if (!world || !IsValid(world) || world->IsPendingKill()) { - if(!IsValid(actors[i]) || actors[i]->IsPendingKill()) continue; - //tweak directional lights - ADirectionalLight* directionallight = Cast(actors[i]); - if(directionallight) + return; + } + TArray actors; + UGameplayStatics::GetAllActorsOfClass(world, ALight::StaticClass(), actors); + for (int32 i = 0; i < actors.Num(); i++) + { + if (!IsValid(actors[i]) || actors[i]->IsPendingKill()) + { + continue; + } + // tweak directional lights + ADirectionalLight *directionallight = Cast(actors[i]); + if (directionallight) { directionallight->SetCastShadows(cast_shadows); directionallight->SetLightFunctionFadeDistance(max_distance_fade); continue; } - //disable any other type of light + // disable any other type of light actors[i]->SetActorHiddenInGame(hide_non_directional); } }); - -} +} diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.h index a875ff91f..2b21dff9b 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.h @@ -16,61 +16,67 @@ class CARLA_API UCarlaSettingsDelegate : public UObject GENERATED_BODY() public: - /** Constructor */ + UCarlaSettingsDelegate(); - /** Reset settings to default */ + /// Reset settings to default. void Reset(); - /** Create the event trigger handler for all new spawned actors to be processed with a custom function here */ + /// Create the event trigger handler for all the newly spawned actors to be + /// processed with a custom function here. void RegisterSpawnHandler(UWorld *World); - /** After loading a level, apply the current settings */ - UFUNCTION(BlueprintCallable, Category="CARLA Settings", meta=(HidePin="InWorld")) - void ApplyQualitySettingsLevelPostRestart(); + /// After loading a level, apply the current settings. + UFUNCTION(BlueprintCallable, Category = "CARLA Settings", meta = (HidePin = "InWorld")) + void ApplyQualityLevelPostRestart(); - /** Before loading a level, apply the current settings */ - UFUNCTION(BlueprintCallable, Category="CARLA Settings", meta=(HidePin="InWorld")) - void ApplyQualitySettingsLevelPreRestart(); + /// Before loading a level, apply the current settings. + UFUNCTION(BlueprintCallable, Category = "CARLA Settings", meta = (HidePin = "InWorld")) + void ApplyQualityLevelPreRestart(); private: - UWorld* GetLocalWorld(); - /** Function to apply to the actor that is being spawned to apply the current settings */ + + UWorld *GetLocalWorld(); + + /// Function to apply to the actor that is being spawned to apply the current + /// settings. void OnActorSpawned(AActor *Actor); - /** Check that the world ,instance and settings are valid and save the CarlaSettings instance - * @param world used to get the instance of CarlaSettings - */ - void CheckCarlaSettings(UWorld* world); - /** Execute engine commands to apply the low quality settings to the world */ - void LaunchLowQualityCommands(UWorld* world) const; + /// Check that the world, instance and settings are valid and save the + /// CarlaSettings instance. + /// + /// @param world used to get the instance of CarlaSettings. + void CheckCarlaSettings(UWorld *world); - /** */ - void SetAllRoads(UWorld* world,const float max_draw_distance, const TArray &road_pieces_materials) const; + /// Execute engine commands to apply the low quality level to the world. + void LaunchLowQualityCommands(UWorld *world) const; - /** */ - void SetActorComponentsDrawDistance(AActor* actor, const float max_draw_distance) const; + void SetAllRoads( + UWorld *world, + float max_draw_distance, + const TArray &road_pieces_materials) const; - /** */ - void SetAllActorsDrawDistance(UWorld* world, const float max_draw_distance) const; + void SetActorComponentsDrawDistance(AActor *actor, float max_draw_distance) const; - /** */ - void SetPostProcessEffectsEnabled(UWorld* world, const bool enabled) const; - - /** Execute engine commands to apply the epic quality settings to the world */ - void LaunchEpicQualityCommands(UWorld* world) const; + void SetAllActorsDrawDistance(UWorld *world, float max_draw_distance) const; - /** */ - void SetAllLights(UWorld* world, const float max_distance_fade, const bool cast_shadows, const bool hide_non_directional) const; + void SetPostProcessEffectsEnabled(UWorld *world, bool enabled) const; + + /// Execute engine commands to apply the epic quality level to the world. + void LaunchEpicQualityCommands(UWorld *world) const; + + void SetAllLights( + UWorld *world, + float max_distance_fade, + bool cast_shadows, + bool hide_non_directional) const; private: - /** currently applied settings level after level is restarted */ - static EQualitySettingsLevel AppliedLowPostResetQualitySettingsLevel; + /// Currently applied quality level after level is restarted. + static EQualityLevel AppliedLowPostResetQualityLevel; - /** */ - UCarlaSettings* CarlaSettings = nullptr; + UCarlaSettings *CarlaSettings = nullptr; - /** */ FOnActorSpawned::FDelegate ActorSpawnedDelegate; };