mirror of
https://github.com/a-b-street/abstreet.git
synced 2025-01-08 15:55:12 +03:00
do validation upfront in TripSpawner
This commit is contained in:
parent
3c219a035a
commit
41169a7c5b
@ -191,6 +191,7 @@ fn spawn_car(sim: &mut new_des_model::Sim, rng: &mut XorShiftRng, map: &Map, sta
|
||||
vehicle,
|
||||
new_des_model::DrivingGoal::Border(map.get_l(last_lane).dst_i, last_lane),
|
||||
),
|
||||
map,
|
||||
);
|
||||
}
|
||||
|
||||
@ -236,6 +237,7 @@ fn seed_parked_cars_near(
|
||||
map.all_buildings().choose(rng).unwrap().id,
|
||||
),
|
||||
),
|
||||
map,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -308,5 +310,6 @@ fn random_ped_near(
|
||||
new_des_model::SidewalkSpot::bike_rack(pos1, map),
|
||||
new_des_model::SidewalkSpot::bike_rack(pos2, map),
|
||||
),
|
||||
map,
|
||||
);
|
||||
}
|
||||
|
@ -149,21 +149,6 @@ impl DrivingSimState {
|
||||
);
|
||||
}
|
||||
|
||||
if params.start_dist < params.vehicle.length {
|
||||
panic!(
|
||||
"Can't spawn a car at {}; too close to the start",
|
||||
params.start_dist
|
||||
);
|
||||
}
|
||||
if params.start_dist >= params.router.head().length(map) {
|
||||
panic!(
|
||||
"Can't spawn a car at {}; {:?} isn't that long",
|
||||
params.start_dist,
|
||||
params.router.head()
|
||||
);
|
||||
}
|
||||
params.router.validate_start_dist(params.start_dist);
|
||||
|
||||
let first_lane = params.router.head().as_lane();
|
||||
|
||||
if !intersections.nobody_headed_towards(first_lane, map.get_l(first_lane).src_i) {
|
||||
|
@ -33,14 +33,6 @@ enum Goal {
|
||||
|
||||
impl Router {
|
||||
pub fn stop_suddenly(path: Vec<Traversable>, end_dist: Distance, map: &Map) -> Router {
|
||||
if end_dist >= path.last().unwrap().length(map) {
|
||||
panic!(
|
||||
"Can't end a car at {}; {:?} isn't that long",
|
||||
end_dist,
|
||||
path.last().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
Router {
|
||||
path: VecDeque::from(path),
|
||||
goal: Goal::StopSuddenly { end_dist },
|
||||
@ -57,20 +49,6 @@ impl Router {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_start_dist(&self, start_dist: Distance) {
|
||||
match self.goal {
|
||||
Goal::StopSuddenly { end_dist } => {
|
||||
if self.path.len() == 1 && start_dist >= end_dist {
|
||||
panic!(
|
||||
"Can't start a car with one path in its step and go from {} to {}",
|
||||
start_dist, end_dist
|
||||
);
|
||||
}
|
||||
}
|
||||
Goal::ParkNearBuilding { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn head(&self) -> Traversable {
|
||||
self.path[0]
|
||||
}
|
||||
|
@ -68,8 +68,9 @@ impl Sim {
|
||||
self.walking.get_draw_peds(time, on, map)
|
||||
}
|
||||
|
||||
pub fn schedule_trip(&mut self, start_time: Duration, spec: TripSpec) {
|
||||
self.spawner.schedule_trip(start_time, spec);
|
||||
pub fn schedule_trip(&mut self, start_time: Duration, spec: TripSpec, map: &Map) {
|
||||
self.spawner
|
||||
.schedule_trip(start_time, spec, map, &self.parking);
|
||||
}
|
||||
|
||||
pub fn spawn_all_trips(&mut self, map: &Map) {
|
||||
|
@ -38,7 +38,53 @@ impl TripSpawner {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn schedule_trip(&mut self, start_time: Duration, spec: TripSpec) {
|
||||
pub fn schedule_trip(
|
||||
&mut self,
|
||||
start_time: Duration,
|
||||
spec: TripSpec,
|
||||
map: &Map,
|
||||
parking: &ParkingSimState,
|
||||
) {
|
||||
// TODO We'll want to repeat this validation when we spawn stuff later for a second leg...
|
||||
match &spec {
|
||||
TripSpec::CarAppearing(start_pos, vehicle_spec, goal) => {
|
||||
if start_pos.dist_along() < vehicle_spec.length {
|
||||
panic!(
|
||||
"Can't spawn a car at {}; too close to the start",
|
||||
start_pos.dist_along()
|
||||
);
|
||||
}
|
||||
if start_pos.dist_along() >= map.get_l(start_pos.lane()).length() {
|
||||
panic!(
|
||||
"Can't spawn a car at {}; {} isn't that long",
|
||||
start_pos.dist_along(),
|
||||
start_pos.lane()
|
||||
);
|
||||
}
|
||||
match goal {
|
||||
DrivingGoal::Border(_, end_lane) => {
|
||||
if start_pos.lane() == *end_lane
|
||||
&& start_pos.dist_along() == map.get_l(*end_lane).length()
|
||||
{
|
||||
panic!("Can't start a car at the edge of a border already");
|
||||
}
|
||||
}
|
||||
DrivingGoal::ParkNear(_) => {}
|
||||
}
|
||||
}
|
||||
TripSpec::UsingParkedCar(_, spot, _) => {
|
||||
let car_id = parking.get_car_at_spot(*spot);
|
||||
if self.parked_cars_claimed.contains(&car_id) {
|
||||
panic!(
|
||||
"A TripSpec wants to use {}, which is already claimed",
|
||||
car_id
|
||||
);
|
||||
}
|
||||
self.parked_cars_claimed.insert(car_id);
|
||||
}
|
||||
TripSpec::JustWalking(_, _) => {}
|
||||
};
|
||||
|
||||
self.trips.push((start_time, spec));
|
||||
}
|
||||
|
||||
@ -100,15 +146,6 @@ impl TripSpawner {
|
||||
let ped_id = PedestrianID::tmp_new(self.ped_id_counter);
|
||||
self.ped_id_counter += 1;
|
||||
let car_id = parking.get_car_at_spot(spot);
|
||||
|
||||
if self.parked_cars_claimed.contains(&car_id) {
|
||||
panic!(
|
||||
"A TripSpec wants to use {}, which is already claimed",
|
||||
car_id
|
||||
);
|
||||
}
|
||||
self.parked_cars_claimed.insert(car_id);
|
||||
|
||||
//assert_eq!(parked.owner, Some(start_bldg));
|
||||
|
||||
let parking_spot = SidewalkSpot::parking_spot(spot, map, parking);
|
||||
|
Loading…
Reference in New Issue
Block a user