From fd5a813357e51b3633c118c1c5a55067c2cbc856 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 20 Aug 2024 15:28:36 -0700 Subject: [PATCH] graphics: bundle FrameState into struct --- src/graphics.rs | 12 ++++++++---- src/graphics_worker.rs | 8 +++----- src/physics_worker.rs | 12 ++++++++---- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/graphics.rs b/src/graphics.rs index f430dee..84dad48 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -98,6 +98,12 @@ impl std::default::Default for GraphicsCamera{ } } +pub struct FrameState{ + pub physics_output:crate::physics::PhysicsOutputState, + pub predicted_time:integer::Time, + pub mouse_pos:glam::IVec2, +} + pub struct GraphicsState{ pipelines:GraphicsPipelines, bind_groups:GraphicsBindGroups, @@ -876,16 +882,14 @@ impl GraphicsState{ view:&wgpu::TextureView, device:&wgpu::Device, queue:&wgpu::Queue, - physics_output:crate::physics::PhysicsOutputState, - predicted_time:integer::Time, - mouse_pos:glam::IVec2, + frame_state:FrameState, ){ //TODO:use scheduled frame times to create beautiful smoothing simulation physics extrapolation assuming no input let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None}); // update rotation - let camera_uniforms=self.camera.to_uniform_data(physics_output.extrapolate(strafesnet_common::mouse::MouseState{pos:mouse_pos,time:predicted_time})); + let camera_uniforms=self.camera.to_uniform_data(frame_state.physics_output.extrapolate(strafesnet_common::mouse::MouseState{pos:frame_state.mouse_pos,time:frame_state.predicted_time})); self.staging_belt .write_buffer( &mut encoder, diff --git a/src/graphics_worker.rs b/src/graphics_worker.rs index af028ef..9950785 100644 --- a/src/graphics_worker.rs +++ b/src/graphics_worker.rs @@ -1,7 +1,5 @@ -use strafesnet_common::integer; - pub enum Instruction{ - Render(crate::physics::PhysicsOutputState,integer::Time,glam::IVec2), + Render(crate::graphics::FrameState), //UpdateModel(crate::graphics::GraphicsModelUpdate), Resize(winit::dpi::PhysicalSize,crate::settings::UserSettings), ChangeMap(strafesnet_common::map::CompleteMap), @@ -33,7 +31,7 @@ pub fn new<'a>( Instruction::Resize(size,user_settings)=>{ resize=Some((size,user_settings)); } - Instruction::Render(physics_output,predicted_time,mouse_pos)=>{ + Instruction::Render(frame_state)=>{ if let Some((size,user_settings))=resize.take(){ println!("Resizing to {:?}",size); let t0=std::time::Instant::now(); @@ -58,7 +56,7 @@ pub fn new<'a>( ..wgpu::TextureViewDescriptor::default() }); - graphics.render(&view,&device,&queue,physics_output,predicted_time,mouse_pos); + graphics.render(&view,&device,&queue,frame_state); frame.present(); } diff --git a/src/physics_worker.rs b/src/physics_worker.rs index 0a1aec3..9116daf 100644 --- a/src/physics_worker.rs +++ b/src/physics_worker.rs @@ -180,8 +180,12 @@ impl MouseInterpolator{ self.empty_queue(); } } - pub fn get_render_stuff(&self,time:Time)->(crate::physics::PhysicsOutputState,Time,glam::IVec2){ - (self.physics.output(),self.timer.time(time),self.physics.get_next_mouse().pos) + pub fn get_frame_state(&self,time:Time)->crate::graphics::FrameState{ + crate::graphics::FrameState{ + physics_output:self.physics.output(), + mouse_pos:self.physics.get_next_mouse().pos, + predicted_time:self.timer.time(time), + } } pub fn change_map(&mut self,time:Time,map:&strafesnet_common::map::CompleteMap){ //dump any pending interpolation state @@ -221,8 +225,8 @@ pub fn new<'a>( interpolator.handle_instruction(&ins); match ins.instruction{ Instruction::Render=>{ - let (physics_output,time,mouse_pos)=interpolator.get_render_stuff(ins.time); - graphics_worker.send(crate::graphics_worker::Instruction::Render(physics_output,time,mouse_pos)).unwrap(); + let frame_state=interpolator.get_frame_state(ins.time); + graphics_worker.send(crate::graphics_worker::Instruction::Render(frame_state)).unwrap(); }, Instruction::Resize(size)=>{ graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,interpolator.user_settings().clone())).unwrap();