forked from StrafesNET/strafe-project
Compare commits
2 Commits
load-bsp
...
thread-tex
Author | SHA1 | Date | |
---|---|---|---|
17b0d12d4d | |||
1f9bdd9a34 |
65
Cargo.lock
generated
65
Cargo.lock
generated
@ -92,15 +92,6 @@ version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9"
|
||||
dependencies = [
|
||||
"nodrop",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.4"
|
||||
@ -206,7 +197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec 0.7.4",
|
||||
"arrayvec",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"constant_time_eq",
|
||||
@ -247,33 +238,12 @@ dependencies = [
|
||||
"objc2-encode",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bsp"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9d6d699bcff31f0c8a5951d29b9a7edfe3270218c20f6c3509f90ae7e1c46e7"
|
||||
dependencies = [
|
||||
"arrayvec 0.4.12",
|
||||
"bitflags 1.3.2",
|
||||
"bv",
|
||||
"byteorder 0.5.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
|
||||
|
||||
[[package]]
|
||||
name = "bv"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8834bb1d8ee5dc048ee3124f2c7c1afcc6bc9aed03f11e9dfd8c69470a5db340"
|
||||
dependencies = [
|
||||
"feature-probe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.13.1"
|
||||
@ -294,12 +264,6 @@ dependencies = [
|
||||
"syn 2.0.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
@ -459,7 +423,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "594ecd967c2f40db5dde8da4c356975fc1fe030e951c7c3962f6dc2e80042e87"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"byteorder 1.4.3",
|
||||
"byteorder",
|
||||
"enum_primitive",
|
||||
]
|
||||
|
||||
@ -568,12 +532,6 @@ dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "feature-probe"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.27"
|
||||
@ -1100,12 +1058,6 @@ dependencies = [
|
||||
"memoffset",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nodrop"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
@ -1554,7 +1506,7 @@ version = "0.8.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20"
|
||||
dependencies = [
|
||||
"byteorder 1.4.3",
|
||||
"byteorder",
|
||||
"num-traits 0.2.16",
|
||||
"paste",
|
||||
]
|
||||
@ -1565,7 +1517,7 @@ version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a"
|
||||
dependencies = [
|
||||
"byteorder 1.4.3",
|
||||
"byteorder",
|
||||
"rmp",
|
||||
"serde",
|
||||
]
|
||||
@ -1710,7 +1662,6 @@ name = "strafe-client"
|
||||
version = "0.7.0"
|
||||
dependencies = [
|
||||
"async-executor",
|
||||
"bsp",
|
||||
"bytemuck",
|
||||
"ddsfile",
|
||||
"env_logger",
|
||||
@ -1797,7 +1748,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df8493a203431061e901613751931f047d1971337153f96d0e5e363d6dbf6a67"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec 0.7.4",
|
||||
"arrayvec",
|
||||
"bytemuck",
|
||||
"cfg-if",
|
||||
"png",
|
||||
@ -2041,7 +1992,7 @@ version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7472f3b69449a8ae073f6ec41d05b6f846902d92a6c45313c50cb25857b736ce"
|
||||
dependencies = [
|
||||
"arrayvec 0.7.4",
|
||||
"arrayvec",
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"log",
|
||||
@ -2065,7 +2016,7 @@ version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecf7454d9386f602f7399225c92dd2fbdcde52c519bc8fb0bd6fbeb388075dc2"
|
||||
dependencies = [
|
||||
"arrayvec 0.7.4",
|
||||
"arrayvec",
|
||||
"bit-vec",
|
||||
"bitflags 2.4.0",
|
||||
"codespan-reporting",
|
||||
@ -2089,7 +2040,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6654a13885a17f475e8324efb46dc6986d7aaaa98353330f8de2077b153d0101"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"arrayvec 0.7.4",
|
||||
"arrayvec",
|
||||
"ash",
|
||||
"bit-set",
|
||||
"bitflags 2.4.0",
|
||||
|
@ -7,7 +7,6 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
async-executor = "1.5.1"
|
||||
bsp = "0.1.2"
|
||||
bytemuck = { version = "1.13.1", features = ["derive"] }
|
||||
ddsfile = "0.5.1"
|
||||
env_logger = "0.10.0"
|
||||
|
52
src/body.rs
52
src/body.rs
@ -976,50 +976,64 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
||||
self.walk.state=WalkEnum::Reached;
|
||||
},
|
||||
PhysicsInstruction::Input(input_instruction) => {
|
||||
let mut refresh_walk_target=true;
|
||||
let mut refresh_walk_target_velocity=true;
|
||||
let mut refresh_walk_target=false;
|
||||
match input_instruction{
|
||||
InputInstruction::MoveMouse(m) => {
|
||||
self.camera.angles=self.camera.simulate_move_angles(self.mouse_interpolation.mouse1-self.mouse_interpolation.mouse0);
|
||||
self.mouse_interpolation.move_mouse(self.time,m);
|
||||
refresh_walk_target=true;
|
||||
},
|
||||
InputInstruction::MoveForward(s) => {
|
||||
self.set_control(CONTROL_MOVEFORWARD,s);
|
||||
refresh_walk_target=true;
|
||||
},
|
||||
InputInstruction::MoveLeft(s) => {
|
||||
self.set_control(CONTROL_MOVELEFT,s);
|
||||
refresh_walk_target=true;
|
||||
},
|
||||
InputInstruction::MoveBack(s) => {
|
||||
self.set_control(CONTROL_MOVEBACK,s);
|
||||
refresh_walk_target=true;
|
||||
},
|
||||
InputInstruction::MoveRight(s) => {
|
||||
self.set_control(CONTROL_MOVERIGHT,s);
|
||||
refresh_walk_target=true;
|
||||
},
|
||||
InputInstruction::MoveUp(s) => {
|
||||
self.set_control(CONTROL_MOVEUP,s);
|
||||
refresh_walk_target=true;
|
||||
},
|
||||
InputInstruction::MoveDown(s) => {
|
||||
self.set_control(CONTROL_MOVEDOWN,s);
|
||||
refresh_walk_target=true;
|
||||
},
|
||||
InputInstruction::MoveForward(s) => self.set_control(CONTROL_MOVEFORWARD,s),
|
||||
InputInstruction::MoveLeft(s) => self.set_control(CONTROL_MOVELEFT,s),
|
||||
InputInstruction::MoveBack(s) => self.set_control(CONTROL_MOVEBACK,s),
|
||||
InputInstruction::MoveRight(s) => self.set_control(CONTROL_MOVERIGHT,s),
|
||||
InputInstruction::MoveUp(s) => self.set_control(CONTROL_MOVEUP,s),
|
||||
InputInstruction::MoveDown(s) => self.set_control(CONTROL_MOVEDOWN,s),
|
||||
InputInstruction::Jump(s) => {
|
||||
self.set_control(CONTROL_JUMP,s);
|
||||
refresh_walk_target=true;
|
||||
if self.grounded{
|
||||
self.jump();
|
||||
}
|
||||
refresh_walk_target_velocity=false;
|
||||
},
|
||||
InputInstruction::Zoom(s) => {
|
||||
self.set_control(CONTROL_ZOOM,s);
|
||||
refresh_walk_target=false;
|
||||
},
|
||||
InputInstruction::Reset => {
|
||||
//temp
|
||||
self.body.position=self.spawn_point;
|
||||
self.body.velocity=glam::Vec3::ZERO;
|
||||
//manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))}
|
||||
self.contacts.clear();
|
||||
self.body.acceleration=self.gravity;
|
||||
self.walk.state=WalkEnum::Reached;
|
||||
self.grounded=false;
|
||||
refresh_walk_target=false;
|
||||
},
|
||||
InputInstruction::Idle => {refresh_walk_target=false;},//literally idle!
|
||||
InputInstruction::Idle => (),//literally idle!
|
||||
}
|
||||
//calculate control dir
|
||||
let camera_mat=self.camera.simulate_move_rotation_y(self.mouse_interpolation.interpolated_position(self.time).x-self.mouse_interpolation.mouse0.x);
|
||||
let control_dir=camera_mat*get_control_dir(self.controls);
|
||||
//calculate walk target velocity
|
||||
if refresh_walk_target{
|
||||
//calculate walk target velocity
|
||||
if refresh_walk_target_velocity{
|
||||
let camera_mat=self.camera.simulate_move_rotation_y(self.mouse_interpolation.interpolated_position(self.time).x-self.mouse_interpolation.mouse0.x);
|
||||
let control_dir=camera_mat*get_control_dir(self.controls);
|
||||
self.walk.target_velocity=self.walkspeed*control_dir;
|
||||
}
|
||||
self.walk.target_velocity=self.walkspeed*control_dir;
|
||||
self.refresh_walk_target();
|
||||
}
|
||||
},
|
||||
|
@ -51,9 +51,8 @@ pub trait Example: 'static + Sized {
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
);
|
||||
fn update(&mut self, window: &winit::window::Window, device: &wgpu::Device, queue: &wgpu::Queue, event: WindowEvent);
|
||||
fn device_event(&mut self, window: &winit::window::Window, event: DeviceEvent);
|
||||
fn load_file(&mut self, path:std::path::PathBuf, device: &wgpu::Device, queue: &wgpu::Queue);
|
||||
fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, event: WindowEvent);
|
||||
fn device_event(&mut self, event: DeviceEvent);
|
||||
fn render(
|
||||
&mut self,
|
||||
view: &wgpu::TextureView,
|
||||
@ -368,14 +367,14 @@ fn start<E: Example>(
|
||||
println!("{:#?}", instance.generate_report());
|
||||
}
|
||||
_ => {
|
||||
example.update(&window,&device,&queue,event);
|
||||
example.update(&device,&queue,event);
|
||||
}
|
||||
},
|
||||
event::Event::DeviceEvent {
|
||||
event,
|
||||
..
|
||||
} => {
|
||||
example.device_event(&window,event);
|
||||
example.device_event(event);
|
||||
},
|
||||
event::Event::RedrawRequested(_) => {
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:R) -> crate::model::IndexedModelInstances{
|
||||
let mut spawn_point=glam::Vec3::ZERO;
|
||||
|
||||
let mut indexed_models=Vec::new();
|
||||
|
||||
match bsp::Bsp::read(input){
|
||||
Ok(guac)=>println!("we got the guac {:?}", guac),
|
||||
Err(e)=>println!("rotten {:?}",e),
|
||||
}
|
||||
|
||||
crate::model::IndexedModelInstances{
|
||||
textures:Vec::new(),
|
||||
models:indexed_models,
|
||||
spawn_point,
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
use crate::model::{IndexedModelInstances,ModelInstance};
|
||||
|
||||
use crate::primitives;
|
||||
|
||||
fn class_is_a(class: &str, superclass: &str) -> bool {
|
||||
@ -109,7 +111,7 @@ enum RobloxBasePartDescription{
|
||||
Wedge(RobloxWedgeDescription),
|
||||
CornerWedge(RobloxCornerWedgeDescription),
|
||||
}
|
||||
pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::IndexedModelInstances{
|
||||
pub fn generate_indexed_models_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(IndexedModelInstances,glam::Vec3), Box<dyn std::error::Error>>{
|
||||
//IndexedModelInstances includes textures
|
||||
let mut spawn_point=glam::Vec3::ZERO;
|
||||
|
||||
@ -157,7 +159,6 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index
|
||||
continue;
|
||||
}
|
||||
|
||||
//TODO: also detect "CylinderMesh" etc here
|
||||
let shape=match &object.class[..]{
|
||||
"Part"=>{
|
||||
if let Some(rbx_dom_weak::types::Variant::Enum(shape))=object.properties.get("Shape"){
|
||||
@ -167,10 +168,14 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index
|
||||
2=>primitives::Primitives::Cylinder,
|
||||
3=>primitives::Primitives::Wedge,
|
||||
4=>primitives::Primitives::CornerWedge,
|
||||
_=>panic!("Funky roblox PartType={};",shape.to_u32()),
|
||||
_=>{
|
||||
println!("Funky roblox PartType={}; defaulting to cube",shape.to_u32());
|
||||
primitives::Primitives::Cube
|
||||
},
|
||||
}
|
||||
}else{
|
||||
panic!("Part has no Shape!");
|
||||
println!("Part has no Shape! defaulting to cube");
|
||||
primitives::Primitives::Cube
|
||||
}
|
||||
},
|
||||
"WedgePart"=>primitives::Primitives::Wedge,
|
||||
@ -181,6 +186,38 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index
|
||||
}
|
||||
};
|
||||
|
||||
//TODO: also detect "CylinderMesh" etc here
|
||||
let mut face_map=std::collections::HashMap::new();
|
||||
match shape{
|
||||
primitives::Primitives::Cube => {
|
||||
face_map.insert(0,0);//Right
|
||||
face_map.insert(1,1);//Top
|
||||
face_map.insert(2,2);//Back
|
||||
face_map.insert(3,3);//Left
|
||||
face_map.insert(4,4);//Bottom
|
||||
face_map.insert(5,5);//Front
|
||||
},
|
||||
primitives::Primitives::Wedge => {
|
||||
face_map.insert(0,0);//Right
|
||||
face_map.insert(1,1);//Top -> TopFront (some surf maps put surf textures on the Top face)
|
||||
face_map.insert(2,1);//Front -> TopFront
|
||||
face_map.insert(3,2);//Back
|
||||
face_map.insert(4,3);//Left
|
||||
face_map.insert(5,4);//Bottom
|
||||
},
|
||||
primitives::Primitives::CornerWedge => {
|
||||
//Right -> None
|
||||
face_map.insert(1,0);//Top
|
||||
//Back -> None
|
||||
face_map.insert(3,1);//Right
|
||||
face_map.insert(4,2);//Bottom
|
||||
face_map.insert(5,3);//Front
|
||||
},
|
||||
//do not support textured spheres/cylinders imported from roblox
|
||||
//this can be added later, there are some maps that use it
|
||||
primitives::Primitives::Sphere
|
||||
|primitives::Primitives::Cylinder => (),
|
||||
}
|
||||
//use the biggest one and cut it down later...
|
||||
let mut part_texture_description:RobloxPartDescription=[None,None,None,None,None,None];
|
||||
temp_objects.clear();
|
||||
@ -208,7 +245,7 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index
|
||||
texture_id
|
||||
};
|
||||
let normal_id=normalid.to_u32();
|
||||
if normal_id<6{
|
||||
if let Some(&face)=face_map.get(&normal_id){
|
||||
let mut roblox_texture_transform=RobloxTextureTransform::default();
|
||||
let mut roblox_texture_color=glam::Vec4::ONE;
|
||||
if decal.class=="Texture"{
|
||||
@ -232,7 +269,7 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index
|
||||
3=>(size.z,size.y),//left
|
||||
4=>(size.x,size.z),//bottom
|
||||
5=>(size.x,size.y),//front
|
||||
_=>panic!("unreachable"),
|
||||
_=>(1.,1.),
|
||||
};
|
||||
roblox_texture_transform=RobloxTextureTransform{
|
||||
offset_u:*ox/(*sx),offset_v:*oy/(*sy),
|
||||
@ -241,7 +278,7 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index
|
||||
roblox_texture_color=glam::vec4(decal_color3.r,decal_color3.g,decal_color3.b,1.0-*decal_transparency);
|
||||
}
|
||||
}
|
||||
part_texture_description[normal_id as usize]=Some(RobloxFaceTextureDescription{
|
||||
part_texture_description[face]=Some(RobloxFaceTextureDescription{
|
||||
texture:texture_id,
|
||||
color:roblox_texture_color,
|
||||
transform:roblox_texture_transform,
|
||||
@ -259,11 +296,11 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index
|
||||
primitives::Primitives::Sphere=>RobloxBasePartDescription::Sphere,
|
||||
primitives::Primitives::Cube=>RobloxBasePartDescription::Part([f0,f1,f2,f3,f4,f5]),
|
||||
primitives::Primitives::Cylinder=>RobloxBasePartDescription::Cylinder,
|
||||
//use front face texture first and use top face texture as a fallback
|
||||
primitives::Primitives::Wedge=>RobloxBasePartDescription::Wedge([f0,if f2.is_some(){f2}else{f1},f3,f4,f5]),
|
||||
primitives::Primitives::CornerWedge=>RobloxBasePartDescription::CornerWedge([f1,f3,f4,f5]),
|
||||
//HAHAHA
|
||||
primitives::Primitives::Wedge=>RobloxBasePartDescription::Wedge([f0,f1,f2,f3,f4]),
|
||||
primitives::Primitives::CornerWedge=>RobloxBasePartDescription::CornerWedge([f0,f1,f2,f3]),
|
||||
};
|
||||
//make new model if unit cube has not been created before
|
||||
//make new model if unit cube has not been crated before
|
||||
let model_id=if let Some(&model_id)=model_id_from_description.get(&basepart_texture_description){
|
||||
//push to existing texture model
|
||||
model_id
|
||||
@ -333,16 +370,15 @@ pub fn generate_indexed_models(dom:rbx_dom_weak::WeakDom) -> crate::model::Index
|
||||
});
|
||||
model_id
|
||||
};
|
||||
indexed_models[model_id].instances.push(crate::model::ModelInstance {
|
||||
indexed_models[model_id].instances.push(ModelInstance {
|
||||
transform:model_transform,
|
||||
color:glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::model::IndexedModelInstances{
|
||||
Ok((IndexedModelInstances{
|
||||
textures:asset_id_from_texture_id.iter().map(|t|t.to_string()).collect(),
|
||||
models:indexed_models,
|
||||
spawn_point,
|
||||
}
|
||||
},spawn_point))
|
||||
}
|
||||
|
263
src/main.rs
263
src/main.rs
@ -10,7 +10,6 @@ mod zeroes;
|
||||
mod framework;
|
||||
mod primitives;
|
||||
mod instruction;
|
||||
mod load_bsp;
|
||||
mod load_roblox;
|
||||
|
||||
struct Entity {
|
||||
@ -47,7 +46,6 @@ pub struct GraphicsPipelines {
|
||||
pub struct GraphicsData {
|
||||
start_time: std::time::Instant,
|
||||
screen_size: (u32, u32),
|
||||
manual_mouse_lock:bool,
|
||||
physics: body::PhysicsState,
|
||||
pipelines: GraphicsPipelines,
|
||||
bind_groups: GraphicsBindGroups,
|
||||
@ -100,18 +98,17 @@ impl GraphicsData {
|
||||
//idk how to do this gooder lol
|
||||
let mut double_map=std::collections::HashMap::<u32,u32>::new();
|
||||
let mut texture_loading_threads=Vec::new();
|
||||
let num_textures=indexed_models.textures.len();
|
||||
for (i,texture_id) in indexed_models.textures.into_iter().enumerate(){
|
||||
if let Ok(mut file) = std::fs::File::open(std::path::Path::new(&format!("textures/{}.dds",texture_id))){
|
||||
for (i,t) in indexed_models.textures.iter().enumerate(){
|
||||
if let Ok(mut file) = std::fs::File::open(std::path::Path::new(&format!("textures/{}.dds",t))){
|
||||
double_map.insert(i as u32, texture_loading_threads.len() as u32);
|
||||
texture_loading_threads.push((texture_id,std::thread::spawn(move ||{
|
||||
ddsfile::Dds::read(&mut file).unwrap()
|
||||
})));
|
||||
texture_loading_threads.push(std::thread::spawn(move ||{
|
||||
(i,ddsfile::Dds::read(&mut file).unwrap())
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
let texture_views:Vec<wgpu::TextureView>=texture_loading_threads.into_iter().map(|(texture_id,thread)|{
|
||||
let image=thread.join().unwrap();
|
||||
let texture_views:Vec<wgpu::TextureView>=texture_loading_threads.into_iter().map(|t|{
|
||||
let (i,image)=t.join().unwrap();
|
||||
|
||||
let (mut width,mut height)=(image.get_width(),image.get_height());
|
||||
|
||||
@ -147,23 +144,23 @@ impl GraphicsData {
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format,
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||
label: Some(format!("Texture{}",texture_id).as_str()),
|
||||
label: Some(format!("Texture{}",i).as_str()),
|
||||
view_formats: &[],
|
||||
},
|
||||
&image.data,
|
||||
);
|
||||
texture.create_view(&wgpu::TextureViewDescriptor {
|
||||
label: Some(format!("Texture{} View",texture_id).as_str()),
|
||||
label: Some(format!("Texture{} View",i).as_str()),
|
||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
||||
..wgpu::TextureViewDescriptor::default()
|
||||
})
|
||||
}).collect();
|
||||
|
||||
let indexed_models_len=indexed_models.models.len();
|
||||
//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.
|
||||
let indexed_models_len=indexed_models.models.len();
|
||||
let mut unique_texture_models=Vec::with_capacity(indexed_models_len);
|
||||
for mut model in indexed_models.models.into_iter(){
|
||||
let mut unique_texture_models=Vec::with_capacity(indexed_models.models.len());
|
||||
for mut model in indexed_models.models.drain(..){
|
||||
//convert ModelInstance into ModelGraphicsInstance
|
||||
let instances:Vec<ModelGraphicsInstance>=model.instances.iter().map(|instance|{
|
||||
ModelGraphicsInstance{
|
||||
@ -202,7 +199,7 @@ impl GraphicsData {
|
||||
}
|
||||
//de-index models
|
||||
let mut models=Vec::with_capacity(unique_texture_models.len());
|
||||
for model in unique_texture_models.into_iter(){
|
||||
for model in unique_texture_models.drain(..){
|
||||
let mut vertices = Vec::new();
|
||||
let mut index_from_vertex = std::collections::HashMap::new();//::<IndexedVertex,usize>
|
||||
let mut entities = Vec::new();
|
||||
@ -245,7 +242,7 @@ impl GraphicsData {
|
||||
let uniform_buffer_binding_size=<GraphicsData as framework::Example>::required_limits().max_uniform_buffer_binding_size as usize;
|
||||
let chunk_size=uniform_buffer_binding_size/MODEL_BUFFER_SIZE_BYTES;
|
||||
self.models.reserve(models.len());
|
||||
for model in models.into_iter() {
|
||||
for model in models.drain(..) {
|
||||
instance_count+=model.instances.len();
|
||||
for instances_chunk in model.instances.rchunks(chunk_size){
|
||||
model_count+=1;
|
||||
@ -307,7 +304,7 @@ impl GraphicsData {
|
||||
});
|
||||
}
|
||||
}
|
||||
println!("Texture References={}",num_textures);
|
||||
println!("Texture References={}",indexed_models.textures.len());
|
||||
println!("Textures Loaded={}",texture_views.len());
|
||||
println!("Indexed Models={}",indexed_models_len);
|
||||
println!("Graphics Objects: {}",self.models.len());
|
||||
@ -746,7 +743,6 @@ impl framework::Example for GraphicsData {
|
||||
let depth_view = Self::create_depth_texture(config, device);
|
||||
|
||||
let mut graphics=GraphicsData {
|
||||
manual_mouse_lock:false,
|
||||
start_time: Instant::now(),
|
||||
screen_size: (config.width,config.height),
|
||||
physics,
|
||||
@ -770,111 +766,82 @@ impl framework::Example for GraphicsData {
|
||||
let indexed_model_instances=model::IndexedModelInstances{
|
||||
textures:Vec::new(),
|
||||
models:indexed_models,
|
||||
spawn_point:glam::Vec3::Y*50.0,
|
||||
};
|
||||
graphics.generate_model_physics(&indexed_model_instances);
|
||||
graphics.generate_model_graphics(&device,&queue,indexed_model_instances);
|
||||
|
||||
let args:Vec<String>=std::env::args().collect();
|
||||
if args.len()==2{
|
||||
graphics.load_file(std::path::PathBuf::from(&args[1]), device, queue);
|
||||
}
|
||||
|
||||
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 = "<roblox!"
|
||||
//.rbxmx roblox xml = "<roblox "
|
||||
//.bsp = "VBSP"
|
||||
//.vmf =
|
||||
//.snf = "SNMF"
|
||||
//.snf = "SNBF"
|
||||
if let (Ok(()),Ok(()))=(std::io::Read::read_exact(&mut input, &mut first_8),std::io::Seek::rewind(&mut input)){
|
||||
//
|
||||
if let Some(indexed_model_instances)={
|
||||
match &first_8[0..4]{
|
||||
b"<rob"=>{
|
||||
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(dom)),
|
||||
Err(e)=>{
|
||||
println!("Error loading roblox file:{:?}",e);
|
||||
None
|
||||
},
|
||||
}
|
||||
},
|
||||
b"VBSP"=>{
|
||||
let mut entire_file=Vec::new();
|
||||
match std::io::Read::read_to_end(&mut input, &mut entire_file){
|
||||
Ok(_)=>{
|
||||
//haha yes this is a quake file what do you mean
|
||||
entire_file[0]=b'I';
|
||||
entire_file[4..8].copy_from_slice(&0x2ei32.to_le_bytes());
|
||||
Some(load_bsp::generate_indexed_models(&mut std::io::Cursor::new(entire_file)))
|
||||
},
|
||||
Err(e)=>{
|
||||
println!("Error loading \"valve\" file:{:?}",e);
|
||||
None
|
||||
},
|
||||
}
|
||||
},
|
||||
//b"SNFM"=>Some(sniffer::generate_indexed_models(input)),
|
||||
//b"SNFB"=>Some(sniffer::load_bot(input)),
|
||||
other=>{
|
||||
println!("loser file {:?}",other);
|
||||
None
|
||||
},
|
||||
}
|
||||
}{
|
||||
let spawn_point=indexed_model_instances.spawn_point;
|
||||
//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) {
|
||||
fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) {
|
||||
//nothing atm
|
||||
match event {
|
||||
winit::event::WindowEvent::DroppedFile(path) => self.load_file(path,device,queue),
|
||||
winit::event::WindowEvent::Focused(state)=>{
|
||||
//pause unpause
|
||||
//recalculate pressed keys on focus
|
||||
}
|
||||
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 = "<roblox!"
|
||||
//.rbxmx roblox xml = "<roblox "
|
||||
//.bsp = "VBSP"
|
||||
//.vmf =
|
||||
//.snf = "SNMF"
|
||||
//.snf = "SNBF"
|
||||
if let (Ok(()),Ok(()))=(std::io::Read::read_exact(&mut input, &mut first_8),std::io::Seek::rewind(&mut input)){
|
||||
//
|
||||
if let Some(Ok((indexed_model_instances,spawn_point)))={
|
||||
match &first_8[0..4]{
|
||||
b"<rob"=>{
|
||||
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");
|
||||
}
|
||||
},
|
||||
_=>(),
|
||||
}
|
||||
}
|
||||
|
||||
fn device_event(&mut self, window: &winit::window::Window, event: winit::event::DeviceEvent) {
|
||||
fn device_event(&mut self, event: winit::event::DeviceEvent) {
|
||||
//there's no way this is the best way get a timestamp.
|
||||
let time=self.start_time.elapsed().as_nanos() as i64;
|
||||
match event {
|
||||
@ -888,58 +855,18 @@ impl framework::Example for GraphicsData {
|
||||
winit::event::ElementState::Released => false,
|
||||
};
|
||||
if let Some(input_instruction)=match keycode {
|
||||
17=>Some(InputInstruction::MoveForward(s)),//W
|
||||
30=>Some(InputInstruction::MoveLeft(s)),//A
|
||||
31=>Some(InputInstruction::MoveBack(s)),//S
|
||||
32=>Some(InputInstruction::MoveRight(s)),//D
|
||||
18=>Some(InputInstruction::MoveUp(s)),//E
|
||||
16=>Some(InputInstruction::MoveDown(s)),//Q
|
||||
57=>Some(InputInstruction::Jump(s)),//Space
|
||||
44=>Some(InputInstruction::Zoom(s)),//Z
|
||||
19=>if s{Some(InputInstruction::Reset)}else{None},//R
|
||||
01=>{//Esc
|
||||
if s{
|
||||
self.manual_mouse_lock=false;
|
||||
match window.set_cursor_grab(winit::window::CursorGrabMode::None){
|
||||
Ok(())=>(),
|
||||
Err(e)=>println!("Could not release cursor: {:?}",e),
|
||||
}
|
||||
window.set_cursor_visible(true);
|
||||
}
|
||||
None
|
||||
},
|
||||
15=>{//Tab
|
||||
if s{
|
||||
self.manual_mouse_lock=false;
|
||||
match window.set_cursor_position(winit::dpi::PhysicalPosition::new(self.screen_size.0 as f32/2.0, self.screen_size.1 as f32/2.0)){
|
||||
Ok(())=>(),
|
||||
Err(e)=>println!("Could not set cursor position: {:?}",e),
|
||||
}
|
||||
match window.set_cursor_grab(winit::window::CursorGrabMode::None){
|
||||
Ok(())=>(),
|
||||
Err(e)=>println!("Could not release cursor: {:?}",e),
|
||||
}
|
||||
}else{
|
||||
//if cursor is outside window don't lock but apparently there's no get pos function
|
||||
//let pos=window.get_cursor_pos();
|
||||
match window.set_cursor_grab(winit::window::CursorGrabMode::Locked){
|
||||
Ok(())=>(),
|
||||
Err(_)=>{
|
||||
match window.set_cursor_grab(winit::window::CursorGrabMode::Confined){
|
||||
Ok(())=>(),
|
||||
Err(e)=>{
|
||||
self.manual_mouse_lock=true;
|
||||
println!("Could not confine cursor: {:?}",e)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
window.set_cursor_visible(s);
|
||||
None
|
||||
},
|
||||
_ => {println!("scancode {}",keycode);None},
|
||||
}{
|
||||
17 => Some(InputInstruction::MoveForward(s)),//W
|
||||
30 => Some(InputInstruction::MoveLeft(s)),//A
|
||||
31 => Some(InputInstruction::MoveBack(s)),//S
|
||||
32 => Some(InputInstruction::MoveRight(s)),//D
|
||||
18 => Some(InputInstruction::MoveUp(s)),//E
|
||||
16 => Some(InputInstruction::MoveDown(s)),//Q
|
||||
57 => Some(InputInstruction::Jump(s)),//Space
|
||||
44 => Some(InputInstruction::Zoom(s)),//Z
|
||||
19 => if s{Some(InputInstruction::Reset)}else{None},//R
|
||||
_ => None,
|
||||
}
|
||||
{
|
||||
self.physics.run(time);
|
||||
self.physics.process_instruction(TimedInstruction{
|
||||
time,
|
||||
@ -950,12 +877,6 @@ impl framework::Example for GraphicsData {
|
||||
winit::event::DeviceEvent::MouseMotion {
|
||||
delta,//these (f64,f64) are integers on my machine
|
||||
} => {
|
||||
if self.manual_mouse_lock{
|
||||
match window.set_cursor_position(winit::dpi::PhysicalPosition::new(self.screen_size.0 as f32/2.0, self.screen_size.1 as f32/2.0)){
|
||||
Ok(())=>(),
|
||||
Err(e)=>println!("Could not set cursor position: {:?}",e),
|
||||
}
|
||||
}
|
||||
//do not step the physics because the mouse polling rate is higher than the physics can run.
|
||||
//essentially the previous input will be overwritten until a true step runs
|
||||
//which is fine because they run all the time.
|
||||
@ -967,8 +888,8 @@ impl framework::Example for GraphicsData {
|
||||
winit::event::DeviceEvent::MouseWheel {
|
||||
delta,
|
||||
} => {
|
||||
println!("mousewheel {:?}",delta);
|
||||
if false{//self.physics.style.use_scroll{
|
||||
println!("mousewheel{:?}",delta);
|
||||
if true{//self.physics.use_scroll
|
||||
self.physics.run(time);
|
||||
self.physics.process_instruction(TimedInstruction{
|
||||
time,
|
||||
|
@ -63,7 +63,6 @@ pub struct IndexedModelInstances{
|
||||
pub textures:Vec<String>,//RenderPattern
|
||||
pub models:Vec<IndexedModel>,
|
||||
//object_index for spawns, triggers etc?
|
||||
pub spawn_point:glam::Vec3,
|
||||
}
|
||||
|
||||
pub fn generate_indexed_model_list_from_obj(data:obj::ObjData,color:[f32;4]) -> Vec<IndexedModel>{
|
||||
|
@ -206,7 +206,7 @@ pub fn generate_partial_unit_cube(face_descriptions:CubeFaceDescription)->crate:
|
||||
let mut groups=Vec::new();
|
||||
let mut transforms=Vec::new();
|
||||
//note that on a cube every vertex is guaranteed to be unique, so there's no need to hash them against existing vertices.
|
||||
for (face,face_description) in face_descriptions.into_iter(){
|
||||
for (face,face_description) in face_descriptions.iter(){
|
||||
//assume that scanning short lists is faster than hashing.
|
||||
let transform_index=if let Some(transform_index)=transforms.iter().position(|&transform|transform==face_description.transform){
|
||||
transform_index
|
||||
@ -321,7 +321,7 @@ pub fn generate_partial_unit_wedge(face_descriptions:WedgeFaceDescription)->crat
|
||||
let mut groups=Vec::new();
|
||||
let mut transforms=Vec::new();
|
||||
//note that on a cube every vertex is guaranteed to be unique, so there's no need to hash them against existing vertices.
|
||||
for (face,face_description) in face_descriptions.into_iter(){
|
||||
for (face,face_description) in face_descriptions.iter(){
|
||||
//assume that scanning short lists is faster than hashing.
|
||||
let transform_index=if let Some(transform_index)=transforms.iter().position(|&transform|transform==face_description.transform){
|
||||
transform_index
|
||||
@ -433,7 +433,7 @@ pub fn generate_partial_unit_cornerwedge(face_descriptions:CornerWedgeFaceDescri
|
||||
let mut groups=Vec::new();
|
||||
let mut transforms=Vec::new();
|
||||
//note that on a cube every vertex is guaranteed to be unique, so there's no need to hash them against existing vertices.
|
||||
for (face,face_description) in face_descriptions.into_iter(){
|
||||
for (face,face_description) in face_descriptions.iter(){
|
||||
//assume that scanning short lists is faster than hashing.
|
||||
let transform_index=if let Some(transform_index)=transforms.iter().position(|&transform|transform==face_description.transform){
|
||||
transform_index
|
||||
|
Reference in New Issue
Block a user