make physics-graphics communication a bit less insane

This commit is contained in:
Quaternions 2024-08-20 16:24:28 -07:00
parent 6d0d694d0c
commit 41bd781c7f
3 changed files with 19 additions and 28 deletions

View File

@ -75,7 +75,7 @@ impl GraphicsCamera{
glam::Mat4::from_translation(pos)*glam::Mat4::from_euler(glam::EulerRot::YXZ,angles.x,angles.y,0f32)
}
pub fn to_uniform_data(&self,(pos,angles):(glam::Vec3,glam::Vec2))->[f32; 16 * 4]{
pub fn to_uniform_data(&self,pos:glam::Vec3,angles:glam::Vec2)->[f32;16*4]{
let proj=self.proj();
let proj_inv=proj.inverse();
let view_inv=self.world(pos,angles);
@ -99,9 +99,9 @@ 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 body:crate::physics::Body,
pub camera:crate::physics::PhysicsCamera,
pub time:integer::Time,
}
pub struct GraphicsState{
@ -814,7 +814,7 @@ impl GraphicsState{
});
let camera=GraphicsCamera::default();
let camera_uniforms=camera.to_uniform_data(crate::physics::PhysicsOutputState::default().extrapolate(strafesnet_common::mouse::MouseState::default()));
let camera_uniforms=camera.to_uniform_data(glam::Vec3::ZERO,glam::Vec2::ZERO);
let camera_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
label:Some("Camera"),
contents:bytemuck::cast_slice(&camera_uniforms),
@ -889,7 +889,10 @@ impl GraphicsState{
let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
// update rotation
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}));
let camera_uniforms=self.camera.to_uniform_data(
frame_state.body.extrapolated_position(frame_state.time).into(),
frame_state.camera.simulate_move_angles(glam::IVec2::ZERO)
);
self.staging_belt
.write_buffer(
&mut encoder,

View File

@ -613,19 +613,6 @@ impl MoveState{
}
}
#[derive(Clone,Default)]
pub struct PhysicsOutputState{
body:Body,
camera:PhysicsCamera,
camera_offset:Planar64Vec3,
mouse_pos:glam::IVec2,
}
impl PhysicsOutputState{
pub fn extrapolate(&self,mouse:MouseState)->(glam::Vec3,glam::Vec2){
((self.body.extrapolated_position(mouse.time)+self.camera_offset).into(),self.camera.simulate_move_angles(mouse.pos-self.mouse_pos))
}
}
#[derive(Clone,Hash,Eq,PartialEq)]
enum PhysicsCollisionAttributes{
Contact(gameplay_attributes::ContactAttributes),
@ -1047,14 +1034,15 @@ impl instruction::InstructionEmitter<PhysicsInternalInstruction> for PhysicsCont
}
}
impl PhysicsContext{
pub const fn output(&self)->PhysicsOutputState{
PhysicsOutputState{
body:self.state.body,
camera:self.state.camera,
camera_offset:self.state.style.camera_offset,
mouse_pos:self.state.input_state.mouse.pos,
pub fn camera_body(&self)->Body{
Body{
position:self.state.body.position+self.state.style.camera_offset,
..self.state.body
}
}
pub const fn camera(&self)->PhysicsCamera{
self.state.camera
}
pub const fn get_next_mouse(&self)->&MouseState{
self.state.input_state.get_next_mouse()
}

View File

@ -182,9 +182,9 @@ impl MouseInterpolator{
}
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),
body:self.physics.camera_body(),
camera:self.physics.camera(),
time:self.timer.time(time),
}
}
pub fn change_map(&mut self,time:Time,map:&strafesnet_common::map::CompleteMap){