mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
Refactor: Just remember ID -> quadtree ID
This commit is contained in:
parent
c16f185019
commit
4a0635fa5a
@ -40,8 +40,7 @@ pub struct DrawMap {
|
||||
|
||||
quadtree: QuadTree<ID>,
|
||||
// Remember these so we can modify the bounding box of some objects.
|
||||
lane_ids: HashMap<LaneID, aabb_quadtree::ItemId>,
|
||||
intersection_ids: HashMap<IntersectionID, aabb_quadtree::ItemId>,
|
||||
quadtree_ids: HashMap<ID, aabb_quadtree::ItemId>,
|
||||
}
|
||||
|
||||
impl DrawMap {
|
||||
@ -143,8 +142,7 @@ impl DrawMap {
|
||||
|
||||
timer.start("create quadtree");
|
||||
let mut quadtree = QuadTree::default(map.get_bounds().as_bbox());
|
||||
let mut lane_ids = HashMap::new();
|
||||
let mut intersection_ids = HashMap::new();
|
||||
let mut quadtree_ids = HashMap::new();
|
||||
// TODO use iter chain if everything was boxed as a renderable...
|
||||
for obj in &roads {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_outline(map).get_bounds().as_bbox());
|
||||
@ -152,12 +150,12 @@ impl DrawMap {
|
||||
for (_, obj) in &lanes {
|
||||
let item_id =
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_outline(map).get_bounds().as_bbox());
|
||||
lane_ids.insert(obj.id, item_id);
|
||||
quadtree_ids.insert(obj.get_id(), item_id);
|
||||
}
|
||||
for obj in &intersections {
|
||||
let item_id =
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_outline(map).get_bounds().as_bbox());
|
||||
intersection_ids.insert(obj.id, item_id);
|
||||
quadtree_ids.insert(obj.get_id(), item_id);
|
||||
}
|
||||
for obj in &buildings {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_outline(map).get_bounds().as_bbox());
|
||||
@ -196,8 +194,7 @@ impl DrawMap {
|
||||
draw_all_areas,
|
||||
|
||||
quadtree,
|
||||
lane_ids,
|
||||
intersection_ids,
|
||||
quadtree_ids,
|
||||
|
||||
zorder_range: (low_z, high_z),
|
||||
show_zorder: high_z,
|
||||
@ -454,7 +451,7 @@ impl DrawMap {
|
||||
pub fn create_lane(&mut self, l: LaneID, map: &Map) {
|
||||
// If we're recreating an existing lane, don't create a duplicate quadtree entry for it!
|
||||
// quadtree.insert_with_box isn't idempotent.
|
||||
if let Some(item_id) = self.lane_ids.remove(&l) {
|
||||
if let Some(item_id) = self.quadtree_ids.remove(&ID::Lane(l)) {
|
||||
self.quadtree.remove(item_id).unwrap();
|
||||
}
|
||||
|
||||
@ -462,25 +459,25 @@ impl DrawMap {
|
||||
let item_id = self
|
||||
.quadtree
|
||||
.insert_with_box(draw.get_id(), draw.get_outline(map).get_bounds().as_bbox());
|
||||
self.lane_ids.insert(l, item_id);
|
||||
self.quadtree_ids.insert(draw.get_id(), item_id);
|
||||
self.lanes.insert(l, draw);
|
||||
}
|
||||
|
||||
pub fn delete_lane(&mut self, l: LaneID) {
|
||||
self.lanes.remove(&l).unwrap();
|
||||
let item_id = self.lane_ids.remove(&l).unwrap();
|
||||
let item_id = self.quadtree_ids.remove(&ID::Lane(l)).unwrap();
|
||||
self.quadtree.remove(item_id).unwrap();
|
||||
}
|
||||
|
||||
pub fn recreate_intersection(&mut self, i: IntersectionID, map: &Map) {
|
||||
let item_id = self.intersection_ids.remove(&i).unwrap();
|
||||
let item_id = self.quadtree_ids.remove(&ID::Intersection(i)).unwrap();
|
||||
self.quadtree.remove(item_id).unwrap();
|
||||
|
||||
let draw = DrawIntersection::new(map.get_i(i), map);
|
||||
let item_id = self
|
||||
.quadtree
|
||||
.insert_with_box(draw.get_id(), draw.get_outline(map).get_bounds().as_bbox());
|
||||
self.intersection_ids.insert(i, item_id);
|
||||
self.quadtree_ids.insert(draw.get_id(), item_id);
|
||||
self.intersections[i.0] = draw;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user