Skip to content

Commit

Permalink
Clean warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Aug 11, 2019
1 parent dbc5e12 commit 0c8e175
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 129 deletions.
11 changes: 0 additions & 11 deletions src/drawing/drawable_layer.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
use crate::vector_tile::transform::Layer;
use core::ops::Range;

#[derive(Debug, Clone)]
pub struct DrawableLayer {
pub id: u32,
pub indices_range: Range<u32>,
pub features: Vec<(u32, Range<u32>)>
}

impl DrawableLayer {
pub fn from_layer(layer: &Layer) -> Self {
Self {
id: layer.id,
indices_range: layer.indices_range.clone(),
features: layer.features.clone(),
}
}
}
24 changes: 10 additions & 14 deletions src/drawing/drawable_tile.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use wgpu::RenderPipeline;
use core::ops::Range;
use crate::drawing::layer_collection::LayerCollection;
use crate::drawing::feature_collection::FeatureCollection;
use crate::vector_tile::math::TileId;
use crate::drawing::{
drawable_layer::DrawableLayer,
};
use wgpu::{
RenderPass,
Buffer,
Expand Down Expand Up @@ -52,9 +49,8 @@ impl DrawableTile {
render_pass: &mut RenderPass,
blend_pipeline: &RenderPipeline,
noblend_pipeline: &RenderPipeline,
layer_collection: &LayerCollection,
tile_id: u32,
outline: bool
feature_collection: &FeatureCollection,
tile_id: u32
) {
render_pass.set_index_buffer(&self.index_buffer, 0);
render_pass.set_vertex_buffers(&[(&self.vertex_buffer, 0)]);
Expand All @@ -63,13 +59,13 @@ impl DrawableTile {
let mut opaque_set = vec![];

self.features.sort_by(|a, b| {
layer_collection
feature_collection
.get_zindex(a.0)
.partial_cmp(&layer_collection.get_zindex(b.0)).unwrap()
.partial_cmp(&feature_collection.get_zindex(b.0)).unwrap()
});

for (id, range) in &self.features {
if layer_collection.has_alpha(*id) {
if feature_collection.has_alpha(*id) {
alpha_set.push((id, range));
} else {
opaque_set.push((id, range));
Expand All @@ -79,14 +75,14 @@ impl DrawableTile {
let mut i = 0;
render_pass.set_pipeline(noblend_pipeline);
for (id, range) in opaque_set {
if range.len() > 0 && layer_collection.is_visible(*id) {
if range.len() > 0 && feature_collection.is_visible(*id) {
render_pass.set_stencil_reference(i as u32);
i += 1;

let range_start = (tile_id << 1) | 1;
render_pass.draw_indexed(range.clone(), 0, 0 + range_start .. 1 + range_start);

if layer_collection.has_outline(*id) {
if feature_collection.has_outline(*id) {
let range_start = tile_id << 1;
render_pass.draw_indexed(range.clone(), 0, 0 + range_start .. 1 + range_start);
}
Expand All @@ -96,14 +92,14 @@ impl DrawableTile {
let mut i = 0;
render_pass.set_pipeline(blend_pipeline);
for (id, range) in alpha_set {
if range.len() > 0 && layer_collection.is_visible(*id) {
if range.len() > 0 && feature_collection.is_visible(*id) {
render_pass.set_stencil_reference(i as u32);
i += 1;

let range_start = (tile_id << 1) | 1;
render_pass.draw_indexed(range.clone(), 0, 0 + range_start .. 1 + range_start);

if layer_collection.has_outline(*id) {
if feature_collection.has_outline(*id) {
let range_start = tile_id << 1;
render_pass.draw_indexed(range.clone(), 0, 0 + range_start .. 1 + range_start);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
use std::slice::Iter;
use crate::css::RulesCache;
use crate::drawing::feature::{
Feature,
FeatureStyle,
};

#[derive(Debug, Clone)]
pub struct LayerCollection {
layers: Vec<bool>,
pub struct FeatureCollection {
features: Vec<Feature>,
n_features_max: u32,
}

impl LayerCollection {
pub fn new(n_layers: u32, n_features_max: u32) -> Self {
impl FeatureCollection {
pub fn new(n_features_max: u32) -> Self {
Self {
layers: vec![false; n_layers as usize],
features: vec![],
n_features_max,
}
}

pub fn is_layer_set(&self, id: u32) -> bool {
self.layers[id as usize]
}

pub fn set_layer(&mut self, id: u32) {
self.layers[id as usize] = true;
}

pub fn get_features(&self) -> &Vec<Feature> {
&self.features
}
Expand All @@ -44,24 +33,6 @@ impl LayerCollection {
self.features.len() as u32 - 1
}

pub fn _has_outline(&self) -> bool {
for feature in &self.features {
if feature.style.border_width > 0.0 && feature.style.border_color.a > 0.0 {
return true;
}
}
false
}

pub fn _has_fill(&self) -> bool {
for feature in &self.features {
if feature.style.background_color.a > 0.0 {
return true;
}
}
false
}

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
2 changes: 1 addition & 1 deletion src/drawing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pub mod drawable_tile;
mod drawable_layer;
pub mod mesh;
pub mod feature;
pub mod layer_collection;
pub mod feature_collection;

pub use painter::Painter;
47 changes: 21 additions & 26 deletions src/drawing/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use nalgebra_glm::{
vec4,
vec2,
};
use crate::drawing::layer_collection::LayerCollection;
use crate::drawing::feature_collection::FeatureCollection;
use crate::vector_tile::math::Screen;
use wgpu::TextureView;
use crossbeam_channel::{
Expand Down Expand Up @@ -88,7 +88,7 @@ pub struct Painter {
bind_group: BindGroup,
rx: crossbeam_channel::Receiver<std::result::Result<notify::event::Event, notify::Error>>,
_watcher: RecommendedWatcher,
layer_collection: Arc<RwLock<LayerCollection>>,
feature_collection: Arc<RwLock<FeatureCollection>>,
}

impl Painter {
Expand Down Expand Up @@ -190,7 +190,7 @@ impl Painter {
]
});

let layer_collection = Arc::new(RwLock::new(LayerCollection::new(20, 500)));
let feature_collection = Arc::new(RwLock::new(FeatureCollection::new(500)));

let swap_chain_descriptor = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
Expand Down Expand Up @@ -277,7 +277,7 @@ impl Painter {
bind_group,
_watcher: watcher,
rx,
layer_collection,
feature_collection,
}
}

Expand Down Expand Up @@ -364,7 +364,7 @@ impl Painter {
}

/// Creates a new bind group containing all the relevant uniform buffers.
fn create_uniform_buffers(device: &Device, screen: &Screen, layer_collection: &LayerCollection) -> Vec<(Buffer, usize)> {
fn create_uniform_buffers(device: &Device, screen: &Screen, feature_collection: &FeatureCollection) -> Vec<(Buffer, usize)> {
let canvas_size_len = 4 * 4;
let canvas_size_buffer = device
.create_buffer_mapped(
Expand All @@ -373,7 +373,7 @@ impl Painter {
)
.fill_from_slice(&[screen.width as f32, screen.height as f32, 0.0, 0.0]);

let buffer = layer_collection.assemble_style_buffer();
let buffer = feature_collection.assemble_style_buffer();
let layer_data_len = buffer.len() * 12 * 4;
let layer_data_buffer = device
.create_buffer_mapped(
Expand Down Expand Up @@ -550,8 +550,8 @@ impl Painter {

pub fn update_styles(&mut self, zoom: f32, css_cache: &mut RulesCache) {
if css_cache.update() {
let mut layer_collection = self.layer_collection.write().unwrap();
layer_collection.load_styles(zoom, css_cache);
let mut feature_collection = self.feature_collection.write().unwrap();
feature_collection.load_styles(zoom, css_cache);
}
}

Expand All @@ -575,14 +575,14 @@ impl Painter {
&mut self,
encoder: &mut CommandEncoder,
app_state: &AppState,
layer_collection: &LayerCollection
feature_collection: &FeatureCollection
) {
Self::copy_uniform_buffers(
encoder,
&Self::create_uniform_buffers(
&self.device,
&app_state.screen,
layer_collection
feature_collection
),
&self.uniform_buffer
);
Expand Down Expand Up @@ -658,7 +658,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.layer_collection.clone());
app_state.tile_cache.request_tile(&tile_id, self.feature_collection.clone());

let tile_cache = &mut app_state.tile_cache;
if let Some(tile) = tile_cache.try_get_tile(&tile_id) {
Expand Down Expand Up @@ -711,27 +711,27 @@ impl Painter {
}
}

let mut layer_collection = self.layer_collection.write().unwrap();
layer_collection.load_styles(app_state.zoom, &mut app_state.css_cache);
let mut feature_collection = self.feature_collection.write().unwrap();
feature_collection.load_styles(app_state.zoom, &mut app_state.css_cache);
}

pub fn paint(&mut self, app_state: &mut AppState) {
let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 });
self.load_tiles(app_state);
let layer_collection = {
let lock = self.layer_collection.clone();
let layer_collection = lock.read().unwrap();
(*layer_collection).clone()
let feature_collection = {
let lock = self.feature_collection.clone();
let feature_collection = lock.read().unwrap();
(*feature_collection).clone()
};
self.update_uniforms(&mut encoder, &app_state, &layer_collection);
self.update_uniforms(&mut encoder, &app_state, &feature_collection);
self.bind_group = Self::create_blend_bind_group(
&self.device,
&self.bind_group_layout,
&self.uniform_buffer,
&self.tile_transform_buffer
);
let num_tiles = self.loaded_tiles.len();
let features = layer_collection.get_features();
let features = feature_collection.get_features();
if features.len() > 0 && num_tiles > 0 {
let frame = self.swap_chain.get_next_texture();
{
Expand Down Expand Up @@ -788,15 +788,10 @@ impl Painter {
(e.x - s.x) as u32,
(e.y - s.y) as u32
);
dt.paint(&mut render_pass, &self.blend_pipeline, &self.noblend_pipeline, &layer_collection, i as u32, false);
dt.paint(&mut render_pass, &self.blend_pipeline, &self.noblend_pipeline, &feature_collection, i as u32);
}
}
self.device.get_queue().submit(&[encoder.finish()]);
}
}
}

// pub fn timestamp(old: std::time::Instant, string: &str) -> std::time::Instant {
// log::debug!("{}: {}", string, old.elapsed().as_micros());
// std::time::Instant::now()
// }
}
6 changes: 3 additions & 3 deletions src/vector_tile/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::drawing::layer_collection::LayerCollection;
use crate::drawing::feature_collection::FeatureCollection;
use std::sync::{
Arc,
RwLock,
Expand Down Expand Up @@ -61,7 +61,7 @@ impl TileCache {
}
}

pub fn request_tile(&mut self, tile_id: &math::TileId, layer_collection: Arc<RwLock<LayerCollection>>) {
pub fn request_tile(&mut self, tile_id: &math::TileId, feature_collection: Arc<RwLock<FeatureCollection>>) {
let id = self.id;
self.id += 1;

Expand All @@ -74,7 +74,7 @@ impl TileCache {
id,
spawn(move|| {
if let Some(data) = crate::vector_tile::fetch_tile_data(&tile_id_clone) {
let tile = Tile::from_mbvt(&tile_id_clone, &data, layer_collection);
let tile = Tile::from_mbvt(&tile_id_clone, &data, feature_collection);
match tx.send(id) {
Err(_) => log::debug!("Could not send the tile load message. This most likely happened because the app was terminated."),
_ => (),
Expand Down
6 changes: 3 additions & 3 deletions src/vector_tile/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// 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.layer_collection.clone());
// app_state.tile_cache.request_tile(&tile_id, self.feature_collection.clone());

// let tile_cache = &mut app_state.tile_cache;
// if let Some(tile) = tile_cache.try_get_tile(&tile_id) {
Expand Down Expand Up @@ -83,7 +83,7 @@
// }
// }

// let mut layer_collection = self.layer_collection.write().unwrap();
// layer_collection.load_styles(app_state.zoom, &mut app_state.css_cache);
// let mut feature_collection = self.feature_collection.write().unwrap();
// feature_collection.load_styles(app_state.zoom, &mut app_state.css_cache);
// }
// }
Loading

0 comments on commit 0c8e175

Please sign in to comment.