use autocxx::prelude::*;
use carla_sys::carla_rust::rpc::FfiEpisodeSettings;
#[derive(Debug, Clone)]
pub struct EpisodeSettings {
pub synchronous_mode: bool,
pub no_rendering_mode: bool,
pub fixed_delta_seconds: Option<f64>,
pub substepping: bool,
pub max_substep_delta_time: f64,
pub max_substeps: u64,
pub max_culling_distance: f32,
pub deterministic_ragdolls: bool,
pub tile_stream_distance: f32,
pub actor_active_distance: f32,
#[cfg(carla_0915)]
pub spectator_as_ego: bool,
}
impl EpisodeSettings {
pub(crate) fn from_cxx(from: &FfiEpisodeSettings) -> Self {
let fixed_delta_seconds = from.fixed_delta_seconds();
let fixed_delta_seconds = if fixed_delta_seconds.is_nan() {
None
} else {
Some(fixed_delta_seconds)
};
Self {
synchronous_mode: from.synchronous_mode(),
no_rendering_mode: from.no_rendering_mode(),
fixed_delta_seconds,
substepping: from.substepping(),
max_substep_delta_time: from.max_substep_delta_time(),
max_substeps: from.max_substeps().0 as u64,
max_culling_distance: from.max_culling_distance(),
deterministic_ragdolls: from.deterministic_ragdolls(),
tile_stream_distance: from.tile_stream_distance(),
actor_active_distance: from.actor_active_distance(),
#[cfg(carla_0915)]
spectator_as_ego: from.spectator_as_ego(),
}
}
pub(crate) fn to_cxx(&self) -> UniquePtr<FfiEpisodeSettings> {
let fixed_delta_seconds = self.fixed_delta_seconds.unwrap_or(0.0);
#[allow(unused_mut)]
let mut settings = FfiEpisodeSettings::new2(
self.synchronous_mode,
self.no_rendering_mode,
fixed_delta_seconds,
self.substepping,
self.max_substep_delta_time,
c_int(self.max_substeps as std::os::raw::c_int),
self.max_culling_distance,
self.deterministic_ragdolls,
self.tile_stream_distance,
self.actor_active_distance,
)
.within_unique_ptr();
#[cfg(carla_0915)]
settings
.pin_mut()
.set_spectator_as_ego(self.spectator_as_ego);
settings
}
}
impl Default for EpisodeSettings {
fn default() -> Self {
let ffi = FfiEpisodeSettings::new().within_unique_ptr();
Self::from_cxx(&ffi)
}
}