diff --git a/src/graphics.rs b/src/graphics.rs index fbeb0cc0..e24268d2 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -816,7 +816,7 @@ impl GraphicsState{ }); let camera=GraphicsCamera::default(); - let camera_uniforms=camera.to_uniform_data(crate::physics::PhysicsOutputState::default().extrapolate(crate::physics::MouseState::default())); + let camera_uniforms=camera.to_uniform_data(crate::physics::PhysicsOutputState::default().extrapolate(strafesnet_common::mouse::MouseState::default())); let camera_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{ label:Some("Camera"), contents:bytemuck::cast_slice(&camera_uniforms), @@ -893,7 +893,7 @@ impl GraphicsState{ let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None}); // update rotation - let camera_uniforms=self.camera.to_uniform_data(physics_output.extrapolate(crate::physics::MouseState{pos:mouse_pos,time:predicted_time})); + let camera_uniforms=self.camera.to_uniform_data(physics_output.extrapolate(strafesnet_common::mouse::MouseState{pos:mouse_pos,time:predicted_time})); self.staging_belt .write_buffer( &mut encoder, diff --git a/src/physics.rs b/src/physics.rs index 5e6d4022..5e821869 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -5,6 +5,7 @@ use strafesnet_common::map; use strafesnet_common::run; use strafesnet_common::aabb; use strafesnet_common::model::{MeshId,ModelId}; +use strafesnet_common::mouse::MouseState; use strafesnet_common::gameplay_attributes::{self,CollisionAttributesId}; use strafesnet_common::gameplay_modes::{self,StageId}; use strafesnet_common::gameplay_style::{self,StyleModifiers}; @@ -13,6 +14,10 @@ use strafesnet_common::instruction::{self,InstructionEmitter,InstructionConsumer use strafesnet_common::integer::{self,Time,Planar64,Planar64Vec3,Planar64Mat3,Angle32,Ratio64Vec2}; use gameplay::ModeState; +//external influence +//this is how you influence the physics from outside +use strafesnet_common::physics::Instruction as PhysicsInputInstruction; + //internal influence //when the physics asks itself what happens next, this is how it's represented #[derive(Debug)] @@ -22,34 +27,6 @@ enum PhysicsInternalInstruction{ StrafeTick, ReachWalkTargetVelocity, // Water, - // Spawn( - // Option, - // bool,//true = Trigger; false = teleport - // bool,//true = Force - // ) -} -//external influence -//this is how you influence the physics from outside -#[derive(Debug)] -pub enum PhysicsInputInstruction{ - ReplaceMouse(MouseState,MouseState), - SetNextMouse(MouseState), - SetMoveRight(bool), - SetMoveUp(bool), - SetMoveBack(bool), - SetMoveLeft(bool), - SetMoveDown(bool), - SetMoveForward(bool), - SetJump(bool), - SetZoom(bool), - Restart, - Spawn(gameplay_modes::ModeId,StageId), - Idle, - //Idle: there were no input events, but the simulation is safe to advance to this timestep - //for interpolation / networking / playback reasons, most playback heads will always want - //to be 1 instruction ahead to generate the next state for interpolation. - PracticeFly, - SetSensitivity(Ratio64Vec2), } #[derive(Debug)] enum PhysicsInstruction{ @@ -78,32 +55,6 @@ impl std::ops::Neg for Body{ } } -//hey dumbass just use a delta -#[derive(Clone,Debug)] -pub struct MouseState { - pub pos: glam::IVec2, - pub time:Time, -} -impl Default for MouseState{ - fn default() -> Self { - Self { - time:Time::ZERO, - pos:glam::IVec2::ZERO, - } - } -} -impl MouseState { - pub fn lerp(&self,target:&MouseState,time:Time)->glam::IVec2 { - let m0=self.pos.as_i64vec2(); - let m1=target.pos.as_i64vec2(); - //these are deltas - let t1t=(target.time-time).nanos(); - let tt0=(time-self.time).nanos(); - let dt=(target.time-self.time).nanos(); - ((m0*t1t+m1*tt0)/dt).as_ivec2() - } -} - #[derive(Clone,Debug,Default)] pub struct InputState{ mouse:MouseState, @@ -1542,6 +1493,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI //the body may as well be a quantum wave function //as far as these instruction are concerned (they don't care where it is) PhysicsInputInstruction::SetSensitivity(..) + |PhysicsInputInstruction::Reset |PhysicsInputInstruction::Restart |PhysicsInputInstruction::Spawn(..) |PhysicsInputInstruction::SetZoom(..) @@ -1603,10 +1555,13 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI state.input_state.set_control(Controls::Zoom,s); b_refresh_walk_target=false; }, - PhysicsInputInstruction::Restart=>{ + PhysicsInputInstruction::Reset=>{ //totally reset physics state state.reset_to_default(); - //spawn at start zone + b_refresh_walk_target=false; + }, + PhysicsInputInstruction::Restart=>{ + //teleport to start zone let spawn_point=data.modes.get_mode(state.mode_state.get_mode_id()).map(|mode| //TODO: spawn at the bottom of the start zone plus the hitbox size //TODO: set camera andles to face the same way as the start zone diff --git a/src/physics_worker.rs b/src/physics_worker.rs index 7d1da1ed..7bd1d785 100644 --- a/src/physics_worker.rs +++ b/src/physics_worker.rs @@ -1,4 +1,5 @@ -use crate::physics::{MouseState,PhysicsInputInstruction}; +use strafesnet_common::mouse::MouseState; +use strafesnet_common::physics::Instruction as PhysicsInputInstruction; use strafesnet_common::integer::Time; use strafesnet_common::instruction::TimedInstruction; use strafesnet_common::timer::{Scaled,Timer,TimerState}; diff --git a/src/window.rs b/src/window.rs index a75fa3fd..14132278 100644 --- a/src/window.rs +++ b/src/window.rs @@ -13,7 +13,7 @@ pub enum WindowInstruction{ //holds thread handles to dispatch to struct WindowContext<'a>{ manual_mouse_lock:bool, - mouse:crate::physics::MouseState,//std::sync::Arc> + mouse:strafesnet_common::mouse::MouseState,//std::sync::Arc> screen_size:glam::UVec2, user_settings:crate::settings::UserSettings, window:&'a winit::window::Window, @@ -113,7 +113,7 @@ impl WindowContext<'_>{ "z"=>Some(InputInstruction::Zoom(s)), "r"=>if s{ //mouse needs to be reset since the position is absolute - self.mouse=crate::physics::MouseState::default(); + self.mouse=strafesnet_common::mouse::MouseState::default(); Some(InputInstruction::Restart) }else{None}, "f"=>if s{Some(InputInstruction::PracticeFly)}else{None}, @@ -200,7 +200,7 @@ impl<'a> WindowContextSetup<'a>{ let graphics_thread=crate::graphics_worker::new(self.graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue); WindowContext{ manual_mouse_lock:false, - mouse:crate::physics::MouseState::default(), + mouse:strafesnet_common::mouse::MouseState::default(), //make sure to update this!!!!! screen_size, user_settings:self.user_settings, diff --git a/src/worker.rs b/src/worker.rs index 325a3b95..08287f69 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -190,7 +190,7 @@ mod test{ for _ in 0..5 { let task = instruction::TimedInstruction{ time:integer::Time::ZERO, - instruction:physics::PhysicsInputInstruction::Idle, + instruction:strafesnet_common::physics::Instruction::Idle, }; worker.send(task).unwrap(); } @@ -204,7 +204,7 @@ mod test{ // Send a new task let task = instruction::TimedInstruction{ time:integer::Time::ZERO, - instruction:physics::PhysicsInputInstruction::Idle, + instruction:strafesnet_common::physics::Instruction::Idle, }; worker.send(task).unwrap();