From ced855524c78e971a59f25cd219dc3dda9eaccf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=A6=80=20adia-dev?= Date: Wed, 28 Feb 2024 21:33:30 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Cycling=20of=20the=20colors=20inpla?= =?UTF-8?q?ce,=20no=20need=20to=20re-process=20iterations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/src/rendering/mod.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/shared/src/rendering/mod.rs b/shared/src/rendering/mod.rs index a0a2a06..f599ad7 100644 --- a/shared/src/rendering/mod.rs +++ b/shared/src/rendering/mod.rs @@ -30,6 +30,7 @@ struct World { height: u32, rendering_data_shards: SharedRenderingData, palette: PaletteHandler, + iterations: Vec, } fn initialize_shared_data(shard_count: usize) -> SharedRenderingData { @@ -54,12 +55,14 @@ pub async fn launch_graphics_engine( // TODO: decomission this sharded rendering data let rendering_data = initialize_shared_data(1); + let iterations: Vec = vec![0.0; (width * height) as usize]; let mut graphics_world = World { server, width, height, rendering_data_shards: rendering_data.clone(), palette: PaletteHandler::new(), + iterations, }; tokio::spawn(async move { @@ -139,12 +142,18 @@ pub async fn launch_graphics_engine( if input_helper.key_pressed(VirtualKeyCode::L) { graphics_world.cycle_color_palette_forward(); - window.request_redraw(); + graphics_world.re_render(pixels.frame_mut()); + if pixels.render().is_err() { + *control_flow = ControlFlow::Exit; + } } if input_helper.key_pressed(VirtualKeyCode::J) { graphics_world.cycle_color_palette_backward(); - window.request_redraw(); + graphics_world.re_render(pixels.frame_mut()); + if pixels.render().is_err() { + *control_flow = ControlFlow::Exit; + } } if let Some(size) = input_helper.window_resized() { @@ -164,28 +173,34 @@ impl World { fn cycle_color_palette_forward(&mut self) { self.palette.cycle_palette_forward(); - self.server.lock().unwrap().regenerate_tiles(); + // self.server.lock().unwrap().regenerate_tiles(); } fn cycle_color_palette_backward(&mut self) { self.palette.cycle_palette_backward(); - self.server.lock().unwrap().regenerate_tiles(); + // self.server.lock().unwrap().regenerate_tiles(); + } + + fn re_render(&self, frame_buffer: &mut [u8]) { + for y in 0..self.width { + for x in 0..self.height { + let t = self.iterations[(y as u32 * self.width + x as u32) as usize]; + self.draw_pixel(frame_buffer, self.width, x as u32, y as u32, t); + } + } } - fn render(&self, frame_buffer: &mut [u8]) { + fn render(&mut self, frame_buffer: &mut [u8]) { for shard in self.rendering_data_shards.iter() { if let Ok(mut data_lock) = shard.lock() { if let Some(render_data) = data_lock.take() { // Safely take the value, replacing it with None - info!("Rendering result: {:?}", render_data.result); let result = render_data.result; - let (start_x, start_y) = self.start_point(result.range); - info!("Drawing fragment at ({}, {})", start_x, start_y); - for y in 0..result.resolution.ny { for x in 0..result.resolution.nx { let t = render_data.iterations[(x + y * result.resolution.ny) as usize]; + self.iterations[((start_y + (y as u32)) * self.width + (start_x + x as u32)) as usize] = t; self.draw_pixel( frame_buffer, self.width,