Skip to content

Commit f114dc0

Browse files
authored
Remove intermediate map when changing map. (carla-simulator#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
1 parent d8c165a commit f114dc0

File tree

7 files changed

+8
-67
lines changed

7 files changed

+8
-67
lines changed

LibCarla/source/carla/client/detail/Client.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ namespace detail {
145145
_pimpl->CallAndWait<void>("load_new_episode", std::move(map_name));
146146
}
147147

148-
bool Client::CheckIntermediateEpisode() {
149-
return _pimpl->CallAndWait<bool>("check_intermediate_episode");
150-
}
151-
152148
void Client::CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters & params) {
153149
// Await response, we need to be sure in this one.
154150
_pimpl->CallAndWait<void>("copy_opendrive_to_file", std::move(opendrive), params);

LibCarla/source/carla/client/detail/Client.h

-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ namespace detail {
8989

9090
void LoadEpisode(std::string map_name);
9191

92-
bool CheckIntermediateEpisode();
93-
9492
void CopyOpenDriveToServer(
9593
std::string opendrive, const rpc::OpendriveGenerationParameters & params);
9694

LibCarla/source/carla/client/detail/Simulator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace detail {
9090
using namespace std::literals::chrono_literals;
9191
_episode->WaitForState(10ms);
9292
auto episode = GetCurrentEpisode();
93-
if (episode.GetId() != id && !_client.CheckIntermediateEpisode()) {
93+
if (episode.GetId() != id) {
9494
return episode;
9595
}
9696
}

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.cpp

-15
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,3 @@ UCarlaGameInstance::UCarlaGameInstance() {
1717
}
1818

1919
UCarlaGameInstance::~UCarlaGameInstance() = default;
20-
21-
void UCarlaGameInstance::SetMapToLoad(const FString MapName)
22-
{
23-
MapToLoad = MapName;
24-
bShouldLoadLevel = true;
25-
}
26-
27-
void UCarlaGameInstance::CheckAndLoadMap(UWorld *world, UCarlaEpisode &Episode)
28-
{
29-
if(bShouldLoadLevel)
30-
{
31-
Episode.LoadNewEpisode(MapToLoad);
32-
bShouldLoadLevel = false;
33-
}
34-
}

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameInstance.h

-13
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ class CARLA_API UCarlaGameInstance : public UGameInstance
8383
return GenerationParameters;
8484
}
8585

86-
void SetMapToLoad(const FString MapName);
87-
88-
void CheckAndLoadMap(UWorld *world, UCarlaEpisode &Episode);
89-
90-
bool IsLevelPendingLoad() const {
91-
return bShouldLoadLevel;
92-
}
93-
9486
private:
9587

9688
UPROPERTY(Category = "CARLA Settings", EditAnywhere)
@@ -100,9 +92,4 @@ class CARLA_API UCarlaGameInstance : public UGameInstance
10092

10193
carla::rpc::OpendriveGenerationParameters GenerationParameters;
10294

103-
UPROPERTY()
104-
bool bShouldLoadLevel = false;
105-
106-
UPROPERTY()
107-
FString MapToLoad;
10895
};

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ void ACarlaGameModeBase::BeginPlay()
142142
Recorder->GetReplayer()->CheckPlayAfterMapLoaded();
143143
}
144144

145-
UCarlaStatics::GetGameInstance(GetWorld())->CheckAndLoadMap(GetWorld(), *Episode);
146145
}
147146

148147
void ACarlaGameModeBase::Tick(float DeltaSeconds)
@@ -194,15 +193,12 @@ void ACarlaGameModeBase::SpawnActorFactories()
194193

195194
void ACarlaGameModeBase::ParseOpenDrive(const FString &MapName)
196195
{
197-
if(!UCarlaStatics::GetGameInstance(Episode->GetWorld())->IsLevelPendingLoad())
198-
{
199-
std::string opendrive_xml = carla::rpc::FromLongFString(UOpenDrive::LoadXODR(MapName));
200-
Map = carla::opendrive::OpenDriveParser::Load(opendrive_xml);
201-
if (!Map.has_value()) {
202-
UE_LOG(LogCarla, Error, TEXT("Invalid Map"));
203-
} else {
204-
Episode->MapGeoReference = Map->GetGeoReference();
205-
}
196+
std::string opendrive_xml = carla::rpc::FromLongFString(UOpenDrive::LoadXODR(MapName));
197+
Map = carla::opendrive::OpenDriveParser::Load(opendrive_xml);
198+
if (!Map.has_value()) {
199+
UE_LOG(LogCarla, Error, TEXT("Invalid Map"));
200+
} else {
201+
Episode->MapGeoReference = Map->GetGeoReference();
206202
}
207203
}
208204

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp

+1-22
Original file line numberDiff line numberDiff line change
@@ -229,34 +229,13 @@ void FCarlaServer::FPimpl::BindActions()
229229
BIND_SYNC(load_new_episode) << [this](const std::string &map_name) -> R<void>
230230
{
231231
REQUIRE_CARLA_EPISODE();
232-
FString MapName = cr::ToFString(map_name);
233-
MapName = MapName.IsEmpty() ? Episode->GetMapName() : MapName;
234-
auto Maps = UCarlaStatics::GetAllMapNames();
235-
Maps.Add("OpenDriveMap");
236-
bool bMissingMap = true;
237-
for (auto & Map : Maps)
238-
{
239-
if(Map.Contains(MapName))
240-
{
241-
bMissingMap = false;
242-
break;
243-
}
244-
}
245-
if(bMissingMap)
232+
if(!Episode->LoadNewEpisode(cr::ToFString(map_name)))
246233
{
247234
RESPOND_ERROR("map not found");
248235
}
249-
UCarlaStatics::GetGameInstance(Episode->GetWorld())->SetMapToLoad(MapName);
250-
Episode->LoadNewEpisode(cr::ToFString("EmptyMap"));
251236
return R<void>::Success();
252237
};
253238

254-
BIND_SYNC(check_intermediate_episode) << [this]() -> R<bool>
255-
{
256-
REQUIRE_CARLA_EPISODE();
257-
return UCarlaStatics::GetGameInstance(Episode->GetWorld())->IsLevelPendingLoad();
258-
};
259-
260239
BIND_SYNC(copy_opendrive_to_file) << [this](const std::string &opendrive, cr::OpendriveGenerationParameters Params) -> R<void>
261240
{
262241
REQUIRE_CARLA_EPISODE();

0 commit comments

Comments
 (0)