Adding a new function to load a map only if it is different

This commit is contained in:
Adri Ollero 2023-07-20 20:45:23 +02:00
parent bc719a1056
commit 57b68f5be8
2 changed files with 41 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include "carla/client/detail/Simulator.h"
#include "carla/client/World.h"
#include "carla/client/Map.h"
#include "carla/PythonUtil.h"
#include "carla/trafficmanager/TrafficManager.h"
@ -77,6 +78,45 @@ namespace client {
return World{_simulator->LoadEpisode(std::move(map_name), reset_settings, map_layers)};
}
/// Return (and load) a new world (map) only when the requested map is different from the current one
void LoadWorldIfDifferent(
std::string map_name,
bool reset_settings = true,
rpc::MapLayer map_layers = rpc::MapLayer::All) const {
carla::client::World world = GetWorld();
carla::SharedPtr<carla::client::Map> current_map = world.GetMap();
std::string current_map_name = current_map->GetName();
std::string map_name_prefix = "Carla/Maps/";
std::string map_name_without_prefix = map_name;
std::string map_name_with_prefix = map_name_prefix + map_name;
if(!(map_name_without_prefix == current_map_name) && !(map_name_with_prefix == current_map_name)){
World World{_simulator->LoadEpisode(std::move(map_name), reset_settings, map_layers)};
}else{
}
}
/*
bool LoadWorldIfDifferent(
std::string map_name,
bool reset_settings = true,
rpc::MapLayer map_layers = rpc::MapLayer::All) const {
carla::client::World world = GetWorld();
carla::SharedPtr<carla::client::Map> current_map = world.GetMap();
std::string current_map_name = current_map->GetName();
std::string name_prefix = "Carla/Maps/";
std::string final_name = name_prefix + current_map_name;
if(!(current_map_name == map_name)){
World world = LoadWorld(map_name,reset_settings,map_layers);
return true;
}
else
return false;
}
*/
World GenerateOpenDriveWorld(
std::string opendrive,
const rpc::OpendriveGenerationParameters & params,

View File

@ -198,6 +198,7 @@ void export_client() {
.def("request_file", &cc::Client::RequestFile, (arg("name")))
.def("reload_world", CONST_CALL_WITHOUT_GIL_1(cc::Client, ReloadWorld, bool), (arg("reset_settings")=true))
.def("load_world", CONST_CALL_WITHOUT_GIL_3(cc::Client, LoadWorld, std::string, bool, rpc::MapLayer), (arg("map_name"), arg("reset_settings")=true, arg("map_layers")=rpc::MapLayer::All))
.def("load_world_if_different", &cc::Client::LoadWorldIfDifferent, (arg("map_name"), arg("reset_settings")=true, arg("map_layers")=rpc::MapLayer::All))
.def("generate_opendrive_world", CONST_CALL_WITHOUT_GIL_3(cc::Client, GenerateOpenDriveWorld, std::string,
rpc::OpendriveGenerationParameters, bool), (arg("opendrive"), arg("parameters")=rpc::OpendriveGenerationParameters(),
arg("reset_settings")=true))