Compare commits
41 Commits
mouse-inte
...
feature/st
Author | SHA1 | Date | |
---|---|---|---|
a139b5a409 | |||
1b71bda9c7 | |||
5f1b162775 | |||
ed27ee060b | |||
5c107c1e5f | |||
3834194156 | |||
d0432188b5 | |||
9ff946c325 | |||
63b2b1676c | |||
b7fc7d2a12 | |||
f273bbf4a9 | |||
cc19917025 | |||
cc58f23512 | |||
b6e7ce4e25 | |||
b0d8f2e09a | |||
9b4b09798b | |||
5a55aefb4f | |||
8f606b7cfc | |||
fad7ed393b | |||
d2a864e2c1 | |||
f027594ab4 | |||
0026b92a72 | |||
4dc706b783 | |||
9bf3f55191 | |||
eb34cce746 | |||
623a2d2a4f | |||
aadcca91ea | |||
04c70ba0bc | |||
865c086f14 | |||
619049c11f | |||
2acefe9a1a | |||
2496d71afa | |||
8ffbca204b | |||
05e2f67e36 | |||
b955407b06 | |||
fb47b09925 | |||
dbd08729d7 | |||
c895a66ad6 | |||
efdb4c97be | |||
9396623f0c | |||
c55156bb92 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/target
|
||||
/textures
|
100
Cargo.lock
generated
100
Cargo.lock
generated
@ -149,18 +149,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "173901312e9850391d4d7c1318c4e099fdc037d61870fca427429830efdb4e5f"
|
||||
dependencies = [
|
||||
"array-init",
|
||||
"binrw_derive 0.13.3",
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "binrw"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f36b7cb3ab9ff6a2858650d8dc360e783a5d14dc29594db48c56a3c233cc265"
|
||||
dependencies = [
|
||||
"array-init",
|
||||
"binrw_derive 0.14.0",
|
||||
"binrw_derive",
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
@ -177,19 +166,6 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "binrw_derive"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20ea7a8c5c8eeffffac6d54d172444e15beffac6f817fac714460a9a9aa88da3"
|
||||
dependencies = [
|
||||
"either",
|
||||
"owo-colors",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.6.0"
|
||||
@ -326,9 +302,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.1.7"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc"
|
||||
checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"libc",
|
||||
@ -675,9 +651,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "glam"
|
||||
version = "0.28.0"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "779ae4bf7e8421cf91c0b3b64e7e8b40b862fba4d393f59150042de7c4965a94"
|
||||
checksum = "151665d9be52f9bb40fc7966565d39666f2d1e69233571b71b87791c7e0528b3"
|
||||
|
||||
[[package]]
|
||||
name = "glow"
|
||||
@ -843,9 +819,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.32"
|
||||
version = "0.1.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
|
||||
checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
@ -878,9 +854,9 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
||||
|
||||
[[package]]
|
||||
name = "lazy-regex"
|
||||
version = "3.2.0"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "576c8060ecfdf2e56995cf3274b4f2d71fa5e4fa3607c1c0b63c10180ee58741"
|
||||
checksum = "5d12be4595afdf58bd19e4a9f4e24187da2a66700786ff660a418e9059937a4c"
|
||||
dependencies = [
|
||||
"lazy-regex-proc_macros",
|
||||
"once_cell",
|
||||
@ -889,9 +865,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lazy-regex-proc_macros"
|
||||
version = "3.2.0"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9efb9e65d4503df81c615dc33ff07042a9408ac7f26b45abee25566f7fbfd12c"
|
||||
checksum = "44bcd58e6c97a7fcbaffcdc95728b393b8d98933bfadad49ed4097845b57ef0b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1109,18 +1085,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
version = "0.7.3"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179"
|
||||
checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845"
|
||||
dependencies = [
|
||||
"num_enum_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum_derive"
|
||||
version = "0.7.3"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
|
||||
checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@ -1594,11 +1570,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rbx_mesh"
|
||||
version = "0.1.2"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "864ead0e98afce28c960f653d6203483834890d07f87b60e2f01415530a2fe9d"
|
||||
checksum = "b9f5cad033f5b4e15d13176f1f15aa1c6b9f025ce6b7ae64a5ce00f97367f2d0"
|
||||
dependencies = [
|
||||
"binrw 0.14.0",
|
||||
"binrw",
|
||||
"lazy-regex",
|
||||
]
|
||||
|
||||
@ -1877,7 +1853,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strafe-client"
|
||||
version = "0.10.1"
|
||||
version = "0.9.5"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"configparser",
|
||||
@ -1890,16 +1866,15 @@ dependencies = [
|
||||
"strafesnet_common",
|
||||
"strafesnet_deferred_loader",
|
||||
"strafesnet_rbx_loader",
|
||||
"strafesnet_snf",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_bsp_loader"
|
||||
version = "0.1.3"
|
||||
version = "0.1.1"
|
||||
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||
checksum = "6d4af68c422b5f57febbaa218f44ba02d413fd25e84afff9e45e557a8caee2ce"
|
||||
checksum = "fa4f0e59adc42910a08bdfeabbe8c8fdfd9295f999d642226214a3784eacf654"
|
||||
dependencies = [
|
||||
"glam",
|
||||
"strafesnet_common",
|
||||
@ -1909,9 +1884,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_common"
|
||||
version = "0.2.0"
|
||||
version = "0.1.2"
|
||||
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||
checksum = "74580c59a09194ce39db49cd814a5c2fc2d61513c88c6b811b5b40c0da6de057"
|
||||
checksum = "0704e795010e6ca97f3d3dd6c24e76bf2d23f91186e1807ad4c7cb84ba6b8239"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"glam",
|
||||
@ -1920,9 +1895,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_deferred_loader"
|
||||
version = "0.3.1"
|
||||
version = "0.3.0"
|
||||
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||
checksum = "c3891dcbdbc20b03cf561786b810e839ae7c11dd8810fd005f2474805ee9cccc"
|
||||
checksum = "737954ffff299d244b0267b8101092034935d98fff7694628dbe438151579c3a"
|
||||
dependencies = [
|
||||
"lazy-regex",
|
||||
"strafesnet_common",
|
||||
@ -1931,9 +1906,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_rbx_loader"
|
||||
version = "0.3.2"
|
||||
version = "0.3.0"
|
||||
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||
checksum = "21ea93b0170063dd2a063a138c41e6f7a6c14a82c6553fa4ba32df65a26efc6e"
|
||||
checksum = "d093481d64ce60837f8d2fbb512b935e5730932ed2aae90e94b3ba6112350176"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"glam",
|
||||
@ -1946,17 +1921,6 @@ dependencies = [
|
||||
"strafesnet_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_snf"
|
||||
version = "0.1.1"
|
||||
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||
checksum = "78479f73437a3f10230efd2304be0f3ef30dff98c54d93613ed1621bfd6a7da6"
|
||||
dependencies = [
|
||||
"binrw 0.14.0",
|
||||
"id",
|
||||
"strafesnet_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strict-num"
|
||||
version = "0.1.1"
|
||||
@ -2052,9 +2016,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.7"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fb9f64314842840f1d940ac544da178732128f1c78c21772e876579e0da1db"
|
||||
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
@ -2136,7 +2100,7 @@ checksum = "d9267540dab0c93bb5201c40ba3b2d027e2717bf355a8f9bf25377b06a5b32f6"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"arrayvec",
|
||||
"binrw 0.13.3",
|
||||
"binrw",
|
||||
"bitflags 2.6.0",
|
||||
"bv",
|
||||
"cgmath",
|
||||
@ -2163,9 +2127,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "vmdl"
|
||||
|
24
Cargo.toml
24
Cargo.toml
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "strafe-client"
|
||||
version = "0.10.1"
|
||||
version = "0.9.5"
|
||||
edition = "2021"
|
||||
repository = "https://git.itzana.me/StrafesNET/strafe-client"
|
||||
license = "Custom"
|
||||
@ -8,29 +8,23 @@ 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
|
||||
[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]
|
||||
bytemuck = { version = "1.13.1", features = ["derive"] }
|
||||
configparser = "3.0.2"
|
||||
ddsfile = "0.5.1"
|
||||
glam = "0.28.0"
|
||||
glam = "0.25.0"
|
||||
id = { version = "0.1.0", registry = "strafesnet" }
|
||||
parking_lot = "0.12.1"
|
||||
pollster = "0.3.0"
|
||||
strafesnet_bsp_loader = { version = "0.1.3", registry = "strafesnet", optional = true }
|
||||
strafesnet_common = { version = "0.2.0", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { version = "0.3.1", features = ["legacy"], registry = "strafesnet", optional = true }
|
||||
strafesnet_rbx_loader = { version = "0.3.2", registry = "strafesnet", optional = true }
|
||||
strafesnet_snf = { version = "0.1.0", registry = "strafesnet", optional = true }
|
||||
strafesnet_bsp_loader = { version = "0.1.1", registry = "strafesnet" }
|
||||
strafesnet_common = { version = "0.1.2", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { version = "0.3.0", features = ["legacy"], registry = "strafesnet" }
|
||||
strafesnet_rbx_loader = { version = "0.3.0", registry = "strafesnet" }
|
||||
wgpu = "22.0.0"
|
||||
winit = "0.30.4"
|
||||
|
||||
[profile.release]
|
||||
#[profile.release]
|
||||
#lto = true
|
||||
strip = true
|
||||
codegen-units = 1
|
||||
#strip = true
|
||||
#codegen-units = 1
|
||||
|
27
src/file.rs
27
src/file.rs
@ -2,14 +2,8 @@ use std::io::Read;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ReadError{
|
||||
#[cfg(feature="roblox")]
|
||||
Roblox(strafesnet_rbx_loader::ReadError),
|
||||
#[cfg(feature="source")]
|
||||
Source(strafesnet_bsp_loader::ReadError),
|
||||
#[cfg(feature="snf")]
|
||||
StrafesNET(strafesnet_snf::Error),
|
||||
#[cfg(feature="snf")]
|
||||
StrafesNETMap(strafesnet_snf::map::Error),
|
||||
Io(std::io::Error),
|
||||
UnknownFileFormat,
|
||||
}
|
||||
@ -21,27 +15,16 @@ impl std::fmt::Display for ReadError{
|
||||
impl std::error::Error for ReadError{}
|
||||
|
||||
pub enum DataStructure{
|
||||
#[cfg(feature="roblox")]
|
||||
Roblox(strafesnet_rbx_loader::Dom),
|
||||
#[cfg(feature="source")]
|
||||
Source(strafesnet_bsp_loader::Bsp),
|
||||
#[cfg(feature="snf")]
|
||||
StrafesNET(strafesnet_common::map::CompleteMap),
|
||||
Source(strafesnet_bsp_loader::Bsp)
|
||||
}
|
||||
|
||||
pub fn read<R:Read+std::io::Seek>(input:R)->Result<DataStructure,ReadError>{
|
||||
pub fn read<R:Read>(input:R)->Result<DataStructure,ReadError>{
|
||||
let mut buf=std::io::BufReader::new(input);
|
||||
let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::Io)?;
|
||||
match &peek[0..4]{
|
||||
#[cfg(feature="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)?)),
|
||||
#[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),
|
||||
}
|
||||
}
|
||||
@ -63,9 +46,6 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
||||
//blocking because it's simpler...
|
||||
let file=std::fs::File::open(path).map_err(LoadError::File)?;
|
||||
match read(file).map_err(LoadError::ReadError)?{
|
||||
#[cfg(feature="snf")]
|
||||
DataStructure::StrafesNET(map)=>Ok(map),
|
||||
#[cfg(feature="roblox")]
|
||||
DataStructure::Roblox(dom)=>{
|
||||
let mut loader=strafesnet_deferred_loader::roblox_legacy();
|
||||
|
||||
@ -98,7 +78,6 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
||||
|
||||
Ok(map)
|
||||
},
|
||||
#[cfg(feature="source")]
|
||||
DataStructure::Source(bsp)=>{
|
||||
let mut loader=strafesnet_deferred_loader::source_legacy();
|
||||
|
||||
@ -138,4 +117,4 @@ pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<strafesnet_common::map::Co
|
||||
Ok(map)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
mod file;
|
||||
mod setup;
|
||||
mod timer;
|
||||
mod window;
|
||||
mod worker;
|
||||
mod physics;
|
||||
|
@ -137,22 +137,22 @@ impl PhysicsMesh{
|
||||
//go go gadget debug print mesh
|
||||
let data=PhysicsMeshData{
|
||||
faces:vec![
|
||||
Face{normal:Planar64Vec3::raw_xyz( 4294967296, 0, 0),dot:Planar64::raw(4294967296)},
|
||||
Face{normal:Planar64Vec3::raw_xyz( 0, 4294967296, 0),dot:Planar64::raw(4294967296)},
|
||||
Face{normal:Planar64Vec3::raw_xyz( 0, 0, 4294967296),dot:Planar64::raw(4294967296)},
|
||||
Face{normal:Planar64Vec3::raw_xyz(-4294967296, 0, 0),dot:Planar64::raw(4294967296)},
|
||||
Face{normal:Planar64Vec3::raw_xyz( 0,-4294967296, 0),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( 0, 4294967296, 0),dot:Planar64::raw(4294967296)},
|
||||
Face{normal:Planar64Vec3::raw( 0, 0, 4294967296),dot:Planar64::raw(4294967296)},
|
||||
Face{normal:Planar64Vec3::raw(-4294967296, 0, 0),dot:Planar64::raw(4294967296)},
|
||||
Face{normal:Planar64Vec3::raw( 0,-4294967296, 0),dot:Planar64::raw(4294967296)},
|
||||
Face{normal:Planar64Vec3::raw( 0, 0,-4294967296),dot:Planar64::raw(4294967296)}
|
||||
],
|
||||
verts:vec![
|
||||
Vert(Planar64Vec3::raw_xyz( 4294967296,-4294967296,-4294967296)),
|
||||
Vert(Planar64Vec3::raw_xyz( 4294967296, 4294967296,-4294967296)),
|
||||
Vert(Planar64Vec3::raw_xyz( 4294967296, 4294967296, 4294967296)),
|
||||
Vert(Planar64Vec3::raw_xyz( 4294967296,-4294967296, 4294967296)),
|
||||
Vert(Planar64Vec3::raw_xyz(-4294967296, 4294967296,-4294967296)),
|
||||
Vert(Planar64Vec3::raw_xyz(-4294967296, 4294967296, 4294967296)),
|
||||
Vert(Planar64Vec3::raw_xyz(-4294967296,-4294967296, 4294967296)),
|
||||
Vert(Planar64Vec3::raw_xyz(-4294967296,-4294967296,-4294967296))
|
||||
Vert(Planar64Vec3::raw( 4294967296,-4294967296,-4294967296)),
|
||||
Vert(Planar64Vec3::raw( 4294967296, 4294967296,-4294967296)),
|
||||
Vert(Planar64Vec3::raw( 4294967296, 4294967296, 4294967296)),
|
||||
Vert(Planar64Vec3::raw( 4294967296,-4294967296, 4294967296)),
|
||||
Vert(Planar64Vec3::raw(-4294967296, 4294967296,-4294967296)),
|
||||
Vert(Planar64Vec3::raw(-4294967296, 4294967296, 4294967296)),
|
||||
Vert(Planar64Vec3::raw(-4294967296,-4294967296, 4294967296)),
|
||||
Vert(Planar64Vec3::raw(-4294967296,-4294967296,-4294967296))
|
||||
]
|
||||
};
|
||||
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)]}
|
||||
],
|
||||
edge_topology:vec![
|
||||
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(2)],verts:[SubmeshVertId(2),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(3)],verts:[SubmeshVertId(4),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(2),SubmeshFaceId(3)],verts:[SubmeshVertId(5),SubmeshVertId(6)]},
|
||||
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(0),SubmeshFaceId(5)],verts:[SubmeshVertId(0),SubmeshVertId(1)]},
|
||||
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(4),SubmeshFaceId(0)],verts:[SubmeshVertId(0),SubmeshVertId(3)]},
|
||||
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(2),SubmeshFaceId(1)],verts:[SubmeshVertId(2),SubmeshVertId(5)]},
|
||||
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(3),SubmeshFaceId(5)],verts:[SubmeshVertId(4),SubmeshVertId(7)]},
|
||||
EdgeRefs{faces:[SubmeshFaceId(4),SubmeshFaceId(3)],verts:[SubmeshVertId(6),SubmeshVertId(7)]},
|
||||
EdgeRefs{faces:[SubmeshFaceId(5),SubmeshFaceId(4)],verts:[SubmeshVertId(0),SubmeshVertId(7)]}
|
||||
],
|
||||
vert_topology:vec![
|
||||
@ -961,4 +961,4 @@ fn test_is_empty_volume(){
|
||||
fn build_me_a_cube(){
|
||||
let mesh=PhysicsMesh::unit_cube();
|
||||
//println!("mesh={:?}",mesh);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
use std::collections::{HashMap,HashSet};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use crate::model_physics::{self,PhysicsMesh,PhysicsMeshTransform,TransformedMesh,MeshQuery,PhysicsMeshId,PhysicsSubmeshId};
|
||||
use strafesnet_common::bvh;
|
||||
use strafesnet_common::map;
|
||||
@ -104,8 +105,7 @@ impl InputState{
|
||||
&self.next_mouse
|
||||
}
|
||||
fn set_next_mouse(&mut self,next_mouse:MouseState){
|
||||
//I like your functions magic language
|
||||
self.mouse=std::mem::replace(&mut self.next_mouse,next_mouse);
|
||||
(self.next_mouse,self.mouse)=(next_mouse,self.next_mouse.clone());
|
||||
}
|
||||
fn replace_mouse(&mut self,mouse:MouseState,next_mouse:MouseState){
|
||||
(self.next_mouse,self.mouse)=(next_mouse,mouse);
|
||||
@ -1161,7 +1161,7 @@ impl PhysicsContext{
|
||||
aabb.inflate(data.hitbox_mesh.halfsize);
|
||||
//common body
|
||||
let relative_body=VirtualBody::relative(&Body::default(),&state.body).body(state.time);
|
||||
data.bvh.the_tester(&aabb,&mut |&convex_mesh_id|{
|
||||
data.bvh.the_tester(&aabb,&mut |convex_mesh_id|{
|
||||
//no checks are needed because of the time limits.
|
||||
let model_mesh=data.models.mesh(convex_mesh_id);
|
||||
let minkowski=model_physics::MinkowskiMesh::minkowski_sum(model_mesh,data.hitbox_mesh.transformed_mesh());
|
||||
@ -1763,4 +1763,4 @@ mod test{
|
||||
Time::ZERO
|
||||
),None);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,190 +16,116 @@ pub enum InputInstruction{
|
||||
PracticeFly,
|
||||
}
|
||||
pub enum Instruction{
|
||||
Passthrough(PassthroughInstruction),
|
||||
Interpolate(InputInstruction),
|
||||
}
|
||||
pub enum PassthroughInstruction{
|
||||
Input(InputInstruction),
|
||||
Render,
|
||||
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
||||
GenerateModels(strafesnet_common::map::CompleteMap),
|
||||
ClearModels,
|
||||
//Graphics(crate::graphics_worker::Instruction),
|
||||
}
|
||||
pub struct MouseInterpolator{
|
||||
queue:std::collections::VecDeque<TimedInstruction<InputInstruction>>,
|
||||
}
|
||||
fn drain_queue(physics:&mut crate::physics::PhysicsContext,iterable:impl IntoIterator<Item=TimedInstruction<InputInstruction>>){
|
||||
for ins in iterable{
|
||||
let physics_input=match &ins.instruction{
|
||||
InputInstruction::MoveMouse(_)=>panic!("Queue was confirmed to contain no MoveMouse events1"),
|
||||
&InputInstruction::MoveForward(s)=>PhysicsInputInstruction::SetMoveForward(s),
|
||||
&InputInstruction::MoveLeft(s)=>PhysicsInputInstruction::SetMoveLeft(s),
|
||||
&InputInstruction::MoveBack(s)=>PhysicsInputInstruction::SetMoveBack(s),
|
||||
&InputInstruction::MoveRight(s)=>PhysicsInputInstruction::SetMoveRight(s),
|
||||
&InputInstruction::MoveUp(s)=>PhysicsInputInstruction::SetMoveUp(s),
|
||||
&InputInstruction::MoveDown(s)=>PhysicsInputInstruction::SetMoveDown(s),
|
||||
&InputInstruction::Jump(s)=>PhysicsInputInstruction::SetJump(s),
|
||||
&InputInstruction::Zoom(s)=>PhysicsInputInstruction::SetZoom(s),
|
||||
InputInstruction::Reset=>PhysicsInputInstruction::Reset,
|
||||
InputInstruction::PracticeFly=>PhysicsInputInstruction::PracticeFly,
|
||||
};
|
||||
physics.run_input_instruction(TimedInstruction{
|
||||
time:ins.time,
|
||||
instruction:physics_input,
|
||||
});
|
||||
}
|
||||
}
|
||||
impl MouseInterpolator{
|
||||
fn handle_instruction(&mut self,physics:&mut crate::physics::PhysicsContext,ins:TimedInstruction<InputInstruction>){
|
||||
//need to handle the case where mouse polling rate is less than 100hz
|
||||
//also the whole thing is probably wrong lol
|
||||
let is_inserting_mouse_instruction=matches!(ins.instruction,InputInstruction::MoveMouse(_));
|
||||
self.queue.push_back(ins);
|
||||
//We just pushed an element.
|
||||
//The first element is guaranteed to exist.
|
||||
let mut iter=self.queue.iter();
|
||||
//find a mouse input
|
||||
'outer:loop{
|
||||
match iter.next(){
|
||||
Some(ins0)=>{
|
||||
let physics_input=match &ins0.instruction{
|
||||
&InputInstruction::MoveMouse(mut mouse0)=>{
|
||||
//mouse instruction found.
|
||||
//enter a new loop with different behaviour
|
||||
//we have to wait for the next mouse event
|
||||
//so there is a before and after interpolation target
|
||||
//write down ins0.time to appease the borrow checker
|
||||
let mut t0=ins0.time;
|
||||
'inner:loop{
|
||||
match iter.next(){
|
||||
Some(ins1)=>match &ins1.instruction{
|
||||
&InputInstruction::MoveMouse(mouse1)=>{
|
||||
//we found two mouse events to interpolate between
|
||||
let consume_count=self.queue.len()-iter.len()-1;//don't consume the mouse1 instruction
|
||||
//fire off a mouse instruction
|
||||
physics.run_input_instruction(TimedInstruction{
|
||||
time:t0,
|
||||
instruction:PhysicsInputInstruction::SetNextMouse(
|
||||
MouseState{time:ins1.time,pos:mouse1}
|
||||
),
|
||||
});
|
||||
//update inner loop state
|
||||
mouse0=mouse1;
|
||||
t0=ins1.time;
|
||||
//drain and handle the elements from the front
|
||||
std::mem::drop(iter);
|
||||
let mut hot_queue=self.queue.drain(0..consume_count);
|
||||
hot_queue.next();
|
||||
drain_queue(physics,hot_queue);
|
||||
iter=self.queue.iter();
|
||||
//keep looking for another mouse instruction in the inner loop
|
||||
continue 'inner;
|
||||
},
|
||||
_=>if Time::from_millis(10)<ins1.time-t0{
|
||||
//we have passed more than 10ms of instructions and have not seen a mouse event.
|
||||
let consume_count=self.queue.len()-iter.len();
|
||||
//run an event to extrapolate no movement from
|
||||
let last_mouse=physics.get_next_mouse();
|
||||
physics.run_input_instruction(TimedInstruction{
|
||||
time:last_mouse.time,
|
||||
instruction:PhysicsInputInstruction::SetNextMouse(
|
||||
MouseState{time:ins1.time,pos:last_mouse.pos}
|
||||
),
|
||||
});
|
||||
//drop the iterator so we can consume the queue up to this point
|
||||
std::mem::drop(iter);
|
||||
//consume queue up to the scanned point
|
||||
let mut hot_queue=self.queue.drain(0..consume_count);
|
||||
//the first element is always the last mouse instruction (last_mouse above)
|
||||
hot_queue.next();
|
||||
drain_queue(physics,hot_queue);
|
||||
//make a new iterator starting from the new beginning
|
||||
//and continue looping like nothing happened
|
||||
iter=self.queue.iter();
|
||||
continue 'outer;
|
||||
},
|
||||
},
|
||||
None=>{
|
||||
if is_inserting_mouse_instruction{
|
||||
//the mouse started moving again after being still for over 10ms.
|
||||
//replace the entire mouse state
|
||||
physics.run_input_instruction(TimedInstruction{
|
||||
time:physics.get_next_mouse().time,
|
||||
instruction:PhysicsInputInstruction::ReplaceMouse(
|
||||
physics.get_next_mouse().clone(),
|
||||
MouseState{time:t0,pos:mouse0}
|
||||
),
|
||||
});
|
||||
}
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
&InputInstruction::MoveForward(s)=>PhysicsInputInstruction::SetMoveForward(s),
|
||||
&InputInstruction::MoveLeft(s)=>PhysicsInputInstruction::SetMoveLeft(s),
|
||||
&InputInstruction::MoveBack(s)=>PhysicsInputInstruction::SetMoveBack(s),
|
||||
&InputInstruction::MoveRight(s)=>PhysicsInputInstruction::SetMoveRight(s),
|
||||
&InputInstruction::MoveUp(s)=>PhysicsInputInstruction::SetMoveUp(s),
|
||||
&InputInstruction::MoveDown(s)=>PhysicsInputInstruction::SetMoveDown(s),
|
||||
&InputInstruction::Jump(s)=>PhysicsInputInstruction::SetJump(s),
|
||||
&InputInstruction::Zoom(s)=>PhysicsInputInstruction::SetZoom(s),
|
||||
InputInstruction::Reset=>PhysicsInputInstruction::Reset,
|
||||
InputInstruction::PracticeFly=>PhysicsInputInstruction::PracticeFly,
|
||||
};
|
||||
//handle each event immediately, we are not waiting for mouse
|
||||
physics.run_input_instruction(TimedInstruction{
|
||||
time:ins0.time,
|
||||
instruction:physics_input,
|
||||
});
|
||||
//drop it and pop it! consume one element and continue the loop
|
||||
std::mem::drop(iter);
|
||||
self.queue.pop_front();
|
||||
iter=self.queue.iter();
|
||||
|
||||
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;
|
||||
let mut last_mouse_time=physics.get_next_mouse().time;
|
||||
let mut timeline=std::collections::VecDeque::new();
|
||||
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
|
||||
if if let Some(phys_input)=match &ins.instruction{
|
||||
Instruction::Input(input_instruction)=>match input_instruction{
|
||||
&InputInstruction::MoveMouse(m)=>{
|
||||
if mouse_blocking{
|
||||
//tell the game state which is living in the past about its future
|
||||
timeline.push_front(TimedInstruction{
|
||||
time:last_mouse_time,
|
||||
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins.time,pos:m}),
|
||||
});
|
||||
}else{
|
||||
//mouse has just started moving again after being still for longer than 10ms.
|
||||
//replace the entire mouse interpolation state to avoid an intermediate state with identical m0.t m1.t timestamps which will divide by zero
|
||||
timeline.push_front(TimedInstruction{
|
||||
time:last_mouse_time,
|
||||
instruction:PhysicsInputInstruction::ReplaceMouse(
|
||||
MouseState{time:last_mouse_time,pos:physics.get_next_mouse().pos},
|
||||
MouseState{time:ins.time,pos:m}
|
||||
),
|
||||
});
|
||||
//delay physics execution until we have an interpolation target
|
||||
mouse_blocking=true;
|
||||
}
|
||||
last_mouse_time=ins.time;
|
||||
None
|
||||
},
|
||||
&InputInstruction::MoveForward(s)=>Some(PhysicsInputInstruction::SetMoveForward(s)),
|
||||
&InputInstruction::MoveLeft(s)=>Some(PhysicsInputInstruction::SetMoveLeft(s)),
|
||||
&InputInstruction::MoveBack(s)=>Some(PhysicsInputInstruction::SetMoveBack(s)),
|
||||
&InputInstruction::MoveRight(s)=>Some(PhysicsInputInstruction::SetMoveRight(s)),
|
||||
&InputInstruction::MoveUp(s)=>Some(PhysicsInputInstruction::SetMoveUp(s)),
|
||||
&InputInstruction::MoveDown(s)=>Some(PhysicsInputInstruction::SetMoveDown(s)),
|
||||
&InputInstruction::Jump(s)=>Some(PhysicsInputInstruction::SetJump(s)),
|
||||
&InputInstruction::Zoom(s)=>Some(PhysicsInputInstruction::SetZoom(s)),
|
||||
InputInstruction::Reset=>Some(PhysicsInputInstruction::Reset),
|
||||
InputInstruction::PracticeFly=>Some(PhysicsInputInstruction::PracticeFly),
|
||||
},
|
||||
None=>{
|
||||
//if mouse0 is never found and the loop ends, we can drain the entire queue
|
||||
//because we are not waiting for mouse events.
|
||||
drain_queue(physics,self.queue.drain(..));
|
||||
break 'outer;
|
||||
Instruction::GenerateModels(_)=>Some(PhysicsInputInstruction::Idle),
|
||||
Instruction::ClearModels=>Some(PhysicsInputInstruction::Idle),
|
||||
Instruction::Resize(_,_)=>Some(PhysicsInputInstruction::Idle),
|
||||
Instruction::Render=>Some(PhysicsInputInstruction::Idle),
|
||||
}{
|
||||
//non-mouse event
|
||||
timeline.push_back(TimedInstruction{
|
||||
time:ins.time,
|
||||
instruction:phys_input,
|
||||
});
|
||||
|
||||
if 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)<ins.time-physics.get_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.get_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{
|
||||
//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
|
||||
last_mouse_time=ins.time;
|
||||
true
|
||||
}
|
||||
}else{
|
||||
//mouse event
|
||||
true
|
||||
}{
|
||||
//empty queue
|
||||
while let Some(instruction)=timeline.pop_front(){
|
||||
physics.run_input_instruction(instruction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 interpolator=MouseInterpolator{
|
||||
queue:std::collections::VecDeque::new(),
|
||||
};
|
||||
crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction>|{
|
||||
let passthrough_instruction=match ins.instruction{
|
||||
Instruction::Passthrough(passthrough_instruction)=>passthrough_instruction,
|
||||
Instruction::Interpolate(input_instruction)=>{
|
||||
interpolator.handle_instruction(&mut physics,TimedInstruction{
|
||||
instruction:input_instruction,
|
||||
time:ins.time,
|
||||
});
|
||||
return;
|
||||
},
|
||||
};
|
||||
match passthrough_instruction{
|
||||
PassthroughInstruction::Render=>{
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.get_next_mouse().pos)).unwrap();
|
||||
},
|
||||
PassthroughInstruction::Resize(size,user_settings)=>{
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
|
||||
},
|
||||
PassthroughInstruction::GenerateModels(map)=>{
|
||||
physics.generate_models(&map);
|
||||
physics.spawn();
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map)).unwrap();
|
||||
},
|
||||
PassthroughInstruction::ClearModels=>{
|
||||
physics.clear();
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap();
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
match ins.instruction{
|
||||
Instruction::Render=>{
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::Render(physics.output(),ins.time,physics.get_next_mouse().pos)).unwrap();
|
||||
},
|
||||
Instruction::Resize(size,user_settings)=>{
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::Resize(size,user_settings)).unwrap();
|
||||
},
|
||||
Instruction::GenerateModels(map)=>{
|
||||
physics.generate_models(&map);
|
||||
physics.spawn();
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::GenerateModels(map)).unwrap();
|
||||
},
|
||||
Instruction::ClearModels=>{
|
||||
physics.clear();
|
||||
graphics_worker.send(crate::graphics_worker::Instruction::ClearModels).unwrap();
|
||||
},
|
||||
_=>(),
|
||||
}
|
||||
})
|
||||
}
|
179
src/timer.rs
179
src/timer.rs
@ -1,179 +0,0 @@
|
||||
use strafesnet_common::integer::{Time,Ratio64};
|
||||
|
||||
pub trait TimerState:Copy{
|
||||
fn get_time(&self,time:Time)->Time;
|
||||
fn set_time(&mut self,time:Time,new_time:Time);
|
||||
fn get_offset(&self)->Time;
|
||||
fn set_offset(&mut self,offset:Time);
|
||||
}
|
||||
|
||||
#[derive(Clone,Copy,Debug)]
|
||||
struct Scaled{
|
||||
scale:Ratio64,
|
||||
offset:Time,
|
||||
}
|
||||
impl Scaled{
|
||||
fn scale(&self,time:Time)->Time{
|
||||
Time::raw(self.scale.mul_int(time.get()))
|
||||
}
|
||||
fn get_scale(&self)->Ratio64{
|
||||
self.scale
|
||||
}
|
||||
fn set_scale(&mut self,time:Time,new_scale:Ratio64){
|
||||
let new_time=self.get_time(time);
|
||||
self.scale=new_scale;
|
||||
self.set_time(time,new_time);
|
||||
}
|
||||
}
|
||||
impl TimerState for Scaled{
|
||||
fn get_time(&self,time:Time)->Time{
|
||||
self.scale(time)+self.offset
|
||||
}
|
||||
fn set_time(&mut self,time:Time,new_time:Time){
|
||||
self.offset=new_time-self.scale(time);
|
||||
}
|
||||
fn get_offset(&self)->Time{
|
||||
self.offset
|
||||
}
|
||||
fn set_offset(&mut self,offset:Time){
|
||||
self.offset=offset;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone,Copy,Debug)]
|
||||
struct Realtime{
|
||||
offset:Time,
|
||||
}
|
||||
impl TimerState for Realtime{
|
||||
fn get_time(&self,time:Time)->Time{
|
||||
time+self.offset
|
||||
}
|
||||
fn set_time(&mut self,time:Time,new_time:Time){
|
||||
self.offset=new_time-time;
|
||||
}
|
||||
fn get_offset(&self)->Time{
|
||||
self.offset
|
||||
}
|
||||
fn set_offset(&mut self,offset:Time){
|
||||
self.offset=offset;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone,Debug)]
|
||||
pub struct Timer<T>{
|
||||
state:T,
|
||||
paused:bool,
|
||||
}
|
||||
|
||||
impl Timer<Realtime>{
|
||||
pub fn realtime(offset:Time)->Self{
|
||||
Self{
|
||||
state:Realtime{offset},
|
||||
paused:false,
|
||||
}
|
||||
}
|
||||
pub fn realtime_paused(offset:Time)->Self{
|
||||
Self{
|
||||
state:Realtime{offset},
|
||||
paused:true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
AlreadyPaused,
|
||||
AlreadyUnpaused,
|
||||
}
|
||||
impl std::fmt::Display for Error{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for Error{}
|
||||
|
||||
impl Timer<Scaled>{
|
||||
pub fn scaled(scale:Ratio64,offset:Time)->Self{
|
||||
Self{
|
||||
state:Scaled{scale,offset},
|
||||
paused:false,
|
||||
}
|
||||
}
|
||||
pub fn scaled_paused(scale:Ratio64,offset:Time)->Self{
|
||||
Self{
|
||||
state:Scaled{scale,offset},
|
||||
paused:true,
|
||||
}
|
||||
}
|
||||
pub fn get_scale(&mut self)->Ratio64{
|
||||
self.state.get_scale()
|
||||
}
|
||||
pub fn set_scale(&mut self,time:Time,new_scale:Ratio64){
|
||||
self.state.set_scale(time,new_scale)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:TimerState> Timer<T>{
|
||||
pub fn time(&self,time:Time)->Time{
|
||||
match self.paused{
|
||||
true=>self.state.get_offset(),
|
||||
false=>self.state.get_time(time),
|
||||
}
|
||||
}
|
||||
pub fn set_time(&mut self,time:Time,new_time:Time){
|
||||
match self.paused{
|
||||
true=>self.state.set_offset(new_time),
|
||||
false=>self.state.set_time(time,new_time),
|
||||
}
|
||||
}
|
||||
pub fn pause(&mut self,time:Time)->Result<(),Error>{
|
||||
match self.paused{
|
||||
true=>Err(Error::AlreadyPaused),
|
||||
false=>{
|
||||
let new_time=self.time(time);
|
||||
self.state.set_offset(new_time);
|
||||
self.paused=true;
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
pub fn unpause(&mut self,time:Time)->Result<(),Error>{
|
||||
match self.paused{
|
||||
true=>{
|
||||
let new_time=self.time(time);
|
||||
self.state.set_time(time,new_time);
|
||||
self.paused=false;
|
||||
Ok(())
|
||||
},
|
||||
false=>Err(Error::AlreadyUnpaused),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod test{
|
||||
use super::{Time,Timer,Error};
|
||||
macro_rules! sec {
|
||||
($s: expr) => {
|
||||
Time::from_secs($s)
|
||||
};
|
||||
}
|
||||
#[test]
|
||||
fn test_timer()->Result<(),Error>{
|
||||
//create a paused timer that reads 0s
|
||||
let mut timer=Timer::realtime_paused(sec!(0));
|
||||
//the paused timer at 1 second should read 0s
|
||||
assert_eq!(timer.time(sec!(1)),sec!(0));
|
||||
|
||||
//unpause it after one second
|
||||
timer.unpause(sec!(1))?;
|
||||
//the timer at 6 seconds should read 5s
|
||||
assert_eq!(timer.time(sec!(6)),sec!(5));
|
||||
|
||||
//pause the timer after 11 seconds
|
||||
timer.pause(sec!(11))?;
|
||||
//the paused timer at 20 seconds should read 10s
|
||||
assert_eq!(timer.time(sec!(20)),sec!(10));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -29,12 +29,8 @@ impl WindowContext<'_>{
|
||||
winit::event::WindowEvent::DroppedFile(path)=>{
|
||||
match crate::file::load(path.as_path()){
|
||||
Ok(map)=>{
|
||||
self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::Passthrough(
|
||||
crate::physics_worker::PassthroughInstruction::ClearModels
|
||||
)}).unwrap();
|
||||
self.physics_thread.send(TimedInstruction{time,instruction:crate::physics_worker::Instruction::Passthrough(
|
||||
crate::physics_worker::PassthroughInstruction::GenerateModels(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}"),
|
||||
}
|
||||
@ -119,7 +115,7 @@ impl WindowContext<'_>{
|
||||
}{
|
||||
self.physics_thread.send(TimedInstruction{
|
||||
time,
|
||||
instruction:crate::physics_worker::Instruction::Interpolate(input_instruction),
|
||||
instruction:crate::physics_worker::Instruction::Input(input_instruction),
|
||||
}).unwrap();
|
||||
}
|
||||
},
|
||||
@ -147,7 +143,7 @@ impl WindowContext<'_>{
|
||||
self.mouse.pos+=delta;
|
||||
self.physics_thread.send(TimedInstruction{
|
||||
time,
|
||||
instruction:crate::physics_worker::Instruction::Interpolate(InputInstruction::MoveMouse(self.mouse.pos)),
|
||||
instruction:crate::physics_worker::Instruction::Input(InputInstruction::MoveMouse(self.mouse.pos)),
|
||||
}).unwrap();
|
||||
},
|
||||
winit::event::DeviceEvent::MouseWheel {
|
||||
@ -157,7 +153,7 @@ impl WindowContext<'_>{
|
||||
if false{//self.physics.style.use_scroll{
|
||||
self.physics_thread.send(TimedInstruction{
|
||||
time,
|
||||
instruction:crate::physics_worker::Instruction::Interpolate(InputInstruction::Jump(true)),//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump
|
||||
instruction:crate::physics_worker::Instruction::Input(InputInstruction::Jump(true)),//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump
|
||||
}).unwrap();
|
||||
}
|
||||
}
|
||||
@ -222,9 +218,7 @@ impl<'a> WindowContextSetup<'a>{
|
||||
window_context.physics_thread.send(
|
||||
TimedInstruction{
|
||||
time:ins.time,
|
||||
instruction:crate::physics_worker::Instruction::Passthrough(
|
||||
crate::physics_worker::PassthroughInstruction::Resize(size,window_context.user_settings.clone())
|
||||
)
|
||||
instruction:crate::physics_worker::Instruction::Resize(size,window_context.user_settings.clone())
|
||||
}
|
||||
).unwrap();
|
||||
}
|
||||
@ -232,13 +226,11 @@ impl<'a> WindowContextSetup<'a>{
|
||||
window_context.physics_thread.send(
|
||||
TimedInstruction{
|
||||
time:ins.time,
|
||||
instruction:crate::physics_worker::Instruction::Passthrough(
|
||||
crate::physics_worker::PassthroughInstruction::Render
|
||||
)
|
||||
instruction:crate::physics_worker::Instruction::Render
|
||||
}
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
mangohud ../target/release/strafe-client bhop_maps/5692113331.snfm
|
||||
mangohud ../target/release/strafe-client bhop_maps/5692113331.rbxm
|
||||
|
@ -1 +1 @@
|
||||
/run/media/quat/Files/Documents/map-files/verify-scripts/maps/bhop_snfm
|
||||
/run/media/quat/Files/Documents/map-files/verify-scripts/maps/bhop_all/
|
@ -1 +1 @@
|
||||
cargo build --release --target x86_64-pc-windows-gnu --all-features
|
||||
cargo build --release --target x86_64-pc-windows-gnu
|
||||
|
1
tools/meshes
Symbolic link
1
tools/meshes
Symbolic link
@ -0,0 +1 @@
|
||||
/run/media/quat/Files/Documents/map-files/verify-scripts/meshes/
|
@ -1 +1 @@
|
||||
/run/media/quat/Files/Documents/map-files/verify-scripts/maps/surf_snfm
|
||||
/run/media/quat/Files/Documents/map-files/verify-scripts/maps/surf_all/
|
1
tools/textures
Symbolic link
1
tools/textures
Symbolic link
@ -0,0 +1 @@
|
||||
/run/media/quat/Files/Documents/map-files/verify-scripts/textures/dds/
|
@ -1 +1 @@
|
||||
mangohud ../target/release/strafe-client bhop_maps/5692152916.snfm
|
||||
mangohud ../target/release/strafe-client bhop_maps/5692152916.rbxm
|
||||
|
@ -1 +1 @@
|
||||
mangohud ../target/release/strafe-client surf_maps/5692145408.snfm
|
||||
mangohud ../target/release/strafe-client surf_maps/5692145408.rbxm
|
||||
|
Reference in New Issue
Block a user