From f114dc0aa187c5e0abad04731ba1e1d7b32102f0 Mon Sep 17 00:00:00 2001 From: doterop Date: Mon, 15 Jun 2020 10:53:26 +0200 Subject: [PATCH] Remove intermediate map when changing map. (#2911) * Fixed load_new_episode and removed intermediate check. * Recovered intermediate state. * Removing intermediate map * Fixing merge issue * Remove unnecessary check in load_new_episode --- .../source/carla/client/detail/Client.cpp | 4 ---- LibCarla/source/carla/client/detail/Client.h | 2 -- .../source/carla/client/detail/Simulator.cpp | 2 +- .../Source/Carla/Game/CarlaGameInstance.cpp | 15 ------------ .../Source/Carla/Game/CarlaGameInstance.h | 13 ----------- .../Source/Carla/Game/CarlaGameModeBase.cpp | 16 +++++-------- .../Carla/Source/Carla/Server/CarlaServer.cpp | 23 +------------------ 7 files changed, 8 insertions(+), 67 deletions(-) diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index b14981b80..16ad14055 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -145,10 +145,6 @@ namespace detail { _pimpl->CallAndWait("load_new_episode", std::move(map_name)); } - bool Client::CheckIntermediateEpisode() { - return _pimpl->CallAndWait("check_intermediate_episode"); - } - void Client::CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters & params) { // Await response, we need to be sure in this one. _pimpl->CallAndWait("copy_opendrive_to_file", std::move(opendrive), params); diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index 9b687665f..b9630a772 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -89,8 +89,6 @@ namespace detail { void LoadEpisode(std::string map_name); - bool CheckIntermediateEpisode(); - void CopyOpenDriveToServer( std::string opendrive, const rpc::OpendriveGenerationParameters & params); diff --git a/LibCarla/source/carla/client/detail/Simulator.cpp b/LibCarla/source/carla/client/detail/Simulator.cpp index 4b83bcc0e..3b4861537 100644 --- a/LibCarla/source/carla/client/detail/Simulator.cpp +++ b/LibCarla/source/carla/client/detail/Simulator.cpp @@ -90,7 +90,7 @@ namespace detail { using namespace std::literals::chrono_literals; _episode->WaitForState(10ms); auto episode = GetCurrentEpisode(); - if (episode.GetId() != id && !_client.CheckIntermediateEpisode()) { + if (episode.GetId() != id) { return episode; } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.cpp index a1c69fd8e..0c03ada25 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.cpp @@ -17,18 +17,3 @@ UCarlaGameInstance::UCarlaGameInstance() { } UCarlaGameInstance::~UCarlaGameInstance() = default; - -void UCarlaGameInstance::SetMapToLoad(const FString MapName) -{ - MapToLoad = MapName; - bShouldLoadLevel = true; -} - -void UCarlaGameInstance::CheckAndLoadMap(UWorld *world, UCarlaEpisode &Episode) -{ - if(bShouldLoadLevel) - { - Episode.LoadNewEpisode(MapToLoad); - bShouldLoadLevel = false; - } -} diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.h index eafe8d801..c8331b393 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.h @@ -83,14 +83,6 @@ public: return GenerationParameters; } - void SetMapToLoad(const FString MapName); - - void CheckAndLoadMap(UWorld *world, UCarlaEpisode &Episode); - - bool IsLevelPendingLoad() const { - return bShouldLoadLevel; - } - private: UPROPERTY(Category = "CARLA Settings", EditAnywhere) @@ -100,9 +92,4 @@ private: carla::rpc::OpendriveGenerationParameters GenerationParameters; - UPROPERTY() - bool bShouldLoadLevel = false; - - UPROPERTY() - FString MapToLoad; }; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp index e8a02fb08..79f747bce 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp @@ -142,7 +142,6 @@ void ACarlaGameModeBase::BeginPlay() Recorder->GetReplayer()->CheckPlayAfterMapLoaded(); } - UCarlaStatics::GetGameInstance(GetWorld())->CheckAndLoadMap(GetWorld(), *Episode); } void ACarlaGameModeBase::Tick(float DeltaSeconds) @@ -194,15 +193,12 @@ void ACarlaGameModeBase::SpawnActorFactories() void ACarlaGameModeBase::ParseOpenDrive(const FString &MapName) { - if(!UCarlaStatics::GetGameInstance(Episode->GetWorld())->IsLevelPendingLoad()) - { - std::string opendrive_xml = carla::rpc::FromLongFString(UOpenDrive::LoadXODR(MapName)); - Map = carla::opendrive::OpenDriveParser::Load(opendrive_xml); - if (!Map.has_value()) { - UE_LOG(LogCarla, Error, TEXT("Invalid Map")); - } else { - Episode->MapGeoReference = Map->GetGeoReference(); - } + std::string opendrive_xml = carla::rpc::FromLongFString(UOpenDrive::LoadXODR(MapName)); + Map = carla::opendrive::OpenDriveParser::Load(opendrive_xml); + if (!Map.has_value()) { + UE_LOG(LogCarla, Error, TEXT("Invalid Map")); + } else { + Episode->MapGeoReference = Map->GetGeoReference(); } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index b642a6c01..2817f0c93 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -229,34 +229,13 @@ void FCarlaServer::FPimpl::BindActions() BIND_SYNC(load_new_episode) << [this](const std::string &map_name) -> R { REQUIRE_CARLA_EPISODE(); - FString MapName = cr::ToFString(map_name); - MapName = MapName.IsEmpty() ? Episode->GetMapName() : MapName; - auto Maps = UCarlaStatics::GetAllMapNames(); - Maps.Add("OpenDriveMap"); - bool bMissingMap = true; - for (auto & Map : Maps) - { - if(Map.Contains(MapName)) - { - bMissingMap = false; - break; - } - } - if(bMissingMap) + if(!Episode->LoadNewEpisode(cr::ToFString(map_name))) { RESPOND_ERROR("map not found"); } - UCarlaStatics::GetGameInstance(Episode->GetWorld())->SetMapToLoad(MapName); - Episode->LoadNewEpisode(cr::ToFString("EmptyMap")); return R::Success(); }; - BIND_SYNC(check_intermediate_episode) << [this]() -> R - { - REQUIRE_CARLA_EPISODE(); - return UCarlaStatics::GetGameInstance(Episode->GetWorld())->IsLevelPendingLoad(); - }; - BIND_SYNC(copy_opendrive_to_file) << [this](const std::string &opendrive, cr::OpendriveGenerationParameters Params) -> R { REQUIRE_CARLA_EPISODE();