make physics-graphics communication a bit less insane
This commit is contained in:
parent
b9dc97053f
commit
0468484788
@ -75,7 +75,7 @@ impl GraphicsCamera{
|
|||||||
glam::Mat4::from_translation(pos)*glam::Mat4::from_euler(glam::EulerRot::YXZ,angles.x,angles.y,0f32)
|
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=self.proj();
|
||||||
let proj_inv=proj.inverse();
|
let proj_inv=proj.inverse();
|
||||||
let view_inv=self.world(pos,angles);
|
let view_inv=self.world(pos,angles);
|
||||||
@ -99,9 +99,9 @@ impl std::default::Default for GraphicsCamera{
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct FrameState{
|
pub struct FrameState{
|
||||||
pub physics_output:crate::physics::PhysicsOutputState,
|
pub body:crate::physics::Body,
|
||||||
pub predicted_time:integer::Time,
|
pub camera:crate::physics::PhysicsCamera,
|
||||||
pub mouse_pos:glam::IVec2,
|
pub time:integer::Time,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GraphicsState{
|
pub struct GraphicsState{
|
||||||
@ -814,7 +814,7 @@ impl GraphicsState{
|
|||||||
});
|
});
|
||||||
|
|
||||||
let camera=GraphicsCamera::default();
|
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{
|
let camera_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
||||||
label:Some("Camera"),
|
label:Some("Camera"),
|
||||||
contents:bytemuck::cast_slice(&camera_uniforms),
|
contents:bytemuck::cast_slice(&camera_uniforms),
|
||||||
@ -889,7 +889,10 @@ impl GraphicsState{
|
|||||||
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(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
|
self.staging_belt
|
||||||
.write_buffer(
|
.write_buffer(
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
|
@ -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)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
enum PhysicsCollisionAttributes{
|
enum PhysicsCollisionAttributes{
|
||||||
Contact(gameplay_attributes::ContactAttributes),
|
Contact(gameplay_attributes::ContactAttributes),
|
||||||
@ -1047,14 +1034,15 @@ impl instruction::InstructionEmitter<PhysicsInternalInstruction> for PhysicsCont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl PhysicsContext{
|
impl PhysicsContext{
|
||||||
pub const fn output(&self)->PhysicsOutputState{
|
pub fn camera_body(&self)->Body{
|
||||||
PhysicsOutputState{
|
Body{
|
||||||
body:self.state.body,
|
position:self.state.body.position+self.state.style.camera_offset,
|
||||||
camera:self.state.camera,
|
..self.state.body
|
||||||
camera_offset:self.state.style.camera_offset,
|
|
||||||
mouse_pos:self.state.input_state.mouse.pos,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub const fn camera(&self)->PhysicsCamera{
|
||||||
|
self.state.camera
|
||||||
|
}
|
||||||
pub const fn get_next_mouse(&self)->&MouseState{
|
pub const fn get_next_mouse(&self)->&MouseState{
|
||||||
self.state.input_state.get_next_mouse()
|
self.state.input_state.get_next_mouse()
|
||||||
}
|
}
|
||||||
|
@ -182,9 +182,9 @@ impl MouseInterpolator{
|
|||||||
}
|
}
|
||||||
pub fn get_frame_state(&self,time:Time)->crate::graphics::FrameState{
|
pub fn get_frame_state(&self,time:Time)->crate::graphics::FrameState{
|
||||||
crate::graphics::FrameState{
|
crate::graphics::FrameState{
|
||||||
physics_output:self.physics.output(),
|
body:self.physics.camera_body(),
|
||||||
mouse_pos:self.physics.get_next_mouse().pos,
|
camera:self.physics.camera(),
|
||||||
predicted_time:self.timer.time(time),
|
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){
|
||||||
|
Loading…
Reference in New Issue
Block a user