Compare commits

...

7 Commits

5 changed files with 611 additions and 379 deletions

695
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@ rbx_dom_weak = "2.5.0"
rbx_reflection_database = "0.2.7" rbx_reflection_database = "0.2.7"
rbx_xml = "0.13.1" rbx_xml = "0.13.1"
wgpu = "0.17.0" wgpu = "0.17.0"
winit = "0.28.6" winit = { version = "0.29.2", features = ["rwh_05"] }
#[profile.release] #[profile.release]
#lto = true #lto = true

View File

@ -5,7 +5,7 @@ use std::str::FromStr;
use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas}; use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas};
use winit::{ use winit::{
event::{self, WindowEvent, DeviceEvent}, event::{self, WindowEvent, DeviceEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::EventLoop,
}; };
#[allow(dead_code)] #[allow(dead_code)]
@ -88,7 +88,7 @@ async fn setup<E: Example>(title: &str) -> Setup {
env_logger::init(); env_logger::init();
}; };
let event_loop = EventLoop::new(); let event_loop = EventLoop::new().unwrap();
let mut builder = winit::window::WindowBuilder::new(); let mut builder = winit::window::WindowBuilder::new();
builder = builder.with_title(title); builder = builder.with_title(title);
#[cfg(windows_OFF)] // TODO #[cfg(windows_OFF)] // TODO
@ -302,15 +302,15 @@ fn start<E: Example>(
let mut example = E::init(&config, &adapter, &device, &queue); let mut example = E::init(&config, &adapter, &device, &queue);
log::info!("Entering render loop..."); log::info!("Entering render loop...");
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, elwt| {
let _ = (&instance, &adapter); // force ownership by the closure let _ = (&instance, &adapter); // force ownership by the closure
*control_flow = if cfg!(feature = "metal-auto-capture") { // *control_flow = if cfg!(feature = "metal-auto-capture") {
ControlFlow::Exit // ControlFlow::Exit
} else { // } else {
ControlFlow::Poll // ControlFlow::Poll
}; // };
match event { match event {
event::Event::RedrawEventsCleared => { event::Event::AboutToWait => {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
spawner.run_until_stalled(); spawner.run_until_stalled();
@ -318,48 +318,44 @@ fn start<E: Example>(
} }
event::Event::WindowEvent { event::Event::WindowEvent {
event: event:
WindowEvent::Resized(size) // WindowEvent::Resized(size)
| WindowEvent::ScaleFactorChanged { // | WindowEvent::ScaleFactorChanged {
new_inner_size: &mut size, // new_inner_size: &mut size,
.. // ..
}, // },
WindowEvent::Resized(size),//ignoring scale factor changed for now because mutex bruh
.. ..
} => { } => {
// Once winit is fixed, the detection conditions here can be removed.
// https://github.com/rust-windowing/winit/issues/2876
let max_dimension = adapter.limits().max_texture_dimension_2d;
if size.width > max_dimension || size.height > max_dimension {
log::warn!(
"The resizing size {:?} exceeds the limit of {}.",
size,
max_dimension
);
} else {
log::info!("Resizing to {:?}", size); log::info!("Resizing to {:?}", size);
config.width = size.width.max(1); config.width = size.width.max(1);
config.height = size.height.max(1); config.height = size.height.max(1);
example.resize(&config, &device, &queue); example.resize(&config, &device, &queue);
surface.configure(&device, &config); surface.configure(&device, &config);
} }
} event::Event::DeviceEvent {
event,
..
} => {
example.device_event(&window,event);
},
event::Event::WindowEvent { event, .. } => match event { event::Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput { WindowEvent::KeyboardInput {
input: event:
event::KeyboardInput { event::KeyEvent {
virtual_keycode: Some(event::VirtualKeyCode::Escape), logical_key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape),
state: event::ElementState::Pressed, state: event::ElementState::Pressed,
.. ..
}, },
.. ..
} }
| WindowEvent::CloseRequested => { | WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit; elwt.exit();
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
WindowEvent::KeyboardInput { WindowEvent::KeyboardInput {
input: event:
event::KeyboardInput { event::KeyEvent {
virtual_keycode: Some(event::VirtualKeyCode::Scroll), logical_key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::ScrollLock),
state: event::ElementState::Pressed, state: event::ElementState::Pressed,
.. ..
}, },
@ -367,18 +363,7 @@ fn start<E: Example>(
} => { } => {
println!("{:#?}", instance.generate_report()); println!("{:#?}", instance.generate_report());
} }
_ => { WindowEvent::RedrawRequested => {
example.update(&window,&device,&queue,event);
}
},
event::Event::DeviceEvent {
event,
..
} => {
example.device_event(&window,event);
},
event::Event::RedrawRequested(_) => {
let frame = match surface.get_current_texture() { let frame = match surface.get_current_texture() {
Ok(frame) => frame, Ok(frame) => frame,
Err(_) => { Err(_) => {
@ -412,9 +397,13 @@ fn start<E: Example>(
} }
} }
} }
_ => {
example.update(&window,&device,&queue,event);
}
},
_ => {} _ => {}
} }
}); }).unwrap();
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]

