From 70ae42b5675279d10c43f62c1a2c89e497d1bec1 Mon Sep 17 00:00:00 2001 From: "Victor A." <52110451+cs50victor@users.noreply.github.com> Date: Mon, 29 Jan 2024 17:18:14 -0500 Subject: [PATCH 1/2] docs: update docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7e7ea7..e54b8cc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # bevy_headless -Derived from `bevy_image_export` with +Derived from `bevy_image_export` with access to the current generated image frame. ## Examples - [minimal](./examples/minimal.rs) From 3de7bd64825a369bbc966f28ec8d69472fac9abe Mon Sep 17 00:00:00 2001 From: "Victor A." <52110451+cs50victor@users.noreply.github.com> Date: Mon, 29 Jan 2024 17:35:30 -0500 Subject: [PATCH 2/2] chore: lint --- src/node.rs | 5 ++--- src/plugin.rs | 48 +++++++++++++----------------------------------- 2 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/node.rs b/src/node.rs index fce9ac1..d8a5c48 100644 --- a/src/node.rs +++ b/src/node.rs @@ -22,9 +22,8 @@ impl Node for ImageExportNode { world: &World, ) -> Result<(), NodeRunError> { for (_, source) in world.resource::>().iter() { - if let Some(gpu_image) = world - .resource::>() - .get(&source.source_handle) + if let Some(gpu_image) = + world.resource::>().get(&source.source_handle) { render_context.command_encoder().copy_texture_to_buffer( gpu_image.texture.as_image_copy(), diff --git a/src/plugin.rs b/src/plugin.rs index e65bc99..409a4d3 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -70,11 +70,7 @@ pub struct GpuImageExportSource { impl GpuImageExportSource { fn get_bps(&self) -> (usize, usize, Extent3d) { - ( - self.bytes_per_row as usize, - self.padded_bytes_per_row as usize, - self.source_size, - ) + (self.bytes_per_row as usize, self.padded_bytes_per_row as usize, self.source_size) } } @@ -122,29 +118,20 @@ pub struct ImageExportStartFrame(u64); impl Default for ImageExportSettings { fn default() -> Self { - Self { - extension: "png".into(), - } + Self { extension: "png".into() } } } impl ExtractComponent for ImageExportSettings { type Filter = (); type Out = (Self, Handle, ImageExportStartFrame); - type Query = ( - &'static Self, - &'static Handle, - &'static ImageExportStartFrame, - ); + type Query = + (&'static Self, &'static Handle, &'static ImageExportStartFrame); fn extract_component( (settings, source_handle, start_frame): QueryItem<'_, Self::Query>, ) -> Option { - Some(( - settings.clone(), - source_handle.clone_weak(), - start_frame.clone(), - )) + Some((settings.clone(), source_handle.clone_weak(), start_frame.clone())) } } @@ -155,9 +142,7 @@ fn setup_exporters( ) { *frame_id = frame_id.wrapping_add(1); for entity in &exporters { - commands - .entity(entity) - .insert(ImageExportStartFrame(*frame_id)); + commands.entity(entity).insert(ImageExportStartFrame(*frame_id)); } } @@ -228,7 +213,7 @@ fn save_buffer_as_resource( frame_id, extension, ); - } + }, _ => { capture_img_bytes::>( &image_bytes, @@ -237,7 +222,7 @@ fn save_buffer_as_resource( frame_id, extension, ); - } + }, } } } @@ -255,14 +240,11 @@ fn capture_img_bytes( { match ImageBuffer::::from_raw(source_size.width, source_size.height, image_bytes) { Some(image_bytes) => { - curr_img - .0 - .lock() - .update_data(frame_id, &image_bytes, extension.to_owned()); - } + curr_img.0.lock().update_data(frame_id, &image_bytes, extension.to_owned()); + }, None => { log::error!("Failed creating image buffer for frame - '{frame_id}'"); - } + }, } } @@ -295,9 +277,7 @@ impl Plugin for HeadlessPlugin { app.configure_sets( PostUpdate, - (SetupImageExport, SetupImageExportFlush) - .chain() - .before(CameraUpdateSystem), + (SetupImageExport, SetupImageExportFlush).chain().before(CameraUpdateSystem), ) .register_type::() .init_asset::() @@ -320,9 +300,7 @@ impl Plugin for HeadlessPlugin { render_app.add_systems( Render, - save_buffer_as_resource - .after(RenderSet::Render) - .before(RenderSet::Cleanup), + save_buffer_as_resource.after(RenderSet::Render).before(RenderSet::Cleanup), ); let mut graph = render_app.world.get_resource_mut::().unwrap();