move physics types to common

This commit is contained in:
Quaternions 2024-08-02 13:47:02 -07:00
parent 4eccd27237
commit 8d4db7e654

View File

@ -13,6 +13,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 +26,6 @@ enum PhysicsInternalInstruction{
StrafeTick,
ReachWalkTargetVelocity,
// 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)]
enum PhysicsInstruction{
@ -78,32 +54,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,