Adding a new function that loads a map only if it is different (#6651)

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

* Removing commented code

* Updated AddVehicleWheelsAnimation function

* Revert "Updated AddVehicleWheelsAnimation function"

This reverts commit 55405a3de7.

* Small correction: removing blank space

* Changelog.md update

---------

Co-authored-by: Adri Ollero <adriollero@gmail.com>
Co-authored-by: Axel1092 <35765780+Axel1092@users.noreply.github.com>
This commit is contained in:
javiergrCS 2023-09-06 12:34:59 +02:00 committed by GitHub
parent 51fde10129
commit 14447def90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -16,6 +16,7 @@
* Add keyword arguments for `carla.TrafficManager` Python API functions
* Fixed bug causing the `FPixelReader::SavePixelsToDisk(PixelData, FilePath)` function to crash due to pixel array not set correctly.
* Collisions detected by the CollisionSensor no longer generate more than one event per frame.
* Added API function to load a map only if it is different from the current one.
## CARLA 0.9.14

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,23 @@ 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{}
}
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))