View File

@ -1093,20 +1093,20 @@ impl framework::Example for GlobalState {
let time=integer::Time::from_nanos(self.start_time.elapsed().as_nanos() as i64); let time=integer::Time::from_nanos(self.start_time.elapsed().as_nanos() as i64);
match event { match event {
winit::event::WindowEvent::DroppedFile(path) => self.load_file(path,device,queue), winit::event::WindowEvent::DroppedFile(path) => self.load_file(path,device,queue),
winit::event::WindowEvent::Focused(state)=>{ winit::event::WindowEvent::Focused(_state)=>{
//pause unpause //pause unpause
//recalculate pressed keys on focus //recalculate pressed keys on focus
}, },
winit::event::WindowEvent::KeyboardInput { winit::event::WindowEvent::KeyboardInput{
input:winit::event::KeyboardInput{state, virtual_keycode,..}, event:winit::event::KeyEvent{state,logical_key,repeat:false,..},
.. ..
}=>{ }=>{
let s=match state { let s=match state {
winit::event::ElementState::Pressed => true, winit::event::ElementState::Pressed => true,
winit::event::ElementState::Released => false, winit::event::ElementState::Released => false,
}; };
match virtual_keycode{ match logical_key{
Some(winit::event::VirtualKeyCode::Tab)=>{ winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab)=>{
if s{ if s{
self.manual_mouse_lock=false; self.manual_mouse_lock=false;
match window.set_cursor_position(winit::dpi::PhysicalPosition::new(self.graphics.camera.screen_size.x as f32/2.0, self.graphics.camera.screen_size.y as f32/2.0)){ match window.set_cursor_position(winit::dpi::PhysicalPosition::new(self.graphics.camera.screen_size.x as f32/2.0, self.graphics.camera.screen_size.y as f32/2.0)){
@ -1135,7 +1135,7 @@ impl framework::Example for GlobalState {
} }
window.set_cursor_visible(s); window.set_cursor_visible(s);
}, },
Some(winit::event::VirtualKeyCode::F11)=>{ winit::keyboard::Key::Named(winit::keyboard::NamedKey::F11)=>{
if s{ if s{
if window.fullscreen().is_some(){ if window.fullscreen().is_some(){
window.set_fullscreen(None); window.set_fullscreen(None);
@ -1144,7 +1144,7 @@ impl framework::Example for GlobalState {
} }
} }
}, },
Some(winit::event::VirtualKeyCode::Escape)=>{ winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape)=>{
if s{ if s{
self.manual_mouse_lock=false; self.manual_mouse_lock=false;
match window.set_cursor_grab(winit::window::CursorGrabMode::None){ match window.set_cursor_grab(winit::window::CursorGrabMode::None){
@ -1154,18 +1154,21 @@ impl framework::Example for GlobalState {
window.set_cursor_visible(true); window.set_cursor_visible(true);
} }
}, },
Some(keycode)=>{ keycode=>{
if let Some(input_instruction)=match keycode { if let Some(input_instruction)=match keycode {
winit::event::VirtualKeyCode::W => Some(InputInstruction::MoveForward(s)), winit::keyboard::Key::Named(winit::keyboard::NamedKey::Space)=>Some(InputInstruction::Jump(s)),
winit::event::VirtualKeyCode::A => Some(InputInstruction::MoveLeft(s)), winit::keyboard::Key::Character(c)=>match c.as_str(){
winit::event::VirtualKeyCode::S => Some(InputInstruction::MoveBack(s)), "w"=>Some(InputInstruction::MoveForward(s)),
winit::event::VirtualKeyCode::D => Some(InputInstruction::MoveRight(s)), "a"=>Some(InputInstruction::MoveLeft(s)),
winit::event::VirtualKeyCode::E => Some(InputInstruction::MoveUp(s)), "s"=>Some(InputInstruction::MoveBack(s)),
winit::event::VirtualKeyCode::Q => Some(InputInstruction::MoveDown(s)), "d"=>Some(InputInstruction::MoveRight(s)),
winit::event::VirtualKeyCode::Space => Some(InputInstruction::Jump(s)), "e"=>Some(InputInstruction::MoveUp(s)),
winit::event::VirtualKeyCode::Z => Some(InputInstruction::Zoom(s)), "q"=>Some(InputInstruction::MoveDown(s)),
winit::event::VirtualKeyCode::R => if s{Some(InputInstruction::Reset)}else{None}, "z"=>Some(InputInstruction::Zoom(s)),
_ => None, "r"=>if s{Some(InputInstruction::Reset)}else{None},
_=>None,
}
_=>None,
}{ }{
self.physics_thread.send(TimedInstruction{ self.physics_thread.send(TimedInstruction{
time, time,
@ -1173,7 +1176,6 @@ impl framework::Example for GlobalState {
}).unwrap(); }).unwrap();
} }
}, },
_=>(),
} }
}, },
_=>(), _=>(),

View File

@ -291,7 +291,7 @@ enum JumpImpulse{
struct StyleModifiers{ struct StyleModifiers{
controls_mask:u32,//controls which are unable to be activated controls_mask:u32,//controls which are unable to be activated
controls_held:u32,//controls which must be active to be able to strafe controls_held:u32,//controls which must be active to be able to strafe
strafe_tick_rate:Ratio64, strafe_tick_rate:Option<Ratio64>,
jump_impulse:JumpImpulse, jump_impulse:JumpImpulse,
jump_calculation:JumpCalculation, jump_calculation:JumpCalculation,
static_friction:Planar64, static_friction:Planar64,
@ -305,6 +305,7 @@ struct StyleModifiers{
mass:Planar64, mass:Planar64,
mv:Planar64, mv:Planar64,
air_accel_limit:Option<Planar64>, air_accel_limit:Option<Planar64>,
rocket_force:Option<Planar64>,
gravity:Planar64Vec3, gravity:Planar64Vec3,
hitbox_halfsize:Planar64Vec3, hitbox_halfsize:Planar64Vec3,
} }
@ -331,7 +332,7 @@ impl StyleModifiers{
Self{ Self{
controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN),
controls_held:0, controls_held:0,
strafe_tick_rate:Ratio64::new(128,Time::ONE_SECOND.nanos() as u64).unwrap(), strafe_tick_rate:Some(Ratio64::new(128,Time::ONE_SECOND.nanos() as u64).unwrap()),
jump_impulse:JumpImpulse::FromEnergy(Planar64::int(512)), jump_impulse:JumpImpulse::FromEnergy(Planar64::int(512)),
jump_calculation:JumpCalculation::Energy, jump_calculation:JumpCalculation::Energy,
gravity:Planar64Vec3::int(0,-80,0), gravity:Planar64Vec3::int(0,-80,0),
@ -340,6 +341,7 @@ impl StyleModifiers{
mass:Planar64::int(1), mass:Planar64::int(1),
mv:Planar64::int(2), mv:Planar64::int(2),
air_accel_limit:None, air_accel_limit:None,
rocket_force:None,
walk_speed:Planar64::int(16), walk_speed:Planar64::int(16),
walk_accel:Planar64::int(80), walk_accel:Planar64::int(80),
ladder_speed:Planar64::int(16), ladder_speed:Planar64::int(16),
@ -354,7 +356,7 @@ impl StyleModifiers{
Self{ Self{
controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN),
controls_held:0, controls_held:0,
strafe_tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), strafe_tick_rate:Some(Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap()),
jump_impulse:JumpImpulse::FromTime(Time::from_micros(715_588)), jump_impulse:JumpImpulse::FromTime(Time::from_micros(715_588)),
jump_calculation:JumpCalculation::Capped, jump_calculation:JumpCalculation::Capped,
gravity:Planar64Vec3::int(0,-100,0), gravity:Planar64Vec3::int(0,-100,0),
@ -363,6 +365,7 @@ impl StyleModifiers{
mass:Planar64::int(1), mass:Planar64::int(1),
mv:Planar64::int(27)/10, mv:Planar64::int(27)/10,
air_accel_limit:None, air_accel_limit:None,
rocket_force:None,
walk_speed:Planar64::int(18), walk_speed:Planar64::int(18),
walk_accel:Planar64::int(90), walk_accel:Planar64::int(90),
ladder_speed:Planar64::int(18), ladder_speed:Planar64::int(18),
@ -376,7 +379,7 @@ impl StyleModifiers{
Self{ Self{
controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN),
controls_held:0, controls_held:0,
strafe_tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), strafe_tick_rate:Some(Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap()),
jump_impulse:JumpImpulse::FromTime(Time::from_micros(715_588)), jump_impulse:JumpImpulse::FromTime(Time::from_micros(715_588)),
jump_calculation:JumpCalculation::Capped, jump_calculation:JumpCalculation::Capped,
gravity:Planar64Vec3::int(0,-50,0), gravity:Planar64Vec3::int(0,-50,0),
@ -385,6 +388,7 @@ impl StyleModifiers{
mass:Planar64::int(1), mass:Planar64::int(1),
mv:Planar64::int(27)/10, mv:Planar64::int(27)/10,
air_accel_limit:None, air_accel_limit:None,
rocket_force:None,
walk_speed:Planar64::int(18), walk_speed:Planar64::int(18),
walk_accel:Planar64::int(90), walk_accel:Planar64::int(90),
ladder_speed:Planar64::int(18), ladder_speed:Planar64::int(18),
@ -400,7 +404,7 @@ impl StyleModifiers{
Self{ Self{
controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN),
controls_held:0, controls_held:0,
strafe_tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), strafe_tick_rate:Some(Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap()),
jump_impulse:JumpImpulse::FromHeight(Planar64::raw(52<<28)), jump_impulse:JumpImpulse::FromHeight(Planar64::raw(52<<28)),
jump_calculation:JumpCalculation::Linear, jump_calculation:JumpCalculation::Linear,
gravity:Planar64Vec3::raw(0,-800<<28,0), gravity:Planar64Vec3::raw(0,-800<<28,0),
@ -409,6 +413,7 @@ impl StyleModifiers{
mass:Planar64::int(1), mass:Planar64::int(1),
mv:Planar64::raw(30<<28), mv:Planar64::raw(30<<28),
air_accel_limit:Some(Planar64::raw(150<<28)*66), air_accel_limit:Some(Planar64::raw(150<<28)*66),
rocket_force:None,
walk_speed:Planar64::int(18),//? walk_speed:Planar64::int(18),//?
walk_accel:Planar64::int(90),//? walk_accel:Planar64::int(90),//?
ladder_speed:Planar64::int(18),//? ladder_speed:Planar64::int(18),//?
@ -423,7 +428,7 @@ impl StyleModifiers{
Self{ Self{
controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN),
controls_held:0, controls_held:0,
strafe_tick_rate:Ratio64::new(66,Time::ONE_SECOND.nanos() as u64).unwrap(), strafe_tick_rate:Some(Ratio64::new(66,Time::ONE_SECOND.nanos() as u64).unwrap()),
jump_impulse:JumpImpulse::FromHeight(Planar64::raw(52<<28)), jump_impulse:JumpImpulse::FromHeight(Planar64::raw(52<<28)),
jump_calculation:JumpCalculation::Linear, jump_calculation:JumpCalculation::Linear,
gravity:Planar64Vec3::raw(0,-800<<28,0), gravity:Planar64Vec3::raw(0,-800<<28,0),
@ -432,6 +437,7 @@ impl StyleModifiers{
mass:Planar64::int(1), mass:Planar64::int(1),
mv:Planar64::raw(30<<28), mv:Planar64::raw(30<<28),
air_accel_limit:Some(Planar64::raw(150<<28)*66), air_accel_limit:Some(Planar64::raw(150<<28)*66),
rocket_force:None,
walk_speed:Planar64::int(18),//? walk_speed:Planar64::int(18),//?
walk_accel:Planar64::int(90),//? walk_accel:Planar64::int(90),//?
ladder_speed:Planar64::int(18),//? ladder_speed:Planar64::int(18),//?
@ -441,6 +447,29 @@ impl StyleModifiers{
hitbox_halfsize:Planar64Vec3::raw(33<<28,73<<28,33<<28)/2, hitbox_halfsize:Planar64Vec3::raw(33<<28,73<<28,33<<28)/2,
} }
} }
fn roblox_rocket()->Self{
Self{
controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN),
controls_held:0,
strafe_tick_rate:None,
jump_impulse:JumpImpulse::FromTime(Time::from_micros(715_588)),
jump_calculation:JumpCalculation::Capped,
gravity:Planar64Vec3::int(0,-100,0),
static_friction:Planar64::int(2),
kinetic_friction:Planar64::int(3),//unrealistic: kinetic friction is typically lower than static
mass:Planar64::int(1),
mv:Planar64::int(27)/10,
air_accel_limit:None,
rocket_force:Some(Planar64::int(200)),
walk_speed:Planar64::int(18),
walk_accel:Planar64::int(90),
ladder_speed:Planar64::int(18),
ladder_accel:Planar64::int(180),
ladder_dot:(Planar64::int(1)/2).sqrt(),
swim_speed:Planar64::int(12),
hitbox_halfsize:Planar64Vec3::int(2,5,2)/2,
}
}
fn get_control(&self,control:u32,controls:u32)->bool{ fn get_control(&self,control:u32,controls:u32)->bool{
controls&self.controls_mask&control==control controls&self.controls_mask&control==control
@ -508,10 +537,9 @@ impl StyleModifiers{
// return cross(cross(Normal,ControlDir),Normal)/sqrt(1-d*d) // return cross(cross(Normal,ControlDir),Normal)/sqrt(1-d*d)
control_dir*self.walk_speed control_dir*self.walk_speed
} }
fn get_propulsion_target_velocity(&self,camera:&PhysicsCamera,controls:u32,next_mouse:&MouseState,time:Time)->Planar64Vec3{ fn get_propulsion_control_dir(&self,camera:&PhysicsCamera,controls:u32,next_mouse:&MouseState,time:Time)->Planar64Vec3{
let camera_mat=camera.simulate_move_rotation(camera.mouse.lerp(&next_mouse,time)); let camera_mat=camera.simulate_move_rotation(camera.mouse.lerp(&next_mouse,time));
let control_dir=camera_mat*self.get_control_dir(controls); camera_mat*self.get_control_dir(controls)
control_dir*self.walk_speed
} }
} }
@ -933,11 +961,13 @@ impl PhysicsState {
} }
fn next_strafe_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> { fn next_strafe_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
return Some(TimedInstruction{ self.style.strafe_tick_rate.as_ref().map(|strafe_tick_rate|{
time:Time::from_nanos(self.style.strafe_tick_rate.rhs_div_int(self.style.strafe_tick_rate.mul_int(self.time.nanos())+1)), TimedInstruction{
time:Time::from_nanos(strafe_tick_rate.rhs_div_int(strafe_tick_rate.mul_int(self.time.nanos())+1)),
//only poll the physics if there is a before and after mouse event //only poll the physics if there is a before and after mouse event
instruction:PhysicsInstruction::StrafeTick instruction:PhysicsInstruction::StrafeTick
}); }
})
} }
//state mutated on collision: //state mutated on collision:
@ -971,16 +1001,20 @@ impl PhysicsState {
// }); // });
// } // }
fn refresh_walk_target(&mut self){ fn refresh_walk_target(&mut self)->Option<Planar64Vec3>{
match &mut self.move_state{ match &mut self.move_state{
MoveState::Air|MoveState::Water=>(), MoveState::Air|MoveState::Water=>None,
MoveState::Walk(WalkState{normal,state})=>{ MoveState::Walk(WalkState{normal,state})=>{
let n=normal; let n=normal;
(*state,self.body.acceleration)=WalkEnum::with_target_velocity(&self.touching,&self.body,&self.style,&self.models,self.style.get_walk_target_velocity(&self.camera,self.controls,&self.next_mouse,self.time),&n); let a;
(*state,a)=WalkEnum::with_target_velocity(&self.touching,&self.body,&self.style,&self.models,self.style.get_walk_target_velocity(&self.camera,self.controls,&self.next_mouse,self.time),&n);
Some(a)
}, },
MoveState::Ladder(WalkState{normal,state})=>{ MoveState::Ladder(WalkState{normal,state})=>{
let n=normal; let n=normal;
(*state,self.body.acceleration)=WalkEnum::with_target_velocity(&self.touching,&self.body,&self.style,&self.models,self.style.get_ladder_target_velocity(&self.camera,self.controls,&self.next_mouse,self.time),&n); let a;
(*state,a)=WalkEnum::with_target_velocity(&self.touching,&self.body,&self.style,&self.models,self.style.get_ladder_target_velocity(&self.camera,self.controls,&self.next_mouse,self.time),&n);
Some(a)
}, },
} }
} }
@ -1151,7 +1185,7 @@ impl PhysicsState {
}, },
} }
//generate instruction //generate instruction
if let Some(face) = exit_face{ if let Some(_face) = exit_face{
return Some(TimedInstruction { return Some(TimedInstruction {
time: best_time, time: best_time,
instruction: PhysicsInstruction::CollisionEnd(collision_data.clone()) instruction: PhysicsInstruction::CollisionEnd(collision_data.clone())
@ -1408,7 +1442,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
match booster{ match booster{
&crate::model::GameMechanicBooster::Affine(transform)=>v=transform.transform_point3(v), &crate::model::GameMechanicBooster::Affine(transform)=>v=transform.transform_point3(v),
&crate::model::GameMechanicBooster::Velocity(velocity)=>v+=velocity, &crate::model::GameMechanicBooster::Velocity(velocity)=>v+=velocity,
&crate::model::GameMechanicBooster::Energy{direction,energy}=>todo!(), &crate::model::GameMechanicBooster::Energy{direction: _,energy: _}=>todo!(),
} }
self.touching.constrain_velocity(&self.models,&mut v); self.touching.constrain_velocity(&self.models,&mut v);
}, },
@ -1419,10 +1453,10 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
match trajectory{ match trajectory{
crate::model::GameMechanicSetTrajectory::AirTime(_) => todo!(), crate::model::GameMechanicSetTrajectory::AirTime(_) => todo!(),
crate::model::GameMechanicSetTrajectory::Height(_) => todo!(), crate::model::GameMechanicSetTrajectory::Height(_) => todo!(),
crate::model::GameMechanicSetTrajectory::TargetPointTime { target_point, time } => todo!(), crate::model::GameMechanicSetTrajectory::TargetPointTime { target_point: _, time: _ } => todo!(),
crate::model::GameMechanicSetTrajectory::TrajectoryTargetPoint { target_point, speed, trajectory_choice } => todo!(), crate::model::GameMechanicSetTrajectory::TrajectoryTargetPoint { target_point: _, speed: _, trajectory_choice: _ } => todo!(),
&crate::model::GameMechanicSetTrajectory::Velocity(velocity)=>v=velocity, &crate::model::GameMechanicSetTrajectory::Velocity(velocity)=>v=velocity,
crate::model::GameMechanicSetTrajectory::DotVelocity { direction, dot } => todo!(), crate::model::GameMechanicSetTrajectory::DotVelocity { direction: _, dot: _ } => todo!(),
} }
self.touching.constrain_velocity(&self.models,&mut v); self.touching.constrain_velocity(&self.models,&mut v);
}, },
@ -1432,9 +1466,11 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
if self.style.get_control(StyleModifiers::CONTROL_JUMP,self.controls){ if self.style.get_control(StyleModifiers::CONTROL_JUMP,self.controls){
self.jump(); self.jump();
} }
self.refresh_walk_target(); if let Some(a)=self.refresh_walk_target(){
self.body.acceleration=a;
}
}, },
PhysicsCollisionAttributes::Intersect{intersecting,general}=>{ PhysicsCollisionAttributes::Intersect{intersecting: _,general}=>{
//I think that setting the velocity to 0 was preventing surface contacts from entering an infinite loop //I think that setting the velocity to 0 was preventing surface contacts from entering an infinite loop
self.touching.insert_intersect(c.model,c); self.touching.insert_intersect(c.model,c);
run_teleport_behaviour(&general.teleport_behaviour,&mut self.game,&self.models,&self.modes,&self.style,&mut self.touching,&mut self.body,model); run_teleport_behaviour(&general.teleport_behaviour,&mut self.game,&self.models,&self.modes,&self.style,&mut self.touching,&mut self.body,model);
@ -1444,9 +1480,12 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
PhysicsInstruction::CollisionEnd(c) => { PhysicsInstruction::CollisionEnd(c) => {
let model=c.model(&self.models).unwrap(); let model=c.model(&self.models).unwrap();
match &model.attributes{ match &model.attributes{
PhysicsCollisionAttributes::Contact{contacting,general}=>{ PhysicsCollisionAttributes::Contact{contacting: _,general: _}=>{
self.touching.remove_contact(c.model);//remove contact before calling contact_constrain_acceleration self.touching.remove_contact(c.model);//remove contact before calling contact_constrain_acceleration
let mut a=self.style.gravity; let mut a=self.style.gravity;
if let Some(rocket_force)=self.style.rocket_force{
a+=self.style.get_propulsion_control_dir(&self.camera,self.controls,&self.next_mouse,self.time)*rocket_force;
}
self.touching.constrain_acceleration(&self.models,&mut a); self.touching.constrain_acceleration(&self.models,&mut a);
self.body.acceleration=a; self.body.acceleration=a;
//check ground //check ground
@ -1456,10 +1495,12 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
//TODO: make this more advanced checking contacts //TODO: make this more advanced checking contacts
self.move_state=MoveState::Air; self.move_state=MoveState::Air;
}, },
_=>self.refresh_walk_target(), _=>if let Some(a)=self.refresh_walk_target(){
self.body.acceleration=a;
},
} }
}, },
PhysicsCollisionAttributes::Intersect{intersecting,general}=>{ PhysicsCollisionAttributes::Intersect{intersecting: _,general: _}=>{
self.touching.remove_intersect(c.model); self.touching.remove_intersect(c.model);
}, },
} }
@ -1533,7 +1574,14 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
PhysicsInputInstruction::Idle => {refresh_walk_target=false;},//literally idle! PhysicsInputInstruction::Idle => {refresh_walk_target=false;},//literally idle!
} }
if refresh_walk_target{ if refresh_walk_target{
self.refresh_walk_target(); if let Some(a)=self.refresh_walk_target(){
self.body.acceleration=a;
}else if let Some(rocket_force)=self.style.rocket_force{
let mut a=self.style.gravity;
a+=self.style.get_propulsion_control_dir(&self.camera,self.controls,&self.next_mouse,self.time)*rocket_force;
self.touching.constrain_acceleration(&self.models,&mut a);
self.body.acceleration=a;
}
} }
}, },
} }