Compare commits
1 Commits
surf-build
...
rustfmt
Author | SHA1 | Date | |
---|---|---|---|
5c835961c4 |
45
Cargo.lock
generated
45
Cargo.lock
generated
@ -1632,7 +1632,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strafe-client"
|
||||
version = "0.9.5"
|
||||
version = "0.9.4"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"configparser",
|
||||
@ -1641,6 +1641,7 @@ dependencies = [
|
||||
"id",
|
||||
"parking_lot",
|
||||
"pollster",
|
||||
"strafesnet_bsp_loader",
|
||||
"strafesnet_common",
|
||||
"strafesnet_deferred_loader",
|
||||
"strafesnet_rbx_loader",
|
||||
@ -1648,6 +1649,17 @@ dependencies = [
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_bsp_loader"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.itzana.me/StrafesNET/bsp_loader?rev=671b86802179572af3385bbd90cbe3bb5b6401a2#671b86802179572af3385bbd90cbe3bb5b6401a2"
|
||||
dependencies = [
|
||||
"glam",
|
||||
"strafesnet_common",
|
||||
"vbsp",
|
||||
"vmdl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_common"
|
||||
version = "0.1.0"
|
||||
@ -1798,14 +1810,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
|
||||
dependencies = [
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ttf-parser"
|
||||
@ -1876,6 +1903,22 @@ version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "vmdl"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "892922743c4c107372331efd8f67c57282590f8c18c26b4465c4b0e1e6678664"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags 2.4.2",
|
||||
"bytemuck",
|
||||
"cgmath",
|
||||
"itertools",
|
||||
"static_assertions",
|
||||
"thiserror",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.4.0"
|
||||
|
10
Cargo.toml
10
Cargo.toml
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "strafe-client"
|
||||
version = "0.9.5"
|
||||
version = "0.9.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@ -14,13 +14,13 @@ id = { git = "https://git.itzana.me/Quaternions/id", rev = "1f710976cc786c8853da
|
||||
parking_lot = "0.12.1"
|
||||
pollster = "0.3.0"
|
||||
strafesnet_common = { git = "https://git.itzana.me/StrafesNET/common", rev = "093a54c527134ef7020a22a0f5778df8cba60228" }
|
||||
#strafesnet_bsp_loader = { git = "https://git.itzana.me/StrafesNET/bsp_loader", rev = "671b86802179572af3385bbd90cbe3bb5b6401a2" }
|
||||
strafesnet_bsp_loader = { git = "https://git.itzana.me/StrafesNET/bsp_loader", rev = "671b86802179572af3385bbd90cbe3bb5b6401a2" }
|
||||
strafesnet_rbx_loader = { git = "https://git.itzana.me/StrafesNET/rbx_loader", rev = "e0739fa792ad506e210f076b90697194005bb7de" }
|
||||
strafesnet_deferred_loader = { git = "https://git.itzana.me/StrafesNET/deferred_loader", rev = "c03cd0e905daf70b03b60b3e12509f96ee94a658", features = ["legacy"] }
|
||||
wgpu = "0.19.0"
|
||||
winit = "0.29.2"
|
||||
|
||||
[profile.release]
|
||||
#[profile.release]
|
||||
#lto = true
|
||||
strip = true
|
||||
codegen-units = 1
|
||||
#strip = true
|
||||
#codegen-units = 1
|
||||
|
15
rustfmt.toml
Normal file
15
rustfmt.toml
Normal file
@ -0,0 +1,15 @@
|
||||
hard_tabs=true
|
||||
imports_layout="HorizontalVertical"
|
||||
match_arm_blocks=false
|
||||
match_block_trailing_comma=true
|
||||
newline_style="Unix"
|
||||
#overflow_delimited_expr=true
|
||||
reorder_impl_items=true
|
||||
reorder_imports=false
|
||||
group_imports="StdExternalCrate"
|
||||
reorder_modules=false
|
||||
space_after_colon=false
|
||||
type_punctuation_density="Compressed"
|
||||
use_field_init_shorthand=true
|
||||
use_try_shorthand=true
|
||||
#wrap_comments=true
|
10
src/file.rs
10
src/file.rs
@ -3,7 +3,7 @@ use std::io::Read;
|
||||
#[derive(Debug)]
|
||||
pub enum ReadError{
|
||||
Roblox(strafesnet_rbx_loader::ReadError),
|
||||
//Source(strafesnet_bsp_loader::ReadError),
|
||||
Source(strafesnet_bsp_loader::ReadError),
|
||||
Io(std::io::Error),
|
||||
UnknownFileFormat,
|
||||
}
|
||||
@ -16,7 +16,7 @@ impl std::error::Error for ReadError{}
|
||||
|
||||
pub enum DataStructure{
|
||||
Roblox(strafesnet_rbx_loader::Dom),
|
||||
//Source(strafesnet_bsp_loader::Bsp)
|
||||
Source(strafesnet_bsp_loader::Bsp)
|
||||
}
|
||||
|
||||
pub fn read<R:Read>(input:R)->Result<DataStructure,ReadError>{
|
||||
@ -24,7 +24,7 @@ pub fn read<R:Read>(input:R)->Result<DataStructure,ReadError>{
|
||||
let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::Io)?;
|
||||
match &peek[0..4]{
|
||||
b"<rob"=>Ok(DataStructure::Roblox(strafesnet_rbx_loader::read(buf).map_err(ReadError::Roblox)?)),
|
||||
//b"VBSP"=>Ok(DataStructure::Source(strafesnet_bsp_loader::read(buf).map_err(ReadError::Source)?)),
|
||||
b"VBSP"=>Ok(DataStructure::Source(strafesnet_bsp_loader::read(buf).map_err(ReadError::Source)?)),
|
||||
_=>Err(ReadError::UnknownFileFormat),
|
||||
}
|
||||
}
|
||||
@ -67,7 +67,6 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
||||
|
||||
Ok(map)
|
||||
},
|
||||
/*
|
||||
DataStructure::Source(bsp)=>{
|
||||
let mut loader=strafesnet_deferred_loader::source_legacy();
|
||||
|
||||
@ -108,6 +107,5 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
||||
|
||||
Ok(map)
|
||||
},
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
@ -218,8 +218,14 @@ impl GraphicsState{
|
||||
color:GraphicsModelColor4::new(model.color),
|
||||
};
|
||||
//get or create owned mesh map
|
||||
let owned_mesh_map=owned_mesh_id_from_mesh_id_render_config_id
|
||||
.entry(model.mesh).or_insert_with(||{
|
||||
if let Some(owned_mesh_map)=owned_mesh_id_from_mesh_id_render_config_id.get(&model.mesh){
|
||||
//the mesh has already been split into a set of unique renderconfig meshes
|
||||
//simply add one instance to each of them
|
||||
for owned_mesh_id in owned_mesh_map.values(){
|
||||
let owned_mesh=unique_render_config_models.get_mut(owned_mesh_id.get() as usize).unwrap();
|
||||
owned_mesh.instances.push(instance.clone());
|
||||
}
|
||||
}else{
|
||||
let mut owned_mesh_map=HashMap::new();
|
||||
//add mesh if renderid never before seen for this model
|
||||
//add instance
|
||||
@ -227,11 +233,17 @@ impl GraphicsState{
|
||||
//check each group, if it's using a new render config then make a new clone of the model
|
||||
if let Some(mesh)=map.meshes.get(model.mesh.get() as usize){
|
||||
for graphics_group in mesh.graphics_groups.iter(){
|
||||
let render_config=&map.render_configs[graphics_group.render.get() as usize];
|
||||
if model.color.w==0.0&&render_config.texture.is_none(){
|
||||
continue;
|
||||
}
|
||||
//get or create owned mesh
|
||||
let owned_mesh_id=owned_mesh_map
|
||||
.entry(graphics_group.render).or_insert_with(||{
|
||||
let owned_mesh_id=if let Some(&owned_mesh_id)=owned_mesh_map.get(&graphics_group.render){
|
||||
owned_mesh_id
|
||||
}else{
|
||||
//create
|
||||
let owned_mesh_id=IndexedGraphicsMeshOwnedRenderConfigId::new(unique_render_config_models.len() as u32);
|
||||
owned_mesh_map.insert(graphics_group.render,owned_mesh_id);
|
||||
unique_render_config_models.push(IndexedGraphicsMeshOwnedRenderConfig{
|
||||
unique_pos:mesh.unique_pos.iter().map(|&v|*Into::<glam::Vec3>::into(v).as_ref()).collect(),
|
||||
unique_tex:mesh.unique_tex.iter().map(|v|*v.as_ref()).collect(),
|
||||
@ -240,10 +252,10 @@ impl GraphicsState{
|
||||
unique_vertices:mesh.unique_vertices.clone(),
|
||||
render_config:graphics_group.render,
|
||||
polys:model::PolygonGroup::PolygonList(model::PolygonList::new(Vec::new())),
|
||||
instances:Vec::new(),
|
||||
instances:vec![instance.clone()],
|
||||
});
|
||||
owned_mesh_id
|
||||
});
|
||||
};
|
||||
let owned_mesh=unique_render_config_models.get_mut(owned_mesh_id.get() as usize).unwrap();
|
||||
match &mut owned_mesh.polys{
|
||||
model::PolygonGroup::PolygonList(polygon_list)=>polygon_list.extend(
|
||||
@ -257,16 +269,8 @@ impl GraphicsState{
|
||||
}
|
||||
}
|
||||
}
|
||||
owned_mesh_map
|
||||
});
|
||||
for owned_mesh_id in owned_mesh_map.values(){
|
||||
let owned_mesh=unique_render_config_models.get_mut(owned_mesh_id.get() as usize).unwrap();
|
||||
let render_config=&map.render_configs[owned_mesh.render_config.get() as usize];
|
||||
if model.color.w==0.0&&render_config.texture.is_none(){
|
||||
continue;
|
||||
}
|
||||
owned_mesh.instances.push(instance.clone());
|
||||
}
|
||||
owned_mesh_id_from_mesh_id_render_config_id.insert(model.mesh,owned_mesh_map);
|
||||
};
|
||||
}
|
||||
//check every model to see if it's using the same (texture,color) but has few instances,if it is combine it into one model
|
||||
//1. collect unique instances of texture and color,note model id
|
||||
@ -285,14 +289,24 @@ impl GraphicsState{
|
||||
continue;
|
||||
}
|
||||
//populate hashmap
|
||||
let unique_color=unique_texture_color
|
||||
.entry(model.render_config)
|
||||
.or_insert_with(||HashMap::new());
|
||||
let unique_color=if let Some(unique_color)=unique_texture_color.get_mut(&model.render_config){
|
||||
unique_color
|
||||
}else{
|
||||
//make new hashmap
|
||||
let unique_color=HashMap::new();
|
||||
unique_texture_color.insert(model.render_config,unique_color);
|
||||
unique_texture_color.get_mut(&model.render_config).unwrap()
|
||||
};
|
||||
//separate instances by color
|
||||
for (instance_id,instance) in model.instances.iter().enumerate(){
|
||||
let model_instance_list=unique_color
|
||||
.entry(instance.color)
|
||||
.or_insert_with(||Vec::new());
|
||||
let model_instance_list=if let Some(model_instance_list)=unique_color.get_mut(&instance.color){
|
||||
model_instance_list
|
||||
}else{
|
||||
//make new hashmap
|
||||
let model_instance_list=Vec::new();
|
||||
unique_color.insert(instance.color.clone(),model_instance_list);
|
||||
unique_color.get_mut(&instance.color).unwrap()
|
||||
};
|
||||
//add model instance to list
|
||||
model_instance_list.push((model_id,instance_id));
|
||||
}
|
||||
@ -328,34 +342,46 @@ impl GraphicsState{
|
||||
let map_pos_id:Vec<PositionId>=model.unique_pos.iter().map(|untransformed_pos|{
|
||||
let pos=instance.transform.transform_point3(glam::Vec3::from_array(untransformed_pos.clone())).to_array();
|
||||
let h=bytemuck::cast::<[f32;3],[u32;3]>(pos);
|
||||
PositionId::new(*pos_id_from.entry(h).or_insert_with(||{
|
||||
PositionId::new((if let Some(&pos_id)=pos_id_from.get(&h){
|
||||
pos_id
|
||||
}else{
|
||||
let pos_id=unique_pos.len();
|
||||
unique_pos.push(pos);
|
||||
pos_id_from.insert(h,pos_id);
|
||||
pos_id
|
||||
}) as u32)
|
||||
}).collect();
|
||||
let map_tex_id:Vec<TextureCoordinateId>=model.unique_tex.iter().map(|&tex|{
|
||||
let h=bytemuck::cast::<[f32;2],[u32;2]>(tex);
|
||||
TextureCoordinateId::new(*tex_id_from.entry(h).or_insert_with(||{
|
||||
TextureCoordinateId::new((if let Some(&tex_id)=tex_id_from.get(&h){
|
||||
tex_id
|
||||
}else{
|
||||
let tex_id=unique_tex.len();
|
||||
unique_tex.push(tex);
|
||||
tex_id_from.insert(h,tex_id);
|
||||
tex_id
|
||||
}) as u32)
|
||||
}).collect();
|
||||
let map_normal_id:Vec<NormalId>=model.unique_normal.iter().map(|untransformed_normal|{
|
||||
let normal=(instance.normal_transform*glam::Vec3::from_array(untransformed_normal.clone())).to_array();
|
||||
let h=bytemuck::cast::<[f32;3],[u32;3]>(normal);
|
||||
NormalId::new(*normal_id_from.entry(h).or_insert_with(||{
|
||||
NormalId::new((if let Some(&normal_id)=normal_id_from.get(&h){
|
||||
normal_id
|
||||
}else{
|
||||
let normal_id=unique_normal.len();
|
||||
unique_normal.push(normal);
|
||||
normal_id_from.insert(h,normal_id);
|
||||
normal_id
|
||||
}) as u32)
|
||||
}).collect();
|
||||
let map_color_id:Vec<ColorId>=model.unique_color.iter().map(|&color|{
|
||||
let h=bytemuck::cast::<[f32;4],[u32;4]>(color);
|
||||
ColorId::new(*color_id_from.entry(h).or_insert_with(||{
|
||||
ColorId::new((if let Some(&color_id)=color_id_from.get(&h){
|
||||
color_id
|
||||
}else{
|
||||
let color_id=unique_color.len();
|
||||
unique_color.push(color);
|
||||
color_id_from.insert(h,color_id);
|
||||
color_id
|
||||
}) as u32)
|
||||
}).collect();
|
||||
@ -368,9 +394,12 @@ impl GraphicsState{
|
||||
normal:map_normal_id[unmapped_vertex.normal.get() as usize],
|
||||
color:map_color_id[unmapped_vertex.color.get() as usize],
|
||||
};
|
||||
VertexId::new(*vertex_id_from.entry(vertex.clone()).or_insert_with(||{
|
||||
VertexId::new((if let Some(&vertex_id)=vertex_id_from.get(&vertex){
|
||||
vertex_id
|
||||
}else{
|
||||
let vertex_id=unique_vertices.len();
|
||||
unique_vertices.push(vertex);
|
||||
unique_vertices.push(vertex.clone());
|
||||
vertex_id_from.insert(vertex,vertex_id);
|
||||
vertex_id
|
||||
}) as u32)
|
||||
}).collect();
|
||||
@ -416,7 +445,9 @@ impl GraphicsState{
|
||||
for end_index in 2..poly.len(){
|
||||
for index in [0,end_index-1,end_index]{
|
||||
let vertex_index=poly[index];
|
||||
indices.push(*index_from_vertex.entry(vertex_index).or_insert_with(||{
|
||||
if let Some(&i)=index_from_vertex.get(&vertex_index){
|
||||
indices.push(i);
|
||||
}else{
|
||||
let i=vertices.len();
|
||||
let vertex=&model.unique_vertices[vertex_index.get() as usize];
|
||||
vertices.push(GraphicsVertex{
|
||||
@ -425,8 +456,9 @@ impl GraphicsState{
|
||||
normal:model.unique_normal[vertex.normal.get() as usize],
|
||||
color:model.unique_color[vertex.color.get() as usize],
|
||||
});
|
||||
i
|
||||
}));
|
||||
index_from_vertex.insert(vertex_index,i);
|
||||
indices.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
mod file;
|
||||
mod setup;
|
||||
mod window;
|
||||
mod worker;
|
||||
@ -12,6 +11,8 @@ mod model_graphics;
|
||||
mod physics_worker;
|
||||
mod graphics_worker;
|
||||
|
||||
mod file;
|
||||
|
||||
fn main(){
|
||||
setup::setup_and_start(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")));
|
||||
}
|
||||
|
@ -854,12 +854,10 @@ pub struct PhysicsData{
|
||||
}
|
||||
impl Default for PhysicsState{
|
||||
fn default()->Self{
|
||||
let mut style=StyleModifiers::default();
|
||||
style.gravity=style.gravity/2;
|
||||
Self{
|
||||
body:Body::new(Planar64Vec3::int(0,50,0),Planar64Vec3::int(0,0,0),Planar64Vec3::int(0,-100,0),Time::ZERO),
|
||||
time:Time::ZERO,
|
||||
style,
|
||||
style:StyleModifiers::default(),
|
||||
touching:TouchingState::default(),
|
||||
move_state: MoveState::Air,
|
||||
camera:PhysicsCamera::default(),
|
||||
@ -994,7 +992,6 @@ impl PhysicsContext{
|
||||
let mut used_meshes=Vec::new();
|
||||
let mut physics_mesh_id_from_model_mesh_id=HashMap::<MeshId,PhysicsMeshId>::new();
|
||||
self.data.models.models=map.models.iter().enumerate().filter_map(|(model_id,model)|{
|
||||
//TODO: use .entry().or_insert_with(||{
|
||||
let attr_id=if let Some(&attr_id)=physics_attr_id_from_model_attr_id.get(&model.attributes){
|
||||
attr_id
|
||||
}else{
|
||||
@ -1697,4 +1694,4 @@ mod test{
|
||||
Time::ZERO
|
||||
),None);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user