snf usage prototype

This commit is contained in:
Quaternions 2024-01-30 18:25:15 -08:00
parent 89868c6a12
commit 6c1ce904ec
2 changed files with 23 additions and 14 deletions

View File

@ -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<String>=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();

View File

@ -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<String>=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,