combine TripLeg::Bike and ::Drive, fixing a bug and simplifying some cases

This commit is contained in:
Dustin Carlino 2019-05-06 11:16:50 -07:00
parent 3ba56a76fb
commit 103e7f28ca
2 changed files with 12 additions and 17 deletions

View File

@ -141,7 +141,8 @@ impl TripSpawner {
let path = maybe_path.unwrap();
match spec {
TripSpec::CarAppearing(start_pos, vehicle_spec, goal) => {
let mut legs = vec![TripLeg::Drive(car_id.unwrap(), goal.clone())];
let vehicle = vehicle_spec.make(car_id.unwrap(), None);
let mut legs = vec![TripLeg::Drive(vehicle.clone(), goal.clone())];
if let DrivingGoal::ParkNear(b) = goal {
legs.push(TripLeg::Walk(
ped_id.unwrap(),
@ -149,14 +150,11 @@ impl TripSpawner {
));
}
let trip = trips.new_trip(start_time, legs);
let router = goal.make_router(path, map, vehicle_spec.vehicle_type);
let router = goal.make_router(path, map, vehicle.vehicle_type);
scheduler.push(
start_time,
Command::SpawnCar(CreateCar::for_appearing(
vehicle_spec.make(car_id.unwrap(), None),
start_pos,
router,
trip,
vehicle, start_pos, router, trip,
)),
);
}
@ -171,7 +169,7 @@ impl TripSpawner {
let mut legs = vec![
TripLeg::Walk(ped_id.unwrap(), parking_spot.clone()),
TripLeg::Drive(vehicle.id, goal.clone()),
TripLeg::Drive(vehicle.clone(), goal.clone()),
];
match goal {
DrivingGoal::ParkNear(b) => {
@ -216,7 +214,7 @@ impl TripSpawner {
let walk_to = SidewalkSpot::bike_rack(start.sidewalk_pos.lane(), map).unwrap();
let mut legs = vec![
TripLeg::Walk(ped_id.unwrap(), walk_to.clone()),
TripLeg::Bike(vehicle.make(car_id.unwrap(), None), goal.clone()),
TripLeg::Drive(vehicle.make(car_id.unwrap(), None), goal.clone()),
];
match goal {
DrivingGoal::ParkNear(b) => {

View File

@ -70,7 +70,7 @@ impl TripManager {
let trip = &mut self.trips[self.active_trip_mode.remove(&AgentID::Car(car)).unwrap().0];
match trip.legs.pop_front() {
Some(TripLeg::Drive(id, DrivingGoal::ParkNear(_))) => assert_eq!(car, id),
Some(TripLeg::Drive(vehicle, DrivingGoal::ParkNear(_))) => assert_eq!(car, vehicle.id),
_ => unreachable!(),
};
@ -106,7 +106,7 @@ impl TripManager {
))
);
let (car, drive_to) = match trip.legs[0] {
TripLeg::Drive(car, ref to) => (car, to.clone()),
TripLeg::Drive(ref vehicle, ref to) => (vehicle.id, to.clone()),
_ => unreachable!(),
};
let parked_car = parking.get_car_at_spot(spot).unwrap();
@ -157,7 +157,7 @@ impl TripManager {
Some(TripLeg::Walk(ped, spot.clone()))
);
let (vehicle, drive_to) = match trip.legs[0] {
TripLeg::Bike(ref vehicle, ref to) => (vehicle.clone(), to.clone()),
TripLeg::Drive(ref vehicle, ref to) => (vehicle.clone(), to.clone()),
_ => unreachable!(),
};
let driving_pos = match spot.connection {
@ -208,7 +208,7 @@ impl TripManager {
let trip = &mut self.trips[self.active_trip_mode.remove(&AgentID::Car(bike)).unwrap().0];
match trip.legs.pop_front() {
Some(TripLeg::Bike(vehicle, DrivingGoal::ParkNear(_))) => assert_eq!(vehicle.id, bike),
Some(TripLeg::Drive(vehicle, DrivingGoal::ParkNear(_))) => assert_eq!(vehicle.id, bike),
_ => unreachable!(),
};
@ -318,7 +318,6 @@ impl TripManager {
let trip = &mut self.trips[self.active_trip_mode.remove(&AgentID::Car(car)).unwrap().0];
match trip.legs.pop_front().unwrap() {
TripLeg::Drive(_, DrivingGoal::Border(int, _)) => assert_eq!(i, int),
TripLeg::Bike(_, DrivingGoal::Border(int, _)) => assert_eq!(i, int),
_ => {
// TODO Should be unreachable
println!(
@ -345,8 +344,7 @@ impl TripManager {
let trip = self.trips.get(id.0)?;
match trip.legs.get(0)? {
TripLeg::Walk(id, _) => Some(AgentID::Pedestrian(*id)),
TripLeg::Drive(id, _) => Some(AgentID::Car(*id)),
TripLeg::Bike(vehicle, _) => Some(AgentID::Car(vehicle.id)),
TripLeg::Drive(vehicle, _) => Some(AgentID::Car(vehicle.id)),
// TODO Should be the bus, but apparently transit sim tracks differently?
TripLeg::RideBus(ped, _, _) => Some(AgentID::Pedestrian(*ped)),
TripLeg::ServeBusRoute(id, _) => Some(AgentID::Car(*id)),
@ -438,8 +436,7 @@ impl Trip {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub enum TripLeg {
Walk(PedestrianID, SidewalkSpot),
Drive(CarID, DrivingGoal),
Bike(Vehicle, DrivingGoal),
Drive(Vehicle, DrivingGoal),
RideBus(PedestrianID, BusRouteID, BusStopID),
ServeBusRoute(CarID, BusRouteID),
}