Compare commits

..

3 Commits
web ... web-map

Author SHA1 Message Date
265f2a2c70 toc 2025-01-06 20:41:16 -08:00
3c516badd4 include map in binary 2025-01-06 20:41:16 -08:00
00dce54aea outrageous resize hack 2025-01-06 20:41:16 -08:00
4 changed files with 27 additions and 11 deletions

View File

@@ -59,10 +59,13 @@ impl std::fmt::Display for LoadError{
}
impl std::error::Error for LoadError{}
pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::CompleteMap,LoadError>{
pub fn load_file<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::CompleteMap,LoadError>{
//blocking because it's simpler...
let file=std::fs::File::open(path).map_err(LoadError::File)?;
match read(file).map_err(LoadError::ReadError)?{
load(file)
}
pub fn load<R:Read+std::io::Seek>(reader:R)->Result<strafesnet_common::map::CompleteMap,LoadError>{
match read(reader).map_err(LoadError::ReadError)?{
#[cfg(feature="snf")]
DataStructure::StrafesNET(map)=>Ok(map),
#[cfg(feature="roblox")]

View File

@@ -14,6 +14,9 @@ WorkerDescription{
*/
//up to three frames in flight, dropping new frame requests when all three are busy, and dropping output frames when one renders out of order
fn print(message:&str){
web_sys::console::log_1(&message.into());
}
pub fn new<'a>(
mut graphics:crate::graphics::GraphicsState,
mut config:wgpu::SurfaceConfiguration,
@@ -33,10 +36,18 @@ pub fn new<'a>(
}
Instruction::Render(frame_state)=>{
if let Some((size,user_settings))=resize.take(){
println!("Resizing to {:?}",size);
print(format!("Resizing to {:?}",size).as_str());
//let t0=std::time::Instant::now();
config.width=size.width.clamp(1,2560/2);
config.height=size.height.clamp(1,1440/2);
match size{
winit::dpi::PhysicalSize{width:2560,height:1440}=>{
config.width=size.width.clamp(1,2560);
config.height=size.height.clamp(1,1440);
},
_=>{
config.width=size.width.clamp(1,1280);
config.height=size.height.clamp(1,720);
}
}
surface.configure(&device,&config);
graphics.resize(&device,&config,&user_settings);
//println!("Resize took {:?}",t0.elapsed());

View File

@@ -211,13 +211,13 @@ pub async fn setup_and_start(title:String){
setup_context,
);
if let Some(arg)=std::env::args().nth(1){
let path=std::path::PathBuf::from(arg);
//if let Some(arg)=std::env::args().nth(1){
//let path=std::path::PathBuf::from(arg);
window_thread.send(TimedInstruction{
time:integer::Time::ZERO,
instruction:WindowInstruction::WindowEvent(winit::event::WindowEvent::DroppedFile(path)),
instruction:WindowInstruction::WindowEvent(winit::event::WindowEvent::DroppedFile("".into())),
}).unwrap();
};
//};
println!("Entering event loop...");
let root_time=chrono::Utc::now();

View File

@@ -25,8 +25,10 @@ impl WindowContext<'_>{
}
fn window_event(&mut self,time:integer::Time,event:winit::event::WindowEvent){
match event{
winit::event::WindowEvent::DroppedFile(path)=>{
match crate::file::load(path.as_path()){
winit::event::WindowEvent::DroppedFile(_path)=>{
//match crate::file::load_file(path.as_path()){
let data=include_bytes!("/run/media/quat/Files/Documents/map-files/verify-scripts/maps/bhop_snfm/5692152916.snfm");
match crate::file::load(std::io::Cursor::new(data.as_slice())){
Ok(map)=>self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ChangeMap(map)}).unwrap(),
Err(e)=>println!("Failed to load map: {e}"),
}