Skip to content

Commit

Permalink
Parallelize tile loading (object part); cleanup code for tile loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Sep 4, 2019
1 parent c5f43a9 commit 1d19ffb
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 141 deletions.
5 changes: 1 addition & 4 deletions src/bin/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ impl AppState {
}

pub fn update_hovered_objects(&mut self, point: (f32, f32)) {
self.hovered_objects = Collider::get_hovered_objects(&self.tile_cache, &self.screen, self.zoom ,point)
.iter()
.map(|o| (**o).clone())
.collect();
self.hovered_objects = Collider::get_hovered_objects(&self.tile_cache, &self.screen, self.zoom ,point);
}

pub fn update_selected_hover_objects(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/drawing/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ impl Painter {
app_state.tile_cache.fetch_tiles();
for tile_id in tile_field.iter() {
if !self.loaded_tiles.contains_key(&tile_id) {
app_state.tile_cache.request_tile(&tile_id, self.feature_collection.clone(), CONFIG.renderer.selection_tags.clone());
app_state.tile_cache.request_tile(&tile_id, self.feature_collection.clone(), &CONFIG.renderer.selection_tags.clone());

let tile_cache = &mut app_state.tile_cache;
if let Some(tile) = tile_cache.try_get_tile(&tile_id) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ impl TileCache {
&mut self,
tile_id: &TileId,
feature_collection: Arc<RwLock<FeatureCollection>>,
selection_tags: Vec<String>
selection_tags: &Vec<String>
) {
let id = self.id;
self.id += 1;

let loader = self.loaders.iter().filter(|l| l.2 == *tile_id).next();
let selection_tags = selection_tags.clone();

if !self.cache.contains_key(&tile_id) && loader.is_none() {
let tile_id_clone = tile_id.clone();
Expand Down
8 changes: 0 additions & 8 deletions src/lib/drawing/drawable_layer.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/lib/drawing/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod line_tesselator;
mod mesh;
mod vertex;
mod drawable_layer;
mod drawable_tile;

pub use line_tesselator::*;
pub use mesh::*;
pub use vertex::*;
pub use drawable_layer::*;
pub use drawable_tile::*;
12 changes: 10 additions & 2 deletions src/lib/feature/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,25 @@ impl FeatureCollection {
&self.features
}

pub fn get_feature_id(&mut self, selector: &crate::css::Selector) -> Option<u32> {
fn get_feature_id(&mut self, selector: &crate::css::Selector) -> Option<u32> {
self.features.iter_mut().enumerate().find(|(_, feature)| &feature.selector == selector).map(|(i, _)| i as u32)
}

pub fn add_feature(&mut self, mut feature: Feature) -> u32 {
fn add_feature(&mut self, mut feature: Feature) -> u32 {
assert!(self.features.len() < self.n_features_max as usize);
feature.id = self.features.len() as u32;
self.features.push(feature);
self.features.len() as u32 - 1
}

pub fn ensure_feature(&mut self, selector: &Selector) -> u32 {
if let Some(feature_id) = self.get_feature_id(selector) {
feature_id
} else {
self.add_feature(Feature::new(selector.clone(), 0))
}
}

pub fn is_visible(&self, feature_id: u32) -> bool {
let feature = &self.features[feature_id as usize];
let bga = feature.style.background_color.a;
Expand Down
18 changes: 11 additions & 7 deletions src/lib/interaction/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub struct Collider {
}

impl Collider {
pub fn get_hovered_objects<'a>(cache: &'a TileCache, screen: &Screen, zoom: f32, point: (f32, f32)) -> Vec<&'a Object> {
let mut objects = vec![];
pub fn get_hovered_objects<'a>(cache: &'a TileCache, screen: &Screen, zoom: f32, point: (f32, f32)) -> Vec<Object> {
let mut return_objects = vec![];
let tile_field = screen.get_tile_boundaries_for_zoom_level(zoom, 1);

for tile_id in tile_field.iter() {
Expand All @@ -27,17 +27,21 @@ impl Collider {

if tile_point.x >= 0.0 && tile_point.x <= tile.extent as f32
&& tile_point.y >= 0.0 && tile_point.y <= tile.extent as f32 {
let object_ids = tile.collider.get_hovered_objects(&tile_point);
for object_id in object_ids {
objects.push(&tile.objects[object_id])
if let Ok(collider) = tile.collider.try_read() {
if let Ok(objects) = tile.objects.try_read() {
let object_ids = collider.get_hovered_objects(&tile_point);
for object_id in object_ids {
return_objects.push(objects[object_id].clone())
}
}
}
return objects
return return_objects
}
} else {
log::trace!("[Intersection pass] Could not read tile {} from cache.", tile_id);
}
}

objects
return_objects
}
}
Loading

0 comments on commit 1d19ffb

Please sign in to comment.