diff --git a/src/framework.rs b/src/framework.rs index 5256e73..c5527e4 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -53,6 +53,7 @@ pub trait Example: 'static + Sized { ); fn update(&mut self, window: &winit::window::Window, device: &wgpu::Device, queue: &wgpu::Queue, event: WindowEvent); fn device_event(&mut self, event: DeviceEvent); + fn load_file(&mut self, path:std::path::PathBuf, device: &wgpu::Device, queue: &wgpu::Queue); fn render( &mut self, view: &wgpu::TextureView, diff --git a/src/main.rs b/src/main.rs index 4d8416e..e523f4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -774,69 +774,71 @@ impl framework::Example for GraphicsData { return graphics; } + fn load_file(&mut self,path: std::path::PathBuf, device: &wgpu::Device, queue: &wgpu::Queue){ + println!("Loading file: {:?}", &path); + //oh boy! let's load the map! + if let Ok(file)=std::fs::File::open(path){ + let mut input = std::io::BufReader::new(file); + let mut first_8=[0u8;8]; + //.rbxm roblox binary = "{ + match match &first_8[4..8]{ + b"lox!"=>rbx_binary::from_reader(input).map_err(|e|format!("{:?}",e)), + b"lox "=>rbx_xml::from_reader(input,rbx_xml::DecodeOptions::default()).map_err(|e|format!("{:?}",e)), + other=>Err(format!("Unknown Roblox file type {:?}",other)), + }{ + Ok(dom)=>Some(load_roblox::generate_indexed_models_roblox(dom)), + Err(e)=>{ + println!("Error loading roblox file:{:?}",e); + None + }, + } + }, + //b"VBSP"=>load_valve::generate_indexed_models_valve(input), + //b"SNFM"=>sniffer::generate_indexed_models(input), + //b"SNFB"=>sniffer::load_bot(input), + _=>None, + } + }{ + //if generate_indexed_models succeeds, clear the previous ones + self.models.clear(); + self.physics.models.clear(); + self.generate_model_physics(&indexed_model_instances); + self.generate_model_graphics(device,queue,indexed_model_instances); + //manual reset + let time=self.physics.time; + instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{ + time, + instruction: body::PhysicsInstruction::SetSpawnPosition(spawn_point), + }); + instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{ + time, + instruction: body::PhysicsInstruction::Input(body::InputInstruction::Reset), + }); + }else{ + println!("No modeldatas were generated"); + } + }else{ + println!("Failed to read first 8 bytes and seek back to beginning of file."); + } + }else{ + println!("Could not open file"); + } + } + #[allow(clippy::single_match)] fn update(&mut self, window: &winit::window::Window, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) { match event { - winit::event::WindowEvent::DroppedFile(path) => { - println!("opening file: {:?}", &path); - //oh boy! let's load the map! - if let Ok(file)=std::fs::File::open(path){ - let mut input = std::io::BufReader::new(file); - let mut first_8=[0u8;8]; - //.rbxm roblox binary = "{ - match match &first_8[4..8]{ - b"lox!"=>rbx_binary::from_reader(input).map_err(|e|format!("{:?}",e)), - b"lox "=>rbx_xml::from_reader(input,rbx_xml::DecodeOptions::default()).map_err(|e|format!("{:?}",e)), - other=>Err(format!("Unknown Roblox file type {:?}",other)), - }{ - Ok(dom)=>Some(load_roblox::generate_indexed_models_roblox(dom)), - Err(e)=>{ - println!("Error loading roblox file:{:?}",e); - None - }, - } - }, - //b"VBSP"=>load_valve::generate_indexed_models_valve(input), - //b"SNFM"=>sniffer::generate_indexed_models(input), - //b"SNFB"=>sniffer::load_bot(input), - _=>None, - } - }{ - //if generate_indexed_models succeeds, clear the previous ones - self.models.clear(); - self.physics.models.clear(); - self.generate_model_physics(&indexed_model_instances); - self.generate_model_graphics(device,queue,indexed_model_instances); - //manual reset - let time=self.physics.time; - instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{ - time, - instruction: body::PhysicsInstruction::SetSpawnPosition(spawn_point), - }); - instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{ - time, - instruction: body::PhysicsInstruction::Input(body::InputInstruction::Reset), - }); - }else{ - println!("No modeldatas were generated"); - } - }else{ - println!("Failed to read first 8 bytes and seek back to beginning of file."); - } - }else{ - println!("Could not open file"); - } - }, + winit::event::WindowEvent::DroppedFile(path) => self.load_file(path,device,queue), winit::event::WindowEvent::KeyboardInput { input:winit::event::KeyboardInput{state, virtual_keycode,..}, ..