From f8120c7fc0d58f4d6f4db074d6a6d39d16e666d2 Mon Sep 17 00:00:00 2001 From: Jakub Arnold Date: Sun, 17 Dec 2023 00:33:28 +0100 Subject: [PATCH] No more need for SmallVec per batch item + cleanup text --- comfy-core/src/camera.rs | 1 + comfy-core/src/text.rs | 1 + comfy-wgpu/src/batching.rs | 24 ++---------------------- comfy-wgpu/src/render_pass.rs | 12 +----------- comfy-wgpu/src/text.rs | 8 ++++---- comfy/src/update_stages.rs | 31 +++++++------------------------ 6 files changed, 16 insertions(+), 61 deletions(-) diff --git a/comfy-core/src/camera.rs b/comfy-core/src/camera.rs index d475220..32ea2ed 100644 --- a/comfy-core/src/camera.rs +++ b/comfy-core/src/camera.rs @@ -209,6 +209,7 @@ impl MainCamera { } self.center += offset * delta * self.smoothing_speed; + self.center = player_position; } } diff --git a/comfy-core/src/text.rs b/comfy-core/src/text.rs index 60fc4f7..06270d3 100644 --- a/comfy-core/src/text.rs +++ b/comfy-core/src/text.rs @@ -137,6 +137,7 @@ pub struct StyledGlyph { pub color: Option, } +#[derive(Debug)] pub struct RichText { pub clean_text: String, pub styled_glyphs: Vec, diff --git a/comfy-wgpu/src/batching.rs b/comfy-wgpu/src/batching.rs index 7f3f693..139a0d6 100644 --- a/comfy-wgpu/src/batching.rs +++ b/comfy-wgpu/src/batching.rs @@ -9,26 +9,6 @@ pub fn run_batched_render_passes( ) { span_with_timing!("run_batched_render_passes"); - // TODO: ... - // TODO: ... - let _empty_pass = ( - MeshGroupKey { - z_index: 0, - blend_mode: BlendMode::Alpha, - texture_id: TextureHandle::from_path("1px"), - shader: ShaderInstanceId::default(), - render_target: RenderTargetId::default(), - }, - RenderPassData { - z_index: 0, - blend_mode: BlendMode::Alpha, - texture: TextureHandle::from_path("1px"), - shader: None, - render_target: None, - data: SmallVec::new(), - }, - ); - let mut is_first = true; let queues = consume_render_queues(); @@ -72,7 +52,7 @@ pub fn run_batched_render_passes( texture: key.texture_id, shader: key.shader, render_target: key.render_target, - data: meshes.into(), + data: meshes, }, surface_view, sprite_shader_id, @@ -152,7 +132,7 @@ pub fn run_batched_render_passes( texture: TextureHandle::from_path("1px"), shader: ShaderInstanceId::default(), render_target: RenderTargetId::default(), - data: SmallVec::new(), + data: Default::default(), }, surface_view, sprite_shader_id, diff --git a/comfy-wgpu/src/render_pass.rs b/comfy-wgpu/src/render_pass.rs index 0d666f2..8a8d840 100644 --- a/comfy-wgpu/src/render_pass.rs +++ b/comfy-wgpu/src/render_pass.rs @@ -5,7 +5,7 @@ pub struct MeshDrawData { pub texture: TextureHandle, pub shader: ShaderInstanceId, pub render_target: RenderTargetId, - pub data: smallvec::SmallVec<[Mesh; 1]>, + pub data: Vec, } pub struct ParticleDrawData { @@ -13,13 +13,3 @@ pub struct ParticleDrawData { pub texture: TextureHandle, pub data: Vec, } - -#[derive(Clone, Debug)] -pub struct RenderPassData { - pub z_index: i32, - pub blend_mode: BlendMode, - pub texture: TextureHandle, - pub data: smallvec::SmallVec<[Mesh; 1]>, - pub shader: Option, - pub render_target: Option, -} diff --git a/comfy-wgpu/src/text.rs b/comfy-wgpu/src/text.rs index 2fb39ac..f9d284a 100644 --- a/comfy-wgpu/src/text.rs +++ b/comfy-wgpu/src/text.rs @@ -95,10 +95,10 @@ impl TextRasterizer { rgba_bitmap.push(*x); } - println!( - "metrics are {} {} for '{}'", - metrics.width, metrics.height, c - ); + // println!( + // "metrics are {} {} for '{}'", + // metrics.width, metrics.height, c + // ); if !(metrics.width == 0 || metrics.height == 0) { let mut image = diff --git a/comfy/src/update_stages.rs b/comfy/src/update_stages.rs index d182133..5af898a 100644 --- a/comfy/src/update_stages.rs +++ b/comfy/src/update_stages.rs @@ -21,9 +21,9 @@ pub(crate) fn run_early_update_stages(c: &mut EngineContext) { set_unpaused_time(get_unpaused_time() + delta as f64); } - render_text(c); update_blood_canvas(c); update_camera(c); + render_text(c); // TODO: not ideal clear_background(BLACK); @@ -179,6 +179,7 @@ fn render_text(c: &mut EngineContext) { )); let assets = ASSETS.borrow(); + let px = px(); for text in consume_text_queue().into_iter() { if let Some(pro_params) = text.pro_params { @@ -194,28 +195,11 @@ fn render_text(c: &mut EngineContext) { let font_handle = pro_params.font; let font = assets.fonts.get(&font_handle).unwrap(); - // let RichText { clean_text, styled_glyphs } = - // simple_styled_text(&text.text); - - // use fontdue::layout::VerticalAlign as VA; - // use fontdue::layout::HorizontalAlign as HA; - let layout = t.layout_text( font, &clean_text, pro_params.font_size, - &fontdue::layout::LayoutSettings { - // vertical_align: match text.align { - // TextAlign::TopLeft => VA::Top, - // TextAlign::TopRight => VA::Top, - // TextAlign::BottomLeft => VA::Bottom, - // TextAlign::BottomRight => VA::Bottom, - // TextAlign::Center => VA::Middle, - // }, - // vertical_align: fontdue::layout::VerticalAlign::Middle, - // horizontal_align: fontdue::layout::HorizontalAlign::Center, - ..Default::default() - }, + &fontdue::layout::LayoutSettings { ..Default::default() }, ); let mut min_x = f32::INFINITY; @@ -243,7 +227,7 @@ fn render_text(c: &mut EngineContext) { if draw_outline { draw_rect_outline( text.position + - layout_rect.size * px() / 2.0 * vec2(1.0, -1.0), + layout_rect.size * px / 2.0 * vec2(1.0, -1.0), Size::screen(layout_rect.size.x, layout_rect.size.y) .to_world(), 0.1, @@ -267,11 +251,10 @@ fn render_text(c: &mut EngineContext) { continue; } - let mut pos = vec2(glyph.x, glyph.y) * px() + + let mut pos = vec2(glyph.x, glyph.y) * px + text.position + - off * layout_rect.size * px() / 2.0 + - vec2(-layout_rect.size.x, layout_rect.size.y) * px() / - 2.0; + off * layout_rect.size * px / 2.0 + + vec2(-layout_rect.size.x, layout_rect.size.y) * px / 2.0; let mut color = text.color;