graphics: bundle FrameState into struct

This commit is contained in:
Quaternions 2024-08-20 15:28:36 -07:00
parent 50726199b9
commit fd5a813357
3 changed files with 19 additions and 13 deletions

View File

@ -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{ pub struct GraphicsState{
pipelines:GraphicsPipelines, pipelines:GraphicsPipelines,
bind_groups:GraphicsBindGroups, bind_groups:GraphicsBindGroups,
@ -876,16 +882,14 @@ impl GraphicsState{
view:&wgpu::TextureView, view:&wgpu::TextureView,
device:&wgpu::Device, device:&wgpu::Device,
queue:&wgpu::Queue, queue:&wgpu::Queue,
physics_output:crate::physics::PhysicsOutputState, frame_state:FrameState,
predicted_time:integer::Time,
mouse_pos:glam::IVec2,
){ ){
//TODO:use scheduled frame times to create beautiful smoothing simulation physics extrapolation assuming no input //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}); let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
// update rotation // 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 self.staging_belt
.write_buffer( .write_buffer(
&mut encoder, &mut encoder,

View File

@ -1,7 +1,5 @@
use strafesnet_common::integer;
pub enum Instruction{ pub enum Instruction{
Render(crate::physics::PhysicsOutputState,integer::Time,glam::IVec2), Render(crate::graphics::FrameState),
//UpdateModel(crate::graphics::GraphicsModelUpdate), //UpdateModel(crate::graphics::GraphicsModelUpdate),
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings), Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
ChangeMap(strafesnet_common::map::CompleteMap), ChangeMap(strafesnet_common::map::CompleteMap),
@ -33,7 +31,7 @@ pub fn new<'a>(
Instruction::Resize(size,user_settings)=>{ Instruction::Resize(size,user_settings)=>{
resize=Some((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(){ if let Some((size,user_settings))=resize.take(){
println!("Resizing to {:?}",size); println!("Resizing to {:?}",size);
let t0=std::time::Instant::now(); let t0=std::time::Instant::now();
@ -58,7 +56,7 @@ pub fn new<'a>(
..wgpu::TextureViewDescriptor::default() ..wgpu::TextureViewDescriptor::default()
}); });
graphics.render(&view,&device,&queue,physics_output,predicted_time,mouse_pos); graphics.render(&view,&device,&queue,frame_state);
frame.present(); frame.present();
} }

View File

@ -180,8 +180,12 @@ impl MouseInterpolator{
self.empty_queue(); self.empty_queue();
} }
} }
pub fn get_render_stuff(&self,time:Time)->(crate::physics::PhysicsOutputState,Time,glam::IVec2){ pub fn get_frame_state(&self,time:Time)->crate::graphics::FrameState{
(self.physics.output(),self.timer.time(time),self.physics.get_next_mouse().pos) 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){ pub fn change_map(&mut self,time:Time,map:&strafesnet_common::map::CompleteMap){
//dump any pending interpolation state //dump any pending interpolation state
@ -221,8 +225,8 @@ pub fn new<'a>(
interpolator.handle_instruction(&ins); interpolator.handle_instruction(&ins);
match ins.instruction{ match ins.instruction{
Instruction::Render=>{ Instruction::Render=>{
let (physics_output,time,mouse_pos)=interpolator.get_render_stuff(ins.time); let frame_state=interpolator.get_frame_state(ins.time);
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics_output,time,mouse_pos)).unwrap(); graphics_worker.send(crate::graphics_worker::Instruction::Render(frame_state)).unwrap();
}, },
Instruction::Resize(size)=>{ Instruction::Resize(size)=>{
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,interpolator.user_settings().clone())).unwrap(); graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,interpolator.user_settings().clone())).unwrap();