mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 16:36:02 +03:00
proper enum for vehicle type
This commit is contained in:
parent
343aeba3b6
commit
6dbdfcb18b
@ -24,7 +24,7 @@ pub use render::lane::DrawLane;
|
||||
pub use render::map::DrawMap;
|
||||
pub use render::pedestrian::DrawPedestrian;
|
||||
pub use render::turn::DrawTurn;
|
||||
use sim::{DrawCarInput, Sim};
|
||||
use sim::{DrawCarInput, Sim, VehicleType};
|
||||
use std::f64;
|
||||
|
||||
// These are all in meters
|
||||
@ -56,7 +56,7 @@ pub struct RenderOptions {
|
||||
}
|
||||
|
||||
pub fn draw_vehicle(input: DrawCarInput, map: &Map) -> Box<Renderable> {
|
||||
if input.is_bike {
|
||||
if input.vehicle_type == VehicleType::Bike {
|
||||
Box::new(DrawBike::new(input))
|
||||
} else {
|
||||
Box::new(DrawCar::new(input, map))
|
||||
|
@ -20,7 +20,7 @@ use transit::TransitSimState;
|
||||
use view::{AgentView, WorldView};
|
||||
use {
|
||||
Acceleration, AgentID, CarID, CarState, Distance, DrawCarInput, Event, ParkedCar, ParkingSpot,
|
||||
Speed, Tick, Time, TripID,
|
||||
Speed, Tick, Time, TripID, VehicleType,
|
||||
};
|
||||
|
||||
const TIME_TO_PARK_OR_DEPART: Time = si::Second {
|
||||
@ -56,9 +56,6 @@ struct Car {
|
||||
parking: Option<ParkingState>,
|
||||
|
||||
debug: bool,
|
||||
// TODO ew? :\
|
||||
is_bus: bool,
|
||||
is_bike: bool,
|
||||
}
|
||||
|
||||
// TODO this is used for verifying sim state determinism, so it should actually check everything.
|
||||
@ -502,7 +499,11 @@ impl DrivingSimState {
|
||||
}
|
||||
|
||||
pub fn is_done(&self) -> bool {
|
||||
self.cars.values().filter(|c| !c.is_bus).count() == 0
|
||||
self.cars
|
||||
.values()
|
||||
.filter(|c| c.vehicle.vehicle_type != VehicleType::Bus)
|
||||
.count()
|
||||
== 0
|
||||
}
|
||||
|
||||
pub fn tooltip_lines(&self, id: CarID) -> Option<Vec<String>> {
|
||||
@ -775,8 +776,6 @@ impl DrivingSimState {
|
||||
speed: 0.0 * si::MPS,
|
||||
vehicle: params.vehicle,
|
||||
debug: false,
|
||||
is_bus: params.is_bus,
|
||||
is_bike: params.is_bike,
|
||||
parking: params.maybe_parked_car.and_then(|parked_car| {
|
||||
Some(ParkingState {
|
||||
is_parking: false,
|
||||
@ -829,7 +828,7 @@ impl DrivingSimState {
|
||||
} else {
|
||||
CarState::Stuck
|
||||
},
|
||||
is_bike: c.is_bike,
|
||||
vehicle_type: c.vehicle.vehicle_type,
|
||||
})
|
||||
}
|
||||
|
||||
@ -896,7 +895,7 @@ impl DrivingSimState {
|
||||
} else {
|
||||
moving_cars += 1;
|
||||
}
|
||||
if c.is_bus {
|
||||
if c.vehicle.vehicle_type == VehicleType::Bus {
|
||||
buses += 1;
|
||||
}
|
||||
}
|
||||
@ -915,6 +914,4 @@ pub struct CreateCar {
|
||||
pub start: LaneID,
|
||||
pub dist_along: Distance,
|
||||
pub router: Router,
|
||||
pub is_bus: bool,
|
||||
pub is_bike: bool,
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ const FOLLOWING_DISTANCE: Distance = si::Meter {
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Vehicle {
|
||||
pub id: CarID,
|
||||
pub vehicle_type: VehicleType,
|
||||
|
||||
// > 0
|
||||
pub max_accel: Acceleration,
|
||||
@ -57,6 +58,13 @@ pub struct Vehicle {
|
||||
pub max_speed: Option<Speed>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum VehicleType {
|
||||
Car,
|
||||
Bus,
|
||||
Bike,
|
||||
}
|
||||
|
||||
// TODO this is used for verifying sim state determinism, so it should actually check everything.
|
||||
// the f64 prevents this from being derived.
|
||||
impl PartialEq for Vehicle {
|
||||
@ -70,6 +78,7 @@ impl Vehicle {
|
||||
pub fn generate_car(id: CarID, rng: &mut XorShiftRng) -> Vehicle {
|
||||
Vehicle {
|
||||
id,
|
||||
vehicle_type: VehicleType::Car,
|
||||
max_accel: rng.gen_range(2.4, 2.8) * si::MPS2,
|
||||
max_deaccel: rng.gen_range(-2.8, -2.4) * si::MPS2,
|
||||
// TODO more realistic to have a few preset lengths and choose between them
|
||||
@ -81,6 +90,7 @@ impl Vehicle {
|
||||
pub fn generate_bus(id: CarID, rng: &mut XorShiftRng) -> Vehicle {
|
||||
Vehicle {
|
||||
id,
|
||||
vehicle_type: VehicleType::Bus,
|
||||
max_accel: rng.gen_range(2.4, 2.8) * si::MPS2,
|
||||
max_deaccel: rng.gen_range(-2.8, -2.4) * si::MPS2,
|
||||
length: BUS_LENGTH,
|
||||
@ -91,6 +101,7 @@ impl Vehicle {
|
||||
pub fn generate_bike(id: CarID, rng: &mut XorShiftRng) -> Vehicle {
|
||||
Vehicle {
|
||||
id,
|
||||
vehicle_type: VehicleType::Bike,
|
||||
// http://eprints.uwe.ac.uk/20767/ says mean 0.231
|
||||
max_accel: rng.gen_range(0.2, 0.3) * si::MPS2,
|
||||
// Just assume it's the same as acceleration for now
|
||||
|
@ -54,6 +54,7 @@ mod walking;
|
||||
use abstutil::Cloneable;
|
||||
pub use events::Event;
|
||||
pub use instrument::save_backtraces;
|
||||
pub use kinematics::VehicleType;
|
||||
pub use make::{
|
||||
load, ABTest, ABTestResults, BorderSpawnOverTime, MapEdits, Neighborhood, NeighborhoodBuilder,
|
||||
OriginDestination, Scenario, SeedParkedCars, SimFlags, SpawnOverTime,
|
||||
|
@ -4,7 +4,7 @@ use map_model;
|
||||
use map_model::{BuildingID, Lane, LaneID, LaneType, Map};
|
||||
use std::collections::HashSet;
|
||||
use std::iter;
|
||||
use {CarID, CarState, Distance, DrawCarInput, ParkedCar, ParkingSpot};
|
||||
use {CarID, CarState, Distance, DrawCarInput, ParkedCar, ParkingSpot, VehicleType};
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct ParkingSimState {
|
||||
@ -223,7 +223,7 @@ impl ParkingLane {
|
||||
angle: angle,
|
||||
stopping_trace: None,
|
||||
state: CarState::Parked,
|
||||
is_bike: false,
|
||||
vehicle_type: VehicleType::Car,
|
||||
})
|
||||
})
|
||||
}).collect()
|
||||
|
@ -1,6 +1,6 @@
|
||||
use geom::{Angle, Pt2D};
|
||||
use map_model::{LaneID, LaneType, Map, Trace, TurnID};
|
||||
use {CarID, Distance, PedestrianID, Sim};
|
||||
use {CarID, Distance, PedestrianID, Sim, VehicleType};
|
||||
|
||||
// Intermediate structures so that sim and editor crates don't have a cyclic dependency.
|
||||
pub struct DrawPedestrianInput {
|
||||
@ -18,7 +18,7 @@ pub struct DrawCarInput {
|
||||
pub angle: Angle,
|
||||
pub stopping_trace: Option<Trace>,
|
||||
pub state: CarState,
|
||||
pub is_bike: bool,
|
||||
pub vehicle_type: VehicleType,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
|
@ -13,7 +13,10 @@ use std::time::Instant;
|
||||
use transit::TransitSimState;
|
||||
use trips::{TripLeg, TripManager};
|
||||
use walking::{SidewalkSpot, WalkingSimState};
|
||||
use {AgentID, CarID, Distance, Event, ParkedCar, ParkingSpot, PedestrianID, Tick, TripID};
|
||||
use {
|
||||
AgentID, CarID, Distance, Event, ParkedCar, ParkingSpot, PedestrianID, Tick, TripID,
|
||||
VehicleType,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Derivative, Debug, Clone)]
|
||||
#[derivative(PartialEq = "feature_allow_slow_enum", Eq)]
|
||||
@ -25,7 +28,6 @@ enum Command {
|
||||
trip: TripID,
|
||||
car: CarID,
|
||||
vehicle: Vehicle,
|
||||
is_bike: bool,
|
||||
start: LaneID,
|
||||
goal: DrivingGoal,
|
||||
},
|
||||
@ -99,7 +101,7 @@ impl Command {
|
||||
Command::DriveFromBorder {
|
||||
start,
|
||||
goal,
|
||||
is_bike,
|
||||
vehicle,
|
||||
..
|
||||
} => {
|
||||
let goal_lane = match goal {
|
||||
@ -111,8 +113,8 @@ impl Command {
|
||||
start_dist: 0.0 * si::M,
|
||||
end: goal_lane,
|
||||
end_dist: map.get_l(goal_lane).length(),
|
||||
can_use_bus_lanes: false,
|
||||
can_use_bike_lanes: *is_bike,
|
||||
can_use_bus_lanes: vehicle.vehicle_type == VehicleType::Bus,
|
||||
can_use_bike_lanes: vehicle.vehicle_type == VehicleType::Bike,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,7 +133,6 @@ impl Command {
|
||||
trip,
|
||||
car,
|
||||
vehicle,
|
||||
is_bike,
|
||||
start,
|
||||
goal,
|
||||
} => Command::DriveFromBorder {
|
||||
@ -139,7 +140,6 @@ impl Command {
|
||||
trip: *trip,
|
||||
car: *car,
|
||||
vehicle: vehicle.clone(),
|
||||
is_bike: *is_bike,
|
||||
start: *start,
|
||||
goal: goal.clone(),
|
||||
},
|
||||
@ -244,8 +244,6 @@ impl Spawner {
|
||||
Router::make_router_to_border(path)
|
||||
}
|
||||
},
|
||||
is_bus: false,
|
||||
is_bike: false,
|
||||
},
|
||||
) {
|
||||
trips.agent_starting_trip_leg(AgentID::Car(car), trip);
|
||||
@ -259,7 +257,6 @@ impl Spawner {
|
||||
trip,
|
||||
car,
|
||||
ref vehicle,
|
||||
is_bike,
|
||||
start,
|
||||
ref goal,
|
||||
..
|
||||
@ -285,8 +282,6 @@ impl Spawner {
|
||||
Router::make_router_to_border(path)
|
||||
}
|
||||
},
|
||||
is_bus: false,
|
||||
is_bike,
|
||||
},
|
||||
) {
|
||||
trips.agent_starting_trip_leg(AgentID::Car(car), trip);
|
||||
@ -321,8 +316,6 @@ impl Spawner {
|
||||
Router::make_router_to_border(path)
|
||||
}
|
||||
},
|
||||
is_bus: false,
|
||||
is_bike: true,
|
||||
},
|
||||
) {
|
||||
trips.agent_starting_trip_leg(AgentID::Car(vehicle.id), trip);
|
||||
@ -396,8 +389,6 @@ impl Spawner {
|
||||
start,
|
||||
dist_along: start_dist_along,
|
||||
router: Router::make_router_for_bus(path),
|
||||
is_bus: true,
|
||||
is_bike: false,
|
||||
},
|
||||
) {
|
||||
transit_sim.bus_created(id, route_id, next_stop_idx);
|
||||
@ -508,7 +499,6 @@ impl Spawner {
|
||||
trip: trips.new_trip(at, ped_id, legs),
|
||||
car: car_id,
|
||||
vehicle: Vehicle::generate_car(car_id, base_rng),
|
||||
is_bike: false,
|
||||
start: first_lane,
|
||||
goal,
|
||||
});
|
||||
@ -614,7 +604,6 @@ impl Spawner {
|
||||
trip: trips.new_trip(at, ped_id, legs),
|
||||
car: bike_id,
|
||||
vehicle,
|
||||
is_bike: true,
|
||||
start: first_lane,
|
||||
goal,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user