Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
No more need for SmallVec per batch item + cleanup text
Browse files Browse the repository at this point in the history
  • Loading branch information
darthdeus committed Dec 16, 2023
1 parent feed94a commit f8120c7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 61 deletions.
1 change: 1 addition & 0 deletions comfy-core/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl MainCamera {
}

self.center += offset * delta * self.smoothing_speed;
self.center = player_position;
}
}

Expand Down
1 change: 1 addition & 0 deletions comfy-core/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pub struct StyledGlyph {
pub color: Option<Color>,
}

#[derive(Debug)]
pub struct RichText {
pub clean_text: String,
pub styled_glyphs: Vec<StyledGlyph>,
Expand Down
24 changes: 2 additions & 22 deletions comfy-wgpu/src/batching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 1 addition & 11 deletions comfy-wgpu/src/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,11 @@ pub struct MeshDrawData {
pub texture: TextureHandle,
pub shader: ShaderInstanceId,
pub render_target: RenderTargetId,
pub data: smallvec::SmallVec<[Mesh; 1]>,
pub data: Vec<Mesh>,
}

pub struct ParticleDrawData {
pub blend_mode: BlendMode,
pub texture: TextureHandle,
pub data: Vec<ParticleDraw>,
}

#[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<ShaderInstanceId>,
pub render_target: Option<RenderTargetId>,
}
8 changes: 4 additions & 4 deletions comfy-wgpu/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
31 changes: 7 additions & 24 deletions comfy/src/update_stages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand Down

0 comments on commit f8120c7

Please sign in to comment.