From 6c1ce904ec9531ac9852b4d25b41eb70649ce46e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 30 Jan 2024 18:25:15 -0800 Subject: [PATCH] snf usage prototype --- src/setup.rs | 9 +++++++++ src/window.rs | 28 ++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/setup.rs b/src/setup.rs index 68ae353..8167c12 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -216,6 +216,15 @@ pub fn setup_and_start(title:String){ //the thread that spawns the physics thread let window_thread=window.into_worker(setup_context); + let args:Vec=std::env::args().collect(); + let indexed_model_instances=if args.len()==2{ + let path=std::path::PathBuf::from(&args[1]); + window_thread.send(TimedInstruction{ + time:0, + instruction:WindowInstruction::WindowEvent(winit::event::WindowEvent::DroppedFile(path)), + }); + }; + println!("Entering event loop..."); let root_time=std::time::Instant::now(); run_event_loop(event_loop,window_thread,root_time).unwrap(); diff --git a/src/window.rs b/src/window.rs index 606db07..bbd0aca 100644 --- a/src/window.rs +++ b/src/window.rs @@ -28,9 +28,20 @@ impl WindowContext<'_>{ match event { winit::event::WindowEvent::DroppedFile(path)=>{ //blocking because it's simpler... - if let Some(indexed_model_instances)=crate::load_file(path){ - self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ClearModels}).unwrap(); - self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::GenerateModels(indexed_model_instances)}).unwrap(); + if let Ok(file)=std::fs::File::open(path){ + match strafesnet_snf::read_snf(std::io::BufReader::new(file)){ + Ok(strafesnet_snf::SNF::Map(streamable_map))=>{ + if let Ok(indexed_model_instances)=streamable_map.load_all(){ + self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ClearModels}).unwrap(); + self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::GenerateModels(indexed_model_instances)}).unwrap(); + } + }, + Ok(strafesnet_snf::SNF::Bot(streamable_map))=>println!("File type not yet supported"), + Ok(strafesnet_snf::SNF::Demo(streamable_map))=>println!("File type not yet supported"), + Err(e)=>println!("Error reading file: {e:?}"), + } + }else{ + println!("Failed to open file {path:?}"); } }, winit::event::WindowEvent::Focused(_state)=>{ @@ -168,24 +179,13 @@ pub struct WindowContextSetup<'a>{ impl<'a> WindowContextSetup<'a>{ pub fn new(context:&crate::setup::SetupContext,window:&'a winit::window::Window)->Self{ - //wee let user_settings=crate::settings::read_user_settings(); - let args:Vec=std::env::args().collect(); - let indexed_model_instances=if args.len()==2{ - crate::load_file(std::path::PathBuf::from(&args[1])) - }else{ - None - }.unwrap_or(crate::default_models()); - let mut physics=crate::physics::PhysicsState::default(); physics.load_user_settings(&user_settings); - physics.generate_models(&indexed_model_instances); - physics.spawn(indexed_model_instances.spawn_point); let mut graphics=crate::graphics::GraphicsState::new(&context.device,&context.queue,&context.config); graphics.load_user_settings(&user_settings); - graphics.generate_models(&context.device,&context.queue,indexed_model_instances); Self{ user_settings,