World: world methods will use same timeout as client

The world methods: tick, wait_for_tick and apply_settings
will use the timeout defined in the client but they still
allow to define a custom one.
This commit is contained in:
Daniel Santos-Oliván 2021-06-14 15:38:13 +02:00 committed by bernat
parent af26ae35bf
commit 15be33e874
2 changed files with 15 additions and 6 deletions

View File

@ -53,6 +53,10 @@ namespace client {
uint64_t World::ApplySettings(const rpc::EpisodeSettings &settings, time_duration timeout) {
rpc::EpisodeSettings new_settings = settings;
uint64_t id = _episode.Lock()->SetEpisodeSettings(settings);
time_duration local_timeout = timeout.milliseconds() == 0 ?
_episode.Lock()->GetNetworkingTimeout() : timeout;
if (settings.fixed_delta_seconds.has_value()) {
using namespace std::literals::chrono_literals;
@ -68,7 +72,7 @@ namespace client {
if (tics_correct >= 2)
return id;
Tick(timeout);
Tick(local_timeout);
}
log_warning("World::ApplySettings: After", number_of_attemps, " attemps, the settings were not correctly set. Please check that everything is consistent.");
@ -129,7 +133,10 @@ namespace client {
}
WorldSnapshot World::WaitForTick(time_duration timeout) const {
return _episode.Lock()->WaitForTick(timeout);
time_duration local_timeout = timeout.milliseconds() == 0 ?
_episode.Lock()->GetNetworkingTimeout() : timeout;
return _episode.Lock()->WaitForTick(local_timeout);
}
size_t World::OnTick(std::function<void(WorldSnapshot)> callback) {
@ -141,7 +148,9 @@ namespace client {
}
uint64_t World::Tick(time_duration timeout) {
return _episode.Lock()->Tick(timeout);
time_duration local_timeout = timeout.milliseconds() == 0 ?
_episode.Lock()->GetNetworkingTimeout() : timeout;
return _episode.Lock()->Tick(local_timeout);
}
void World::SetPedestriansCrossFactor(float percentage) {

View File

@ -271,7 +271,7 @@ void export_world() {
.def("get_random_location_from_navigation", CALL_RETURNING_OPTIONAL_WITHOUT_GIL(cc::World, GetRandomLocationFromNavigation))
.def("get_spectator", CONST_CALL_WITHOUT_GIL(cc::World, GetSpectator))
.def("get_settings", CONST_CALL_WITHOUT_GIL(cc::World, GetSettings))
.def("apply_settings", &ApplySettings, (arg("settings"), arg("seconds")=10.0))
.def("apply_settings", &ApplySettings, (arg("settings"), arg("seconds")=0.0))
.def("get_weather", CONST_CALL_WITHOUT_GIL(cc::World, GetWeather))
.def("set_weather", &cc::World::SetWeather)
.def("get_snapshot", &cc::World::GetSnapshot)
@ -280,10 +280,10 @@ void export_world() {
.def("get_actors", &GetActorsById, (arg("actor_ids")))
.def("spawn_actor", SPAWN_ACTOR_WITHOUT_GIL(SpawnActor))
.def("try_spawn_actor", SPAWN_ACTOR_WITHOUT_GIL(TrySpawnActor))
.def("wait_for_tick", &WaitForTick, (arg("seconds")=10.0))
.def("wait_for_tick", &WaitForTick, (arg("seconds")=0.0))
.def("on_tick", &OnTick, (arg("callback")))
.def("remove_on_tick", &cc::World::RemoveOnTick, (arg("callback_id")))
.def("tick", &Tick, (arg("seconds")=10.0))
.def("tick", &Tick, (arg("seconds")=0.0))
.def("set_pedestrians_cross_factor", CALL_WITHOUT_GIL_1(cc::World, SetPedestriansCrossFactor, float), (arg("percentage")))
.def("get_traffic_sign", CONST_CALL_WITHOUT_GIL_1(cc::World, GetTrafficSign, cc::Landmark), arg("landmark"))
.def("get_traffic_light", CONST_CALL_WITHOUT_GIL_1(cc::World, GetTrafficLight, cc::Landmark), arg("landmark"))