forked from StrafesNET/strafe-project
Compare commits
1 Commits
redo-input
...
redo-input
Author | SHA1 | Date | |
---|---|---|---|
5fb63375d3 |
@ -102,7 +102,7 @@ pub struct MouseInterpolationState {
|
||||
impl MouseInterpolationState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
interpolation:MouseInterpolation::Lerp,
|
||||
interpolation:MouseInterpolation::First,
|
||||
time0:0,
|
||||
time1:1,//ONE NANOSECOND!!!! avoid divide by zero
|
||||
mouse0:glam::IVec2::ZERO,
|
||||
@ -122,9 +122,9 @@ impl MouseInterpolationState {
|
||||
let m0=self.mouse0.as_i64vec2();
|
||||
let m1=self.mouse1.as_i64vec2();
|
||||
//these are deltas
|
||||
let t1t=(self.time1-time) as i64;
|
||||
let tt0=(time-self.time0) as i64;
|
||||
let dt=(self.time1-self.time0) as i64;
|
||||
let t1t=(self.time1-time).clamp(0,dt) as i64;
|
||||
let tt0=(time-self.time0).clamp(0,dt) as i64;
|
||||
((m0*t1t+m1*tt0)/dt).as_ivec2()
|
||||
}
|
||||
}
|
||||
@ -902,6 +902,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
||||
}
|
||||
//selectively update body
|
||||
match &ins.instruction {
|
||||
PhysicsInstruction::Input(InputInstruction::MoveMouse(_)) => (),//dodge time for mouse movement
|
||||
PhysicsInstruction::Input(_)
|
||||
|PhysicsInstruction::ReachWalkTargetVelocity
|
||||
|PhysicsInstruction::CollisionStart(_)
|
||||
|
36
src/main.rs
36
src/main.rs
@ -34,8 +34,6 @@ struct ModelGraphics {
|
||||
}
|
||||
|
||||
pub struct Skybox {
|
||||
block_mouse:strafe_client::body::TIME,
|
||||
period:strafe_client::body::TIME,
|
||||
start_time: std::time::Instant,
|
||||
screen_size: (u32, u32),
|
||||
physics: strafe_client::body::PhysicsState,
|
||||
@ -475,8 +473,6 @@ impl strafe_client::framework::Example for Skybox {
|
||||
let depth_view = Self::create_depth_texture(config, device);
|
||||
|
||||
Skybox {
|
||||
block_mouse:0,
|
||||
period:5_000_000,
|
||||
start_time: Instant::now(),
|
||||
screen_size: (config.width,config.height),
|
||||
physics,
|
||||
@ -522,7 +518,7 @@ impl strafe_client::framework::Example for Skybox {
|
||||
_ => None,
|
||||
}
|
||||
{
|
||||
self.physics.run(time);//call it a day
|
||||
self.physics.run(time);
|
||||
self.physics.process_instruction(TimedInstruction{
|
||||
time,
|
||||
instruction:PhysicsInstruction::Input(input_instruction),
|
||||
@ -532,34 +528,20 @@ impl strafe_client::framework::Example for Skybox {
|
||||
winit::event::DeviceEvent::MouseMotion {
|
||||
delta,//these (f64,f64) are integers on my machine
|
||||
} => {
|
||||
let run_the_physics=
|
||||
if time<self.block_mouse{
|
||||
false
|
||||
}else{
|
||||
if time-self.block_mouse<2*self.period{
|
||||
self.block_mouse+=self.period
|
||||
}else{
|
||||
self.block_mouse=time+self.period
|
||||
}
|
||||
true
|
||||
};
|
||||
if run_the_physics{
|
||||
//This lags like crazy if you require a substep for every mouse event (every 3ms)
|
||||
//I'm going to forgo mouse interpolation for now
|
||||
//because it's actually a hard problem to prevent the physics from running on every mouse update
|
||||
self.physics.run(time);//call it a day
|
||||
self.physics.process_instruction(TimedInstruction{
|
||||
time,
|
||||
instruction:PhysicsInstruction::Input(InputInstruction::MoveMouse(glam::ivec2(delta.0 as i32,delta.1 as i32))),
|
||||
})
|
||||
}
|
||||
//do not step the physics because the mouse polling rate is higher than the physics can run.
|
||||
//essentially the previous input will be overwritten until a true step runs
|
||||
//which is fine because they run all the time.
|
||||
self.physics.process_instruction(TimedInstruction{
|
||||
time,
|
||||
instruction:PhysicsInstruction::Input(InputInstruction::MoveMouse(glam::ivec2(delta.0 as i32,delta.1 as i32))),
|
||||
})
|
||||
},
|
||||
winit::event::DeviceEvent::MouseWheel {
|
||||
delta,
|
||||
} => {
|
||||
println!("mousewheel{:?}",delta);
|
||||
if true{//self.physics.use_scroll
|
||||
self.physics.run(time);//call it a day
|
||||
self.physics.run(time);
|
||||
self.physics.process_instruction(TimedInstruction{
|
||||
time,
|
||||
instruction:PhysicsInstruction::Input(InputInstruction::Jump(true)),//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump
|
||||
|
Reference in New Issue
Block a user