Skip to content

Commit

Permalink
Fix grid display and a couple of other things
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Apr 18, 2024
1 parent 2593559 commit e0c9992
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 46 deletions.
7 changes: 7 additions & 0 deletions crates/components/src/map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@ impl MapView {
let time = ui.input(|i| i.time);
self.map_view
.increment_animation_time(&graphics_state, time);

self.map_view.grid.display.update_viewport_size(
&graphics_state.render_state,
[canvas_rect.size().x, canvas_rect.size().y],
ui.ctx().pixels_per_point(),
);

self.map_view
.paint(&graphics_state, ui.painter(), canvas_rect);

Expand Down
13 changes: 10 additions & 3 deletions crates/components/src/tilepicker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use fragile::Fragile;
use itertools::Itertools;
use luminol_graphics::Renderable;
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -54,21 +55,21 @@ struct Callback {
impl luminol_egui_wgpu::CallbackTrait for Callback {
fn paint<'a>(
&'a self,
info: egui::PaintCallbackInfo,
_: egui::PaintCallbackInfo,
render_pass: &mut wgpu::RenderPass<'a>,
_callback_resources: &'a luminol_egui_wgpu::CallbackResources,
) {
let resources = self.resources.get();
let graphics_state = self.graphics_state.get();

resources.tiles.draw(graphics_state, &[true], render_pass);
resources.tiles.draw(graphics_state, render_pass);

if self.coll_enabled {
resources.collision.draw(graphics_state, render_pass);
}

if self.grid_enabled {
resources.grid.draw(graphics_state, &info, render_pass);
resources.grid.draw(graphics_state, render_pass);
}
}
}
Expand Down Expand Up @@ -233,6 +234,12 @@ impl Tilepicker {
.intersect(scroll_rect.translate(canvas_rect.min.to_vec2()));
let scroll_rect = absolute_scroll_rect.translate(-canvas_rect.min.to_vec2());

self.resources.grid.display.update_viewport_size(
&graphics_state.render_state,
[scroll_rect.size().x, scroll_rect.size().y],
ui.ctx().pixels_per_point(),
);

self.viewport.set_proj(
&graphics_state.render_state,
glam::Mat4::orthographic_rh(
Expand Down
8 changes: 2 additions & 6 deletions crates/graphics/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub struct MapView {
pub pano_enabled: bool,
pub coll_enabled: bool,
pub grid_enabled: bool,
pub enabled_layers: Vec<bool>,
}

impl MapView {
Expand Down Expand Up @@ -145,7 +144,6 @@ impl MapView {
pano_enabled: true,
coll_enabled: false,
grid_enabled: true,
enabled_layers: vec![true; map.data.zsize()],
})
}

Expand Down Expand Up @@ -197,8 +195,7 @@ impl crate::Renderable for MapView {
}
}

self.tiles
.draw(graphics_state, &self.enabled_layers, render_pass);
self.tiles.draw(graphics_state, render_pass);

for (_, event) in self.events.iter() {
event.draw(graphics_state, render_pass);
Expand All @@ -215,8 +212,7 @@ impl crate::Renderable for MapView {
}

if self.grid_enabled {
// self.grid
// .draw(graphics_state, info, &mut render_bundle_encoder);
self.grid.draw(graphics_state, render_pass);
}
}
}
4 changes: 3 additions & 1 deletion crates/graphics/src/primitives/collision/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ impl Collision {
) {
self.instances.set_passage(render_state, passage, position)
}
}

pub fn draw<'rpass>(
impl crate::Renderable for Collision {
fn draw<'rpass>(
&'rpass self,
graphics_state: &'rpass GraphicsState,
render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>,
Expand Down
16 changes: 6 additions & 10 deletions crates/graphics/src/primitives/grid/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,19 @@ impl Display {
}
}

pub(super) fn update_viewport_size(
pub fn update_viewport_size(
&self,
render_state: &luminol_egui_wgpu::RenderState,
info: &egui::PaintCallbackInfo,
viewport_size_in_pixels: [f32; 2],
pixels_per_point: f32,
) {
let viewport_size = info.viewport_in_pixels();
let viewport_size = [
viewport_size.width_px as f32,
viewport_size.height_px as f32,
];
let pixels_per_point = info.pixels_per_point.max(1.).floor();
let pixels_per_point = pixels_per_point.max(1.).floor();
let data = self.data.load();
if data.viewport_size_in_pixels != viewport_size
if data.viewport_size_in_pixels != viewport_size_in_pixels
|| data.pixels_per_point != pixels_per_point
{
self.data.store(Data {
viewport_size_in_pixels: viewport_size,
viewport_size_in_pixels,
pixels_per_point,
..data
});
Expand Down
15 changes: 3 additions & 12 deletions crates/graphics/src/primitives/grid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,18 @@ impl Grid {
bind_group,
}
}
}

pub fn draw<'rpass>(
impl crate::Renderable for Grid {
fn draw<'rpass>(
&'rpass self,
graphics_state: &'rpass GraphicsState,
info: &egui::PaintCallbackInfo,
render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>,
) {
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
struct VertexPushConstant {
viewport: [u8; 64],
display: [u8; 16],
}

render_pass.set_pipeline(&graphics_state.pipelines.grid);

render_pass.set_bind_group(0, &self.bind_group, &[]);

self.display
.update_viewport_size(&graphics_state.render_state, info);

self.instances.draw(render_pass);
}
}
Expand Down
20 changes: 9 additions & 11 deletions crates/graphics/src/primitives/tiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Tiles {
pub instances: Instances,
pub display: Display,
pub viewport: Arc<Viewport>,
pub enabled_layers: Vec<bool>,

pub bind_group: wgpu::BindGroup,
}
Expand Down Expand Up @@ -78,12 +79,14 @@ impl Tiles {
&graphics_state.bind_group_layouts.tiles,
);

let enabled_layers = vec![true; tiles.zsize()];

Self {
autotiles,
atlas,
instances,
display,

enabled_layers,
bind_group,
viewport,
}
Expand Down Expand Up @@ -115,23 +118,18 @@ impl Tiles {
.set_opacity(&graphics_state.render_state, opacity, layer);
}
}
}

pub fn draw<'rpass>(
impl crate::Renderable for Tiles {
fn draw<'rpass>(
&'rpass self,
graphics_state: &'rpass GraphicsState,
enabled_layers: &[bool],
render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>,
) {
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
struct VertexPushConstant {
viewport: [u8; 64],
autotiles: [u8; 48],
}

render_pass.set_pipeline(&graphics_state.pipelines.tiles);

for layer in enabled_layers
for layer in self
.enabled_layers
.iter()
.enumerate()
.filter_map(|(l, e)| e.then_some(l))
Expand Down
11 changes: 8 additions & 3 deletions crates/ui/src/tabs/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,13 @@ impl luminol_core::Tab for Tab {
ui.checkbox(&mut self.view.map_view.pano_enabled, "👁");
ui.end_row();

for (index, layer) in
self.view.map_view.enabled_layers.iter_mut().enumerate()
for (index, layer) in self
.view
.map_view
.tiles
.enabled_layers
.iter_mut()
.enumerate()
{
ui.columns(1, |columns| {
columns[0].selectable_value(
Expand Down Expand Up @@ -631,7 +636,7 @@ impl luminol_core::Tab for Tab {
None
},
(0..map.data.zsize())
.filter(|&i| self.view.map_view.enabled_layers[i])
.filter(|&i| self.view.map_view.tiles.enabled_layers[i])
.rev(),
|x, y, passage| {
if self.passages[(x, y)] != passage {
Expand Down

0 comments on commit e0c9992

Please sign in to comment.