Compare commits

..

10 Commits

Author SHA1 Message Date
3594268cf6 the macroer (we were so close to greatness) 2023-10-12 19:05:36 -07:00
fac0383bb1 include spirv deps 2023-10-12 19:05:36 -07:00
2e8cdf968c silence lint 2023-10-10 16:30:00 -07:00
dd0ac7cc7e overshadowed value by mistake 2023-10-10 16:05:47 -07:00
e2af6fc4ed sort enums like normalid 2023-10-10 15:33:32 -07:00
bdc0dd1b3b move keyboard input to WindowEvent to fix Wayland 2023-10-10 02:45:19 -07:00
95fb316a23 add fullscreen hotkey 2023-10-09 20:39:15 -07:00
9dec53d764 implement config 2023-10-09 19:48:15 -07:00
3552491a9a calculators 2023-10-09 19:48:15 -07:00
dd13a066d0 settings module 2023-10-09 19:47:38 -07:00
6 changed files with 129 additions and 62 deletions

61
Cargo.lock generated

@ -538,6 +538,12 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "fixedbitset"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "flate2"
version = "1.0.27"
@ -617,6 +623,15 @@ dependencies = [
"waker-fn",
]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "generic-array"
version = "0.14.7"
@ -762,6 +777,16 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "include_wgsl"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57ac28436974a64aef47cbf8453e8f1a558b779177fe50b7e3c3774e2cb9ba47"
dependencies = [
"naga 0.7.3",
"syn 1.0.109",
]
[[package]]
name = "indexmap"
version = "1.9.3"
@ -1013,6 +1038,24 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "naga"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "806f448a7ce662ca79ef5484ef8f451a9b7c51b8166c95f5a667228b3825a6ca"
dependencies = [
"bit-set",
"bitflags 1.3.2",
"codespan-reporting",
"fxhash",
"hexf-parse",
"indexmap 1.9.3",
"log",
"num-traits 0.2.16",
"spirv",
"thiserror",
]
[[package]]
name = "naga"
version = "0.13.0"
@ -1026,6 +1069,7 @@ dependencies = [
"indexmap 1.9.3",
"log",
"num-traits 0.2.16",
"petgraph",
"rustc-hash",
"spirv",
"termcolor",
@ -1282,6 +1326,16 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
[[package]]
name = "petgraph"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9"
dependencies = [
"fixedbitset",
"indexmap 2.0.0",
]
[[package]]
name = "pin-project-lite"
version = "0.2.13"
@ -1696,6 +1750,7 @@ dependencies = [
"ddsfile",
"env_logger",
"glam",
"include_wgsl",
"lazy-regex",
"log",
"obj",
@ -2027,7 +2082,7 @@ dependencies = [
"cfg-if",
"js-sys",
"log",
"naga",
"naga 0.13.0",
"parking_lot",
"profiling",
"raw-window-handle",
@ -2052,7 +2107,7 @@ dependencies = [
"bitflags 2.4.0",
"codespan-reporting",
"log",
"naga",
"naga 0.13.0",
"parking_lot",
"profiling",
"raw-window-handle",
@ -2089,7 +2144,7 @@ dependencies = [
"libloading 0.8.0",
"log",
"metal",
"naga",
"naga 0.13.0",
"objc",
"parking_lot",
"profiling",

@ -12,6 +12,7 @@ configparser = "3.0.2"
ddsfile = "0.5.1"
env_logger = "0.10.0"
glam = "0.24.1"
include_wgsl = { version = "1.1.1", features = ["spv-out"] }
lazy-regex = "3.0.2"
log = "0.4.20"
obj = "0.10.2"
@ -21,7 +22,7 @@ rbx_binary = "0.7.1"
rbx_dom_weak = "2.5.0"
rbx_reflection_database = "0.2.7"
rbx_xml = "0.13.1"
wgpu = "0.17.0"
wgpu = { version = "0.17.0", features = ["spirv"] }
winit = "0.28.6"
#[profile.release]

@ -556,7 +556,7 @@ impl framework::Example for GlobalState {
// Create the render pipeline
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
source: wgpu::ShaderSource::SpirV(Cow::Borrowed(include_wgsl_to_spv!("shader.wgsl"))),
});
//load textures
@ -918,51 +918,23 @@ impl framework::Example for GlobalState {
#[allow(clippy::single_match)]
fn update(&mut self, window: &winit::window::Window, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) {
let time=self.start_time.elapsed().as_nanos() as i64;
match event {
winit::event::WindowEvent::DroppedFile(path) => self.load_file(path,device,queue),
winit::event::WindowEvent::Focused(state)=>{
//pause unpause
//recalculate pressed keys on focus
}
_=>(),
}
}
fn device_event(&mut self, window: &winit::window::Window, event: winit::event::DeviceEvent) {
//there's no way this is the best way get a timestamp.
let time=self.start_time.elapsed().as_nanos() as i64;
match event {
winit::event::DeviceEvent::Key(winit::event::KeyboardInput {
state,
scancode: keycode,
},
winit::event::WindowEvent::KeyboardInput {
input:winit::event::KeyboardInput{state, virtual_keycode,..},
..
}) => {
}=>{
let s=match state {
winit::event::ElementState::Pressed => true,
winit::event::ElementState::Released => false,
};
if let Some(input_instruction)=match keycode {
17=>Some(InputInstruction::MoveForward(s)),//W
30=>Some(InputInstruction::MoveLeft(s)),//A
31=>Some(InputInstruction::MoveBack(s)),//S
32=>Some(InputInstruction::MoveRight(s)),//D
18=>Some(InputInstruction::MoveUp(s)),//E
16=>Some(InputInstruction::MoveDown(s)),//Q
57=>Some(InputInstruction::Jump(s)),//Space
44=>Some(InputInstruction::Zoom(s)),//Z
19=>if s{Some(InputInstruction::Reset)}else{None},//R
01=>{//Esc
if s{
self.manual_mouse_lock=false;
match window.set_cursor_grab(winit::window::CursorGrabMode::None){
Ok(())=>(),
Err(e)=>println!("Could not release cursor: {:?}",e),
}
window.set_cursor_visible(true);
}
None
},
15=>{//Tab
match virtual_keycode{
Some(winit::event::VirtualKeyCode::Tab)=>{
if s{
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)){
@ -990,16 +962,56 @@ impl framework::Example for GlobalState {
}
}
window.set_cursor_visible(s);
None
},
_ => {println!("scancode {}",keycode);None},
}{
self.physics_thread.send(TimedInstruction{
time,
instruction:input_instruction,
}).unwrap();
Some(winit::event::VirtualKeyCode::F11)=>{
if s{
if window.fullscreen().is_some(){
window.set_fullscreen(None);
}else{
window.set_fullscreen(Some(winit::window::Fullscreen::Borderless(None)));
}
}
},
Some(winit::event::VirtualKeyCode::Escape)=>{
if s{
self.manual_mouse_lock=false;
match window.set_cursor_grab(winit::window::CursorGrabMode::None){
Ok(())=>(),
Err(e)=>println!("Could not release cursor: {:?}",e),
}
window.set_cursor_visible(true);
}
},
Some(keycode)=>{
if let Some(input_instruction)=match keycode {
winit::event::VirtualKeyCode::W => Some(InputInstruction::MoveForward(s)),
winit::event::VirtualKeyCode::A => Some(InputInstruction::MoveLeft(s)),
winit::event::VirtualKeyCode::S => Some(InputInstruction::MoveBack(s)),
winit::event::VirtualKeyCode::D => Some(InputInstruction::MoveRight(s)),
winit::event::VirtualKeyCode::E => Some(InputInstruction::MoveUp(s)),
winit::event::VirtualKeyCode::Q => Some(InputInstruction::MoveDown(s)),
winit::event::VirtualKeyCode::Space => Some(InputInstruction::Jump(s)),
winit::event::VirtualKeyCode::Z => Some(InputInstruction::Zoom(s)),
winit::event::VirtualKeyCode::R => if s{Some(InputInstruction::Reset)}else{None},
_ => None,
}{
self.physics_thread.send(TimedInstruction{
time,
instruction:input_instruction,
}).unwrap();
}
},
_=>(),
}
},
_=>(),
}
}
fn device_event(&mut self, window: &winit::window::Window, event: winit::event::DeviceEvent) {
//there's no way this is the best way get a timestamp.
let time=self.start_time.elapsed().as_nanos() as i64;
match event {
winit::event::DeviceEvent::MouseMotion {
delta,//these (f64,f64) are integers on my machine
} => {

@ -19,12 +19,12 @@ pub enum PhysicsInstruction {
pub enum PhysicsInputInstruction {
ReplaceMouse(MouseState,MouseState),
SetNextMouse(MouseState),
SetMoveForward(bool),
SetMoveLeft(bool),
SetMoveBack(bool),
SetMoveRight(bool),
SetMoveUp(bool),
SetMoveBack(bool),
SetMoveLeft(bool),
SetMoveDown(bool),
SetMoveForward(bool),
SetJump(bool),
SetZoom(bool),
Reset,
@ -33,12 +33,12 @@ pub enum PhysicsInputInstruction {
#[derive(Debug)]
pub enum InputInstruction {
MoveMouse(glam::IVec2),
MoveForward(bool),
MoveLeft(bool),
MoveBack(bool),
MoveRight(bool),
MoveUp(bool),
MoveBack(bool),
MoveLeft(bool),
MoveDown(bool),
MoveForward(bool),
Jump(bool),
Zoom(bool),
Reset,
@ -913,7 +913,7 @@ impl PhysicsState {
fn predict_collision_start(&self,time:TIME,time_limit:TIME,model_id:u32) -> Option<TimedInstruction<PhysicsInstruction>> {
let mesh0=self.mesh();
let mesh1=self.models.get(model_id as usize).unwrap().mesh();
let (p,v,a,time)=(self.body.position,self.body.velocity,self.body.acceleration,self.body.time);
let (p,v,a,body_time)=(self.body.position,self.body.velocity,self.body.acceleration,self.body.time);
//find best t
let mut best_time=time_limit;
let mut best_face:Option<TreyMeshFace>=None;
@ -922,7 +922,7 @@ impl PhysicsState {
//must collide now or in the future
//must beat the current soonest collision time
//must be moving towards surface
let t_time=time+((t as f64)*1_000_000_000f64) as TIME;
let t_time=body_time+((t as f64)*1_000_000_000f64) as TIME;
if time<=t_time&&t_time<best_time&&0f32<v.x+a.x*t{
let dp=self.body.extrapolated_position(t_time)-p;
//faces must be overlapping
@ -938,7 +938,7 @@ impl PhysicsState {
//must collide now or in the future
//must beat the current soonest collision time
//must be moving towards surface
let t_time=time+((t as f64)*1_000_000_000f64) as TIME;
let t_time=body_time+((t as f64)*1_000_000_000f64) as TIME;
if time<=t_time&&t_time<best_time&&v.x+a.x*t<0f32{
let dp=self.body.extrapolated_position(t_time)-p;
//faces must be overlapping
@ -955,7 +955,7 @@ impl PhysicsState {
//must collide now or in the future
//must beat the current soonest collision time
//must be moving towards surface
let t_time=time+((t as f64)*1_000_000_000f64) as TIME;
let t_time=body_time+((t as f64)*1_000_000_000f64) as TIME;
if time<=t_time&&t_time<best_time&&0f32<v.y+a.y*t{
let dp=self.body.extrapolated_position(t_time)-p;
//faces must be overlapping
@ -971,7 +971,7 @@ impl PhysicsState {
//must collide now or in the future
//must beat the current soonest collision time
//must be moving towards surface
let t_time=time+((t as f64)*1_000_000_000f64) as TIME;
let t_time=body_time+((t as f64)*1_000_000_000f64) as TIME;
if time<=t_time&&t_time<best_time&&v.y+a.y*t<0f32{
let dp=self.body.extrapolated_position(t_time)-p;
//faces must be overlapping
@ -988,7 +988,7 @@ impl PhysicsState {
//must collide now or in the future
//must beat the current soonest collision time
//must be moving towards surface
let t_time=time+((t as f64)*1_000_000_000f64) as TIME;
let t_time=body_time+((t as f64)*1_000_000_000f64) as TIME;
if time<=t_time&&t_time<best_time&&0f32<v.z+a.z*t{
let dp=self.body.extrapolated_position(t_time)-p;
//faces must be overlapping
@ -1004,7 +1004,7 @@ impl PhysicsState {
//must collide now or in the future
//must beat the current soonest collision time
//must be moving towards surface
let t_time=time+((t as f64)*1_000_000_000f64) as TIME;
let t_time=body_time+((t as f64)*1_000_000_000f64) as TIME;
if time<=t_time&&t_time<best_time&&v.z+a.z*t<0f32{
let dp=self.body.extrapolated_position(t_time)-p;
//faces must be overlapping

@ -27,7 +27,6 @@ impl Default for Sensitivity{
}
}
#[derive(Default)]
pub struct UserSettings{
fov:Fov,

@ -79,7 +79,7 @@ fn test_worker() {
);
// Send tasks to the worker
for i in 0..5 {
for _ in 0..5 {
let task = crate::instruction::TimedInstruction{
time:0,
instruction:crate::physics::PhysicsInstruction::StrafeTick,