ruin physics code

This commit is contained in:
Quaternions 2025-01-13 23:55:42 -08:00
parent fb8c2a619a
commit a8847d3632

View File

@ -20,6 +20,8 @@ type MouseState=strafesnet_common::mouse::MouseState<TimeInner>;
//external influence //external influence
//this is how you influence the physics from outside //this is how you influence the physics from outside
use strafesnet_common::physics::Instruction as PhysicsInputInstruction; use strafesnet_common::physics::Instruction as PhysicsInputInstruction;
use strafesnet_common::physics::OtherInstruction as PhysicsOtherInstruction;
use strafesnet_common::physics::MouseInstruction as PhysicsMouseInstruction;
//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
@ -1751,22 +1753,22 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
let should_advance_body=match ins.instruction{ let should_advance_body=match ins.instruction{
//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::Other(PhysicsOtherInstruction::SetSensitivity(..))
|PhysicsInputInstruction::Reset |PhysicsInputInstruction::Other(PhysicsOtherInstruction::Reset)
|PhysicsInputInstruction::Restart |PhysicsInputInstruction::Other(PhysicsOtherInstruction::Restart)
|PhysicsInputInstruction::Spawn(..) |PhysicsInputInstruction::Other(PhysicsOtherInstruction::Spawn(..))
|PhysicsInputInstruction::SetZoom(..) |PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetZoom(..))
|PhysicsInputInstruction::Idle=>false, |PhysicsInputInstruction::Other(PhysicsOtherInstruction::Idle)=>false,
//these controls only update the body if you are on the ground //these controls only update the body if you are on the ground
PhysicsInputInstruction::SetNextMouse(..) PhysicsInputInstruction::Mouse(PhysicsMouseInstruction::SetNextMouse(..))
|PhysicsInputInstruction::ReplaceMouse(..) |PhysicsInputInstruction::Mouse(PhysicsMouseInstruction::ReplaceMouse{..})
|PhysicsInputInstruction::SetMoveForward(..) |PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveForward(..))
|PhysicsInputInstruction::SetMoveLeft(..) |PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveLeft(..))
|PhysicsInputInstruction::SetMoveBack(..) |PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveBack(..))
|PhysicsInputInstruction::SetMoveRight(..) |PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveRight(..))
|PhysicsInputInstruction::SetMoveUp(..) |PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveUp(..))
|PhysicsInputInstruction::SetMoveDown(..) |PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveDown(..))
|PhysicsInputInstruction::SetJump(..)=>{ |PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetJump(..))=>{
match &state.move_state{ match &state.move_state{
MoveState::Fly MoveState::Fly
|MoveState::Water |MoveState::Water
@ -1776,100 +1778,100 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
} }
}, },
//the body must be updated unconditionally //the body must be updated unconditionally
PhysicsInputInstruction::PracticeFly=>true, PhysicsInputInstruction::Other(PhysicsOtherInstruction::PracticeFly)=>true,
}; };
if should_advance_body{ if should_advance_body{
state.body.advance_time(state.time); state.body.advance_time(state.time);
} }
//TODO: UNTAB
let mut b_refresh_walk_target=true; let mut b_refresh_walk_target=true;
match ins.instruction{ match ins.instruction{
PhysicsInputInstruction::SetSensitivity(sensitivity)=>state.camera.sensitivity=sensitivity, PhysicsInputInstruction::Mouse(PhysicsMouseInstruction::SetNextMouse(m))=>{
PhysicsInputInstruction::SetNextMouse(m)=>{ state.camera.move_mouse(state.input_state.mouse_delta());
state.camera.move_mouse(state.input_state.mouse_delta()); state.input_state.set_next_mouse(m);
state.input_state.set_next_mouse(m); },
}, PhysicsInputInstruction::Mouse(PhysicsMouseInstruction::ReplaceMouse{m0,m1})=>{
PhysicsInputInstruction::ReplaceMouse(m0,m1)=>{ state.camera.move_mouse(m0.pos-state.input_state.mouse.pos);
state.camera.move_mouse(m0.pos-state.input_state.mouse.pos); state.input_state.replace_mouse(m0,m1);
state.input_state.replace_mouse(m0,m1); },
}, PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetSensitivity(sensitivity))=>state.camera.sensitivity=sensitivity,
PhysicsInputInstruction::SetMoveForward(s)=>state.input_state.set_control(Controls::MoveForward,s), PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveForward(s))=>state.input_state.set_control(Controls::MoveForward,s),
PhysicsInputInstruction::SetMoveLeft(s)=>state.input_state.set_control(Controls::MoveLeft,s), PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveLeft(s))=>state.input_state.set_control(Controls::MoveLeft,s),
PhysicsInputInstruction::SetMoveBack(s)=>state.input_state.set_control(Controls::MoveBackward,s), PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveBack(s))=>state.input_state.set_control(Controls::MoveBackward,s),
PhysicsInputInstruction::SetMoveRight(s)=>state.input_state.set_control(Controls::MoveRight,s), PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveRight(s))=>state.input_state.set_control(Controls::MoveRight,s),
PhysicsInputInstruction::SetMoveUp(s)=>state.input_state.set_control(Controls::MoveUp,s), PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveUp(s))=>state.input_state.set_control(Controls::MoveUp,s),
PhysicsInputInstruction::SetMoveDown(s)=>state.input_state.set_control(Controls::MoveDown,s), PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetMoveDown(s))=>state.input_state.set_control(Controls::MoveDown,s),
PhysicsInputInstruction::SetJump(s)=>{ PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetJump(s))=>{
state.input_state.set_control(Controls::Jump,s); state.input_state.set_control(Controls::Jump,s);
if let Some(walk_state)=state.move_state.get_walk_state(){ if let Some(walk_state)=state.move_state.get_walk_state(){
if let Some(jump_settings)=&state.style.jump{ if let Some(jump_settings)=&state.style.jump{
let jump_dir=walk_state.jump_direction.direction(&data.models,&data.hitbox_mesh,&walk_state.contact); let jump_dir=walk_state.jump_direction.direction(&data.models,&data.hitbox_mesh,&walk_state.contact);
let booster_option=data.models.contact_attr(walk_state.contact.model_id).general.booster.as_ref(); let booster_option=data.models.contact_attr(walk_state.contact.model_id).general.booster.as_ref();
let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity,booster_option); let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity,booster_option);
state.cull_velocity(&data,jumped_velocity); state.cull_velocity(&data,jumped_velocity);
}
}
b_refresh_walk_target=false;
},
PhysicsInputInstruction::SetZoom(s)=>{
state.input_state.set_control(Controls::Zoom,s);
b_refresh_walk_target=false;
},
PhysicsInputInstruction::Reset=>{
//totally reset physics state
state.reset_to_default();
b_refresh_walk_target=false;
},
PhysicsInputInstruction::Restart=>{
//teleport to start zone
let mode=data.modes.get_mode(state.mode_state.get_mode_id());
let spawn_point=mode.and_then(|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
data.models.get_model_transform(mode.get_start().into()).map(|transform|
transform.vertex.translation
)
).unwrap_or(vec3::ZERO);
set_position(spawn_point,&mut state.move_state,&mut state.body,&mut state.touching,&mut state.run,&mut state.mode_state,mode,&data.models,&data.hitbox_mesh,&data.bvh,&state.style,&state.camera,&state.input_state,state.time);
set_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,vec3::ZERO);
state.set_move_state(data,MoveState::Air);
b_refresh_walk_target=false;
}
PhysicsInputInstruction::Spawn(mode_id,stage_id)=>{
//spawn at a particular stage
if let Some(mode)=data.modes.get_mode(mode_id){
if let Some(stage)=mode.get_stage(stage_id){
let _=teleport_to_spawn(
stage.spawn(),
&mut state.move_state,&mut state.body,&mut state.touching,&mut state.run,&mut state.mode_state,
mode,
&data.models,&data.hitbox_mesh,&data.bvh,&state.style,&state.camera,&state.input_state,state.time
);
}
}
b_refresh_walk_target=false;
},
PhysicsInputInstruction::PracticeFly=>{
match &state.move_state{
MoveState::Fly=>{
state.set_move_state(data,MoveState::Air);
},
_=>{
state.set_move_state(data,MoveState::Fly);
},
}
b_refresh_walk_target=false;
},
PhysicsInputInstruction::Idle=>{
//literally idle!
b_refresh_walk_target=false;
},
} }
if b_refresh_walk_target{ }
state.apply_input_and_body(data); b_refresh_walk_target=false;
state.cull_velocity(data,state.body.velocity); },
//also check if accelerating away from surface PhysicsInputInstruction::Other(PhysicsOtherInstruction::SetZoom(s))=>{
state.input_state.set_control(Controls::Zoom,s);
b_refresh_walk_target=false;
},
PhysicsInputInstruction::Other(PhysicsOtherInstruction::Reset)=>{
//totally reset physics state
state.reset_to_default();
b_refresh_walk_target=false;
},
PhysicsInputInstruction::Other(PhysicsOtherInstruction::Restart)=>{
//teleport to start zone
let mode=data.modes.get_mode(state.mode_state.get_mode_id());
let spawn_point=mode.and_then(|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
data.models.get_model_transform(mode.get_start().into()).map(|transform|
transform.vertex.translation
)
).unwrap_or(vec3::ZERO);
set_position(spawn_point,&mut state.move_state,&mut state.body,&mut state.touching,&mut state.run,&mut state.mode_state,mode,&data.models,&data.hitbox_mesh,&data.bvh,&state.style,&state.camera,&state.input_state,state.time);
set_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,vec3::ZERO);
state.set_move_state(data,MoveState::Air);
b_refresh_walk_target=false;
}
PhysicsInputInstruction::Other(PhysicsOtherInstruction::Spawn(mode_id,stage_id))=>{
//spawn at a particular stage
if let Some(mode)=data.modes.get_mode(mode_id){
if let Some(stage)=mode.get_stage(stage_id){
let _=teleport_to_spawn(
stage.spawn(),
&mut state.move_state,&mut state.body,&mut state.touching,&mut state.run,&mut state.mode_state,
mode,
&data.models,&data.hitbox_mesh,&data.bvh,&state.style,&state.camera,&state.input_state,state.time
);
} }
}
b_refresh_walk_target=false;
},
PhysicsInputInstruction::Other(PhysicsOtherInstruction::PracticeFly)=>{
match &state.move_state{
MoveState::Fly=>{
state.set_move_state(data,MoveState::Air);
},
_=>{
state.set_move_state(data,MoveState::Fly);
},
}
b_refresh_walk_target=false;
},
PhysicsInputInstruction::Other(PhysicsOtherInstruction::Idle)=>{
//literally idle!
b_refresh_walk_target=false;
},
}
if b_refresh_walk_target{
state.apply_input_and_body(data);
state.cull_velocity(data,state.body.velocity);
//also check if accelerating away from surface
}
} }
#[cfg(test)] #[cfg(test)]