Skip to content

Commit

Permalink
Detangle
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Apr 14, 2022
1 parent 901415e commit ba8c6db
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 66 deletions.
11 changes: 7 additions & 4 deletions apps/game/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,13 @@ fn finish_app_setup(
}
Mode::TutorialIntro => sandbox::gameplay::Tutorial::start(ctx, app),
Mode::Challenges => challenges::ChallengesPicker::new_state(ctx, app),
Mode::Sandbox => GameplayMode::PlayScenario(
app.primary.map.get_name().clone(),
Scenario::default_scenario_for_map(app.primary.map.get_name()),
Vec::new(),
Mode::Sandbox => SandboxMode::simple_new(
app,
GameplayMode::PlayScenario(
app.primary.map.get_name().clone(),
Scenario::default_scenario_for_map(app.primary.map.get_name()),
Vec::new(),
),
),
Mode::Proposals => pregame::proposals::Proposals::new_state(ctx, None),
Mode::Ungap => {
Expand Down
2 changes: 1 addition & 1 deletion apps/game/src/pregame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn enter_state(ctx: &mut EventCtx, app: &mut App, args: Vec<&str>) -> Box<dyn St
app,
GameplayMode::PlayScenario(
app.primary.map.get_name().clone(),
"empty".to_string(), //Scenario::default_scenario_for_map(app.primary.map.get_name()),
Scenario::default_scenario_for_map(app.primary.map.get_name()),
Vec::new(),
),
),
Expand Down
10 changes: 2 additions & 8 deletions map_model/src/make/transit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ fn create_route(
};

// Check that the paths are valid
let requests = result.all_path_requests(map);
for req in &requests {
for req in result.all_path_requests(map) {
if req.start == req.end {
bail!(
"Start/end position and a stop position are on top of each other? {}",
Expand All @@ -257,15 +256,10 @@ fn create_route(
);
}

if let Err(err) = map.pathfind(req.clone()) {
if let Err(err) = map.pathfind(req) {
bail!("Created the route, but pathfinding failed: {}", err);
}
}
for pair in requests.windows(2) {
if pair[0].end != pair[1].start {
panic!("what? {} vs {} on {}", pair[0], pair[1], result.long_name);
}
}

map.transit_routes.push(result);
Ok(())
Expand Down
5 changes: 4 additions & 1 deletion sim/src/mechanics/car.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ impl Car {
self.router.head().get_polyline(map).length()
};
if end_dist < start_dist {
error!("broken {:?}", self);
panic!(
"{} trying to make a crossing_state from {} to {} at {}. Something's very wrong",
self.vehicle.id, start_dist, end_dist, start_time
);
}

let dist_int = DistanceInterval::new_driving(start_dist, end_dist);
Expand Down
30 changes: 5 additions & 25 deletions sim/src/mechanics/driving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,21 +341,10 @@ impl DrivingSimState {
&self.cars,
&self.queues,
);
let idx = if let Some(idx) = dists
let idx = dists
.iter()
.position(|entry| entry.member == Queued::Vehicle(id))
{
idx
} else {
error!(
"{} isn't in {:?}?! Dists {:?} Car {:?}",
id,
self.cars[&id].router.head(),
dists,
self.cars[&id]
);
return;
};
.unwrap();

// We need to mutate two different cars in some cases. To avoid fighting the borrow
// checker, temporarily move one of them out of the map.
Expand Down Expand Up @@ -1618,21 +1607,12 @@ impl DrivingSimState {
}

fn get_car_front(&self, now: Time, car: &Car) -> Distance {
if let Some(x) = self.queues[&car.router.head()]
self.queues[&car.router.head()]
.get_car_positions(now, &self.cars, &self.queues)
.into_iter()
.find(|entry| entry.member == Queued::Vehicle(car.vehicle.id))
{
x.front
} else {
panic!(
"get_car_front of {:?} at {} on {:?}... car positions are {:?}",
car,
now,
car.router.head(),
self.queues[&car.router.head()]
);
}
.unwrap()
.front
}

/// Does the given car want to over-take the vehicle in front of it?
Expand Down
7 changes: 0 additions & 7 deletions sim/src/mechanics/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,13 +1020,6 @@ impl IntersectionSimState {
let head = if let Some(c) = q.laggy_head {
c
} else {
if q.get_active_cars().is_empty() {
panic!(
"what? look for {} near {}",
car,
cars[&current].router.head()
);
}
q.get_active_cars()[0]
};
if current != head {
Expand Down
24 changes: 4 additions & 20 deletions sim/src/transit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,24 @@ impl TransitSimState {
});
continue;
}
// TODO Why're we calculating these again? Use bus_route.all_path_requests(), so
// that all the nice checks in the map_model layer are preserved here
let req = PathRequest::vehicle(
stop1.driving_pos,
map.get_ts(bus_route.stops[idx + 1]).driving_pos,
bus_route.route_type,
);
let orig = req.clone();
match map.pathfind(req) {
Ok(path) => {
if path.is_empty() {
panic!("Empty path between stops?! {}", path.get_req());
}
if stop1.driving_pos != path.get_req().start {
panic!(
"will warp! {} to {} for {}. orig req {}",
"{} will warp from {} to {}",
bus_route.long_name,
stop1.driving_pos,
path.get_req().start,
bus_route.long_name,
orig
);
}

Expand Down Expand Up @@ -153,13 +153,6 @@ impl TransitSimState {
} else {
None
};

/*for pair in stops.windows(2) {
if pair[0].next_stop.as_ref().unwrap().end != pair[1].start {
panic!("what? {} vs {} on {}", pair[0], pair[1], result.long_name);
}
}*/

Route {
active_vehicles: BTreeSet::new(),
stops,
Expand Down Expand Up @@ -297,15 +290,6 @@ impl TransitSimState {
self.events
.push(Event::BusDepartedFromStop(id, bus.route, stop.id));
if let Some(path) = stop.next_stop.clone() {
if stop.driving_pos != path.get_req().start {
panic!(
"warp! {} to {} for {}",
stop.driving_pos,
path.get_req().start,
id
);
}

bus.state = BusState::DrivingToStop(stop_idx + 1);
Router::follow_bus_route(id, path)
} else if let Some(path) = route.end_at_border.clone() {
Expand Down

0 comments on commit ba8c6db

Please sign in to comment.