Compare commits
88 Commits
v0.9.5
...
fixed-wide
Author | SHA1 | Date | |
---|---|---|---|
4f79d6c8bf | |||
df12b9f126 | |||
1372e12301 | |||
1841077e49 | |||
e47b1ff6f9 | |||
2c77a36083 | |||
e5e7ccaa3f | |||
78202beb53 | |||
1265926c98 | |||
a916068d16 | |||
f3314308ef | |||
6f389e56ac | |||
ad8b2c3793 | |||
94d8bcfcea | |||
24a7fce2a9 | |||
6ed5dd8028 | |||
1ef659e46a | |||
4cc1a172bd | |||
412d9ada8f | |||
b4abe437f6 | |||
1928c2fc40 | |||
158bad279a | |||
b2a84e3be1 | |||
0468484788 | |||
b9dc97053f | |||
40ed173b60 | |||
fd5a813357 | |||
50726199b9 | |||
0676007430 | |||
97c49c9351 | |||
10689784be | |||
2eff5dda9e | |||
93b04f4f1f | |||
c616e82c47 | |||
d3f84c2dbd | |||
5e45753756 | |||
cfee6f119f | |||
b9e34f53c3 | |||
394f1f1dc2 | |||
05ec7ea5d8 | |||
7996df532e | |||
b4b85b7da4 | |||
3a98eaff7c | |||
4b5b7dc2fb | |||
8a13640c55 | |||
85ba12ff92 | |||
4f492d73b0 | |||
a8d54fdd7c | |||
34ac541260 | |||
099788b746 | |||
305017c6c8 | |||
e47d152af2 | |||
755adeaefd | |||
e04e754abb | |||
5c1f69628d | |||
44031c8b83 | |||
d6470ee81b | |||
a7c7088c1f | |||
dd6acbfc2f | |||
3fea6ec5a2 | |||
38df41e043 | |||
171cd8f2e4 | |||
914b5da897 | |||
52e92bfa5a | |||
938500e39b | |||
d82dfc2bc2 | |||
c59f40892a | |||
4863605af7 | |||
685e74575a | |||
d1aca4519b | |||
4a4ede36ed | |||
33cc2e1a45 | |||
9982a52af5 | |||
34939db8ef | |||
b61088195a | |||
19ab098be0 | |||
bf1fad9fc4 | |||
62b5ba2b33 | |||
f2a7b44884 | |||
c054b6aab3 | |||
7caec210ce | |||
5fdcf9047c | |||
3756af9638 | |||
8424fea634 | |||
46c73b80c6 | |||
0ac1c1aa6b | |||
0a75e78c90 | |||
ecc8d2395b |
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[registries.strafesnet]
|
||||||
|
index = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
/target
|
/target
|
||||||
/textures
|
|
1153
Cargo.lock
generated
1153
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
35
Cargo.toml
35
Cargo.toml
@ -1,26 +1,37 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "strafe-client"
|
name = "strafe-client"
|
||||||
version = "0.9.5"
|
version = "0.10.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
repository = "https://git.itzana.me/StrafesNET/strafe-client"
|
||||||
|
license = "Custom"
|
||||||
|
description = "StrafesNET game client for bhop and surf."
|
||||||
|
authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[features]
|
||||||
|
default = ["snf"]
|
||||||
|
snf = ["dep:strafesnet_snf"]
|
||||||
|
source = ["dep:strafesnet_deferred_loader", "dep:strafesnet_bsp_loader"]
|
||||||
|
roblox = ["dep:strafesnet_deferred_loader", "dep:strafesnet_rbx_loader"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
arrayvec = "0.7.6"
|
||||||
bytemuck = { version = "1.13.1", features = ["derive"] }
|
bytemuck = { version = "1.13.1", features = ["derive"] }
|
||||||
configparser = "3.0.2"
|
configparser = "3.0.2"
|
||||||
ddsfile = "0.5.1"
|
ddsfile = "0.5.1"
|
||||||
glam = "0.25.0"
|
glam = "0.28.0"
|
||||||
id = { git = "https://git.itzana.me/Quaternions/id", rev = "1f710976cc786c8853dab73d6e1cee53158deeb0" }
|
id = { version = "0.1.0", registry = "strafesnet" }
|
||||||
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 = "093a54c527134ef7020a22a0f5778df8cba60228" }
|
strafesnet_bsp_loader = { version = "0.1.3", registry = "strafesnet", optional = true }
|
||||||
strafesnet_bsp_loader = { git = "https://git.itzana.me/StrafesNET/bsp_loader", rev = "671b86802179572af3385bbd90cbe3bb5b6401a2" }
|
strafesnet_common = { version = "0.4.0", registry = "strafesnet" }
|
||||||
strafesnet_rbx_loader = { git = "https://git.itzana.me/StrafesNET/rbx_loader", rev = "e0739fa792ad506e210f076b90697194005bb7de" }
|
strafesnet_deferred_loader = { version = "0.3.1", features = ["legacy"], registry = "strafesnet", optional = true }
|
||||||
strafesnet_deferred_loader = { git = "https://git.itzana.me/StrafesNET/deferred_loader", rev = "c03cd0e905daf70b03b60b3e12509f96ee94a658", features = ["legacy"] }
|
strafesnet_rbx_loader = { version = "0.3.2", registry = "strafesnet", optional = true }
|
||||||
wgpu = "0.19.0"
|
strafesnet_snf = { version = "0.1.2", registry = "strafesnet", optional = true }
|
||||||
winit = "0.29.2"
|
wgpu = "22.0.0"
|
||||||
|
winit = "0.30.4"
|
||||||
|
|
||||||
#[profile.release]
|
[profile.release]
|
||||||
#lto = true
|
#lto = true
|
||||||
#strip = true
|
strip = true
|
||||||
#codegen-units = 1
|
codegen-units = 1
|
||||||
|
44
src/file.rs
44
src/file.rs
@ -2,8 +2,14 @@ use std::io::Read;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ReadError{
|
pub enum ReadError{
|
||||||
|
#[cfg(feature="roblox")]
|
||||||
Roblox(strafesnet_rbx_loader::ReadError),
|
Roblox(strafesnet_rbx_loader::ReadError),
|
||||||
|
#[cfg(feature="source")]
|
||||||
Source(strafesnet_bsp_loader::ReadError),
|
Source(strafesnet_bsp_loader::ReadError),
|
||||||
|
#[cfg(feature="snf")]
|
||||||
|
StrafesNET(strafesnet_snf::Error),
|
||||||
|
#[cfg(feature="snf")]
|
||||||
|
StrafesNETMap(strafesnet_snf::map::Error),
|
||||||
Io(std::io::Error),
|
Io(std::io::Error),
|
||||||
UnknownFileFormat,
|
UnknownFileFormat,
|
||||||
}
|
}
|
||||||
@ -15,16 +21,27 @@ impl std::fmt::Display for ReadError{
|
|||||||
impl std::error::Error for ReadError{}
|
impl std::error::Error for ReadError{}
|
||||||
|
|
||||||
pub enum DataStructure{
|
pub enum DataStructure{
|
||||||
|
#[cfg(feature="roblox")]
|
||||||
Roblox(strafesnet_rbx_loader::Dom),
|
Roblox(strafesnet_rbx_loader::Dom),
|
||||||
Source(strafesnet_bsp_loader::Bsp)
|
#[cfg(feature="source")]
|
||||||
|
Source(strafesnet_bsp_loader::Bsp),
|
||||||
|
#[cfg(feature="snf")]
|
||||||
|
StrafesNET(strafesnet_common::map::CompleteMap),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read<R:Read>(input:R)->Result<DataStructure,ReadError>{
|
pub fn read<R:Read+std::io::Seek>(input:R)->Result<DataStructure,ReadError>{
|
||||||
let mut buf=std::io::BufReader::new(input);
|
let mut buf=std::io::BufReader::new(input);
|
||||||
let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::Io)?;
|
let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::Io)?;
|
||||||
match &peek[0..4]{
|
match &peek[0..4]{
|
||||||
|
#[cfg(feature="roblox")]
|
||||||
b"<rob"=>Ok(DataStructure::Roblox(strafesnet_rbx_loader::read(buf).map_err(ReadError::Roblox)?)),
|
b"<rob"=>Ok(DataStructure::Roblox(strafesnet_rbx_loader::read(buf).map_err(ReadError::Roblox)?)),
|
||||||
|
#[cfg(feature="source")]
|
||||||
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)?)),
|
||||||
|
#[cfg(feature="snf")]
|
||||||
|
b"SNFM"=>Ok(DataStructure::StrafesNET(
|
||||||
|
strafesnet_snf::read_map(buf).map_err(ReadError::StrafesNET)?
|
||||||
|
.into_complete_map().map_err(ReadError::StrafesNETMap)?
|
||||||
|
)),
|
||||||
_=>Err(ReadError::UnknownFileFormat),
|
_=>Err(ReadError::UnknownFileFormat),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,17 +63,31 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
|||||||
//blocking because it's simpler...
|
//blocking because it's simpler...
|
||||||
let file=std::fs::File::open(path).map_err(LoadError::File)?;
|
let file=std::fs::File::open(path).map_err(LoadError::File)?;
|
||||||
match read(file).map_err(LoadError::ReadError)?{
|
match read(file).map_err(LoadError::ReadError)?{
|
||||||
|
#[cfg(feature="snf")]
|
||||||
|
DataStructure::StrafesNET(map)=>Ok(map),
|
||||||
|
#[cfg(feature="roblox")]
|
||||||
DataStructure::Roblox(dom)=>{
|
DataStructure::Roblox(dom)=>{
|
||||||
let mut loader=strafesnet_deferred_loader::roblox_legacy();
|
let mut loader=strafesnet_deferred_loader::roblox_legacy();
|
||||||
|
|
||||||
|
let (texture_loader,mesh_loader)=loader.get_inner_mut();
|
||||||
|
|
||||||
let map_step1=strafesnet_rbx_loader::convert(
|
let map_step1=strafesnet_rbx_loader::convert(
|
||||||
&dom,
|
&dom,
|
||||||
|name|loader.acquire_render_config_id(name)
|
|name|texture_loader.acquire_render_config_id(name),
|
||||||
|
|name|mesh_loader.acquire_mesh_id(name),
|
||||||
|
);
|
||||||
|
|
||||||
|
let meshpart_meshes=mesh_loader.load_meshes().map_err(LoadError::Io)?;
|
||||||
|
|
||||||
|
let map_step2=map_step1.add_meshpart_meshes_and_calculate_attributes(
|
||||||
|
meshpart_meshes.into_iter().map(|(mesh_id,loader_model)|
|
||||||
|
(mesh_id,strafesnet_rbx_loader::data::RobloxMeshBytes::new(loader_model.get()))
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
let (textures,render_configs)=loader.into_render_configs().map_err(LoadError::Io)?.consume();
|
let (textures,render_configs)=loader.into_render_configs().map_err(LoadError::Io)?.consume();
|
||||||
|
|
||||||
let map=map_step1.add_render_configs_and_textures(
|
let map=map_step2.add_render_configs_and_textures(
|
||||||
render_configs.into_iter(),
|
render_configs.into_iter(),
|
||||||
textures.into_iter().map(|(texture_id,texture)|
|
textures.into_iter().map(|(texture_id,texture)|
|
||||||
(texture_id,match texture{
|
(texture_id,match texture{
|
||||||
@ -67,6 +98,7 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
|||||||
|
|
||||||
Ok(map)
|
Ok(map)
|
||||||
},
|
},
|
||||||
|
#[cfg(feature="source")]
|
||||||
DataStructure::Source(bsp)=>{
|
DataStructure::Source(bsp)=>{
|
||||||
let mut loader=strafesnet_deferred_loader::source_legacy();
|
let mut loader=strafesnet_deferred_loader::source_legacy();
|
||||||
|
|
||||||
@ -74,9 +106,7 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
|||||||
|
|
||||||
let map_step1=strafesnet_bsp_loader::convert(
|
let map_step1=strafesnet_bsp_loader::convert(
|
||||||
&bsp,
|
&bsp,
|
||||||
//acquire_render_config_id
|
|
||||||
|name|texture_loader.acquire_render_config_id(name),
|
|name|texture_loader.acquire_render_config_id(name),
|
||||||
//acquire_mesh_id
|
|
||||||
|name|mesh_loader.acquire_mesh_id(name),
|
|name|mesh_loader.acquire_mesh_id(name),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -108,4 +138,4 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
|||||||
Ok(map)
|
Ok(map)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,6 @@ use strafesnet_common::model::{self, ColorId, NormalId, PolygonIter, PositionId,
|
|||||||
use wgpu::{util::DeviceExt,AstcBlock,AstcChannel};
|
use wgpu::{util::DeviceExt,AstcBlock,AstcChannel};
|
||||||
use crate::model_graphics::{self,IndexedGraphicsMeshOwnedRenderConfig,IndexedGraphicsMeshOwnedRenderConfigId,GraphicsMeshOwnedRenderConfig,GraphicsModelColor4,GraphicsModelOwned,GraphicsVertex};
|
use crate::model_graphics::{self,IndexedGraphicsMeshOwnedRenderConfig,IndexedGraphicsMeshOwnedRenderConfigId,GraphicsMeshOwnedRenderConfig,GraphicsModelColor4,GraphicsModelOwned,GraphicsVertex};
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct GraphicsModelUpdate{
|
|
||||||
transform:Option<glam::Mat4>,
|
|
||||||
color:Option<glam::Vec4>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Indices{
|
struct Indices{
|
||||||
count:u32,
|
count:u32,
|
||||||
buf:wgpu::Buffer,
|
buf:wgpu::Buffer,
|
||||||
@ -32,7 +26,6 @@ impl Indices{
|
|||||||
}
|
}
|
||||||
struct GraphicsModel{
|
struct GraphicsModel{
|
||||||
indices:Indices,
|
indices:Indices,
|
||||||
model_buf:wgpu::Buffer,
|
|
||||||
vertex_buf:wgpu::Buffer,
|
vertex_buf:wgpu::Buffer,
|
||||||
bind_group:wgpu::BindGroup,
|
bind_group:wgpu::BindGroup,
|
||||||
instance_count:u32,
|
instance_count:u32,
|
||||||
@ -65,24 +58,24 @@ struct GraphicsCamera{
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn perspective_rh(fov_x_slope:f32,fov_y_slope:f32,z_near:f32,z_far:f32)->glam::Mat4{
|
fn perspective_rh(fov_x_slope:f32,fov_y_slope:f32,z_near:f32,z_far:f32)->glam::Mat4{
|
||||||
//glam_assert!(z_near > 0.0 && z_far > 0.0);
|
//glam_assert!(z_near > 0.0 && z_far > 0.0);
|
||||||
let r=z_far / (z_near-z_far);
|
let r=z_far/(z_near-z_far);
|
||||||
glam::Mat4::from_cols(
|
glam::Mat4::from_cols(
|
||||||
glam::Vec4::new(1.0/fov_x_slope,0.0,0.0,0.0),
|
glam::Vec4::new(1.0/fov_x_slope,0.0,0.0,0.0),
|
||||||
glam::Vec4::new(0.0,1.0/fov_y_slope,0.0,0.0),
|
glam::Vec4::new(0.0,1.0/fov_y_slope,0.0,0.0),
|
||||||
glam::Vec4::new(0.0,0.0,r,-1.0),
|
glam::Vec4::new(0.0,0.0,r,-1.0),
|
||||||
glam::Vec4::new(0.0,0.0,r * z_near,0.0),
|
glam::Vec4::new(0.0,0.0,r*z_near,0.0),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
impl GraphicsCamera{
|
impl GraphicsCamera{
|
||||||
pub fn proj(&self)->glam::Mat4{
|
pub fn proj(&self)->glam::Mat4{
|
||||||
perspective_rh(self.fov.x,self.fov.y,0.5,2000.0)
|
perspective_rh(self.fov.x,self.fov.y,0.4,4000.0)
|
||||||
}
|
}
|
||||||
pub fn world(&self,pos:glam::Vec3,angles:glam::Vec2)->glam::Mat4{
|
pub fn world(&self,pos:glam::Vec3,angles:glam::Vec2)->glam::Mat4{
|
||||||
//f32 good enough for view matrix
|
//f32 good enough for view matrix
|
||||||
glam::Mat4::from_translation(pos) * glam::Mat4::from_euler(glam::EulerRot::YXZ,angles.x,angles.y,0f32)
|
glam::Mat4::from_translation(pos)*glam::Mat4::from_euler(glam::EulerRot::YXZ,angles.x,angles.y,0f32)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_uniform_data(&self,(pos,angles):(glam::Vec3,glam::Vec2))->[f32; 16 * 4]{
|
pub fn to_uniform_data(&self,pos:glam::Vec3,angles:glam::Vec2)->[f32;16*4]{
|
||||||
let proj=self.proj();
|
let proj=self.proj();
|
||||||
let proj_inv=proj.inverse();
|
let proj_inv=proj.inverse();
|
||||||
let view_inv=self.world(pos,angles);
|
let view_inv=self.world(pos,angles);
|
||||||
@ -105,6 +98,12 @@ impl std::default::Default for GraphicsCamera{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct FrameState{
|
||||||
|
pub body:crate::physics::Body,
|
||||||
|
pub camera:crate::physics::PhysicsCamera,
|
||||||
|
pub time:integer::Time,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct GraphicsState{
|
pub struct GraphicsState{
|
||||||
pipelines:GraphicsPipelines,
|
pipelines:GraphicsPipelines,
|
||||||
bind_groups:GraphicsBindGroups,
|
bind_groups:GraphicsBindGroups,
|
||||||
@ -151,7 +150,13 @@ impl GraphicsState{
|
|||||||
//generate texture view per texture
|
//generate texture view per texture
|
||||||
let texture_views:HashMap<strafesnet_common::model::TextureId,wgpu::TextureView>=map.textures.iter().enumerate().filter_map(|(texture_id,texture_data)|{
|
let texture_views:HashMap<strafesnet_common::model::TextureId,wgpu::TextureView>=map.textures.iter().enumerate().filter_map(|(texture_id,texture_data)|{
|
||||||
let texture_id=model::TextureId::new(texture_id as u32);
|
let texture_id=model::TextureId::new(texture_id as u32);
|
||||||
let image=ddsfile::Dds::read(std::io::Cursor::new(texture_data)).ok()?;
|
let image=match ddsfile::Dds::read(std::io::Cursor::new(texture_data)){
|
||||||
|
Ok(image)=>image,
|
||||||
|
Err(e)=>{
|
||||||
|
println!("Error loading texture: {e}");
|
||||||
|
return None;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let (mut width,mut height)=(image.get_width(),image.get_height());
|
let (mut width,mut height)=(image.get_width(),image.get_height());
|
||||||
|
|
||||||
@ -413,22 +418,26 @@ impl GraphicsState{
|
|||||||
//this mut be combined in a more complex way if the models use different render patterns per group
|
//this mut be combined in a more complex way if the models use different render patterns per group
|
||||||
let mut indices=Vec::new();
|
let mut indices=Vec::new();
|
||||||
for poly in model.polys.polys(){
|
for poly in model.polys.polys(){
|
||||||
for end_index in 2..poly.len(){
|
let mut poly_vertices=poly.iter()
|
||||||
for index in [0,end_index-1,end_index]{
|
.map(|&vertex_index|*index_from_vertex.entry(vertex_index).or_insert_with(||{
|
||||||
let vertex_index=poly[index];
|
let i=vertices.len();
|
||||||
indices.push(*index_from_vertex.entry(vertex_index).or_insert_with(||{
|
let vertex=&model.unique_vertices[vertex_index.get() as usize];
|
||||||
let i=vertices.len();
|
vertices.push(GraphicsVertex{
|
||||||
let vertex=&model.unique_vertices[vertex_index.get() as usize];
|
pos:model.unique_pos[vertex.pos.get() as usize],
|
||||||
vertices.push(GraphicsVertex{
|
tex:model.unique_tex[vertex.tex.get() as usize],
|
||||||
pos:model.unique_pos[vertex.pos.get() as usize],
|
normal:model.unique_normal[vertex.normal.get() as usize],
|
||||||
tex:model.unique_tex[vertex.tex.get() as usize],
|
color:model.unique_color[vertex.color.get() as usize],
|
||||||
normal:model.unique_normal[vertex.normal.get() as usize],
|
});
|
||||||
color:model.unique_color[vertex.color.get() as usize],
|
i
|
||||||
});
|
}));
|
||||||
i
|
|
||||||
}));
|
let a=poly_vertices.next().unwrap();
|
||||||
}
|
let mut b=poly_vertices.next().unwrap();
|
||||||
}
|
|
||||||
|
poly_vertices.for_each(|c|{
|
||||||
|
indices.extend([a,b,c]);
|
||||||
|
b=c;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
GraphicsMeshOwnedRenderConfig{
|
GraphicsMeshOwnedRenderConfig{
|
||||||
instances:model.instances,
|
instances:model.instances,
|
||||||
@ -453,7 +462,9 @@ impl GraphicsState{
|
|||||||
instance_count+=model.instances.len();
|
instance_count+=model.instances.len();
|
||||||
for instances_chunk in model.instances.rchunks(chunk_size){
|
for instances_chunk in model.instances.rchunks(chunk_size){
|
||||||
model_count+=1;
|
model_count+=1;
|
||||||
let model_uniforms=get_instances_buffer_data(instances_chunk);
|
let mut model_uniforms=get_instances_buffer_data(instances_chunk);
|
||||||
|
//TEMP: fill with zeroes to pass validation
|
||||||
|
model_uniforms.resize(MODEL_BUFFER_SIZE*512,0.0f32);
|
||||||
let model_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
let model_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
||||||
label:Some(format!("Model{} Buf",model_count).as_str()),
|
label:Some(format!("Model{} Buf",model_count).as_str()),
|
||||||
contents:bytemuck::cast_slice(&model_uniforms),
|
contents:bytemuck::cast_slice(&model_uniforms),
|
||||||
@ -495,7 +506,6 @@ impl GraphicsState{
|
|||||||
model_graphics::Indices::U16(indices)=>Indices::new(device,indices,wgpu::IndexFormat::Uint16),
|
model_graphics::Indices::U16(indices)=>Indices::new(device,indices,wgpu::IndexFormat::Uint16),
|
||||||
},
|
},
|
||||||
bind_group,
|
bind_group,
|
||||||
model_buf,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -744,11 +754,13 @@ impl GraphicsState{
|
|||||||
module:&shader,
|
module:&shader,
|
||||||
entry_point:"vs_sky",
|
entry_point:"vs_sky",
|
||||||
buffers:&[],
|
buffers:&[],
|
||||||
|
compilation_options:wgpu::PipelineCompilationOptions::default(),
|
||||||
},
|
},
|
||||||
fragment:Some(wgpu::FragmentState{
|
fragment:Some(wgpu::FragmentState{
|
||||||
module:&shader,
|
module:&shader,
|
||||||
entry_point:"fs_sky",
|
entry_point:"fs_sky",
|
||||||
targets:&[Some(config.view_formats[0].into())],
|
targets:&[Some(config.view_formats[0].into())],
|
||||||
|
compilation_options:wgpu::PipelineCompilationOptions::default(),
|
||||||
}),
|
}),
|
||||||
primitive:wgpu::PrimitiveState{
|
primitive:wgpu::PrimitiveState{
|
||||||
front_face:wgpu::FrontFace::Cw,
|
front_face:wgpu::FrontFace::Cw,
|
||||||
@ -763,6 +775,7 @@ impl GraphicsState{
|
|||||||
}),
|
}),
|
||||||
multisample:wgpu::MultisampleState::default(),
|
multisample:wgpu::MultisampleState::default(),
|
||||||
multiview:None,
|
multiview:None,
|
||||||
|
cache:None,
|
||||||
});
|
});
|
||||||
let model_pipeline=device.create_render_pipeline(&wgpu::RenderPipelineDescriptor{
|
let model_pipeline=device.create_render_pipeline(&wgpu::RenderPipelineDescriptor{
|
||||||
label:Some("Model Pipeline"),
|
label:Some("Model Pipeline"),
|
||||||
@ -775,11 +788,13 @@ impl GraphicsState{
|
|||||||
step_mode:wgpu::VertexStepMode::Vertex,
|
step_mode:wgpu::VertexStepMode::Vertex,
|
||||||
attributes:&wgpu::vertex_attr_array![0=>Float32x3,1=>Float32x2,2=>Float32x3,3=>Float32x4],
|
attributes:&wgpu::vertex_attr_array![0=>Float32x3,1=>Float32x2,2=>Float32x3,3=>Float32x4],
|
||||||
}],
|
}],
|
||||||
|
compilation_options:wgpu::PipelineCompilationOptions::default(),
|
||||||
},
|
},
|
||||||
fragment:Some(wgpu::FragmentState{
|
fragment:Some(wgpu::FragmentState{
|
||||||
module:&shader,
|
module:&shader,
|
||||||
entry_point:"fs_entity_texture",
|
entry_point:"fs_entity_texture",
|
||||||
targets:&[Some(config.view_formats[0].into())],
|
targets:&[Some(config.view_formats[0].into())],
|
||||||
|
compilation_options:wgpu::PipelineCompilationOptions::default(),
|
||||||
}),
|
}),
|
||||||
primitive:wgpu::PrimitiveState{
|
primitive:wgpu::PrimitiveState{
|
||||||
front_face:wgpu::FrontFace::Cw,
|
front_face:wgpu::FrontFace::Cw,
|
||||||
@ -795,10 +810,11 @@ impl GraphicsState{
|
|||||||
}),
|
}),
|
||||||
multisample:wgpu::MultisampleState::default(),
|
multisample:wgpu::MultisampleState::default(),
|
||||||
multiview:None,
|
multiview:None,
|
||||||
|
cache:None,
|
||||||
});
|
});
|
||||||
|
|
||||||
let camera=GraphicsCamera::default();
|
let camera=GraphicsCamera::default();
|
||||||
let camera_uniforms=camera.to_uniform_data(crate::physics::PhysicsOutputState::default().extrapolate(glam::IVec2::ZERO,integer::Time::ZERO));
|
let camera_uniforms=camera.to_uniform_data(glam::Vec3::ZERO,glam::Vec2::ZERO);
|
||||||
let camera_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
let camera_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
||||||
label:Some("Camera"),
|
label:Some("Camera"),
|
||||||
contents:bytemuck::cast_slice(&camera_uniforms),
|
contents:bytemuck::cast_slice(&camera_uniforms),
|
||||||
@ -866,16 +882,17 @@ impl GraphicsState{
|
|||||||
view:&wgpu::TextureView,
|
view:&wgpu::TextureView,
|
||||||
device:&wgpu::Device,
|
device:&wgpu::Device,
|
||||||
queue:&wgpu::Queue,
|
queue:&wgpu::Queue,
|
||||||
physics_output:crate::physics::PhysicsOutputState,
|
frame_state:FrameState,
|
||||||
predicted_time:integer::Time,
|
|
||||||
mouse_pos:glam::IVec2,
|
|
||||||
){
|
){
|
||||||
//TODO:use scheduled frame times to create beautiful smoothing simulation physics extrapolation assuming no input
|
//TODO:use scheduled frame times to create beautiful smoothing simulation physics extrapolation assuming no input
|
||||||
|
|
||||||
let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
|
let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
|
||||||
|
|
||||||
// update rotation
|
// update rotation
|
||||||
let camera_uniforms=self.camera.to_uniform_data(physics_output.extrapolate(mouse_pos,predicted_time));
|
let camera_uniforms=self.camera.to_uniform_data(
|
||||||
|
frame_state.body.extrapolated_position(frame_state.time).into(),
|
||||||
|
frame_state.camera.simulate_move_angles(glam::IVec2::ZERO)
|
||||||
|
);
|
||||||
self.staging_belt
|
self.staging_belt
|
||||||
.write_buffer(
|
.write_buffer(
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
use strafesnet_common::integer;
|
|
||||||
|
|
||||||
pub enum Instruction{
|
pub enum Instruction{
|
||||||
Render(crate::physics::PhysicsOutputState,integer::Time,glam::IVec2),
|
Render(crate::graphics::FrameState),
|
||||||
//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),
|
ChangeMap(strafesnet_common::map::CompleteMap),
|
||||||
ClearModels,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Ideally the graphics thread worker description is:
|
//Ideally the graphics thread worker description is:
|
||||||
@ -18,36 +15,32 @@ 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
|
//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
|
||||||
|
|
||||||
pub fn new<'a>(
|
pub fn new<'a>(
|
||||||
mut graphics:crate::graphics::GraphicsState,
|
mut graphics:crate::graphics::GraphicsState,
|
||||||
mut config:wgpu::SurfaceConfiguration,
|
mut config:wgpu::SurfaceConfiguration,
|
||||||
surface:wgpu::Surface<'a>,
|
surface:wgpu::Surface<'a>,
|
||||||
device:wgpu::Device,
|
device:wgpu::Device,
|
||||||
queue:wgpu::Queue,
|
queue:wgpu::Queue,
|
||||||
)->crate::compat_worker::INWorker<'a,Instruction>{
|
)->crate::compat_worker::INWorker<'a,Instruction>{
|
||||||
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(map)=>{
|
Instruction::ChangeMap(map)=>{
|
||||||
graphics.generate_models(&device,&queue,&map);
|
|
||||||
},
|
|
||||||
Instruction::ClearModels=>{
|
|
||||||
graphics.clear();
|
graphics.clear();
|
||||||
|
graphics.generate_models(&device,&queue,&map);
|
||||||
},
|
},
|
||||||
Instruction::Resize(size,user_settings)=>{
|
Instruction::Resize(size,user_settings)=>{
|
||||||
resize=Some((size,user_settings));
|
resize=Some((size,user_settings));
|
||||||
}
|
}
|
||||||
Instruction::Render(physics_output,predicted_time,mouse_pos)=>{
|
Instruction::Render(frame_state)=>{
|
||||||
if let Some((size,user_settings))=&resize{
|
if let Some((size,user_settings))=resize.take(){
|
||||||
println!("Resizing to {:?}",size);
|
println!("Resizing to {:?}",size);
|
||||||
let t0=std::time::Instant::now();
|
let t0=std::time::Instant::now();
|
||||||
config.width=size.width.max(1);
|
config.width=size.width.max(1);
|
||||||
config.height=size.height.max(1);
|
config.height=size.height.max(1);
|
||||||
surface.configure(&device,&config);
|
surface.configure(&device,&config);
|
||||||
graphics.resize(&device,&config,user_settings);
|
graphics.resize(&device,&config,&user_settings);
|
||||||
println!("Resize took {:?}",t0.elapsed());
|
println!("Resize took {:?}",t0.elapsed());
|
||||||
}
|
}
|
||||||
//clear every time w/e
|
|
||||||
resize=None;
|
|
||||||
//this has to go deeper somehow
|
//this has to go deeper somehow
|
||||||
let frame=match surface.get_current_texture(){
|
let frame=match surface.get_current_texture(){
|
||||||
Ok(frame)=>frame,
|
Ok(frame)=>frame,
|
||||||
@ -63,10 +56,10 @@ pub fn new<'a>(
|
|||||||
..wgpu::TextureViewDescriptor::default()
|
..wgpu::TextureViewDescriptor::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
graphics.render(&view,&device,&queue,physics_output,predicted_time,mouse_pos);
|
graphics.render(&view,&device,&queue,frame_state);
|
||||||
|
|
||||||
frame.present();
|
frame.present();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ mod worker;
|
|||||||
mod physics;
|
mod physics;
|
||||||
mod graphics;
|
mod graphics;
|
||||||
mod settings;
|
mod settings;
|
||||||
|
mod push_solve;
|
||||||
mod face_crawler;
|
mod face_crawler;
|
||||||
mod compat_worker;
|
mod compat_worker;
|
||||||
mod model_physics;
|
mod model_physics;
|
||||||
|
@ -137,22 +137,22 @@ impl PhysicsMesh{
|
|||||||
//go go gadget debug print mesh
|
//go go gadget debug print mesh
|
||||||
let data=PhysicsMeshData{
|
let data=PhysicsMeshData{
|
||||||
faces:vec![
|
faces:vec![
|
||||||
Face{normal:Planar64Vec3::raw( 4294967296, 0, 0),dot:Planar64::raw(4294967296)},
|
Face{normal:Planar64Vec3::raw_xyz( 4294967296, 0, 0),dot:Planar64::raw(4294967296)},
|
||||||
Face{normal:Planar64Vec3::raw( 0, 4294967296, 0),dot:Planar64::raw(4294967296)},
|
Face{normal:Planar64Vec3::raw_xyz( 0, 4294967296, 0),dot:Planar64::raw(4294967296)},
|
||||||
Face{normal:Planar64Vec3::raw( 0, 0, 4294967296),dot:Planar64::raw(4294967296)},
|
Face{normal:Planar64Vec3::raw_xyz( 0, 0, 4294967296),dot:Planar64::raw(4294967296)},
|
||||||
Face{normal:Planar64Vec3::raw(-4294967296, 0, 0),dot:Planar64::raw(4294967296)},
|
Face{normal:Planar64Vec3::raw_xyz(-4294967296, 0, 0),dot:Planar64::raw(4294967296)},
|
||||||
Face{normal:Planar64Vec3::raw( 0,-4294967296, 0),dot:Planar64::raw(4294967296)},
|
Face{normal:Planar64Vec3::raw_xyz( 0,-4294967296, 0),dot:Planar64::raw(4294967296)},
|
||||||
Face{normal:Planar64Vec3::raw( 0, 0,-4294967296),dot:Planar64::raw(4294967296)}
|
Face{normal:Planar64Vec3::raw_xyz( 0, 0,-4294967296),dot:Planar64::raw(4294967296)}
|
||||||
],
|
],
|
||||||
verts:vec![
|
verts:vec![
|
||||||
Vert(Planar64Vec3::raw( 4294967296,-4294967296,-4294967296)),
|
Vert(Planar64Vec3::raw_xyz( 4294967296,-4294967296,-4294967296)),
|
||||||
Vert(Planar64Vec3::raw( 4294967296, 4294967296,-4294967296)),
|
Vert(Planar64Vec3::raw_xyz( 4294967296, 4294967296,-4294967296)),
|
||||||
Vert(Planar64Vec3::raw( 4294967296, 4294967296, 4294967296)),
|
Vert(Planar64Vec3::raw_xyz( 4294967296, 4294967296, 4294967296)),
|
||||||
Vert(Planar64Vec3::raw( 4294967296,-4294967296, 4294967296)),
|
Vert(Planar64Vec3::raw_xyz( 4294967296,-4294967296, 4294967296)),
|
||||||
Vert(Planar64Vec3::raw(-4294967296, 4294967296,-4294967296)),
|
Vert(Planar64Vec3::raw_xyz(-4294967296, 4294967296,-4294967296)),
|
||||||
Vert(Planar64Vec3::raw(-4294967296, 4294967296, 4294967296)),
|
Vert(Planar64Vec3::raw_xyz(-4294967296, 4294967296, 4294967296)),
|
||||||
Vert(Planar64Vec3::raw(-4294967296,-4294967296, 4294967296)),
|
Vert(Planar64Vec3::raw_xyz(-4294967296,-4294967296, 4294967296)),
|
||||||
Vert(Planar64Vec3::raw(-4294967296,-4294967296,-4294967296))
|
Vert(Planar64Vec3::raw_xyz(-4294967296,-4294967296,-4294967296))
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
let mesh_topology=PhysicsMeshTopology{
|
let mesh_topology=PhysicsMeshTopology{
|
||||||
@ -167,17 +167,17 @@ impl PhysicsMesh{
|
|||||||
FaceRefs{edges:vec![SubmeshDirectedEdgeId(4),SubmeshDirectedEdgeId(0),SubmeshDirectedEdgeId((9223372036854775819u64-(1<<63)+(1<<31)) as u32),SubmeshDirectedEdgeId(9)]}
|
FaceRefs{edges:vec![SubmeshDirectedEdgeId(4),SubmeshDirectedEdgeId(0),SubmeshDirectedEdgeId((9223372036854775819u64-(1<<63)+(1<<31)) as u32),SubmeshDirectedEdgeId(9)]}
|
||||||
],
|
],
|
||||||
edge_topology:vec![
|
edge_topology:vec![
|
||||||
EdgeRefs{faces:[SubmeshFaceId(0),SubmeshFaceId(5)],verts:[SubmeshVertId(0),SubmeshVertId(1)]},
|
EdgeRefs{faces:[SubmeshFaceId(0),SubmeshFaceId(5)],verts:[SubmeshVertId(0),SubmeshVertId(1)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(0),SubmeshFaceId(1)],verts:[SubmeshVertId(1),SubmeshVertId(2)]},
|
EdgeRefs{faces:[SubmeshFaceId(0),SubmeshFaceId(1)],verts:[SubmeshVertId(1),SubmeshVertId(2)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(0),SubmeshFaceId(2)],verts:[SubmeshVertId(2),SubmeshVertId(3)]},
|
EdgeRefs{faces:[SubmeshFaceId(0),SubmeshFaceId(2)],verts:[SubmeshVertId(2),SubmeshVertId(3)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(4),SubmeshFaceId(0)],verts:[SubmeshVertId(0),SubmeshVertId(3)]},
|
EdgeRefs{faces:[SubmeshFaceId(4),SubmeshFaceId(0)],verts:[SubmeshVertId(0),SubmeshVertId(3)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(1),SubmeshFaceId(5)],verts:[SubmeshVertId(1),SubmeshVertId(4)]},
|
EdgeRefs{faces:[SubmeshFaceId(1),SubmeshFaceId(5)],verts:[SubmeshVertId(1),SubmeshVertId(4)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(1),SubmeshFaceId(3)],verts:[SubmeshVertId(4),SubmeshVertId(5)]},
|
EdgeRefs{faces:[SubmeshFaceId(1),SubmeshFaceId(3)],verts:[SubmeshVertId(4),SubmeshVertId(5)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(2),SubmeshFaceId(1)],verts:[SubmeshVertId(2),SubmeshVertId(5)]},
|
EdgeRefs{faces:[SubmeshFaceId(2),SubmeshFaceId(1)],verts:[SubmeshVertId(2),SubmeshVertId(5)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(4),SubmeshFaceId(2)],verts:[SubmeshVertId(3),SubmeshVertId(6)]},
|
EdgeRefs{faces:[SubmeshFaceId(4),SubmeshFaceId(2)],verts:[SubmeshVertId(3),SubmeshVertId(6)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(2),SubmeshFaceId(3)],verts:[SubmeshVertId(5),SubmeshVertId(6)]},
|
EdgeRefs{faces:[SubmeshFaceId(2),SubmeshFaceId(3)],verts:[SubmeshVertId(5),SubmeshVertId(6)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(3),SubmeshFaceId(5)],verts:[SubmeshVertId(4),SubmeshVertId(7)]},
|
EdgeRefs{faces:[SubmeshFaceId(3),SubmeshFaceId(5)],verts:[SubmeshVertId(4),SubmeshVertId(7)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(4),SubmeshFaceId(3)],verts:[SubmeshVertId(6),SubmeshVertId(7)]},
|
EdgeRefs{faces:[SubmeshFaceId(4),SubmeshFaceId(3)],verts:[SubmeshVertId(6),SubmeshVertId(7)]},
|
||||||
EdgeRefs{faces:[SubmeshFaceId(5),SubmeshFaceId(4)],verts:[SubmeshVertId(0),SubmeshVertId(7)]}
|
EdgeRefs{faces:[SubmeshFaceId(5),SubmeshFaceId(4)],verts:[SubmeshVertId(0),SubmeshVertId(7)]}
|
||||||
],
|
],
|
||||||
vert_topology:vec![
|
vert_topology:vec![
|
||||||
@ -284,6 +284,7 @@ impl EdgePool{
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum PhysicsMeshError{
|
pub enum PhysicsMeshError{
|
||||||
ZeroVertices,
|
ZeroVertices,
|
||||||
|
NoPhysicsGroups,
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for PhysicsMeshError{
|
impl std::fmt::Display for PhysicsMeshError{
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
@ -341,9 +342,9 @@ impl TryFrom<&model::Mesh> for PhysicsMesh{
|
|||||||
let v0=mesh.unique_pos[vert0_id.get() as usize];
|
let v0=mesh.unique_pos[vert0_id.get() as usize];
|
||||||
let v1=mesh.unique_pos[vert1_id.get() as usize];
|
let v1=mesh.unique_pos[vert1_id.get() as usize];
|
||||||
normal+=Planar64Vec3::new(
|
normal+=Planar64Vec3::new(
|
||||||
(v0.y()-v1.y())*(v0.z()+v1.z()),
|
(v0.y-v1.y)*(v0.z+v1.z),
|
||||||
(v0.z()-v1.z())*(v0.x()+v1.x()),
|
(v0.z-v1.z)*(v0.x+v1.x),
|
||||||
(v0.x()-v1.x())*(v0.y()+v1.y()),
|
(v0.x-v1.x)*(v0.y+v1.y),
|
||||||
);
|
);
|
||||||
//get/create edge and push face into it
|
//get/create edge and push face into it
|
||||||
let (edge_ref_verts,is_sorted)=EdgeRefVerts::new(submesh_vert0_id,submesh_vert1_id);
|
let (edge_ref_verts,is_sorted)=EdgeRefVerts::new(submesh_vert0_id,submesh_vert1_id);
|
||||||
@ -404,7 +405,7 @@ impl TryFrom<&model::Mesh> for PhysicsMesh{
|
|||||||
faces,
|
faces,
|
||||||
verts,
|
verts,
|
||||||
},
|
},
|
||||||
complete_mesh:mesh_topologies.pop().unwrap(),
|
complete_mesh:mesh_topologies.pop().ok_or(PhysicsMeshError::NoPhysicsGroups)?,
|
||||||
submeshes:mesh_topologies,
|
submeshes:mesh_topologies,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -461,7 +462,7 @@ pub struct TransformedMesh<'a>{
|
|||||||
transform:&'a PhysicsMeshTransform,
|
transform:&'a PhysicsMeshTransform,
|
||||||
}
|
}
|
||||||
impl TransformedMesh<'_>{
|
impl TransformedMesh<'_>{
|
||||||
pub fn new<'a>(
|
pub const fn new<'a>(
|
||||||
view:PhysicsMeshView<'a>,
|
view:PhysicsMeshView<'a>,
|
||||||
transform:&'a PhysicsMeshTransform,
|
transform:&'a PhysicsMeshTransform,
|
||||||
)->TransformedMesh<'a>{
|
)->TransformedMesh<'a>{
|
||||||
@ -750,6 +751,23 @@ impl MinkowskiMesh<'_>{
|
|||||||
}
|
}
|
||||||
best_edge.map(|e|(e.as_undirected(),best_time))
|
best_edge.map(|e|(e.as_undirected(),best_time))
|
||||||
}
|
}
|
||||||
|
fn infinity_in(&self,infinity_body:crate::physics::Body)->Option<(MinkowskiFace,integer::Time)>{
|
||||||
|
let infinity_fev=self.infinity_fev(-infinity_body.velocity,infinity_body.position);
|
||||||
|
match crate::face_crawler::crawl_fev(infinity_fev,self,&infinity_body,integer::Time::MIN,infinity_body.time){
|
||||||
|
crate::face_crawler::CrawlResult::Miss(_)=>None,
|
||||||
|
crate::face_crawler::CrawlResult::Hit(face,time)=>Some((face,time)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn is_point_in_mesh(&self,point:Planar64Vec3)->bool{
|
||||||
|
let infinity_body=crate::physics::Body::new(point,Planar64Vec3::Y,Planar64Vec3::ZERO,integer::Time::ZERO);
|
||||||
|
//movement must escape the mesh forwards and backwards in time,
|
||||||
|
//otherwise the point is not inside the mesh
|
||||||
|
self.infinity_in(infinity_body)
|
||||||
|
.is_some_and(|_|
|
||||||
|
self.infinity_in(-infinity_body)
|
||||||
|
.is_some()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl MeshQuery<MinkowskiFace,MinkowskiDirectedEdge,MinkowskiVert> for MinkowskiMesh<'_>{
|
impl MeshQuery<MinkowskiFace,MinkowskiDirectedEdge,MinkowskiVert> for MinkowskiMesh<'_>{
|
||||||
fn face_nd(&self,face_id:MinkowskiFace)->(Planar64Vec3,Planar64){
|
fn face_nd(&self,face_id:MinkowskiFace)->(Planar64Vec3,Planar64){
|
||||||
@ -937,7 +955,7 @@ fn is_empty_volume(normals:Vec<Planar64Vec3>)->bool{
|
|||||||
if k!=i&&k!=j{
|
if k!=i&&k!=j{
|
||||||
let d=n.dot(normals[k]);
|
let d=n.dot(normals[k]);
|
||||||
if let Some(comp)=&d_comp{
|
if let Some(comp)=&d_comp{
|
||||||
if *comp*d<Planar64::ZERO{
|
if comp.is_negative()&&d.is_negative()||comp.is_positive()&&d.is_positive(){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@ -960,4 +978,4 @@ fn test_is_empty_volume(){
|
|||||||
fn build_me_a_cube(){
|
fn build_me_a_cube(){
|
||||||
let mesh=PhysicsMesh::unit_cube();
|
let mesh=PhysicsMesh::unit_cube();
|
||||||
//println!("mesh={:?}",mesh);
|
//println!("mesh={:?}",mesh);
|
||||||
}
|
}
|
||||||
|
2127
src/physics.rs
2127
src/physics.rs
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,10 @@
|
|||||||
use crate::physics::{MouseState,PhysicsInputInstruction};
|
use strafesnet_common::mouse::MouseState;
|
||||||
|
use strafesnet_common::physics::Instruction as PhysicsInputInstruction;
|
||||||
use strafesnet_common::integer::Time;
|
use strafesnet_common::integer::Time;
|
||||||
use strafesnet_common::instruction::{TimedInstruction,InstructionConsumer};
|
use strafesnet_common::instruction::TimedInstruction;
|
||||||
|
use strafesnet_common::timer::{Scaled,Timer,TimerState};
|
||||||
|
use mouse_interpolator::MouseInterpolator;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum InputInstruction{
|
pub enum InputInstruction{
|
||||||
MoveMouse(glam::IVec2),
|
MoveMouse(glam::IVec2),
|
||||||
@ -12,122 +16,227 @@ pub enum InputInstruction{
|
|||||||
MoveForward(bool),
|
MoveForward(bool),
|
||||||
Jump(bool),
|
Jump(bool),
|
||||||
Zoom(bool),
|
Zoom(bool),
|
||||||
Reset,
|
ResetAndRestart,
|
||||||
|
ResetAndSpawn(strafesnet_common::gameplay_modes::ModeId,strafesnet_common::gameplay_modes::StageId),
|
||||||
|
PracticeFly,
|
||||||
}
|
}
|
||||||
pub enum Instruction{
|
pub enum Instruction{
|
||||||
Input(InputInstruction),
|
Input(InputInstruction),
|
||||||
Render,
|
Render,
|
||||||
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
Resize(winit::dpi::PhysicalSize<u32>),
|
||||||
GenerateModels(strafesnet_common::map::CompleteMap),
|
ChangeMap(strafesnet_common::map::CompleteMap),
|
||||||
ClearModels,
|
//SetPaused is not an InputInstruction: the physics doesn't know that it's paused.
|
||||||
|
SetPaused(bool),
|
||||||
//Graphics(crate::graphics_worker::Instruction),
|
//Graphics(crate::graphics_worker::Instruction),
|
||||||
}
|
}
|
||||||
|
mod mouse_interpolator{
|
||||||
|
use super::*;
|
||||||
|
//TODO: move this or tab
|
||||||
|
pub struct MouseInterpolator{
|
||||||
|
//"PlayerController"
|
||||||
|
user_settings:crate::settings::UserSettings,
|
||||||
|
//"MouseInterpolator"
|
||||||
|
timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>,
|
||||||
|
last_mouse_time:Time,//this value is pre-transformed to simulation time
|
||||||
|
mouse_blocking:bool,
|
||||||
|
//"Simulation"
|
||||||
|
timer:Timer<Scaled>,
|
||||||
|
physics:crate::physics::PhysicsContext,
|
||||||
|
|
||||||
pub fn new(mut physics:crate::physics::PhysicsContext,mut graphics_worker:crate::compat_worker::INWorker<crate::graphics_worker::Instruction>)->crate::compat_worker::QNWorker<TimedInstruction<Instruction>>{
|
}
|
||||||
let mut mouse_blocking=true;
|
impl MouseInterpolator{
|
||||||
let mut last_mouse_time=physics.state.next_mouse.time;
|
pub fn new(
|
||||||
let mut timeline=std::collections::VecDeque::new();
|
physics:crate::physics::PhysicsContext,
|
||||||
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
|
user_settings:crate::settings::UserSettings,
|
||||||
if if let Some(phys_input)=match &ins.instruction{
|
)->MouseInterpolator{
|
||||||
Instruction::Input(input_instruction)=>match input_instruction{
|
MouseInterpolator{
|
||||||
&InputInstruction::MoveMouse(m)=>{
|
mouse_blocking:true,
|
||||||
if mouse_blocking{
|
last_mouse_time:physics.get_next_mouse().time,
|
||||||
//tell the game state which is living in the past about its future
|
timeline:std::collections::VecDeque::new(),
|
||||||
timeline.push_front(TimedInstruction{
|
timer:Timer::from_state(Scaled::identity(),false),
|
||||||
time:last_mouse_time,
|
physics,
|
||||||
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:m}),
|
user_settings,
|
||||||
});
|
}
|
||||||
}else{
|
}
|
||||||
//mouse has just started moving again after being still for longer than 10ms.
|
fn push_mouse_instruction(&mut self,ins:&TimedInstruction<Instruction>,m:glam::IVec2){
|
||||||
//replace the entire mouse interpolation state to avoid an intermediate state with identical m0.t m1.t timestamps which will divide by zero
|
if self.mouse_blocking{
|
||||||
timeline.push_front(TimedInstruction{
|
//tell the game state which is living in the past about its future
|
||||||
time:last_mouse_time,
|
self.timeline.push_front(TimedInstruction{
|
||||||
instruction:PhysicsInputInstruction::ReplaceMouse(
|
time:self.last_mouse_time,
|
||||||
MouseState{time:last_mouse_time,pos:physics.state.next_mouse.pos},
|
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:self.timer.time(ins.time),pos:m}),
|
||||||
MouseState{time:ins.time,pos:m}
|
});
|
||||||
),
|
}else{
|
||||||
});
|
//mouse has just started moving again after being still for longer than 10ms.
|
||||||
//delay physics execution until we have an interpolation target
|
//replace the entire mouse interpolation state to avoid an intermediate state with identical m0.t m1.t timestamps which will divide by zero
|
||||||
mouse_blocking=true;
|
self.timeline.push_front(TimedInstruction{
|
||||||
}
|
time:self.last_mouse_time,
|
||||||
last_mouse_time=ins.time;
|
instruction:PhysicsInputInstruction::ReplaceMouse(
|
||||||
None
|
MouseState{time:self.last_mouse_time,pos:self.physics.get_next_mouse().pos},
|
||||||
},
|
MouseState{time:self.timer.time(ins.time),pos:m}
|
||||||
&InputInstruction::MoveForward(s)=>Some(PhysicsInputInstruction::SetMoveForward(s)),
|
),
|
||||||
&InputInstruction::MoveLeft(s)=>Some(PhysicsInputInstruction::SetMoveLeft(s)),
|
});
|
||||||
&InputInstruction::MoveBack(s)=>Some(PhysicsInputInstruction::SetMoveBack(s)),
|
//delay physics execution until we have an interpolation target
|
||||||
&InputInstruction::MoveRight(s)=>Some(PhysicsInputInstruction::SetMoveRight(s)),
|
self.mouse_blocking=true;
|
||||||
&InputInstruction::MoveUp(s)=>Some(PhysicsInputInstruction::SetMoveUp(s)),
|
}
|
||||||
&InputInstruction::MoveDown(s)=>Some(PhysicsInputInstruction::SetMoveDown(s)),
|
self.last_mouse_time=self.timer.time(ins.time);
|
||||||
&InputInstruction::Jump(s)=>Some(PhysicsInputInstruction::SetJump(s)),
|
}
|
||||||
&InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)),
|
fn push(&mut self,time:Time,phys_input:PhysicsInputInstruction){
|
||||||
InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset),
|
//This is always a non-mouse event
|
||||||
},
|
self.timeline.push_back(TimedInstruction{
|
||||||
Instruction::GenerateModels(_)=>Some(PhysicsInputInstruction::Idle),
|
time:self.timer.time(time),
|
||||||
Instruction::ClearModels=>Some(PhysicsInputInstruction::Idle),
|
instruction:phys_input,
|
||||||
Instruction::Resize(_,_)=>Some(PhysicsInputInstruction::Idle),
|
});
|
||||||
Instruction::Render=>Some(PhysicsInputInstruction::Idle),
|
}
|
||||||
}{
|
/// returns should_empty_queue
|
||||||
//non-mouse event
|
/// may or may not mutate internal state XD!
|
||||||
timeline.push_back(TimedInstruction{
|
fn map_instruction(&mut self,ins:&TimedInstruction<Instruction>)->bool{
|
||||||
time:ins.time,
|
let mut update_mouse_blocking=true;
|
||||||
instruction:phys_input,
|
match &ins.instruction{
|
||||||
});
|
Instruction::Input(input_instruction)=>match input_instruction{
|
||||||
|
&InputInstruction::MoveMouse(m)=>{
|
||||||
if mouse_blocking{
|
if !self.timer.is_paused(){
|
||||||
//assume the mouse has stopped moving after 10ms.
|
self.push_mouse_instruction(ins,m);
|
||||||
//shitty mice are 125Hz which is 8ms so this should cover that.
|
|
||||||
//setting this to 100us still doesn't print even though it's 10x lower than the polling rate,
|
|
||||||
//so mouse events are probably not handled separately from drawing and fire right before it :(
|
|
||||||
if Time::from_millis(10)<ins.time-physics.state.next_mouse.time{
|
|
||||||
//push an event to extrapolate no movement from
|
|
||||||
timeline.push_front(TimedInstruction{
|
|
||||||
time:last_mouse_time,
|
|
||||||
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:physics.state.next_mouse.pos}),
|
|
||||||
});
|
|
||||||
last_mouse_time=ins.time;
|
|
||||||
//stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets.
|
|
||||||
mouse_blocking=false;
|
|
||||||
true
|
|
||||||
}else{
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}else{
|
update_mouse_blocking=false;
|
||||||
//keep this up to date so that it can be used as a known-timestamp
|
},
|
||||||
//that the mouse was not moving when the mouse starts moving again
|
&InputInstruction::MoveForward(s)=>self.push(ins.time,PhysicsInputInstruction::SetMoveForward(s)),
|
||||||
last_mouse_time=ins.time;
|
&InputInstruction::MoveLeft(s)=>self.push(ins.time,PhysicsInputInstruction::SetMoveLeft(s)),
|
||||||
true
|
&InputInstruction::MoveBack(s)=>self.push(ins.time,PhysicsInputInstruction::SetMoveBack(s)),
|
||||||
|
&InputInstruction::MoveRight(s)=>self.push(ins.time,PhysicsInputInstruction::SetMoveRight(s)),
|
||||||
|
&InputInstruction::MoveUp(s)=>self.push(ins.time,PhysicsInputInstruction::SetMoveUp(s)),
|
||||||
|
&InputInstruction::MoveDown(s)=>self.push(ins.time,PhysicsInputInstruction::SetMoveDown(s)),
|
||||||
|
&InputInstruction::Jump(s)=>self.push(ins.time,PhysicsInputInstruction::SetJump(s)),
|
||||||
|
&InputInstruction::Zoom(s)=>self.push(ins.time,PhysicsInputInstruction::SetZoom(s)),
|
||||||
|
&InputInstruction::ResetAndSpawn(mode_id,stage_id)=>{
|
||||||
|
self.push(ins.time,PhysicsInputInstruction::Reset);
|
||||||
|
self.push(ins.time,PhysicsInputInstruction::SetSensitivity(self.user_settings.calculate_sensitivity()));
|
||||||
|
self.push(ins.time,PhysicsInputInstruction::Spawn(mode_id,stage_id));
|
||||||
|
},
|
||||||
|
InputInstruction::ResetAndRestart=>{
|
||||||
|
self.push(ins.time,PhysicsInputInstruction::Reset);
|
||||||
|
self.push(ins.time,PhysicsInputInstruction::SetSensitivity(self.user_settings.calculate_sensitivity()));
|
||||||
|
self.push(ins.time,PhysicsInputInstruction::Restart);
|
||||||
|
},
|
||||||
|
InputInstruction::PracticeFly=>self.push(ins.time,PhysicsInputInstruction::PracticeFly),
|
||||||
|
},
|
||||||
|
//do these really need to idle the physics?
|
||||||
|
//sending None dumps the instruction queue
|
||||||
|
Instruction::ChangeMap(_)=>self.push(ins.time,PhysicsInputInstruction::Idle),
|
||||||
|
Instruction::Resize(_)=>self.push(ins.time,PhysicsInputInstruction::Idle),
|
||||||
|
Instruction::Render=>self.push(ins.time,PhysicsInputInstruction::Idle),
|
||||||
|
&Instruction::SetPaused(paused)=>{
|
||||||
|
if let Err(e)=self.timer.set_paused(ins.time,paused){
|
||||||
|
println!("Cannot pause: {e}");
|
||||||
}
|
}
|
||||||
}else{
|
self.push(ins.time,PhysicsInputInstruction::Idle);
|
||||||
//mouse event
|
},
|
||||||
|
}
|
||||||
|
if update_mouse_blocking{
|
||||||
|
//this returns the bool for us
|
||||||
|
self.update_mouse_blocking(ins.time)
|
||||||
|
}else{
|
||||||
|
//do flush that queue
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// must check if self.mouse_blocking==true before calling!
|
||||||
|
fn unblock_mouse(&mut self,time:Time){
|
||||||
|
//push an event to extrapolate no movement from
|
||||||
|
self.timeline.push_front(TimedInstruction{
|
||||||
|
time:self.last_mouse_time,
|
||||||
|
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:self.timer.time(time),pos:self.physics.get_next_mouse().pos}),
|
||||||
|
});
|
||||||
|
self.last_mouse_time=self.timer.time(time);
|
||||||
|
//stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets.
|
||||||
|
self.mouse_blocking=false;
|
||||||
|
}
|
||||||
|
fn update_mouse_blocking(&mut self,time:Time)->bool{
|
||||||
|
if self.mouse_blocking{
|
||||||
|
//assume the mouse has stopped moving after 10ms.
|
||||||
|
//shitty mice are 125Hz which is 8ms so this should cover that.
|
||||||
|
//setting this to 100us still doesn't print even though it's 10x lower than the polling rate,
|
||||||
|
//so mouse events are probably not handled separately from drawing and fire right before it :(
|
||||||
|
if Time::from_millis(10)<self.timer.time(time)-self.physics.get_next_mouse().time{
|
||||||
|
self.unblock_mouse(time);
|
||||||
true
|
true
|
||||||
}{
|
}else{
|
||||||
//empty queue
|
false
|
||||||
while let Some(instruction)=timeline.pop_front(){
|
|
||||||
physics.run(instruction.time);
|
|
||||||
physics.process_instruction(TimedInstruction{
|
|
||||||
time:instruction.time,
|
|
||||||
instruction:crate::physics::PhysicsInstruction::Input(instruction.instruction),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
match ins.instruction{
|
}else{
|
||||||
Instruction::Render=>{
|
//keep this up to date so that it can be used as a known-timestamp
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.state.output(),ins.time,physics.state.next_mouse.pos)).unwrap();
|
//that the mouse was not moving when the mouse starts moving again
|
||||||
},
|
self.last_mouse_time=self.timer.time(time);
|
||||||
Instruction::Resize(size,user_settings)=>{
|
true
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
|
}
|
||||||
},
|
}
|
||||||
Instruction::GenerateModels(map)=>{
|
fn empty_queue(&mut self){
|
||||||
physics.generate_models(&map);
|
while let Some(instruction)=self.timeline.pop_front(){
|
||||||
physics.spawn();
|
self.physics.run_input_instruction(instruction);
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map)).unwrap();
|
}
|
||||||
},
|
}
|
||||||
Instruction::ClearModels=>{
|
pub fn handle_instruction(&mut self,ins:&TimedInstruction<Instruction>){
|
||||||
physics.state.clear();
|
let should_empty_queue=self.map_instruction(ins);
|
||||||
graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap();
|
if should_empty_queue{
|
||||||
},
|
self.empty_queue();
|
||||||
_=>(),
|
}
|
||||||
}
|
}
|
||||||
})
|
pub fn get_frame_state(&self,time:Time)->crate::graphics::FrameState{
|
||||||
}
|
crate::graphics::FrameState{
|
||||||
|
body:self.physics.camera_body(),
|
||||||
|
camera:self.physics.camera(),
|
||||||
|
time:self.timer.time(time),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn change_map(&mut self,time:Time,map:&strafesnet_common::map::CompleteMap){
|
||||||
|
//dump any pending interpolation state
|
||||||
|
if self.mouse_blocking{
|
||||||
|
self.unblock_mouse(time);
|
||||||
|
}
|
||||||
|
self.empty_queue();
|
||||||
|
|
||||||
|
//doing it like this to avoid doing PhysicsInstruction::ChangeMap(Rc<CompleteMap>)
|
||||||
|
self.physics.generate_models(&map);
|
||||||
|
|
||||||
|
//use the standard input interface so the instructions are written out to bots
|
||||||
|
self.handle_instruction(&TimedInstruction{
|
||||||
|
time:self.timer.time(time),
|
||||||
|
instruction:Instruction::Input(InputInstruction::ResetAndSpawn(
|
||||||
|
strafesnet_common::gameplay_modes::ModeId::MAIN,
|
||||||
|
strafesnet_common::gameplay_modes::StageId::FIRST,
|
||||||
|
)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
pub const fn user_settings(&self)->&crate::settings::UserSettings{
|
||||||
|
&self.user_settings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new<'a>(
|
||||||
|
mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>,
|
||||||
|
user_settings:crate::settings::UserSettings,
|
||||||
|
)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction>>{
|
||||||
|
let physics=crate::physics::PhysicsContext::default();
|
||||||
|
let mut interpolator=MouseInterpolator::new(
|
||||||
|
physics,
|
||||||
|
user_settings
|
||||||
|
);
|
||||||
|
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
|
||||||
|
interpolator.handle_instruction(&ins);
|
||||||
|
match ins.instruction{
|
||||||
|
Instruction::Render=>{
|
||||||
|
let frame_state=interpolator.get_frame_state(ins.time);
|
||||||
|
graphics_worker.send(crate::graphics_worker::Instruction::Render(frame_state)).unwrap();
|
||||||
|
},
|
||||||
|
Instruction::Resize(size)=>{
|
||||||
|
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,interpolator.user_settings().clone())).unwrap();
|
||||||
|
},
|
||||||
|
Instruction::ChangeMap(map)=>{
|
||||||
|
interpolator.change_map(ins.time,&map);
|
||||||
|
graphics_worker.send(crate::graphics_worker::Instruction::ChangeMap(map)).unwrap();
|
||||||
|
},
|
||||||
|
Instruction::Input(_)=>(),
|
||||||
|
Instruction::SetPaused(_)=>(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
339
src/push_solve.rs
Normal file
339
src/push_solve.rs
Normal file
@ -0,0 +1,339 @@
|
|||||||
|
use strafesnet_common::integer::{Planar64,Planar64Vec3};
|
||||||
|
|
||||||
|
// This algorithm is based on Lua code
|
||||||
|
// written by Trey Reynolds in 2021
|
||||||
|
|
||||||
|
// 1/2^10
|
||||||
|
const EPSILON:Planar64=Planar64::raw(1<<(32-10));
|
||||||
|
|
||||||
|
// A stack-allocated variable-size list that holds up to 4 elements
|
||||||
|
// Direct references are used instead of indices i0, i1, i2, i3
|
||||||
|
type Conts<'a>=arrayvec::ArrayVec<&'a Contact,4>;
|
||||||
|
|
||||||
|
struct Ray{
|
||||||
|
origin:Planar64Vec3,
|
||||||
|
direction:Planar64Vec3,
|
||||||
|
}
|
||||||
|
impl Ray{
|
||||||
|
fn extrapolate(&self,t:Planar64)->Planar64Vec3{
|
||||||
|
self.origin+self.direction*t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Information about a contact restriction
|
||||||
|
pub struct Contact{
|
||||||
|
pub position:Planar64Vec3,
|
||||||
|
pub velocity:Planar64Vec3,
|
||||||
|
pub normal:Planar64Vec3,
|
||||||
|
}
|
||||||
|
impl Contact{
|
||||||
|
fn relative_to(&self,point:Planar64Vec3)->Self{
|
||||||
|
Self{
|
||||||
|
position:self.position-point,
|
||||||
|
velocity:self.velocity,
|
||||||
|
normal:self.normal,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn relative_dot(&self,direction:Planar64Vec3)->Planar64{
|
||||||
|
(direction-self.velocity).dot(self.normal)
|
||||||
|
}
|
||||||
|
/// Calculate the time of intersection. (previously get_touch_time)
|
||||||
|
fn solve(&self,ray:&Ray)->Planar64{
|
||||||
|
(self.position-ray.origin).dot(self.normal)/(ray.direction-self.velocity).dot(self.normal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//note that this is horrible with fixed point arithmetic
|
||||||
|
fn solve1(c0:&Contact)->Option<Planar64Vec3>{
|
||||||
|
let det=c0.normal.dot(c0.velocity);
|
||||||
|
if det.get().abs()<EPSILON.get(){
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let d0=c0.normal.dot(c0.position);
|
||||||
|
Some(c0.normal*d0/det)
|
||||||
|
}
|
||||||
|
fn solve2(c0:&Contact,c1:&Contact)->Option<Planar64Vec3>{
|
||||||
|
let u0_u1=c0.velocity.cross(c1.velocity);
|
||||||
|
let n0_n1=c0.normal.cross(c1.normal);
|
||||||
|
let det=u0_u1.dot(n0_n1);
|
||||||
|
if det.get().abs()<EPSILON.get(){
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let d0=c0.normal.dot(c0.position);
|
||||||
|
let d1=c1.normal.dot(c1.position);
|
||||||
|
Some((c1.normal.cross(u0_u1)*d0+u0_u1.cross(c0.normal)*d1)/det)
|
||||||
|
}
|
||||||
|
fn solve3(c0:&Contact,c1:&Contact,c2:&Contact)->Option<Planar64Vec3>{
|
||||||
|
let n0_n1=c0.normal.cross(c1.normal);
|
||||||
|
let det=c2.normal.dot(n0_n1);
|
||||||
|
if det.get().abs()<EPSILON.get(){
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let d0=c0.normal.dot(c0.position);
|
||||||
|
let d1=c1.normal.dot(c1.position);
|
||||||
|
let d2=c2.normal.dot(c2.position);
|
||||||
|
Some((c1.normal.cross(c2.normal)*d0+c2.normal.cross(c0.normal)*d1+c0.normal.cross(c1.normal)*d2)/det)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decompose1(point:Planar64Vec3,u0:Planar64Vec3)->Option<Planar64>{
|
||||||
|
let det=u0.dot(u0);
|
||||||
|
if det==Planar64::ZERO{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let s0=u0.dot(point)/det;
|
||||||
|
Some(s0)
|
||||||
|
}
|
||||||
|
fn decompose2(point:Planar64Vec3,u0:Planar64Vec3,u1:Planar64Vec3)->Option<(Planar64,Planar64)>{
|
||||||
|
let u0_u1=u0.cross(u1);
|
||||||
|
let det=u0_u1.dot(u0_u1);
|
||||||
|
if det==Planar64::ZERO{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let s0=u0_u1.dot(point.cross(u1))/det;
|
||||||
|
let s1=u0_u1.dot(u0.cross(point))/det;
|
||||||
|
Some((s0,s1))
|
||||||
|
}
|
||||||
|
fn decompose3(point:Planar64Vec3,u0:Planar64Vec3,u1:Planar64Vec3,u2:Planar64Vec3)->Option<(Planar64,Planar64,Planar64)>{
|
||||||
|
let det=u0.cross(u1).dot(u2);
|
||||||
|
if det==Planar64::ZERO{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let s0=point.cross(u1).dot(u2)/det;
|
||||||
|
let s1=u0.cross(point).dot(u2)/det;
|
||||||
|
let s2=u0.cross(u1).dot(point)/det;
|
||||||
|
Some((s0,s1,s2))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_space_enclosed_2(
|
||||||
|
a:Planar64Vec3,
|
||||||
|
b:Planar64Vec3,
|
||||||
|
)->bool{
|
||||||
|
a.cross(b)==Planar64Vec3::ZERO
|
||||||
|
&&a.dot(b)<Planar64::ZERO
|
||||||
|
}
|
||||||
|
fn is_space_enclosed_3(
|
||||||
|
a:Planar64Vec3,
|
||||||
|
b:Planar64Vec3,
|
||||||
|
c:Planar64Vec3
|
||||||
|
)->bool{
|
||||||
|
a.cross(b).dot(c)==Planar64::ZERO
|
||||||
|
&&{
|
||||||
|
let det_abac=a.cross(b).dot(a.cross(c));
|
||||||
|
let det_abbc=a.cross(b).dot(b.cross(c));
|
||||||
|
let det_acbc=a.cross(c).dot(b.cross(c));
|
||||||
|
return det_abac*det_abbc<=Planar64::ZERO
|
||||||
|
&& det_abbc*det_acbc<=Planar64::ZERO
|
||||||
|
&&-det_acbc*det_abac<=Planar64::ZERO
|
||||||
|
||is_space_enclosed_2(a,b)
|
||||||
|
||is_space_enclosed_2(a,c)
|
||||||
|
||is_space_enclosed_2(b,c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn is_space_enclosed_4(
|
||||||
|
a:Planar64Vec3,
|
||||||
|
b:Planar64Vec3,
|
||||||
|
c:Planar64Vec3,
|
||||||
|
d:Planar64Vec3,
|
||||||
|
)->bool{
|
||||||
|
let det_abc=a.cross(b).dot(c);
|
||||||
|
let det_abd=a.cross(b).dot(d);
|
||||||
|
let det_acd=a.cross(c).dot(d);
|
||||||
|
let det_bcd=b.cross(c).dot(d);
|
||||||
|
return det_abc*det_abd<Planar64::ZERO
|
||||||
|
&&-det_abc*det_acd<Planar64::ZERO
|
||||||
|
&& det_abd*det_acd<Planar64::ZERO
|
||||||
|
&& det_abc*det_bcd<Planar64::ZERO
|
||||||
|
&&-det_abd*det_bcd<Planar64::ZERO
|
||||||
|
&& det_acd*det_bcd<Planar64::ZERO
|
||||||
|
||is_space_enclosed_3(a,b,c)
|
||||||
|
||is_space_enclosed_3(a,b,d)
|
||||||
|
||is_space_enclosed_3(a,c,d)
|
||||||
|
||is_space_enclosed_3(b,c,d)
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn get_push_ray_0(point:Planar64Vec3)->Option<Ray>{
|
||||||
|
Some(Ray{origin:point,direction:Planar64Vec3::ZERO})
|
||||||
|
}
|
||||||
|
fn get_push_ray_1(point:Planar64Vec3,c0:&Contact)->Option<Ray>{
|
||||||
|
let direction=solve1(c0)?;
|
||||||
|
let s0=decompose1(direction,c0.velocity)?;
|
||||||
|
if s0<Planar64::ZERO{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let origin=point+solve1(
|
||||||
|
&c0.relative_to(point),
|
||||||
|
)?;
|
||||||
|
Some(Ray{origin,direction})
|
||||||
|
}
|
||||||
|
fn get_push_ray_2(point:Planar64Vec3,c0:&Contact,c1:&Contact)->Option<Ray>{
|
||||||
|
let direction=solve2(c0,c1)?;
|
||||||
|
let (s0,s1)=decompose2(direction,c0.velocity,c1.velocity)?;
|
||||||
|
if s0<Planar64::ZERO||s1<Planar64::ZERO{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let origin=point+solve2(
|
||||||
|
&c0.relative_to(point),
|
||||||
|
&c1.relative_to(point),
|
||||||
|
)?;
|
||||||
|
Some(Ray{origin,direction})
|
||||||
|
}
|
||||||
|
fn get_push_ray_3(point:Planar64Vec3,c0:&Contact,c1:&Contact,c2:&Contact)->Option<Ray>{
|
||||||
|
let direction=solve3(c0,c1,c2)?;
|
||||||
|
let (s0,s1,s2)=decompose3(direction,c0.velocity,c1.velocity,c2.velocity)?;
|
||||||
|
if s0<Planar64::ZERO||s1<Planar64::ZERO||s2<Planar64::ZERO{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let origin=point+solve3(
|
||||||
|
&c0.relative_to(point),
|
||||||
|
&c1.relative_to(point),
|
||||||
|
&c2.relative_to(point),
|
||||||
|
)?;
|
||||||
|
Some(Ray{origin,direction})
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn get_best_push_ray_and_conts_0<'a>(point:Planar64Vec3)->Option<(Ray,Conts<'a>)>{
|
||||||
|
match get_push_ray_0(point){
|
||||||
|
Some(ray)=>Some((ray,Conts::new_const())),
|
||||||
|
None=>None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn get_best_push_ray_and_conts_1(point:Planar64Vec3,c0:&Contact)->Option<(Ray,Conts)>{
|
||||||
|
get_push_ray_1(point,c0)
|
||||||
|
.map(|ray|(ray,Conts::from_iter([c0])))
|
||||||
|
}
|
||||||
|
fn get_best_push_ray_and_conts_2<'a>(point:Planar64Vec3,c0:&'a Contact,c1:&'a Contact)->Option<(Ray,Conts<'a>)>{
|
||||||
|
if is_space_enclosed_2(c0.normal,c1.normal){
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
if let Some(ray)=get_push_ray_2(point,c0,c1){
|
||||||
|
return Some((ray,Conts::from_iter([c0,c1])));
|
||||||
|
}
|
||||||
|
if let Some(ray)=get_push_ray_1(point,c0){
|
||||||
|
if Planar64::ZERO<=c1.relative_dot(ray.direction){
|
||||||
|
return Some((ray,Conts::from_iter([c0])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
fn get_best_push_ray_and_conts_3<'a>(point:Planar64Vec3,c0:&'a Contact,c1:&'a Contact,c2:&'a Contact)->Option<(Ray,Conts<'a>)>{
|
||||||
|
if is_space_enclosed_3(c0.normal,c1.normal,c2.normal){
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
if let Some(ray)=get_push_ray_3(point,c0,c1,c2){
|
||||||
|
return Some((ray,Conts::from_iter([c0,c1,c2])));
|
||||||
|
}
|
||||||
|
if let Some(ray)=get_push_ray_2(point,c0,c1){
|
||||||
|
if Planar64::ZERO<=c2.relative_dot(ray.direction){
|
||||||
|
return Some((ray,Conts::from_iter([c0,c1])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(ray)=get_push_ray_2(point,c0,c2){
|
||||||
|
if Planar64::ZERO<=c1.relative_dot(ray.direction){
|
||||||
|
return Some((ray,Conts::from_iter([c0,c2])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(ray)=get_push_ray_1(point,c0){
|
||||||
|
if Planar64::ZERO<=c1.relative_dot(ray.direction)
|
||||||
|
&&Planar64::ZERO<=c2.relative_dot(ray.direction){
|
||||||
|
return Some((ray,Conts::from_iter([c0])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
fn get_best_push_ray_and_conts_4<'a>(point:Planar64Vec3,c0:&'a Contact,c1:&'a Contact,c2:&'a Contact,c3:&'a Contact)->Option<(Ray,Conts<'a>)>{
|
||||||
|
if is_space_enclosed_4(c0.normal,c1.normal,c2.normal,c3.normal){
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (ray012,conts012)=get_best_push_ray_and_conts_3(point,c0,c1,c2)?;
|
||||||
|
let (ray013,conts013)=get_best_push_ray_and_conts_3(point,c0,c1,c3)?;
|
||||||
|
let (ray023,conts023)=get_best_push_ray_and_conts_3(point,c0,c2,c3)?;
|
||||||
|
|
||||||
|
let err012=c3.relative_dot(ray012.direction);
|
||||||
|
let err013=c2.relative_dot(ray013.direction);
|
||||||
|
let err023=c1.relative_dot(ray023.direction);
|
||||||
|
|
||||||
|
let best_err=err012.max(err013).max(err023);
|
||||||
|
|
||||||
|
if best_err==err012{
|
||||||
|
return Some((ray012,conts012))
|
||||||
|
}else if best_err==err013{
|
||||||
|
return Some((ray013,conts013))
|
||||||
|
}else if best_err==err023{
|
||||||
|
return Some((ray023,conts023))
|
||||||
|
}
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_best_push_ray_and_conts<'a>(
|
||||||
|
point:Planar64Vec3,
|
||||||
|
conts:Conts<'a>,
|
||||||
|
)->Option<(Ray,Conts<'a>)>{
|
||||||
|
match conts.as_slice(){
|
||||||
|
&[c0,c1,c2,c3]=>get_best_push_ray_and_conts_4(point,c0,c1,c2,c3),
|
||||||
|
&[c0,c1,c2]=>get_best_push_ray_and_conts_3(point,c0,c1,c2),
|
||||||
|
&[c0,c1]=>get_best_push_ray_and_conts_2(point,c0,c1),
|
||||||
|
&[c0]=>get_best_push_ray_and_conts_1(point,c0),
|
||||||
|
&[]=>get_best_push_ray_and_conts_0(point),
|
||||||
|
_=>unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_first_touch<'a>(contacts:&'a Vec<Contact>,ray:&Ray,conts:&Conts)->Option<(Planar64,&'a Contact)>{
|
||||||
|
contacts.iter()
|
||||||
|
.filter(|&contact|
|
||||||
|
!conts.iter().any(|&c|std::ptr::eq(c,contact))
|
||||||
|
&&contact.relative_dot(ray.direction)< -EPSILON
|
||||||
|
)
|
||||||
|
.map(|contact|(contact.solve(ray),contact))
|
||||||
|
.min_by_key(|&(t,_)|t)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn push_solve(contacts:&Vec<Contact>,point:Planar64Vec3)->Option<Planar64Vec3>{
|
||||||
|
let (mut ray,mut conts)=get_best_push_ray_and_conts_0(point)?;
|
||||||
|
loop{
|
||||||
|
let (next_t,next_cont)=match get_first_touch(contacts,&ray,&conts){
|
||||||
|
Some((t,conts))=>(t,conts),
|
||||||
|
None=>return Some(ray.origin),
|
||||||
|
};
|
||||||
|
|
||||||
|
if Planar64::ZERO<=next_t{
|
||||||
|
return Some(ray.origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
//push_front
|
||||||
|
if conts.len()==conts.capacity(){
|
||||||
|
//this is a dead case, new_conts never has more than 3 elements
|
||||||
|
conts.rotate_right(1);
|
||||||
|
conts[0]=next_cont;
|
||||||
|
}else{
|
||||||
|
conts.push(next_cont);
|
||||||
|
conts.rotate_right(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let meet_point=ray.extrapolate(next_t);
|
||||||
|
match get_best_push_ray_and_conts(meet_point,conts){
|
||||||
|
Some((new_ray,new_conts))=>(ray,conts)=(new_ray,new_conts),
|
||||||
|
None=>return Some(meet_point),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests{
|
||||||
|
use super::*;
|
||||||
|
#[test]
|
||||||
|
fn test_push_solve(){
|
||||||
|
let contacts=vec![
|
||||||
|
Contact{
|
||||||
|
position:Planar64Vec3::ZERO,
|
||||||
|
velocity:Planar64Vec3::Y,
|
||||||
|
normal:Planar64Vec3::Y,
|
||||||
|
}
|
||||||
|
];
|
||||||
|
assert_eq!(
|
||||||
|
Some(Planar64Vec3::ZERO),
|
||||||
|
push_solve(&contacts,Planar64Vec3::NEG_Y)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
22
src/setup.rs
22
src/setup.rs
@ -25,14 +25,14 @@ struct SetupContextPartial1{
|
|||||||
instance:wgpu::Instance,
|
instance:wgpu::Instance,
|
||||||
}
|
}
|
||||||
fn create_window(title:&str,event_loop:&winit::event_loop::EventLoop<()>)->Result<winit::window::Window,winit::error::OsError>{
|
fn create_window(title:&str,event_loop:&winit::event_loop::EventLoop<()>)->Result<winit::window::Window,winit::error::OsError>{
|
||||||
let mut builder = winit::window::WindowBuilder::new();
|
let mut attr=winit::window::WindowAttributes::default();
|
||||||
builder = builder.with_title(title);
|
attr=attr.with_title(title);
|
||||||
#[cfg(windows_OFF)] // TODO
|
#[cfg(windows_OFF)] // TODO
|
||||||
{
|
{
|
||||||
use winit::platform::windows::WindowBuilderExtWindows;
|
use winit::platform::windows::WindowBuilderExtWindows;
|
||||||
builder = builder.with_no_redirection_bitmap(true);
|
builder=builder.with_no_redirection_bitmap(true);
|
||||||
}
|
}
|
||||||
builder.build(event_loop)
|
event_loop.create_window(attr)
|
||||||
}
|
}
|
||||||
fn create_instance()->SetupContextPartial1{
|
fn create_instance()->SetupContextPartial1{
|
||||||
let backends=wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
|
let backends=wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
|
||||||
@ -143,6 +143,7 @@ impl<'a> SetupContextPartial3<'a>{
|
|||||||
label: None,
|
label: None,
|
||||||
required_features: (optional_features & self.adapter.features()) | required_features,
|
required_features: (optional_features & self.adapter.features()) | required_features,
|
||||||
required_limits: needed_limits,
|
required_limits: needed_limits,
|
||||||
|
memory_hints:wgpu::MemoryHints::Performance,
|
||||||
},
|
},
|
||||||
trace_dir.ok().as_ref().map(std::path::Path::new),
|
trace_dir.ok().as_ref().map(std::path::Path::new),
|
||||||
))
|
))
|
||||||
@ -212,13 +213,14 @@ pub fn setup_and_start(title:String){
|
|||||||
|
|
||||||
//dedicated thread to ping request redraw back and resize the window doesn't seem logical
|
//dedicated thread to ping request redraw back and resize the window doesn't seem logical
|
||||||
|
|
||||||
let window=crate::window::WindowContextSetup::new(&setup_context,&window);
|
|
||||||
//the thread that spawns the physics thread
|
//the thread that spawns the physics thread
|
||||||
let mut window_thread=window.into_worker(setup_context);
|
let mut window_thread=crate::window::worker(
|
||||||
|
&window,
|
||||||
|
setup_context,
|
||||||
|
);
|
||||||
|
|
||||||
let args:Vec<String>=std::env::args().collect();
|
if let Some(arg)=std::env::args().nth(1){
|
||||||
if args.len()==2{
|
let path=std::path::PathBuf::from(arg);
|
||||||
let path=std::path::PathBuf::from(&args[1]);
|
|
||||||
window_thread.send(TimedInstruction{
|
window_thread.send(TimedInstruction{
|
||||||
time:integer::Time::ZERO,
|
time:integer::Time::ZERO,
|
||||||
instruction:WindowInstruction::WindowEvent(winit::event::WindowEvent::DroppedFile(path)),
|
instruction:WindowInstruction::WindowEvent(winit::event::WindowEvent::DroppedFile(path)),
|
||||||
@ -287,4 +289,4 @@ fn run_event_loop(
|
|||||||
_=>{}
|
_=>{}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ struct ModelInstance{
|
|||||||
//my fancy idea is to create a megatexture for each model that includes all the textures each intance will need
|
//my fancy idea is to create a megatexture for each model that includes all the textures each intance will need
|
||||||
//the texture transform then maps the texture coordinates to the location of the specific texture
|
//the texture transform then maps the texture coordinates to the location of the specific texture
|
||||||
//group 1 is the model
|
//group 1 is the model
|
||||||
const MAX_MODEL_INSTANCES=4096;
|
const MAX_MODEL_INSTANCES=512;
|
||||||
@group(2)
|
@group(2)
|
||||||
@binding(0)
|
@binding(0)
|
||||||
var<uniform> model_instances: array<ModelInstance, MAX_MODEL_INSTANCES>;
|
var<uniform> model_instances: array<ModelInstance, MAX_MODEL_INSTANCES>;
|
||||||
|
@ -13,9 +13,8 @@ pub enum WindowInstruction{
|
|||||||
//holds thread handles to dispatch to
|
//holds thread handles to dispatch to
|
||||||
struct WindowContext<'a>{
|
struct WindowContext<'a>{
|
||||||
manual_mouse_lock:bool,
|
manual_mouse_lock:bool,
|
||||||
mouse:crate::physics::MouseState,//std::sync::Arc<std::sync::Mutex<>>
|
mouse:strafesnet_common::mouse::MouseState,//std::sync::Arc<std::sync::Mutex<>>
|
||||||
screen_size:glam::UVec2,
|
screen_size:glam::UVec2,
|
||||||
user_settings:crate::settings::UserSettings,
|
|
||||||
window:&'a winit::window::Window,
|
window:&'a winit::window::Window,
|
||||||
physics_thread:crate::compat_worker::QNWorker<'a, TimedInstruction<crate::physics_worker::Instruction>>,
|
physics_thread:crate::compat_worker::QNWorker<'a, TimedInstruction<crate::physics_worker::Instruction>>,
|
||||||
}
|
}
|
||||||
@ -28,15 +27,16 @@ impl WindowContext<'_>{
|
|||||||
match event {
|
match event {
|
||||||
winit::event::WindowEvent::DroppedFile(path)=>{
|
winit::event::WindowEvent::DroppedFile(path)=>{
|
||||||
match crate::file::load(path.as_path()){
|
match crate::file::load(path.as_path()){
|
||||||
Ok(map)=>{
|
Ok(map)=>self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::ChangeMap(map)}).unwrap(),
|
||||||
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)}).unwrap();
|
|
||||||
},
|
|
||||||
Err(e)=>println!("Failed to load map: {e}"),
|
Err(e)=>println!("Failed to load map: {e}"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
winit::event::WindowEvent::Focused(_state)=>{
|
winit::event::WindowEvent::Focused(state)=>{
|
||||||
//pause unpause
|
//pause unpause
|
||||||
|
self.physics_thread.send(TimedInstruction{
|
||||||
|
time,
|
||||||
|
instruction:crate::physics_worker::Instruction::SetPaused(!state),
|
||||||
|
}).unwrap();
|
||||||
//recalculate pressed keys on focus
|
//recalculate pressed keys on focus
|
||||||
},
|
},
|
||||||
winit::event::WindowEvent::KeyboardInput{
|
winit::event::WindowEvent::KeyboardInput{
|
||||||
@ -107,7 +107,12 @@ impl WindowContext<'_>{
|
|||||||
"e"=>Some(InputInstruction::MoveUp(s)),
|
"e"=>Some(InputInstruction::MoveUp(s)),
|
||||||
"q"=>Some(InputInstruction::MoveDown(s)),
|
"q"=>Some(InputInstruction::MoveDown(s)),
|
||||||
"z"=>Some(InputInstruction::Zoom(s)),
|
"z"=>Some(InputInstruction::Zoom(s)),
|
||||||
"r"=>if s{Some(InputInstruction::Reset)}else{None},
|
"r"=>if s{
|
||||||
|
//mouse needs to be reset since the position is absolute
|
||||||
|
self.mouse=strafesnet_common::mouse::MouseState::default();
|
||||||
|
Some(InputInstruction::ResetAndRestart)
|
||||||
|
}else{None},
|
||||||
|
"f"=>if s{Some(InputInstruction::PracticeFly)}else{None},
|
||||||
_=>None,
|
_=>None,
|
||||||
},
|
},
|
||||||
_=>None,
|
_=>None,
|
||||||
@ -160,48 +165,32 @@ impl WindowContext<'_>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn worker<'a>(
|
||||||
pub struct WindowContextSetup<'a>{
|
|
||||||
user_settings:crate::settings::UserSettings,
|
|
||||||
window:&'a winit::window::Window,
|
window:&'a winit::window::Window,
|
||||||
physics:crate::physics::PhysicsContext,
|
setup_context:crate::setup::SetupContext<'a>,
|
||||||
graphics:crate::graphics::GraphicsState,
|
)->crate::compat_worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{
|
||||||
}
|
// WindowContextSetup::new
|
||||||
|
|
||||||
impl<'a> WindowContextSetup<'a>{
|
|
||||||
pub fn new(context:&crate::setup::SetupContext,window:&'a winit::window::Window)->Self{
|
|
||||||
let user_settings=crate::settings::read_user_settings();
|
let user_settings=crate::settings::read_user_settings();
|
||||||
|
|
||||||
let mut physics=crate::physics::PhysicsContext::default();
|
let mut graphics=crate::graphics::GraphicsState::new(&setup_context.device,&setup_context.queue,&setup_context.config);
|
||||||
physics.state.load_user_settings(&user_settings);
|
|
||||||
|
|
||||||
let mut graphics=crate::graphics::GraphicsState::new(&context.device,&context.queue,&context.config);
|
|
||||||
graphics.load_user_settings(&user_settings);
|
graphics.load_user_settings(&user_settings);
|
||||||
|
|
||||||
Self{
|
//WindowContextSetup::into_context
|
||||||
user_settings,
|
|
||||||
window,
|
|
||||||
graphics,
|
|
||||||
physics,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn into_context(self,setup_context:crate::setup::SetupContext<'a>)->WindowContext<'a>{
|
|
||||||
let screen_size=glam::uvec2(setup_context.config.width,setup_context.config.height);
|
let screen_size=glam::uvec2(setup_context.config.width,setup_context.config.height);
|
||||||
let graphics_thread=crate::graphics_worker::new(self.graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue);
|
let graphics_thread=crate::graphics_worker::new(graphics,setup_context.config,setup_context.surface,setup_context.device,setup_context.queue);
|
||||||
WindowContext{
|
let mut window_context=WindowContext{
|
||||||
manual_mouse_lock:false,
|
manual_mouse_lock:false,
|
||||||
mouse:crate::physics::MouseState::default(),
|
mouse:strafesnet_common::mouse::MouseState::default(),
|
||||||
//make sure to update this!!!!!
|
//make sure to update this!!!!!
|
||||||
screen_size,
|
screen_size,
|
||||||
user_settings:self.user_settings,
|
window,
|
||||||
window:self.window,
|
physics_thread:crate::physics_worker::new(
|
||||||
physics_thread:crate::physics_worker::new(self.physics,graphics_thread),
|
graphics_thread,
|
||||||
}
|
user_settings,
|
||||||
}
|
),
|
||||||
|
};
|
||||||
|
|
||||||
pub fn into_worker(self,setup_context:crate::setup::SetupContext<'a>)->crate::compat_worker::QNWorker<'a,TimedInstruction<WindowInstruction>>{
|
//WindowContextSetup::into_worker
|
||||||
let mut window_context=self.into_context(setup_context);
|
|
||||||
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<WindowInstruction>|{
|
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<WindowInstruction>|{
|
||||||
match ins.instruction{
|
match ins.instruction{
|
||||||
WindowInstruction::RequestRedraw=>{
|
WindowInstruction::RequestRedraw=>{
|
||||||
@ -217,7 +206,7 @@ impl<'a> WindowContextSetup<'a>{
|
|||||||
window_context.physics_thread.send(
|
window_context.physics_thread.send(
|
||||||
TimedInstruction{
|
TimedInstruction{
|
||||||
time:ins.time,
|
time:ins.time,
|
||||||
instruction:crate::physics_worker::Instruction::Resize(size,window_context.user_settings.clone())
|
instruction:crate::physics_worker::Instruction::Resize(size)
|
||||||
}
|
}
|
||||||
).unwrap();
|
).unwrap();
|
||||||
}
|
}
|
||||||
@ -231,5 +220,4 @@ impl<'a> WindowContextSetup<'a>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -190,7 +190,7 @@ mod test{
|
|||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
let task = instruction::TimedInstruction{
|
let task = instruction::TimedInstruction{
|
||||||
time:integer::Time::ZERO,
|
time:integer::Time::ZERO,
|
||||||
instruction:physics::PhysicsInstruction::StrafeTick,
|
instruction:strafesnet_common::physics::Instruction::Idle,
|
||||||
};
|
};
|
||||||
worker.send(task).unwrap();
|
worker.send(task).unwrap();
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ mod test{
|
|||||||
// Send a new task
|
// Send a new task
|
||||||
let task = instruction::TimedInstruction{
|
let task = instruction::TimedInstruction{
|
||||||
time:integer::Time::ZERO,
|
time:integer::Time::ZERO,
|
||||||
instruction:physics::PhysicsInstruction::StrafeTick,
|
instruction:strafesnet_common::physics::Instruction::Idle,
|
||||||
};
|
};
|
||||||
worker.send(task).unwrap();
|
worker.send(task).unwrap();
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
mangohud ../target/release/strafe-client bhop_maps/5692113331.rbxm
|
mangohud ../target/release/strafe-client bhop_maps/5692113331.snfm
|
||||||
|
@ -1 +1 @@
|
|||||||
/run/media/quat/Files/Documents/map-files/verify-scripts/maps/bhop_all/
|
/run/media/quat/Files/Documents/map-files/verify-scripts/maps/bhop_snfm
|
@ -1 +1 @@
|
|||||||
cargo build --release --target x86_64-pc-windows-gnu
|
cargo build --release --target x86_64-pc-windows-gnu --all-features
|
||||||
|
1
tools/iso
Executable file
1
tools/iso
Executable file
@ -0,0 +1 @@
|
|||||||
|
mangohud ../target/release/strafe-client bhop_maps/5692124338.snfm
|
@ -1 +1 @@
|
|||||||
/run/media/quat/Files/Documents/map-files/verify-scripts/maps/surf_all/
|
/run/media/quat/Files/Documents/map-files/verify-scripts/maps/surf_snfm
|
@ -1 +0,0 @@
|
|||||||
/run/media/quat/Files/Documents/map-files/verify-scripts/textures/dds/
|
|
@ -1 +1 @@
|
|||||||
mangohud ../target/release/strafe-client bhop_maps/5692152916.rbxm
|
mangohud ../target/release/strafe-client bhop_maps/5692152916.snfm
|
||||||
|
@ -1 +1 @@
|
|||||||
mangohud ../target/release/strafe-client surf_maps/5692145408.rbxm
|
mangohud ../target/release/strafe-client surf_maps/5692145408.snfm
|
||||||
|
Reference in New Issue
Block a user