Skip to content

Commit

Permalink
Properly clear LTN state when switching maps, even from different app…
Browse files Browse the repository at this point in the history
…s. [rebuild] [release]
  • Loading branch information
dabreegster committed Jan 16, 2022
1 parent 215ca34 commit cfddc5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 1 addition & 6 deletions game/src/ltn/browse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ impl BrowseNeighborhoods {

let style = Style::SimpleColoring;
let world = ctx.loading_screen("calculate neighborhoods", |ctx, timer| {
// TODO Or if the map doesn't match? Do we take care of this in SessionState for
// anything?!
if app.session.partitioning.neighborhoods.is_empty() {
if &app.session.partitioning.map != app.primary.map.get_name() {
app.session.partitioning = Partitioning::seed_using_heuristics(app, timer);
}
make_world(ctx, app, style, timer)
Expand Down Expand Up @@ -92,9 +90,6 @@ impl State<App> for BrowseNeighborhoods {
ctx,
app,
Box::new(|ctx, app| {
// TODO If we leave the LTN tool and change maps elsewhere, this won't
// work! Do we have per-map session state?
app.session.partitioning = Partitioning::empty();
Transition::Replace(BrowseNeighborhoods::new_state(ctx, app))
}),
));
Expand Down
4 changes: 4 additions & 0 deletions game/src/ltn/partition.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;

use abstio::MapName;
use abstutil::Timer;
use map_model::osm::RoadRank;
use map_model::{Block, Perimeter};
Expand All @@ -24,6 +25,7 @@ impl widgetry::mapspace::ObjectID for NeighborhoodID {}

#[derive(Clone)]
pub struct Partitioning {
pub map: MapName,
pub neighborhoods: BTreeMap<NeighborhoodID, (Block, Color)>,
// The single / unmerged blocks never change
pub single_blocks: Vec<Block>,
Expand All @@ -33,6 +35,7 @@ impl Partitioning {
/// Only valid before the LTN tool has been activated this session
pub fn empty() -> Partitioning {
Partitioning {
map: MapName::new("zz", "temp", "orary"),
neighborhoods: BTreeMap::new(),
single_blocks: Vec::new(),
}
Expand Down Expand Up @@ -83,6 +86,7 @@ impl Partitioning {
neighborhoods.insert(NeighborhoodID(neighborhoods.len()), (block, Color::RED));
}
let mut p = Partitioning {
map: map.get_name().clone(),
neighborhoods,
single_blocks,
};
Expand Down

0 comments on commit cfddc5b

Please sign in to comment.