use crate::{
context::MapContext,
render::{
eventually::{Eventually, Eventually::Initialized},
render_commands::DrawMasks,
render_phase::{DrawState, LayerItem, RenderPhase, TileMaskItem},
tile_view_pattern::WgpuTileViewPattern,
},
tcs::tiles::Tile,
vector::{render_commands::DrawVectorTiles, VectorBufferPool},
};
pub fn queue_system(MapContext { world, .. }: &mut MapContext) {
let Some((
Initialized(tile_view_pattern),
Initialized(buffer_pool),
mask_phase,
layer_item_phase,
)) = world.resources.query_mut::<(
&mut Eventually<WgpuTileViewPattern>,
&mut Eventually<VectorBufferPool>,
&mut RenderPhase<TileMaskItem>,
&mut RenderPhase<LayerItem>,
)>()
else {
return;
};
let buffer_pool_index = buffer_pool.index();
for view_tile in tile_view_pattern.iter() {
let coords = &view_tile.coords();
tracing::trace!("Drawing tile at {coords}");
view_tile.render(|source_shape| {
mask_phase.add(TileMaskItem {
draw_function: Box::new(DrawState::<TileMaskItem, DrawMasks>::new()),
source_shape: source_shape.clone(),
});
if let Some(layer_entries) = buffer_pool_index.get_layers(source_shape.coords()) {
for layer_entry in layer_entries {
layer_item_phase.add(LayerItem {
draw_function: Box::new(DrawState::<LayerItem, DrawVectorTiles>::new()),
index: layer_entry.style_layer.index,
style_layer: layer_entry.style_layer.id.clone(),
tile: Tile {
coords: layer_entry.coords,
},
source_shape: source_shape.clone(),
});
}
};
});
}
}