Compare commits
5 Commits
surf-bodge
...
graphics-b
| Author | SHA1 | Date | |
|---|---|---|---|
|
8c66b0bd72
|
|||
|
7c16b41717
|
|||
|
69f182bca1
|
|||
|
9c30fa04a5
|
|||
|
ad4de709da
|
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -4033,7 +4033,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_graphics"
|
||||
version = "0.0.11"
|
||||
version = "0.0.11-depth2"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"ddsfile",
|
||||
@@ -4045,7 +4045,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_physics"
|
||||
version = "0.0.2-surf2"
|
||||
version = "0.0.2"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"glam",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "strafesnet_graphics"
|
||||
version = "0.0.11"
|
||||
version = "0.0.11-depth2"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -134,7 +134,7 @@ pub struct GraphicsState{
|
||||
}
|
||||
|
||||
impl GraphicsState{
|
||||
const DEPTH_FORMAT:wgpu::TextureFormat=wgpu::TextureFormat::Depth24Plus;
|
||||
const DEPTH_FORMAT:wgpu::TextureFormat=wgpu::TextureFormat::Depth32Float;
|
||||
fn create_depth_texture(
|
||||
size:glam::UVec2,
|
||||
device:&wgpu::Device,
|
||||
@@ -149,7 +149,7 @@ impl GraphicsState{
|
||||
sample_count:1,
|
||||
dimension:wgpu::TextureDimension::D2,
|
||||
format:Self::DEPTH_FORMAT,
|
||||
usage:wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
usage:wgpu::TextureUsages::RENDER_ATTACHMENT|wgpu::TextureUsages::COPY_SRC,
|
||||
label:Some("Depth Texture"),
|
||||
view_formats:&[],
|
||||
})
|
||||
@@ -976,7 +976,7 @@ impl GraphicsState{
|
||||
view:&self.depth_view,
|
||||
depth_ops:Some(wgpu::Operations{
|
||||
load:wgpu::LoadOp::Clear(1.0),
|
||||
store:wgpu::StoreOp::Discard,
|
||||
store:wgpu::StoreOp::Store,
|
||||
}),
|
||||
stencil_ops:None,
|
||||
}),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "strafesnet_physics"
|
||||
version = "0.0.2-surf2"
|
||||
version = "0.0.2"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -501,27 +501,6 @@ impl StyleHelper for StyleModifiers{
|
||||
}
|
||||
}
|
||||
#[derive(Clone,Debug)]
|
||||
struct StrafeTickState{
|
||||
tick_number:u64,
|
||||
}
|
||||
impl StrafeTickState{
|
||||
fn new(time:Time,settings:&gameplay_style::StrafeSettings)->Self{
|
||||
// let time=n*seconds/ticks;
|
||||
let time=time.nanos() as i128;
|
||||
let ticks=settings.tick_rate.num() as i128;
|
||||
let seconds=settings.tick_rate.den() as i128;
|
||||
let tick_number=(time*ticks/seconds) as u64;
|
||||
StrafeTickState{tick_number}
|
||||
}
|
||||
fn next_tick(&self,settings:&gameplay_style::StrafeSettings)->Time{
|
||||
let n=self.tick_number as i128;
|
||||
let ticks=settings.tick_rate.num() as i128;
|
||||
let seconds=settings.tick_rate.den() as i128;
|
||||
let time=n*seconds/ticks;
|
||||
Time::from_nanos(time as i64)
|
||||
}
|
||||
}
|
||||
#[derive(Clone,Debug)]
|
||||
enum MoveState{
|
||||
Air,
|
||||
Walk(ContactMoveState),
|
||||
@@ -599,7 +578,7 @@ impl MoveState{
|
||||
=>None,
|
||||
}
|
||||
}
|
||||
fn next_move_instruction(&self)->Option<TimedInstruction<InternalInstruction,Time>>{
|
||||
fn next_move_instruction(&self,strafe:&Option<gameplay_style::StrafeSettings>,time:Time)->Option<TimedInstruction<InternalInstruction,Time>>{
|
||||
//check if you have a valid walk state and create an instruction
|
||||
match self{
|
||||
MoveState::Walk(walk_state)|MoveState::Ladder(walk_state)=>match &walk_state.target{
|
||||
@@ -611,7 +590,13 @@ impl MoveState{
|
||||
|TransientAcceleration::Reached
|
||||
=>None,
|
||||
}
|
||||
MoveState::Air=>None,
|
||||
MoveState::Air=>strafe.as_ref().map(|strafe|{
|
||||
TimedInstruction{
|
||||
time:strafe.next_tick(time),
|
||||
//only poll the physics if there is a before and after mouse event
|
||||
instruction:InternalInstruction::StrafeTick
|
||||
}
|
||||
}),
|
||||
MoveState::Water=>None,//TODO
|
||||
MoveState::Fly=>None,
|
||||
}
|
||||
@@ -620,26 +605,25 @@ impl MoveState{
|
||||
*self=move_state;
|
||||
//this function call reads the above state that was just set
|
||||
self.update_walk_target(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
// Never used? make body immutable
|
||||
self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}
|
||||
fn cull_velocity(&mut self,velocity:Planar64Vec3,body:&mut Body,touching:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
||||
//TODO: be more precise about contacts
|
||||
if set_velocity_cull(body,touching,models,hitbox_mesh,velocity){
|
||||
self.update_move_state(body,touching,models,hitbox_mesh,style,camera,input_state,|contact|!touching.contains_contact(&contact.convex_mesh_id));
|
||||
}
|
||||
}
|
||||
fn update_move_state(&mut self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState,is_contact_removed:impl Fn(&ContactCollision)->bool){
|
||||
match self.get_walk_state(){
|
||||
// did you stop touching the thing you were walking on?
|
||||
Some(walk_state)=>if is_contact_removed(&walk_state.contact){
|
||||
self.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
self.update_walk_target(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
},
|
||||
// not walking, but stopped touching something
|
||||
None=>self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state),
|
||||
// TODO do better
|
||||
// TODO: unduplicate this code
|
||||
match self.get_walk_state(){
|
||||
// did you stop touching the thing you were walking on?
|
||||
Some(walk_state)=>if !touching.contains_contact(&walk_state.contact.convex_mesh_id){
|
||||
self.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
self.update_walk_target(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
},
|
||||
// not walking, but stopped touching something
|
||||
None=>self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -893,7 +877,6 @@ pub struct PhysicsState{
|
||||
//gameplay_state
|
||||
mode_state:ModeState,
|
||||
move_state:MoveState,
|
||||
strafe_tick_state:StrafeTickState,
|
||||
//run is non optional: when you spawn in a run is created
|
||||
//the run cannot be finished unless you start it by visiting
|
||||
//a start zone. If you change mode, a new run is created.
|
||||
@@ -912,7 +895,6 @@ impl Default for PhysicsState{
|
||||
input_state:InputState::default(),
|
||||
_world:WorldState{},
|
||||
mode_state:ModeState::default(),
|
||||
strafe_tick_state:StrafeTickState::new(Time::ZERO,&StyleModifiers::default().strafe.unwrap()),
|
||||
run:run::Run::new(),
|
||||
}
|
||||
}
|
||||
@@ -959,7 +941,10 @@ impl PhysicsState{
|
||||
*self=Self::default();
|
||||
}
|
||||
fn next_move_instruction(&self)->Option<TimedInstruction<InternalInstruction,Time>>{
|
||||
self.move_state.next_move_instruction()
|
||||
self.move_state.next_move_instruction(&self.style.strafe,self.time)
|
||||
}
|
||||
fn cull_velocity(&mut self,data:&PhysicsData,velocity:Planar64Vec3){
|
||||
self.move_state.cull_velocity(velocity,&mut self.body,&mut self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
||||
}
|
||||
fn set_move_state(&mut self,data:&PhysicsData,move_state:MoveState){
|
||||
self.move_state.set_move_state(move_state,&mut self.body,&self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
||||
@@ -1217,18 +1202,8 @@ fn next_instruction_internal(state:&PhysicsState,data:&PhysicsData,time_limit:Ti
|
||||
//JUST POLLING!!! NO MUTATION
|
||||
let mut collector=instruction::InstructionCollector::new(time_limit);
|
||||
|
||||
// walking
|
||||
collector.collect(state.next_move_instruction());
|
||||
|
||||
// strafe tick
|
||||
collector.collect(state.style.strafe.as_ref().map(|strafe|{
|
||||
TimedInstruction{
|
||||
time:state.strafe_tick_state.next_tick(strafe),
|
||||
//only poll the physics if there is a before and after mouse event
|
||||
instruction:InternalInstruction::StrafeTick
|
||||
}
|
||||
}));
|
||||
|
||||
let trajectory=state.body.with_acceleration(state.acceleration(data));
|
||||
//check for collision ends
|
||||
state.touching.predict_collision_end(&mut collector,&data.models,&data.hitbox_mesh,&trajectory,state.time);
|
||||
@@ -1359,7 +1334,7 @@ fn set_velocity_cull(body:&mut Body,touching:&mut TouchingState,models:&PhysicsM
|
||||
let mut culled=false;
|
||||
touching.contacts.retain(|convex_mesh_id,face_id|{
|
||||
let n=contact_normal(models,hitbox_mesh,convex_mesh_id,*face_id);
|
||||
let r=(n.dot(v)>>52).is_positive();
|
||||
let r=n.dot(v).is_positive();
|
||||
if r{
|
||||
culled=true;
|
||||
}
|
||||
@@ -1726,7 +1701,22 @@ fn collision_end_contact(
|
||||
){
|
||||
touching.remove_contact(convex_mesh_id);//remove contact before calling contact_constrain_acceleration
|
||||
//check ground
|
||||
move_state.update_move_state(body,touching,models,hitbox_mesh,style,camera,input_state,|contact|contact.convex_mesh_id==*convex_mesh_id);
|
||||
//TODO do better
|
||||
//this is inner code from move_state.cull_velocity
|
||||
match move_state.get_walk_state(){
|
||||
// did you stop touching the thing you were walking on?
|
||||
// This does not check the face! Is that a bad thing? It should be
|
||||
// impossible to stop touching a different face than you started touching...
|
||||
Some(walk_state)=>if &walk_state.contact.convex_mesh_id==convex_mesh_id{
|
||||
move_state.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
move_state.update_walk_target(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
move_state.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
},
|
||||
// not walking, but stopped touching something
|
||||
None=>move_state.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state),
|
||||
}
|
||||
}
|
||||
fn collision_end_intersect(
|
||||
move_state:&mut MoveState,
|
||||
@@ -1809,7 +1799,6 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
||||
),
|
||||
},
|
||||
InternalInstruction::StrafeTick=>{
|
||||
state.strafe_tick_state.tick_number+=1;
|
||||
//TODO make this less huge
|
||||
if let Some(strafe_settings)=&state.style.strafe{
|
||||
let controls=state.input_state.controls;
|
||||
@@ -1824,7 +1813,7 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
||||
state.body=extrapolated_body;
|
||||
//this is wrong but will work ig
|
||||
//need to note which push planes activate in push solve and keep those
|
||||
state.move_state.cull_velocity(ticked_velocity,&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
state.cull_velocity(data,ticked_velocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1908,7 +1897,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
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.convex_mesh_id.model_id).general.booster.as_ref();
|
||||
let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity,booster_option);
|
||||
state.move_state.cull_velocity(jumped_velocity,&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
state.cull_velocity(data,jumped_velocity);
|
||||
}
|
||||
}
|
||||
b_refresh_walk_target=false;
|
||||
@@ -1981,7 +1970,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
if b_refresh_walk_target{
|
||||
state.move_state.update_walk_target(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
state.move_state.update_fly_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
state.move_state.cull_velocity(state.body.velocity,&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
state.cull_velocity(data,state.body.velocity);
|
||||
//also check if accelerating away from surface
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,18 +244,18 @@ impl InstructionConsumer<Instruction<'_>> for Session{
|
||||
self.clear_recording();
|
||||
let mode_id=self.simulation.physics.mode();
|
||||
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Reset));
|
||||
// TODO: think about this harder. This works around a bug where you fall infinitely when you reset.
|
||||
self.simulation.timer.set_time(ins.time,PhysicsTime::ZERO);
|
||||
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Misc(MiscInstruction::SetSensitivity(self.user_settings().calculate_sensitivity())));
|
||||
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Restart(mode_id)));
|
||||
// TODO: think about this harder. This works around a bug where you fall infinitely when you reset.
|
||||
self.simulation.timer.set_time(ins.time,PhysicsTime::ZERO);
|
||||
},
|
||||
Instruction::Input(SessionInputInstruction::Mode(ImplicitModeInstruction::ResetAndSpawn(mode_id,spawn_id)))=>{
|
||||
self.clear_recording();
|
||||
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Reset));
|
||||
// TODO: think about this harder. This works around a bug where you fall infinitely when you reset.
|
||||
self.simulation.timer.set_time(ins.time,PhysicsTime::ZERO);
|
||||
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Misc(MiscInstruction::SetSensitivity(self.user_settings().calculate_sensitivity())));
|
||||
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Spawn(mode_id,spawn_id)));
|
||||
// TODO: think about this harder. This works around a bug where you fall infinitely when you reset.
|
||||
self.simulation.timer.set_time(ins.time,PhysicsTime::ZERO);
|
||||
},
|
||||
Instruction::Input(SessionInputInstruction::Misc(misc_instruction))=>{
|
||||
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Misc(misc_instruction));
|
||||
|
||||
@@ -111,21 +111,3 @@ fn bug_3(){
|
||||
assert_eq!(body.velocity,vec3::int(0,0,0));
|
||||
assert_eq!(body.time,Time::from_secs(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn press_w(){
|
||||
let physics_data=test_scene();
|
||||
let mut physics=PhysicsState::default();
|
||||
// press W
|
||||
PhysicsContext::run_input_instruction(&mut physics,&physics_data,strafesnet_common::instruction::TimedInstruction{
|
||||
time:Time::ZERO,
|
||||
instruction:strafesnet_common::physics::Instruction::SetControl(strafesnet_common::physics::SetControlInstruction::SetMoveForward(true)),
|
||||
});
|
||||
// wait 10 ms
|
||||
PhysicsContext::run_input_instruction(&mut physics,&physics_data,strafesnet_common::instruction::TimedInstruction{
|
||||
time:Time::from_millis(10),
|
||||
instruction:strafesnet_common::physics::Instruction::Idle,
|
||||
});
|
||||
// observe current velocity
|
||||
assert_eq!(physics.body().velocity,vec3::raw_xyz(0,-1<<32,-0x2b3333333));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ const VALVE_SCALE:Planar64=Planar64::raw(1<<28);// 1/16
|
||||
|
||||
use crate::integer::{int,vec3::int as int3,AbsoluteTime,Ratio64,Planar64,Planar64Vec3};
|
||||
use crate::controls_bitflag::Controls;
|
||||
use crate::physics::Time as PhysicsTime;
|
||||
|
||||
#[derive(Clone,Debug)]
|
||||
pub struct StyleModifiers{
|
||||
@@ -272,6 +273,9 @@ impl StrafeSettings{
|
||||
false=>None,
|
||||
}
|
||||
}
|
||||
pub fn next_tick(&self,time:PhysicsTime)->PhysicsTime{
|
||||
PhysicsTime::from_nanos(self.tick_rate.rhs_div_int(self.tick_rate.mul_int(time.nanos())+1))
|
||||
}
|
||||
pub const fn activates(&self,controls:Controls)->bool{
|
||||
self.enable.activates(controls)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user