mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 15:33:44 +03:00
Recalculate pathfinding at the right time, now that changing to the trip page can immediately trigger pathfinding
This commit is contained in:
parent
d050c885c8
commit
876eff87dd
@ -348,7 +348,7 @@ impl ModeShiftData {
|
|||||||
scenario: Scenario,
|
scenario: Scenario,
|
||||||
timer: &mut Timer,
|
timer: &mut Timer,
|
||||||
) -> ModeShiftData {
|
) -> ModeShiftData {
|
||||||
let map = app
|
let unedited_map = app
|
||||||
.primary
|
.primary
|
||||||
.unedited_map
|
.unedited_map
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@ -367,16 +367,27 @@ impl ModeShiftData {
|
|||||||
|trip| {
|
|trip| {
|
||||||
// TODO Does ? work
|
// TODO Does ? work
|
||||||
if let (Some(driving_path), Some(biking_path)) = (
|
if let (Some(driving_path), Some(biking_path)) = (
|
||||||
TripEndpoint::path_req(trip.origin, trip.destination, TripMode::Drive, map)
|
TripEndpoint::path_req(
|
||||||
.and_then(|req| map.pathfind(req).ok()),
|
trip.origin,
|
||||||
TripEndpoint::path_req(trip.origin, trip.destination, TripMode::Bike, map)
|
trip.destination,
|
||||||
.and_then(|req| map.pathfind(req).ok()),
|
TripMode::Drive,
|
||||||
|
unedited_map,
|
||||||
|
)
|
||||||
|
.and_then(|req| unedited_map.pathfind(req).ok()),
|
||||||
|
TripEndpoint::path_req(
|
||||||
|
trip.origin,
|
||||||
|
trip.destination,
|
||||||
|
TripMode::Bike,
|
||||||
|
unedited_map,
|
||||||
|
)
|
||||||
|
.and_then(|req| unedited_map.pathfind(req).ok()),
|
||||||
) {
|
) {
|
||||||
let (total_elevation_gain, _) = biking_path.get_total_elevation_change(map);
|
let (total_elevation_gain, _) =
|
||||||
|
biking_path.get_total_elevation_change(unedited_map);
|
||||||
Some(CandidateTrip {
|
Some(CandidateTrip {
|
||||||
bike_req: biking_path.get_req().clone(),
|
bike_req: biking_path.get_req().clone(),
|
||||||
estimated_biking_time: biking_path
|
estimated_biking_time: biking_path
|
||||||
.estimate_duration(map, Some(map_model::MAX_BIKE_SPEED)),
|
.estimate_duration(unedited_map, Some(map_model::MAX_BIKE_SPEED)),
|
||||||
driving_distance: driving_path.total_length(),
|
driving_distance: driving_path.total_length(),
|
||||||
total_elevation_gain,
|
total_elevation_gain,
|
||||||
})
|
})
|
||||||
@ -395,18 +406,18 @@ impl ModeShiftData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn recalculate_gaps(&mut self, ctx: &mut EventCtx, app: &App, timer: &mut Timer) {
|
fn recalculate_gaps(&mut self, ctx: &mut EventCtx, app: &App, timer: &mut Timer) {
|
||||||
let map = app
|
let unedited_map = app
|
||||||
.primary
|
.primary
|
||||||
.unedited_map
|
.unedited_map
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap_or(&app.primary.map);
|
.unwrap_or(&app.primary.map);
|
||||||
|
|
||||||
// Find all high-stress roads, since we'll filter by them next
|
// Find all high-stress roads, since we'll filter by them next
|
||||||
let high_stress: HashSet<RoadID> = map
|
let high_stress: HashSet<RoadID> = unedited_map
|
||||||
.all_roads()
|
.all_roads()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|r| {
|
.filter_map(|r| {
|
||||||
if r.high_stress_for_bikes(map) {
|
if r.high_stress_for_bikes(unedited_map) {
|
||||||
Some(r.id)
|
Some(r.id)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -428,7 +439,7 @@ impl ModeShiftData {
|
|||||||
let mut count_per_road = Counter::new();
|
let mut count_per_road = Counter::new();
|
||||||
for (idx, path) in timer
|
for (idx, path) in timer
|
||||||
.parallelize("calculate routes", filtered_requests, |(idx, req)| {
|
.parallelize("calculate routes", filtered_requests, |(idx, req)| {
|
||||||
map.pathfind_v2(req).map(|path| (idx, path))
|
unedited_map.pathfind_v2(req).map(|path| (idx, path))
|
||||||
})
|
})
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
|
@ -12,7 +12,6 @@ mod results;
|
|||||||
|
|
||||||
pub struct TripPlanner {
|
pub struct TripPlanner {
|
||||||
layers: Layers,
|
layers: Layers,
|
||||||
once: bool,
|
|
||||||
|
|
||||||
input_panel: Panel,
|
input_panel: Panel,
|
||||||
waypoints: InputWaypoints,
|
waypoints: InputWaypoints,
|
||||||
@ -39,9 +38,14 @@ impl ObjectID for ID {}
|
|||||||
|
|
||||||
impl TripPlanner {
|
impl TripPlanner {
|
||||||
pub fn new_state(ctx: &mut EventCtx, app: &mut App, layers: Layers) -> Box<dyn State<App>> {
|
pub fn new_state(ctx: &mut EventCtx, app: &mut App, layers: Layers) -> Box<dyn State<App>> {
|
||||||
|
ctx.loading_screen("apply edits", |_, mut timer| {
|
||||||
|
app.primary
|
||||||
|
.map
|
||||||
|
.recalculate_pathfinding_after_edits(&mut timer);
|
||||||
|
});
|
||||||
|
|
||||||
let mut rp = TripPlanner {
|
let mut rp = TripPlanner {
|
||||||
layers,
|
layers,
|
||||||
once: true,
|
|
||||||
|
|
||||||
input_panel: Panel::empty(ctx),
|
input_panel: Panel::empty(ctx),
|
||||||
waypoints: InputWaypoints::new(app),
|
waypoints: InputWaypoints::new(app),
|
||||||
@ -169,15 +173,6 @@ impl TripPlanner {
|
|||||||
|
|
||||||
impl State<App> for TripPlanner {
|
impl State<App> for TripPlanner {
|
||||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||||
if self.once {
|
|
||||||
self.once = false;
|
|
||||||
ctx.loading_screen("apply edits", |_, mut timer| {
|
|
||||||
app.primary
|
|
||||||
.map
|
|
||||||
.recalculate_pathfinding_after_edits(&mut timer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let world_outcome_for_waypoints = match self.world.event(ctx) {
|
let world_outcome_for_waypoints = match self.world.event(ctx) {
|
||||||
WorldOutcome::ClickedObject(ID::AltRoute(idx)) => {
|
WorldOutcome::ClickedObject(ID::AltRoute(idx)) => {
|
||||||
// Switch routes
|
// Switch routes
|
||||||
|
Loading…
Reference in New Issue
Block a user