From 30db7e21d4714666ef264a1b6392c8b1cab8ba98 Mon Sep 17 00:00:00 2001 From: doterop Date: Wed, 9 Dec 2020 15:22:20 +0100 Subject: [PATCH] Added culling control (#3656) * Added culling configuration to settings * Updated changelog --- CHANGELOG.md | 1 + LibCarla/source/carla/rpc/EpisodeSettings.h | 12 ++++++++++-- PythonAPI/carla/source/libcarla/World.cpp | 4 +++- .../Carla/Source/Carla/Game/CarlaGameModeBase.cpp | 11 +++++++++++ .../Carla/Source/Carla/Game/CarlaGameModeBase.h | 4 ++++ .../Source/Carla/Settings/CarlaSettingsDelegate.h | 4 ++-- .../Carla/Source/Carla/Settings/EpisodeSettings.h | 2 ++ 7 files changed, 33 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c38dc1fa2..58853aa90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Latest + * Added parameter to carla settings to control culling * Added `load_map_layer` and `unload_map_layer` to control map layers on new maps that support subleveling * Added `get_environment_objects`call to get all the placed objects in the level * Added `enable_environment_objects`call to enable/disable objects of the level diff --git a/LibCarla/source/carla/rpc/EpisodeSettings.h b/LibCarla/source/carla/rpc/EpisodeSettings.h index 331a9fcd4..83737c360 100644 --- a/LibCarla/source/carla/rpc/EpisodeSettings.h +++ b/LibCarla/source/carla/rpc/EpisodeSettings.h @@ -37,10 +37,12 @@ namespace rpc { int max_substeps = 10; + float max_culling_distance = 0.0f; + bool deterministic_ragdolls = true; MSGPACK_DEFINE_ARRAY(synchronous_mode, no_rendering_mode, fixed_delta_seconds, substepping, - max_substep_delta_time, max_substeps, deterministic_ragdolls); + max_substep_delta_time, max_substeps, max_culling_distance, deterministic_ragdolls); // ========================================================================= // -- Constructors --------------------------------------------------------- @@ -55,13 +57,16 @@ namespace rpc { bool substepping = true, double max_substep_delta_time = 0.01, int max_substeps = 10, + float max_culling_distance = 0.0f, bool deterministic_ragdolls = true) : synchronous_mode(synchronous_mode), no_rendering_mode(no_rendering_mode), fixed_delta_seconds( fixed_delta_seconds > 0.0 ? fixed_delta_seconds : boost::optional{}), substepping(substepping), - max_substep_delta_time(max_substep_delta_time), max_substeps(max_substeps), + max_substep_delta_time(max_substep_delta_time), + max_substeps(max_substeps), + max_culling_distance(max_culling_distance), deterministic_ragdolls(deterministic_ragdolls) {} // ========================================================================= @@ -76,6 +81,7 @@ namespace rpc { (fixed_delta_seconds == rhs.fixed_delta_seconds) && (max_substep_delta_time == rhs.max_substep_delta_time) && (max_substeps == rhs.max_substeps) && + (max_culling_distance == rhs.max_culling_distance) && (deterministic_ragdolls == rhs.deterministic_ragdolls); } @@ -97,6 +103,7 @@ namespace rpc { Settings.bSubstepping, Settings.MaxSubstepDeltaTime, Settings.MaxSubsteps, + Settings.MaxCullingDistance, Settings.bDeterministicRagdolls) {} operator FEpisodeSettings() const { @@ -109,6 +116,7 @@ namespace rpc { Settings.bSubstepping = substepping; Settings.MaxSubstepDeltaTime = max_substep_delta_time; Settings.MaxSubsteps = max_substeps; + Settings.MaxCullingDistance = max_culling_distance; Settings.bDeterministicRagdolls = deterministic_ragdolls; return Settings; diff --git a/PythonAPI/carla/source/libcarla/World.cpp b/PythonAPI/carla/source/libcarla/World.cpp index 05f60f4b4..92d139bcc 100644 --- a/PythonAPI/carla/source/libcarla/World.cpp +++ b/PythonAPI/carla/source/libcarla/World.cpp @@ -141,19 +141,21 @@ void export_world() { ; class_("WorldSettings") - .def(init( + .def(init( (arg("synchronous_mode")=false, arg("no_rendering_mode")=false, arg("fixed_delta_seconds")=0.0, arg("substepping")=true, arg("max_substep_delta_time")=0.01, arg("max_substeps")=10, + arg("max_culling_distance")=0.0f, arg("deterministic_ragdolls")=false))) .def_readwrite("synchronous_mode", &cr::EpisodeSettings::synchronous_mode) .def_readwrite("no_rendering_mode", &cr::EpisodeSettings::no_rendering_mode) .def_readwrite("substepping", &cr::EpisodeSettings::substepping) .def_readwrite("max_substep_delta_time", &cr::EpisodeSettings::max_substep_delta_time) .def_readwrite("max_substeps", &cr::EpisodeSettings::max_substeps) + .def_readwrite("max_culling_distance", &cr::EpisodeSettings::max_culling_distance) .def_readwrite("deterministic_ragdolls", &cr::EpisodeSettings::deterministic_ragdolls) .add_property("fixed_delta_seconds", +[](const cr::EpisodeSettings &self) { diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp index 5435aa80b..1259a1b95 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp @@ -103,6 +103,10 @@ void ACarlaGameModeBase::InitGame( GameInstance->NotifyInitGame(); + OnEpisodeSettingsChangeHandle = FCarlaStaticDelegates::OnEpisodeSettingsChange.AddUObject( + this, + &ACarlaGameModeBase::OnEpisodeSettingsChanged); + SpawnActorFactories(); // make connection between Episode and Recorder @@ -182,6 +186,8 @@ void ACarlaGameModeBase::Tick(float DeltaSeconds) void ACarlaGameModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason) { + FCarlaStaticDelegates::OnEpisodeSettingsChange.Remove(OnEpisodeSettingsChangeHandle); + Episode->EndPlay(); GameInstance->NotifyEndEpisode(); @@ -510,3 +516,8 @@ void ACarlaGameModeBase::OnUnloadStreamLevel() RegisterEnvironmentObjects(); } } + +void ACarlaGameModeBase::OnEpisodeSettingsChanged(const FEpisodeSettings &Settings) +{ + CarlaSettingsDelegate->SetAllActorsDrawDistance(GetWorld(), Settings.MaxCullingDistance); +} \ No newline at end of file diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h index 79f502f07..1f5ac7d69 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h @@ -101,6 +101,8 @@ private: void ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray& OutLevelNames); + void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings); + UPROPERTY() UCarlaGameInstance *GameInstance = nullptr; @@ -134,6 +136,8 @@ private: UPROPERTY() ATrafficLightManager* TrafficLightManager = nullptr; + FDelegateHandle OnEpisodeSettingsChangeHandle; + boost::optional Map; int PendingLevelsToLoad = 0; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.h index f7d401bc4..00bbe0770 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.h @@ -41,6 +41,8 @@ public: UFUNCTION(BlueprintCallable, Category = "CARLA Settings", meta = (HidePin = "InWorld")) void ApplyQualityLevelPreRestart(); + void SetAllActorsDrawDistance(UWorld *world, float max_draw_distance) const; + private: UWorld *GetLocalWorld(); @@ -65,8 +67,6 @@ private: void SetActorComponentsDrawDistance(AActor *actor, float max_draw_distance) const; - void SetAllActorsDrawDistance(UWorld *world, float max_draw_distance) const; - void SetPostProcessEffectsEnabled(UWorld *world, bool enabled) const; /// Execute engine commands to apply the epic quality level to the world. diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/EpisodeSettings.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/EpisodeSettings.h index d7f578faf..32248fd8f 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/EpisodeSettings.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/EpisodeSettings.h @@ -28,6 +28,8 @@ struct CARLA_API FEpisodeSettings int MaxSubsteps = 10; + float MaxCullingDistance = 0.0f; + UPROPERTY(EditAnywhere, BlueprintReadWrite) bool bDeterministicRagdolls = true;