Struct RacingDriver

Source
pub struct RacingDriver { /* private fields */ }

Implementations§

Source§

impl RacingDriver

Source

pub fn new(seed: u64) -> RacingDriver

Source

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);
Source

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);
Source

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

Source§

fn clone(&self) -> RacingDriver

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RacingDriver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for RacingDriver

Source§

fn default() -> RacingDriver

Returns the “default value” for a type. Read more
Source§

impl Copy for RacingDriver

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.