implement texture_loader
This commit is contained in:
parent
7f29e244ed
commit
d494adf42e
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -1515,6 +1515,7 @@ dependencies = [
|
|||||||
"pollster",
|
"pollster",
|
||||||
"strafesnet_common",
|
"strafesnet_common",
|
||||||
"strafesnet_rbx_loader",
|
"strafesnet_rbx_loader",
|
||||||
|
"strafesnet_texture_loader",
|
||||||
"wgpu",
|
"wgpu",
|
||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
@ -1522,7 +1523,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "strafesnet_common"
|
name = "strafesnet_common"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.itzana.me/StrafesNET/common?rev=43f771fb0f19a3751875df1f25bf9cb5874f75f4#43f771fb0f19a3751875df1f25bf9cb5874f75f4"
|
source = "git+https://git.itzana.me/StrafesNET/common?rev=fccb13bc6080ea6db94ef9175affd4aef1d9249d#fccb13bc6080ea6db94ef9175affd4aef1d9249d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glam",
|
"glam",
|
||||||
"id",
|
"id",
|
||||||
@ -1531,7 +1532,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "strafesnet_rbx_loader"
|
name = "strafesnet_rbx_loader"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.itzana.me/StrafesNET/rbx_loader?rev=5c9a79390a36ca33e2fe64d9a59da4a98f77662c#5c9a79390a36ca33e2fe64d9a59da4a98f77662c"
|
source = "git+https://git.itzana.me/StrafesNET/rbx_loader?rev=05e609521a31d14ca2c9def7a778d792022571dc#05e609521a31d14ca2c9def7a778d792022571dc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glam",
|
"glam",
|
||||||
"lazy-regex",
|
"lazy-regex",
|
||||||
@ -1542,6 +1543,15 @@ dependencies = [
|
|||||||
"strafesnet_common",
|
"strafesnet_common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strafesnet_texture_loader"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://git.itzana.me/StrafesNET/texture_loader?rev=94e951ce06fb30873964ec29f30fcf9c8247a9a5#94e951ce06fb30873964ec29f30fcf9c8247a9a5"
|
||||||
|
dependencies = [
|
||||||
|
"lazy-regex",
|
||||||
|
"strafesnet_common",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strict-num"
|
name = "strict-num"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
@ -13,8 +13,9 @@ glam = "0.25.0"
|
|||||||
id = { git = "https://git.itzana.me/Quaternions/id", rev = "1f710976cc786c8853dab73d6e1cee53158deeb0" }
|
id = { git = "https://git.itzana.me/Quaternions/id", rev = "1f710976cc786c8853dab73d6e1cee53158deeb0" }
|
||||||
parking_lot = "0.12.1"
|
parking_lot = "0.12.1"
|
||||||
pollster = "0.3.0"
|
pollster = "0.3.0"
|
||||||
strafesnet_common = { git = "https://git.itzana.me/StrafesNET/common", rev = "43f771fb0f19a3751875df1f25bf9cb5874f75f4" }
|
strafesnet_rbx_loader = { git = "https://git.itzana.me/StrafesNET/rbx_loader", rev = "05e609521a31d14ca2c9def7a778d792022571dc" }
|
||||||
strafesnet_rbx_loader = { git = "https://git.itzana.me/StrafesNET/rbx_loader", rev = "5c9a79390a36ca33e2fe64d9a59da4a98f77662c" }
|
strafesnet_common = { git = "https://git.itzana.me/StrafesNET/common", rev = "fccb13bc6080ea6db94ef9175affd4aef1d9249d" }
|
||||||
|
strafesnet_texture_loader = { git = "https://git.itzana.me/StrafesNET/texture_loader", rev = "94e951ce06fb30873964ec29f30fcf9c8247a9a5", features = ["legacy"] }
|
||||||
wgpu = "0.19.0"
|
wgpu = "0.19.0"
|
||||||
winit = "0.29.2"
|
winit = "0.29.2"
|
||||||
|
|
||||||
|
@ -147,10 +147,9 @@ impl GraphicsState{
|
|||||||
pub fn load_user_settings(&mut self,user_settings:&crate::settings::UserSettings){
|
pub fn load_user_settings(&mut self,user_settings:&crate::settings::UserSettings){
|
||||||
self.camera.fov=user_settings.calculate_fov(1.0,&self.camera.screen_size).as_vec2();
|
self.camera.fov=user_settings.calculate_fov(1.0,&self.camera.screen_size).as_vec2();
|
||||||
}
|
}
|
||||||
pub fn generate_models(&mut self,device:&wgpu::Device,queue:&wgpu::Queue,map:&map::CompleteMap){
|
pub fn generate_models(&mut self,device:&wgpu::Device,queue:&wgpu::Queue,map:&map::CompleteMap,textures:strafesnet_texture_loader::texture_loader::Textures){
|
||||||
//generate texture view per texture
|
//generate texture view per texture
|
||||||
let num_textures=map.textures.len();
|
let texture_views:Vec<wgpu::TextureView>=textures.into_iter().map(|(texture_id,texture_data)|{
|
||||||
let texture_views:Vec<wgpu::TextureView>=map.textures.iter().enumerate().map(|(texture_id,texture_data)|{
|
|
||||||
let image=ddsfile::Dds::read(std::io::Cursor::new(texture_data)).unwrap();
|
let image=ddsfile::Dds::read(std::io::Cursor::new(texture_data)).unwrap();
|
||||||
|
|
||||||
let (mut width,mut height)=(image.get_width(),image.get_height());
|
let (mut width,mut height)=(image.get_width(),image.get_height());
|
||||||
@ -187,18 +186,19 @@ impl GraphicsState{
|
|||||||
dimension:wgpu::TextureDimension::D2,
|
dimension:wgpu::TextureDimension::D2,
|
||||||
format,
|
format,
|
||||||
usage:wgpu::TextureUsages::TEXTURE_BINDING|wgpu::TextureUsages::COPY_DST,
|
usage:wgpu::TextureUsages::TEXTURE_BINDING|wgpu::TextureUsages::COPY_DST,
|
||||||
label:Some(format!("Texture{}",texture_id).as_str()),
|
label:Some(format!("Texture{}",texture_id.get()).as_str()),
|
||||||
view_formats:&[],
|
view_formats:&[],
|
||||||
},
|
},
|
||||||
wgpu::util::TextureDataOrder::LayerMajor,
|
wgpu::util::TextureDataOrder::LayerMajor,
|
||||||
&image.data,
|
&image.data,
|
||||||
);
|
);
|
||||||
texture.create_view(&wgpu::TextureViewDescriptor{
|
texture.create_view(&wgpu::TextureViewDescriptor{
|
||||||
label:Some(format!("Texture{} View",texture_id).as_str()),
|
label:Some(format!("Texture{} View",texture_id.get()).as_str()),
|
||||||
dimension:Some(wgpu::TextureViewDimension::D2),
|
dimension:Some(wgpu::TextureViewDimension::D2),
|
||||||
..wgpu::TextureViewDescriptor::default()
|
..wgpu::TextureViewDescriptor::default()
|
||||||
})
|
})
|
||||||
}).collect();
|
}).collect();
|
||||||
|
let num_textures=texture_views.len();
|
||||||
|
|
||||||
//split groups with different textures into separate models
|
//split groups with different textures into separate models
|
||||||
//the models received here are supposed to be tightly packed,i.e. no code needs to check if two models are using the same groups.
|
//the models received here are supposed to be tightly packed,i.e. no code needs to check if two models are using the same groups.
|
||||||
|
@ -4,7 +4,7 @@ pub enum Instruction{
|
|||||||
Render(crate::physics::PhysicsOutputState,integer::Time,glam::IVec2),
|
Render(crate::physics::PhysicsOutputState,integer::Time,glam::IVec2),
|
||||||
//UpdateModel(crate::graphics::GraphicsModelUpdate),
|
//UpdateModel(crate::graphics::GraphicsModelUpdate),
|
||||||
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
||||||
GenerateModels(strafesnet_common::map::CompleteMap),
|
GenerateModels(strafesnet_common::map::CompleteMap,strafesnet_texture_loader::texture_loader::Textures),
|
||||||
ClearModels,
|
ClearModels,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,8 +27,8 @@ pub fn new<'a>(
|
|||||||
let mut resize=None;
|
let mut resize=None;
|
||||||
crate::compat_worker::INWorker::new(move |ins:Instruction|{
|
crate::compat_worker::INWorker::new(move |ins:Instruction|{
|
||||||
match ins{
|
match ins{
|
||||||
Instruction::GenerateModels(indexed_model_instances)=>{
|
Instruction::GenerateModels(map,textures)=>{
|
||||||
graphics.generate_models(&device,&queue,&indexed_model_instances);
|
graphics.generate_models(&device,&queue,&map,textures);
|
||||||
},
|
},
|
||||||
Instruction::ClearModels=>{
|
Instruction::ClearModels=>{
|
||||||
graphics.clear();
|
graphics.clear();
|
||||||
|
@ -18,7 +18,7 @@ pub enum Instruction{
|
|||||||
Input(InputInstruction),
|
Input(InputInstruction),
|
||||||
Render,
|
Render,
|
||||||
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
||||||
GenerateModels(strafesnet_common::map::CompleteMap),
|
GenerateModels(strafesnet_common::map::CompleteMap,strafesnet_texture_loader::texture_loader::Textures),
|
||||||
ClearModels,
|
ClearModels,
|
||||||
//Graphics(crate::graphics_worker::Instruction),
|
//Graphics(crate::graphics_worker::Instruction),
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ pub enum Instruction{
|
|||||||
&InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)),
|
&InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)),
|
||||||
InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset),
|
InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset),
|
||||||
},
|
},
|
||||||
Instruction::GenerateModels(_)=>Some(PhysicsInputInstruction::Idle),
|
Instruction::GenerateModels(_,_)=>Some(PhysicsInputInstruction::Idle),
|
||||||
Instruction::ClearModels=>Some(PhysicsInputInstruction::Idle),
|
Instruction::ClearModels=>Some(PhysicsInputInstruction::Idle),
|
||||||
Instruction::Resize(_,_)=>Some(PhysicsInputInstruction::Idle),
|
Instruction::Resize(_,_)=>Some(PhysicsInputInstruction::Idle),
|
||||||
Instruction::Render=>Some(PhysicsInputInstruction::Idle),
|
Instruction::Render=>Some(PhysicsInputInstruction::Idle),
|
||||||
@ -118,10 +118,10 @@ pub enum Instruction{
|
|||||||
Instruction::Resize(size,user_settings)=>{
|
Instruction::Resize(size,user_settings)=>{
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
|
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
|
||||||
},
|
},
|
||||||
Instruction::GenerateModels(indexed_model_instances)=>{
|
Instruction::GenerateModels(map,textures)=>{
|
||||||
physics.generate_models(&indexed_model_instances);
|
physics.generate_models(&map);
|
||||||
physics.spawn();
|
physics.spawn();
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(indexed_model_instances)).unwrap();
|
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map,textures)).unwrap();
|
||||||
},
|
},
|
||||||
Instruction::ClearModels=>{
|
Instruction::ClearModels=>{
|
||||||
physics.state.clear();
|
physics.state.clear();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::physics_worker::InputInstruction;
|
use crate::physics_worker::InputInstruction;
|
||||||
use strafesnet_common::integer;
|
use strafesnet_common::integer;
|
||||||
use strafesnet_common::instruction::TimedInstruction;
|
use strafesnet_common::instruction::TimedInstruction;
|
||||||
|
use strafesnet_texture_loader::texture_loader::TextureLoaderTrait;
|
||||||
|
|
||||||
pub enum WindowInstruction{
|
pub enum WindowInstruction{
|
||||||
Resize(winit::dpi::PhysicalSize<u32>),
|
Resize(winit::dpi::PhysicalSize<u32>),
|
||||||
@ -41,12 +42,22 @@ impl WindowContext<'_>{
|
|||||||
// Ok(strafesnet_snf::SNF::Demo(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:?}"),
|
// Err(e)=>println!("Error reading file: {e:?}"),
|
||||||
// }
|
// }
|
||||||
match strafesnet_rbx_loader::read(file){
|
let mut texture_loader=strafesnet_texture_loader::legacy();
|
||||||
Ok(map)=>{
|
match (strafesnet_rbx_loader::read(file,|name|{
|
||||||
self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ClearModels}).unwrap();
|
match texture_loader.acquire_id(name){
|
||||||
self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::GenerateModels(map)}).unwrap();
|
Ok(texture_id)=>Some(texture_id),
|
||||||
|
Err(e)=>{
|
||||||
|
println!("there was error: {e}");
|
||||||
|
None
|
||||||
},
|
},
|
||||||
Err(e)=>println!("Error reading file: {e:?}"),
|
}
|
||||||
|
}),texture_loader.load()){
|
||||||
|
(Ok(map),Ok(textures))=>{
|
||||||
|
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(map,textures)}).unwrap();
|
||||||
|
},
|
||||||
|
(Err(e),_)=>println!("Error reading file: {e:?}"),
|
||||||
|
(_,Err(e))=>println!("Error loading textures: {e:?}"),
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
println!("Failed to open file {path:?}");
|
println!("Failed to open file {path:?}");
|
||||||
|
Loading…
Reference in New Issue
Block a user