use carla::client::Client;
use std::{thread, time::Duration};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== CARLA Start Replaying Example ===\n");
println!("Connecting to CARLA simulator...");
let mut client = Client::connect("localhost", 2000, None)?;
println!("✓ Connected!\n");
let recording_filename = "recording01.log";
let start_time = 0.0; let duration = 0.0; let follow_id = 0; let replay_sensors = true;
println!("Starting replay...");
println!(" Filename: {}", recording_filename);
println!(" Start time: {:.1}s", start_time);
let duration_str = if duration == 0.0 {
"∞ (entire recording)".to_string()
} else {
format!("{:.1}s", duration)
};
println!(" Duration: {}", duration_str);
let follow_str = if follow_id == 0 {
"none".to_string()
} else {
follow_id.to_string()
};
println!(" Follow actor: {}", follow_str);
println!(" Replay sensors: {}", replay_sensors);
let result = client.replay_file(
recording_filename,
start_time,
duration,
follow_id,
replay_sensors,
)?;
println!("✓ Replay started: {}\n", result);
println!("Replaying for 30 seconds...");
for i in 1..=30 {
thread::sleep(Duration::from_secs(1));
println!(" Replaying... {} seconds", i);
}
println!("\nStopping replayer...");
client.stop_replayer(false)?; println!("✓ Replay stopped");
println!("\n=== Replay Complete ===");
println!("\nReplay controls:");
println!(" • client.replay_file(...)? - Start replay");
println!(" • client.stop_replayer(keep_actors)? - Stop replay");
println!(" • client.set_replayer_time_factor(speed)? - Adjust playback speed");
println!(" • client.set_replayer_ignore_hero(true)? - Ignore hero vehicle");
Ok(())
}