pub(crate) struct DrivingSimState {
    cars: FixedMap<CarID, Car>,
    queues: HashMap<Traversable, Queue>,
    events: Vec<Event>,
    waiting_to_spawn: BTreeMap<CarID, (Position, Option<PersonID>)>,
    recalc_lanechanging: bool,
    handle_uber_turns: bool,
    time_to_unpark_onstreet: Duration,
    time_to_park_onstreet: Duration,
    time_to_unpark_offstreet: Duration,
    time_to_park_offstreet: Duration,
}
Expand description

Simulates vehicles!

Fields

cars: FixedMap<CarID, Car>queues: HashMap<Traversable, Queue>events: Vec<Event>waiting_to_spawn: BTreeMap<CarID, (Position, Option<PersonID>)>recalc_lanechanging: boolhandle_uber_turns: booltime_to_unpark_onstreet: Durationtime_to_park_onstreet: Durationtime_to_unpark_offstreet: Durationtime_to_park_offstreet: Duration

Implementations

None if it worked, otherwise returns the CreateCar unmodified for possible retry.

If start_car_on_lane fails and a retry is scheduled, this is an idempotent way to mark the vehicle as active, but waiting to spawn.

State transitions for this car:

Crossing -> Queued or WaitingToAdvance Unparking -> Crossing IdlingAtStop -> Crossing Queued -> last step handling (Parking or done) WaitingToAdvance -> try to advance to the next step of the path Parking -> done

State transitions for other cars:

Crossing -> Crossing (recalculate dist/time) Queued -> Crossing

Why is it safe to process cars in any order, rather than making sure to follow the order of queues? Because of the invariant that distances should never suddenly jump when a car has entered/exiting a queue. This car might have reached the router’s end distance, but maybe not – might actually be stuck behind other cars. We have to calculate the distances right now to be sure.

Abruptly remove a vehicle from the simulation. They may be in any arbitrary state, like in the middle of a turn or parking.

After a leader (maybe an active vehicle, maybe a static blockage) gets out of the way, update the follower so that they don’t suddenly jump forwards.

If the car wants to over-take somebody, what adjacent lane should they use?

  • The lane must be in the same direction as the current; no support for crossing the road’s yellow line yet.
  • Prefer passing on the left (for DrivingSide::Right) For now, just pick one candidate lane, even if both might be usable.

Note the ordering of results is non-deterministic!

Note the ordering of results is non-deterministic!

This is about as expensive as get_draw_cars_on.

Finds vehicles that’re laggy heads on affected parts of the map.

Does the given car want to over-take the vehicle in front of it?

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Deserialize this value from the given Serde deserializer. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.