pub struct RacingDriver { /* private fields */ }Implementations§
Source§impl RacingDriver
impl RacingDriver
pub fn new(seed: u64) -> RacingDriver
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Clears recovery timers and the last observation, retaining the seeded passing/recovery side. Call after teleporting, restarting or replacing the path, before the next simulation tick. This never moves the vehicle.
use ferravex_play::racing::RacingDriver;
let mut driver = RacingDriver::new(7);
// Reset the vehicle pose/velocity in its owning simulation, then:
driver.reset();
assert_eq!(driver.status(), None);Sourcepub fn status(&self) -> Option<DriverStatus>
pub fn status(&self) -> Option<DriverStatus>
Returns the last accepted positive tick’s diagnostics, or None before
that tick and after Self::reset. Invalid and zero-duration steps leave
this snapshot unchanged. Reading it does not advance simulation time.
use ferravex_math::Vec2;
use ferravex_play::racing::{
DriverInput, DriverProgress, DriverRecovery, DriverSettings,
DriverStatus, RacingDriver, WrongWayReason,
};
let path = [Vec2::ZERO, Vec2::X * 200., Vec2::splat(200.), Vec2::Y * 200.];
let mut driver = RacingDriver::new(0);
let input = DriverInput {
position: Vec2::X * 50., forward: -Vec2::X,
velocity: Vec2::ZERO, rivals: &[],
};
driver.step(&path, DriverSettings::default(), input, 0.25)?;
let status: DriverStatus = driver.status().unwrap();
let progress: DriverProgress = status.progress;
assert_eq!(progress.segment, 0);
assert_eq!(progress.distance_along, 50.);
assert_eq!(progress.path_length, 800.);
assert_eq!(status.wrong_way, Some(WrongWayReason::FacingBackward));
assert_eq!(status.recovery, DriverRecovery::Stalled);
assert_eq!(status.stuck_seconds, 0.25);Sourcepub fn step(
&mut self,
path: &[Vec2],
p: DriverSettings,
input: DriverInput<'_>,
dt: f32,
) -> Result<RacingControl, RacingError>
pub fn step( &mut self, path: &[Vec2], p: DriverSettings, input: DriverInput<'_>, dt: f32, ) -> Result<RacingControl, RacingError>
Computes controls for a closed path of 3 through 2048 vertices and at
most 32 perceived rivals. Supply fixed simulation dt in 0..=0.25.
A zero-duration call previews controls without updating timers or status;
invalid inputs also leave state unchanged. All successful outputs and
observations are finite. Recovery does not count intentional stops or
waiting behind slow traffic as stalled time. An initially near-zero
reverse steering command uses the seeded side for the whole attempt so
subsequent heading changes do not undo the escape turn. Zero steer gain
still disables steering.
Trait Implementations§
Source§impl Clone for RacingDriver
impl Clone for RacingDriver
Source§fn clone(&self) -> RacingDriver
fn clone(&self) -> RacingDriver
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more