forked from StrafesNET/strafe-client
move physics instruction to common
This commit is contained in:
parent
4b5b7dc2fb
commit
3a98eaff7c
@ -816,7 +816,7 @@ impl GraphicsState{
|
|||||||
});
|
});
|
||||||
|
|
||||||
let camera=GraphicsCamera::default();
|
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{
|
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),
|
||||||
@ -893,7 +893,7 @@ 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(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
|
self.staging_belt
|
||||||
.write_buffer(
|
.write_buffer(
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
|
@ -5,6 +5,7 @@ use strafesnet_common::map;
|
|||||||
use strafesnet_common::run;
|
use strafesnet_common::run;
|
||||||
use strafesnet_common::aabb;
|
use strafesnet_common::aabb;
|
||||||
use strafesnet_common::model::{MeshId,ModelId};
|
use strafesnet_common::model::{MeshId,ModelId};
|
||||||
|
use strafesnet_common::mouse::MouseState;
|
||||||
use strafesnet_common::gameplay_attributes::{self,CollisionAttributesId};
|
use strafesnet_common::gameplay_attributes::{self,CollisionAttributesId};
|
||||||
use strafesnet_common::gameplay_modes::{self,StageId};
|
use strafesnet_common::gameplay_modes::{self,StageId};
|
||||||
use strafesnet_common::gameplay_style::{self,StyleModifiers};
|
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 strafesnet_common::integer::{self,Time,Planar64,Planar64Vec3,Planar64Mat3,Angle32,Ratio64Vec2};
|
||||||
use gameplay::ModeState;
|
use gameplay::ModeState;
|
||||||
|
|
||||||
|
//external influence
|
||||||
|
//this is how you influence the physics from outside
|
||||||
|
use strafesnet_common::physics::Instruction as PhysicsInputInstruction;
|
||||||
|
|
||||||
//internal influence
|
//internal influence
|
||||||
//when the physics asks itself what happens next, this is how it's represented
|
//when the physics asks itself what happens next, this is how it's represented
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -22,34 +27,6 @@ enum PhysicsInternalInstruction{
|
|||||||
StrafeTick,
|
StrafeTick,
|
||||||
ReachWalkTargetVelocity,
|
ReachWalkTargetVelocity,
|
||||||
// Water,
|
// Water,
|
||||||
// Spawn(
|
|
||||||
// Option<SpawnId>,
|
|
||||||
// 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)]
|
#[derive(Debug)]
|
||||||
enum PhysicsInstruction{
|
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)]
|
#[derive(Clone,Debug,Default)]
|
||||||
pub struct InputState{
|
pub struct InputState{
|
||||||
mouse:MouseState,
|
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
|
//the body may as well be a quantum wave function
|
||||||
//as far as these instruction are concerned (they don't care where it is)
|
//as far as these instruction are concerned (they don't care where it is)
|
||||||
PhysicsInputInstruction::SetSensitivity(..)
|
PhysicsInputInstruction::SetSensitivity(..)
|
||||||
|
|PhysicsInputInstruction::Reset
|
||||||
|PhysicsInputInstruction::Restart
|
|PhysicsInputInstruction::Restart
|
||||||
|PhysicsInputInstruction::Spawn(..)
|
|PhysicsInputInstruction::Spawn(..)
|
||||||
|PhysicsInputInstruction::SetZoom(..)
|
|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);
|
state.input_state.set_control(Controls::Zoom,s);
|
||||||
b_refresh_walk_target=false;
|
b_refresh_walk_target=false;
|
||||||
},
|
},
|
||||||
PhysicsInputInstruction::Restart=>{
|
PhysicsInputInstruction::Reset=>{
|
||||||
//totally reset physics state
|
//totally reset physics state
|
||||||
state.reset_to_default();
|
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|
|
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: 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
|
//TODO: set camera andles to face the same way as the start zone
|
||||||
|
@ -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::integer::Time;
|
||||||
use strafesnet_common::instruction::TimedInstruction;
|
use strafesnet_common::instruction::TimedInstruction;
|
||||||
use strafesnet_common::timer::{Scaled,Timer,TimerState};
|
use strafesnet_common::timer::{Scaled,Timer,TimerState};
|
||||||
|
@ -13,7 +13,7 @@ pub enum WindowInstruction{
|
|||||||
//holds thread handles to dispatch to
|
//holds thread handles to dispatch to
|
||||||
struct WindowContext<'a>{
|
struct WindowContext<'a>{
|
||||||
manual_mouse_lock:bool,
|
manual_mouse_lock:bool,
|
||||||
mouse:crate::physics::MouseState,//std::sync::Arc<std::sync::Mutex<>>
|
mouse:strafesnet_common::mouse::MouseState,//std::sync::Arc<std::sync::Mutex<>>
|
||||||
screen_size:glam::UVec2,
|
screen_size:glam::UVec2,
|
||||||
user_settings:crate::settings::UserSettings,
|
user_settings:crate::settings::UserSettings,
|
||||||
window:&'a winit::window::Window,
|
window:&'a winit::window::Window,
|
||||||
@ -113,7 +113,7 @@ impl WindowContext<'_>{
|
|||||||
"z"=>Some(InputInstruction::Zoom(s)),
|
"z"=>Some(InputInstruction::Zoom(s)),
|
||||||
"r"=>if s{
|
"r"=>if s{
|
||||||
//mouse needs to be reset since the position is absolute
|
//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)
|
Some(InputInstruction::Restart)
|
||||||
}else{None},
|
}else{None},
|
||||||
"f"=>if s{Some(InputInstruction::PracticeFly)}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);
|
let graphics_thread=crate::graphics_worker::new(self.graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue);
|
||||||
WindowContext{
|
WindowContext{
|
||||||
manual_mouse_lock:false,
|
manual_mouse_lock:false,
|
||||||
mouse:crate::physics::MouseState::default(),
|
mouse:strafesnet_common::mouse::MouseState::default(),
|
||||||
//make sure to update this!!!!!
|
//make sure to update this!!!!!
|
||||||
screen_size,
|
screen_size,
|
||||||
user_settings:self.user_settings,
|
user_settings:self.user_settings,
|
||||||
|
@ -190,7 +190,7 @@ mod test{
|
|||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
let task = instruction::TimedInstruction{
|
let task = instruction::TimedInstruction{
|
||||||
time:integer::Time::ZERO,
|
time:integer::Time::ZERO,
|
||||||
instruction:physics::PhysicsInputInstruction::Idle,
|
instruction:strafesnet_common::physics::Instruction::Idle,
|
||||||
};
|
};
|
||||||
worker.send(task).unwrap();
|
worker.send(task).unwrap();
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ mod test{
|
|||||||
// Send a new task
|
// Send a new task
|
||||||
let task = instruction::TimedInstruction{
|
let task = instruction::TimedInstruction{
|
||||||
time:integer::Time::ZERO,
|
time:integer::Time::ZERO,
|
||||||
instruction:physics::PhysicsInputInstruction::Idle,
|
instruction:strafesnet_common::physics::Instruction::Idle,
|
||||||
};
|
};
|
||||||
worker.send(task).unwrap();
|
worker.send(task).unwrap();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user