forked from StrafesNET/strafe-project
Compare commits
64 Commits
master
...
load_roblo
Author | SHA1 | Date | |
---|---|---|---|
41e46f248c | |||
8a9d99cae3 | |||
3216cbb25f | |||
5da40b73ea | |||
5fc4044284 | |||
6f4fda8cc0 | |||
d58f915082 | |||
8e95fe484a | |||
5854128164 | |||
db5b3328bd | |||
4951d1513d | |||
17e71d884f | |||
1dc98d9c2d | |||
fd38502e07 | |||
0632e322cf | |||
7544c6e6ef | |||
2f0a073fd5 | |||
21dc425fc2 | |||
ca141c800c | |||
63ce06f069 | |||
fe14d5e0fa | |||
bffc254a0d | |||
a5f203484b | |||
e67479a9bd | |||
ad7abbdf1c | |||
3a0b3900ec | |||
765ed42b9d | |||
8137a26f81 | |||
21ae7a0e4f | |||
5a886b76d1 | |||
f1e26cb07a | |||
14a74c6e1e | |||
5b55873bd5 | |||
fd5d71e1af | |||
28c3f21736 | |||
a58464efb0 | |||
b070b9706f | |||
dcfbee8de1 | |||
c5636f7fcd | |||
a5aa89064b | |||
0fe14749d3 | |||
8daf432991 | |||
4f5c9afed3 | |||
53605746d4 | |||
cead05b08b | |||
949897a558 | |||
a4ed50fc38 | |||
846f681648 | |||
ff54a03487 | |||
8c2dda5205 | |||
addde65caa | |||
2c4e6f642b | |||
f11742ef3b | |||
e6862b5bad | |||
e18e8a9a7d | |||
f600092f13 | |||
1f1ef5d3ad | |||
54bf0358d6 | |||
6caa273623 | |||
101f0f8d12 | |||
fc751a9fe8 | |||
5391b635fb | |||
230469496e | |||
ea3134de51 |
257
Cargo.lock
generated
257
Cargo.lock
generated
@ -157,6 +157,12 @@ dependencies = [
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.5.3"
|
||||
@ -184,12 +190,35 @@ version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||
|
||||
[[package]]
|
||||
name = "blake3"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"constant_time_eq",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-sys"
|
||||
version = "0.1.0-beta.1"
|
||||
@ -302,6 +331,12 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.3"
|
||||
@ -360,6 +395,16 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "d3d12"
|
||||
version = "0.7.0"
|
||||
@ -382,6 +427,17 @@ dependencies = [
|
||||
"enum_primitive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dispatch"
|
||||
version = "0.2.0"
|
||||
@ -555,6 +611,16 @@ dependencies = [
|
||||
"waker-fn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
@ -822,6 +888,26 @@ version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "lz4"
|
||||
version = "1.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e9e2dd86df36ce760a60f6ff6ad526f7ba1f14ba0356f8254fb6905e6494df1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"lz4-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lz4-sys"
|
||||
version = "1.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57d27b317e207b10f69f5e75494119e391a96f48861ae870d1da6edac98ca900"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "malloc_buf"
|
||||
version = "0.0.6"
|
||||
@ -1198,6 +1284,12 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.1"
|
||||
@ -1222,6 +1314,19 @@ name = "profiling"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46b2164ebdb1dfeec5e337be164292351e11daf63a05174c6776b2f47460f0c9"
|
||||
dependencies = [
|
||||
"profiling-procmacros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "profiling-procmacros"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74c55e9e629af5298a40e0fa106435b2da30484c4ec76b41d19bc4d00dd8b903"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
@ -1232,6 +1337,36 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "range-alloc"
|
||||
version = "0.1.3"
|
||||
@ -1244,6 +1379,69 @@ version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
|
||||
|
||||
[[package]]
|
||||
name = "rbx_binary"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e50573021d04b680018955662eba7dc4aac3de92219231798f6c9b41e38ab01"
|
||||
dependencies = [
|
||||
"log",
|
||||
"lz4",
|
||||
"profiling",
|
||||
"rbx_dom_weak",
|
||||
"rbx_reflection",
|
||||
"rbx_reflection_database",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rbx_dom_weak"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "161729449bbb0cfa657ce7bcca6a160d0af06d8b8d9efdc9abe14735dccacdb9"
|
||||
dependencies = [
|
||||
"rbx_types",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rbx_reflection"
|
||||
version = "4.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08bd48487192046fec8f805f3fa29f3d7d5beb9890b0859b1a92bd8aff580343"
|
||||
dependencies = [
|
||||
"rbx_types",
|
||||
"serde",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rbx_reflection_database"
|
||||
version = "0.2.7+roblox-588"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1be6cf674182806f11ad4899dd1feafe977591f1ae035ae05a58d4b74e487276"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"rbx_reflection",
|
||||
"rmp-serde",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rbx_types"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "070106e926b8ae54c7bc443e5db4d868d7f0af51c1d7cfd7efe1364c1753d8a3"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bitflags 1.3.2",
|
||||
"blake3",
|
||||
"lazy_static",
|
||||
"rand",
|
||||
"serde",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.3.5"
|
||||
@ -1288,6 +1486,28 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b"
|
||||
|
||||
[[package]]
|
||||
name = "rmp"
|
||||
version = "0.8.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"num-traits 0.2.16",
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rmp-serde"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"rmp",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.23"
|
||||
@ -1338,6 +1558,26 @@ dependencies = [
|
||||
"tiny-skia",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.7"
|
||||
@ -1405,7 +1645,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strafe-client"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"async-executor",
|
||||
"bytemuck",
|
||||
@ -1415,6 +1655,9 @@ dependencies = [
|
||||
"log",
|
||||
"obj",
|
||||
"pollster",
|
||||
"rbx_binary",
|
||||
"rbx_dom_weak",
|
||||
"rbx_reflection_database",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
@ -1425,6 +1668,12 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
@ -1524,6 +1773,12 @@ version = "0.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "strafe-client"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@ -14,6 +14,9 @@ glam = "0.24.1"
|
||||
log = "0.4.20"
|
||||
obj = "0.10.2"
|
||||
pollster = "0.3.0"
|
||||
rbx_binary = "0.7.1"
|
||||
rbx_dom_weak = "2.5.0"
|
||||
rbx_reflection_database = "0.2.7"
|
||||
wgpu = "0.17.0"
|
||||
winit = "0.28.6"
|
||||
|
||||
|
BIN
maps/bhop_easyhop.rbxm
Normal file
BIN
maps/bhop_easyhop.rbxm
Normal file
Binary file not shown.
857
src/body.rs
Normal file
857
src/body.rs
Normal file
@ -0,0 +1,857 @@
|
||||
use crate::{instruction::{InstructionEmitter, InstructionConsumer, TimedInstruction}, zeroes::zeroes2};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PhysicsInstruction {
|
||||
CollisionStart(RelativeCollision),
|
||||
CollisionEnd(RelativeCollision),
|
||||
SetControlDir(glam::Vec3),
|
||||
StrafeTick,
|
||||
Jump,
|
||||
SetWalkTargetVelocity(glam::Vec3),
|
||||
RefreshWalkTarget,
|
||||
ReachWalkTargetVelocity,
|
||||
// Water,
|
||||
// Spawn(
|
||||
// Option<SpawnId>,
|
||||
// bool,//true = Trigger; false = teleport
|
||||
// bool,//true = Force
|
||||
// )
|
||||
}
|
||||
|
||||
pub struct Body {
|
||||
position: glam::Vec3,//I64 where 2^32 = 1 u
|
||||
velocity: glam::Vec3,//I64 where 2^32 = 1 u/s
|
||||
acceleration: glam::Vec3,//I64 where 2^32 = 1 u/s/s
|
||||
time: TIME,//nanoseconds x xxxxD!
|
||||
}
|
||||
trait MyHash{
|
||||
fn hash(&self) -> u64;
|
||||
}
|
||||
impl MyHash for Body {
|
||||
fn hash(&self) -> u64 {
|
||||
let mut hasher=std::collections::hash_map::DefaultHasher::new();
|
||||
for &el in self.position.as_ref().iter() {
|
||||
std::hash::Hasher::write(&mut hasher, el.to_ne_bytes().as_slice());
|
||||
}
|
||||
for &el in self.velocity.as_ref().iter() {
|
||||
std::hash::Hasher::write(&mut hasher, el.to_ne_bytes().as_slice());
|
||||
}
|
||||
for &el in self.acceleration.as_ref().iter() {
|
||||
std::hash::Hasher::write(&mut hasher, el.to_ne_bytes().as_slice());
|
||||
}
|
||||
std::hash::Hasher::write(&mut hasher, self.time.to_ne_bytes().as_slice());
|
||||
return std::hash::Hasher::finish(&hasher);//hash check to see if walk target is valid
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MoveRestriction {
|
||||
Air,
|
||||
Water,
|
||||
Ground,
|
||||
Ladder,//multiple ladders how
|
||||
}
|
||||
|
||||
enum MouseInterpolation {
|
||||
First,//just checks the last value
|
||||
Lerp,//lerps between
|
||||
}
|
||||
|
||||
enum InputInstruction {
|
||||
MoveMouse(glam::IVec2),
|
||||
Jump(bool),
|
||||
}
|
||||
|
||||
struct InputState {
|
||||
controls: u32,
|
||||
mouse_interpolation: MouseInterpolation,
|
||||
time: TIME,
|
||||
}
|
||||
|
||||
impl InputState {
|
||||
pub fn get_control(&self,control:u32) -> bool {
|
||||
self.controls&control!=0
|
||||
}
|
||||
pub fn process_instruction(&mut self,ins:InputInstruction){
|
||||
match ins {
|
||||
InputInstruction::MoveMouse(m) => todo!("set mouse_interpolation"),
|
||||
InputInstruction::Jump(b) => todo!("how does info about style modifiers get here"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MouseInterpolationState {
|
||||
interpolation: MouseInterpolation,
|
||||
time0: TIME,
|
||||
time1: TIME,
|
||||
mouse0: glam::IVec2,
|
||||
mouse1: glam::IVec2,
|
||||
}
|
||||
|
||||
impl MouseInterpolationState {
|
||||
pub fn move_mouse(&mut self,time:TIME,pos:glam::IVec2){
|
||||
self.time0=self.time1;
|
||||
self.mouse0=self.mouse1;
|
||||
self.time1=time;
|
||||
self.mouse1=pos;
|
||||
}
|
||||
pub fn interpolated_position(&self,time:TIME) -> glam::IVec2 {
|
||||
match self.interpolation {
|
||||
MouseInterpolation::First => self.mouse0,
|
||||
MouseInterpolation::Lerp => {
|
||||
let m0=self.mouse0.as_i64vec2();
|
||||
let m1=self.mouse1.as_i64vec2();
|
||||
//these are deltas
|
||||
let t1t=(self.time1-time) as i64;
|
||||
let tt0=(time-self.time0) as i64;
|
||||
let dt=(self.time1-self.time0) as i64;
|
||||
((m0*t1t+m1*tt0)/dt).as_ivec2()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum WalkEnum{
|
||||
Reached,
|
||||
Transient,
|
||||
Invalid,
|
||||
}
|
||||
pub struct WalkState {
|
||||
pub target_velocity: glam::Vec3,
|
||||
pub target_time: TIME,
|
||||
pub state: WalkEnum,
|
||||
}
|
||||
impl WalkState {
|
||||
pub fn new() -> Self {
|
||||
Self{
|
||||
target_velocity:glam::Vec3::ZERO,
|
||||
target_time:0,
|
||||
state:WalkEnum::Invalid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PhysicsState {
|
||||
pub body: Body,
|
||||
pub hitbox_halfsize: glam::Vec3,
|
||||
pub contacts: std::collections::HashSet::<RelativeCollision>,
|
||||
//pub intersections: Vec<ModelId>,
|
||||
//temp
|
||||
pub models_cringe_clone: Vec<Model>,
|
||||
pub temp_control_dir: glam::Vec3,
|
||||
//camera must exist in state because wormholes modify the camera, also camera punch
|
||||
//pub camera: Camera,
|
||||
//pub mouse_interpolation: MouseInterpolationState,
|
||||
pub time: TIME,
|
||||
pub strafe_tick_num: TIME,
|
||||
pub strafe_tick_den: TIME,
|
||||
pub tick: u32,
|
||||
pub mv: f32,
|
||||
pub walk: WalkState,
|
||||
pub walkspeed: f32,
|
||||
pub friction: f32,
|
||||
pub walk_accel: f32,
|
||||
pub gravity: glam::Vec3,
|
||||
pub grounded: bool,
|
||||
pub jump_trying: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
|
||||
pub enum AabbFace{
|
||||
Right,//+X
|
||||
Top,
|
||||
Back,
|
||||
Left,
|
||||
Bottom,
|
||||
Front,
|
||||
}
|
||||
|
||||
pub struct Aabb {
|
||||
min: glam::Vec3,
|
||||
max: glam::Vec3,
|
||||
}
|
||||
|
||||
impl Aabb {
|
||||
// const FACE_DATA: [[f32; 3]; 6] = [
|
||||
// [0.0f32, 0., 1.],
|
||||
// [0.0f32, 0., -1.],
|
||||
// [1.0f32, 0., 0.],
|
||||
// [-1.0f32, 0., 0.],
|
||||
// [0.0f32, 1., 0.],
|
||||
// [0.0f32, -1., 0.],
|
||||
// ];
|
||||
const VERTEX_DATA: [glam::Vec3; 8] = [
|
||||
glam::vec3(1., -1., -1.),
|
||||
glam::vec3(1., 1., -1.),
|
||||
glam::vec3(1., 1., 1.),
|
||||
glam::vec3(1., -1., 1.),
|
||||
glam::vec3(-1., -1., 1.),
|
||||
glam::vec3(-1., 1., 1.),
|
||||
glam::vec3(-1., 1., -1.),
|
||||
glam::vec3(-1., -1., -1.),
|
||||
];
|
||||
const VERTEX_DATA_RIGHT: [glam::Vec3; 4] = [
|
||||
glam::vec3(1., -1., -1.),
|
||||
glam::vec3(1., 1., -1.),
|
||||
glam::vec3(1., 1., 1.),
|
||||
glam::vec3(1., -1., 1.),
|
||||
];
|
||||
const VERTEX_DATA_TOP: [glam::Vec3; 4] = [
|
||||
glam::vec3(1., 1., -1.),
|
||||
glam::vec3(-1., 1., -1.),
|
||||
glam::vec3(-1., 1., 1.),
|
||||
glam::vec3(1., 1., 1.),
|
||||
];
|
||||
const VERTEX_DATA_BACK: [glam::Vec3; 4] = [
|
||||
glam::vec3(-1., -1., 1.),
|
||||
glam::vec3(1., -1., 1.),
|
||||
glam::vec3(1., 1., 1.),
|
||||
glam::vec3(-1., 1., 1.),
|
||||
];
|
||||
const VERTEX_DATA_LEFT: [glam::Vec3; 4] = [
|
||||
glam::vec3(-1., -1., 1.),
|
||||
glam::vec3(-1., 1., 1.),
|
||||
glam::vec3(-1., 1., -1.),
|
||||
glam::vec3(-1., -1., -1.),
|
||||
];
|
||||
const VERTEX_DATA_BOTTOM: [glam::Vec3; 4] = [
|
||||
glam::vec3(1., -1., 1.),
|
||||
glam::vec3(-1., -1., 1.),
|
||||
glam::vec3(-1., -1., -1.),
|
||||
glam::vec3(1., -1., -1.),
|
||||
];
|
||||
const VERTEX_DATA_FRONT: [glam::Vec3; 4] = [
|
||||
glam::vec3(-1., 1., -1.),
|
||||
glam::vec3(1., 1., -1.),
|
||||
glam::vec3(1., -1., -1.),
|
||||
glam::vec3(-1., -1., -1.),
|
||||
];
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {min: glam::Vec3::INFINITY,max: glam::Vec3::NEG_INFINITY}
|
||||
}
|
||||
|
||||
pub fn grow(&mut self, point:glam::Vec3){
|
||||
self.min=self.min.min(point);
|
||||
self.max=self.max.max(point);
|
||||
}
|
||||
|
||||
pub fn normal(face:AabbFace) -> glam::Vec3 {
|
||||
match face {
|
||||
AabbFace::Right => glam::vec3(1.,0.,0.),
|
||||
AabbFace::Top => glam::vec3(0.,1.,0.),
|
||||
AabbFace::Back => glam::vec3(0.,0.,1.),
|
||||
AabbFace::Left => glam::vec3(-1.,0.,0.),
|
||||
AabbFace::Bottom => glam::vec3(0.,-1.,0.),
|
||||
AabbFace::Front => glam::vec3(0.,0.,-1.),
|
||||
}
|
||||
}
|
||||
pub fn unit_vertices() -> [glam::Vec3;8] {
|
||||
return Self::VERTEX_DATA;
|
||||
}
|
||||
pub fn unit_face_vertices(face:AabbFace) -> [glam::Vec3;4] {
|
||||
match face {
|
||||
AabbFace::Right => Self::VERTEX_DATA_RIGHT,
|
||||
AabbFace::Top => Self::VERTEX_DATA_TOP,
|
||||
AabbFace::Back => Self::VERTEX_DATA_BACK,
|
||||
AabbFace::Left => Self::VERTEX_DATA_LEFT,
|
||||
AabbFace::Bottom => Self::VERTEX_DATA_BOTTOM,
|
||||
AabbFace::Front => Self::VERTEX_DATA_FRONT,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//pretend to be using what we want to eventually do
|
||||
type TreyMeshFace = AabbFace;
|
||||
type TreyMesh = Aabb;
|
||||
|
||||
pub struct Model {
|
||||
//A model is a thing that has a hitbox. can be represented by a list of TreyMesh-es
|
||||
//in this iteration, all it needs is extents.
|
||||
transform: glam::Mat4,
|
||||
}
|
||||
|
||||
impl Model {
|
||||
pub fn new(transform:glam::Mat4) -> Self {
|
||||
Self{transform}
|
||||
}
|
||||
pub fn unit_vertices(&self) -> [glam::Vec3;8] {
|
||||
Aabb::unit_vertices()
|
||||
}
|
||||
pub fn mesh(&self) -> TreyMesh {
|
||||
let mut aabb=Aabb::new();
|
||||
for &vertex in self.unit_vertices().iter() {
|
||||
aabb.grow(glam::Vec4Swizzles::xyz(self.transform*vertex.extend(1.0)));
|
||||
}
|
||||
return aabb;
|
||||
}
|
||||
pub fn unit_face_vertices(&self,face:TreyMeshFace) -> [glam::Vec3;4] {
|
||||
Aabb::unit_face_vertices(face)
|
||||
}
|
||||
pub fn face_mesh(&self,face:TreyMeshFace) -> TreyMesh {
|
||||
let mut aabb=self.mesh();
|
||||
//in this implementation face = worldspace aabb face
|
||||
match face {
|
||||
AabbFace::Right => aabb.min.x=aabb.max.x,
|
||||
AabbFace::Top => aabb.min.y=aabb.max.y,
|
||||
AabbFace::Back => aabb.min.z=aabb.max.z,
|
||||
AabbFace::Left => aabb.max.x=aabb.min.x,
|
||||
AabbFace::Bottom => aabb.max.y=aabb.min.y,
|
||||
AabbFace::Front => aabb.max.z=aabb.min.z,
|
||||
}
|
||||
return aabb;
|
||||
}
|
||||
pub fn face_normal(&self,face:TreyMeshFace) -> glam::Vec3 {
|
||||
glam::Vec4Swizzles::xyz(Aabb::normal(face).extend(0.0))//this is wrong for scale
|
||||
}
|
||||
}
|
||||
|
||||
//need non-face (full model) variant for CanCollide false objects
|
||||
//OR have a separate list from contacts for model intersection
|
||||
#[derive(Debug,Clone,Eq,Hash,PartialEq)]
|
||||
pub struct RelativeCollision {
|
||||
face: TreyMeshFace,//just an id
|
||||
model: u32,//using id to avoid lifetimes
|
||||
}
|
||||
|
||||
impl RelativeCollision {
|
||||
pub fn mesh(&self,models:&Vec<Model>) -> TreyMesh {
|
||||
return models.get(self.model as usize).unwrap().face_mesh(self.face)
|
||||
}
|
||||
pub fn normal(&self,models:&Vec<Model>) -> glam::Vec3 {
|
||||
return models.get(self.model as usize).unwrap().face_normal(self.face)
|
||||
}
|
||||
}
|
||||
|
||||
pub type TIME = i64;
|
||||
|
||||
impl Body {
|
||||
pub fn with_pva(position:glam::Vec3,velocity:glam::Vec3,acceleration:glam::Vec3) -> Self {
|
||||
Self{
|
||||
position,
|
||||
velocity,
|
||||
acceleration,
|
||||
time: 0,
|
||||
}
|
||||
}
|
||||
pub fn extrapolated_position(&self,time: TIME)->glam::Vec3{
|
||||
let dt=(time-self.time) as f64/1_000_000_000f64;
|
||||
self.position+self.velocity*(dt as f32)+self.acceleration*((0.5*dt*dt) as f32)
|
||||
}
|
||||
pub fn extrapolated_velocity(&self,time: TIME)->glam::Vec3{
|
||||
let dt=(time-self.time) as f64/1_000_000_000f64;
|
||||
self.velocity+self.acceleration*(dt as f32)
|
||||
}
|
||||
pub fn advance_time(&mut self, time: TIME){
|
||||
self.position=self.extrapolated_position(time);
|
||||
self.velocity=self.extrapolated_velocity(time);
|
||||
self.time=time;
|
||||
}
|
||||
}
|
||||
|
||||
impl PhysicsState {
|
||||
//tickless gaming
|
||||
pub fn run(&mut self, time_limit:TIME){
|
||||
//prepare is ommitted - everything is done via instructions.
|
||||
while let Some(instruction) = self.next_instruction(time_limit) {//collect
|
||||
//advance
|
||||
//self.advance_time(instruction.time);
|
||||
//process
|
||||
self.process_instruction(instruction);
|
||||
//write hash lol
|
||||
}
|
||||
}
|
||||
|
||||
pub fn advance_time(&mut self, time: TIME){
|
||||
self.body.advance_time(time);
|
||||
self.time=time;
|
||||
}
|
||||
|
||||
fn contact_constrain_velocity(&self,velocity:&mut glam::Vec3){
|
||||
for contact in self.contacts.iter() {
|
||||
let n=contact.normal(&self.models_cringe_clone);
|
||||
let d=velocity.dot(n);
|
||||
if d<0f32{
|
||||
(*velocity)-=d/n.length_squared()*n;
|
||||
}
|
||||
}
|
||||
}
|
||||
fn contact_constrain_acceleration(&self,acceleration:&mut glam::Vec3){
|
||||
for contact in self.contacts.iter() {
|
||||
let n=contact.normal(&self.models_cringe_clone);
|
||||
let d=acceleration.dot(n);
|
||||
if d<0f32{
|
||||
(*acceleration)-=d/n.length_squared()*n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn next_strafe_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||
return Some(TimedInstruction{
|
||||
time:(self.time*self.strafe_tick_num/self.strafe_tick_den+1)*self.strafe_tick_den/self.strafe_tick_num,
|
||||
//only poll the physics if there is a before and after mouse event
|
||||
instruction:PhysicsInstruction::StrafeTick
|
||||
});
|
||||
}
|
||||
|
||||
//state mutated on collision:
|
||||
//Accelerator
|
||||
//stair step-up
|
||||
|
||||
//state mutated on instruction
|
||||
//change fly acceleration (fly_sustain)
|
||||
//change fly velocity
|
||||
|
||||
//generic event emmiters
|
||||
//PlatformStandTime
|
||||
//walk/swim/air/ladder sounds
|
||||
//VState?
|
||||
|
||||
//falling under the map
|
||||
// fn next_respawn_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||
// if self.body.position<self.world.min_y {
|
||||
// return Some(TimedInstruction{
|
||||
// time:self.time,
|
||||
// instruction:PhysicsInstruction::Trigger(None)
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn next_water_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||
// return Some(TimedInstruction{
|
||||
// time:(self.time*self.strafe_tick_num/self.strafe_tick_den+1)*self.strafe_tick_den/self.strafe_tick_num,
|
||||
// //only poll the physics if there is a before and after mouse event
|
||||
// instruction:PhysicsInstruction::Water
|
||||
// });
|
||||
// }
|
||||
|
||||
fn next_walk_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||
//check if you have a valid walk state and create an instruction
|
||||
if self.grounded{
|
||||
match self.walk.state{
|
||||
WalkEnum::Transient=>Some(TimedInstruction{
|
||||
time:self.walk.target_time,
|
||||
instruction:PhysicsInstruction::ReachWalkTargetVelocity
|
||||
}),
|
||||
WalkEnum::Invalid=>Some(TimedInstruction{
|
||||
time:self.time,
|
||||
instruction:PhysicsInstruction::RefreshWalkTarget,
|
||||
}),
|
||||
WalkEnum::Reached=>None,
|
||||
}
|
||||
}else{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
fn mesh(&self) -> TreyMesh {
|
||||
let mut aabb=Aabb::new();
|
||||
for vertex in Aabb::unit_vertices(){
|
||||
aabb.grow(self.body.position+self.hitbox_halfsize*vertex);
|
||||
}
|
||||
aabb
|
||||
}
|
||||
fn predict_collision_end(&self,time:TIME,time_limit:TIME,collision_data:&RelativeCollision) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||
//must treat cancollide false objects differently: you may not exit through the same face you entered.
|
||||
//RelativeCollsion must reference the full model instead of a particular face
|
||||
//this is Ctrl+C Ctrl+V of predict_collision_start but with v=-v before the calc and t=-t after the calc
|
||||
//find best t
|
||||
let mut best_time=time_limit;
|
||||
let mut exit_face:Option<TreyMeshFace>=None;
|
||||
let mesh0=self.mesh();
|
||||
let mesh1=self.models_cringe_clone.get(collision_data.model as usize).unwrap().mesh();
|
||||
let (v,a)=(-self.body.velocity,self.body.acceleration);
|
||||
//collect x
|
||||
match collision_data.face {
|
||||
AabbFace::Top|AabbFace::Back|AabbFace::Bottom|AabbFace::Front=>{
|
||||
for t in zeroes2(mesh0.max.x-mesh1.min.x,v.x,0.5*a.x) {
|
||||
//negative t = back in time
|
||||
//must be moving towards surface to collide
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&0f32<v.x+a.x*-t{
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
exit_face=Some(TreyMeshFace::Left);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for t in zeroes2(mesh0.min.x-mesh1.max.x,v.x,0.5*a.x) {
|
||||
//negative t = back in time
|
||||
//must be moving towards surface to collide
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&v.x+a.x*-t<0f32{
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
exit_face=Some(TreyMeshFace::Right);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
AabbFace::Left=>{
|
||||
//generate event if v.x<0||a.x<0
|
||||
if -v.x<0f32{
|
||||
best_time=time;
|
||||
exit_face=Some(TreyMeshFace::Left);
|
||||
}
|
||||
},
|
||||
AabbFace::Right=>{
|
||||
//generate event if 0<v.x||0<a.x
|
||||
if 0f32<(-v.x){
|
||||
best_time=time;
|
||||
exit_face=Some(TreyMeshFace::Right);
|
||||
}
|
||||
},
|
||||
}
|
||||
//collect y
|
||||
match collision_data.face {
|
||||
AabbFace::Left|AabbFace::Back|AabbFace::Right|AabbFace::Front=>{
|
||||
for t in zeroes2(mesh0.max.y-mesh1.min.y,v.y,0.5*a.y) {
|
||||
//negative t = back in time
|
||||
//must be moving towards surface to collide
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&0f32<v.y+a.y*-t{
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
exit_face=Some(TreyMeshFace::Bottom);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for t in zeroes2(mesh0.min.y-mesh1.max.y,v.y,0.5*a.y) {
|
||||
//negative t = back in time
|
||||
//must be moving towards surface to collide
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&v.y+a.y*-t<0f32{
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
exit_face=Some(TreyMeshFace::Top);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
AabbFace::Bottom=>{
|
||||
//generate event if v.y<0||a.y<0
|
||||
if -v.y<0f32{
|
||||
best_time=time;
|
||||
exit_face=Some(TreyMeshFace::Bottom);
|
||||
}
|
||||
},
|
||||
AabbFace::Top=>{
|
||||
//generate event if 0<v.y||0<a.y
|
||||
if 0f32<(-v.y){
|
||||
best_time=time;
|
||||
exit_face=Some(TreyMeshFace::Top);
|
||||
}
|
||||
},
|
||||
}
|
||||
//collect z
|
||||
match collision_data.face {
|
||||
AabbFace::Left|AabbFace::Bottom|AabbFace::Right|AabbFace::Top=>{
|
||||
for t in zeroes2(mesh0.max.z-mesh1.min.z,v.z,0.5*a.z) {
|
||||
//negative t = back in time
|
||||
//must be moving towards surface to collide
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&0f32<v.z+a.z*-t{
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
exit_face=Some(TreyMeshFace::Front);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for t in zeroes2(mesh0.min.z-mesh1.max.z,v.z,0.5*a.z) {
|
||||
//negative t = back in time
|
||||
//must be moving towards surface to collide
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&v.z+a.z*-t<0f32{
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
exit_face=Some(TreyMeshFace::Back);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
AabbFace::Front=>{
|
||||
//generate event if v.z<0||a.z<0
|
||||
if -v.z<0f32{
|
||||
best_time=time;
|
||||
exit_face=Some(TreyMeshFace::Front);
|
||||
}
|
||||
},
|
||||
AabbFace::Back=>{
|
||||
//generate event if 0<v.z||0<a.z
|
||||
if 0f32<(-v.z){
|
||||
best_time=time;
|
||||
exit_face=Some(TreyMeshFace::Back);
|
||||
}
|
||||
},
|
||||
}
|
||||
//generate instruction
|
||||
if let Some(face) = exit_face{
|
||||
return Some(TimedInstruction {
|
||||
time: best_time,
|
||||
instruction: PhysicsInstruction::CollisionEnd(collision_data.clone())
|
||||
})
|
||||
}
|
||||
None
|
||||
}
|
||||
fn predict_collision_start(&self,time:TIME,time_limit:TIME,model_id:u32) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||
//find best t
|
||||
let mut best_time=time_limit;
|
||||
let mut best_face:Option<TreyMeshFace>=None;
|
||||
let mesh0=self.mesh();
|
||||
let mesh1=self.models_cringe_clone.get(model_id as usize).unwrap().mesh();
|
||||
let (p,v,a)=(self.body.position,self.body.velocity,self.body.acceleration);
|
||||
//collect x
|
||||
for t in zeroes2(mesh0.max.x-mesh1.min.x,v.x,0.5*a.x) {
|
||||
//must collide now or in the future
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&0f32<v.x+a.x*t{
|
||||
let dp=self.body.extrapolated_position(t_time)-p;
|
||||
//faces must be overlapping
|
||||
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
best_face=Some(TreyMeshFace::Left);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for t in zeroes2(mesh0.min.x-mesh1.max.x,v.x,0.5*a.x) {
|
||||
//must collide now or in the future
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&v.x+a.x*t<0f32{
|
||||
let dp=self.body.extrapolated_position(t_time)-p;
|
||||
//faces must be overlapping
|
||||
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
best_face=Some(TreyMeshFace::Right);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//collect y
|
||||
for t in zeroes2(mesh0.max.y-mesh1.min.y,v.y,0.5*a.y) {
|
||||
//must collide now or in the future
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&0f32<v.y+a.y*t{
|
||||
let dp=self.body.extrapolated_position(t_time)-p;
|
||||
//faces must be overlapping
|
||||
if mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
best_face=Some(TreyMeshFace::Bottom);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for t in zeroes2(mesh0.min.y-mesh1.max.y,v.y,0.5*a.y) {
|
||||
//must collide now or in the future
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&v.y+a.y*t<0f32{
|
||||
let dp=self.body.extrapolated_position(t_time)-p;
|
||||
//faces must be overlapping
|
||||
if mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
best_face=Some(TreyMeshFace::Top);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//collect z
|
||||
for t in zeroes2(mesh0.max.z-mesh1.min.z,v.z,0.5*a.z) {
|
||||
//must collide now or in the future
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&0f32<v.z+a.z*t{
|
||||
let dp=self.body.extrapolated_position(t_time)-p;
|
||||
//faces must be overlapping
|
||||
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x {
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
best_face=Some(TreyMeshFace::Front);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for t in zeroes2(mesh0.min.z-mesh1.max.z,v.z,0.5*a.z) {
|
||||
//must collide now or in the future
|
||||
//must beat the current soonest collision time
|
||||
//must be moving towards surface
|
||||
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||
if time<=t_time&&t_time<best_time&&v.z+a.z*t<0f32{
|
||||
let dp=self.body.extrapolated_position(t_time)-p;
|
||||
//faces must be overlapping
|
||||
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x {
|
||||
//collect valid t
|
||||
best_time=t_time;
|
||||
best_face=Some(TreyMeshFace::Back);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//generate instruction
|
||||
if let Some(face) = best_face{
|
||||
return Some(TimedInstruction {
|
||||
time: best_time,
|
||||
instruction: PhysicsInstruction::CollisionStart(RelativeCollision {
|
||||
face,
|
||||
model: model_id
|
||||
})
|
||||
})
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState {
|
||||
//this little next instruction function can cache its return value and invalidate the cached value by watching the State.
|
||||
fn next_instruction(&self,time_limit:TIME) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||
//JUST POLLING!!! NO MUTATION
|
||||
let mut collector = crate::instruction::InstructionCollector::new(time_limit);
|
||||
//check for collision stop instructions with curent contacts
|
||||
for collision_data in self.contacts.iter() {
|
||||
collector.collect(self.predict_collision_end(self.time,time_limit,collision_data));
|
||||
}
|
||||
//check for collision start instructions (against every part in the game with no optimization!!)
|
||||
for i in 0..self.models_cringe_clone.len() {
|
||||
collector.collect(self.predict_collision_start(self.time,time_limit,i as u32));
|
||||
}
|
||||
if self.grounded {
|
||||
//walk maintenance
|
||||
collector.collect(self.next_walk_instruction());
|
||||
}else{
|
||||
//check to see when the next strafe tick is
|
||||
collector.collect(self.next_strafe_instruction());
|
||||
}
|
||||
collector.instruction()
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsState {
|
||||
fn process_instruction(&mut self, ins:TimedInstruction<PhysicsInstruction>) {
|
||||
match &ins.instruction {
|
||||
PhysicsInstruction::StrafeTick => (),
|
||||
_=>println!("{:?}",ins),
|
||||
}
|
||||
//selectively update body
|
||||
match &ins.instruction {
|
||||
PhysicsInstruction::SetWalkTargetVelocity(_)
|
||||
|PhysicsInstruction::SetControlDir(_) => self.time=ins.time,//TODO: queue instructions
|
||||
PhysicsInstruction::RefreshWalkTarget
|
||||
|PhysicsInstruction::ReachWalkTargetVelocity
|
||||
|PhysicsInstruction::CollisionStart(_)
|
||||
|PhysicsInstruction::CollisionEnd(_)
|
||||
|PhysicsInstruction::StrafeTick
|
||||
|PhysicsInstruction::Jump => self.advance_time(ins.time),
|
||||
}
|
||||
match ins.instruction {
|
||||
PhysicsInstruction::CollisionStart(c) => {
|
||||
//check ground
|
||||
match &c.face {
|
||||
AabbFace::Top => {
|
||||
//ground
|
||||
self.grounded=true;
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
self.contacts.insert(c);
|
||||
//flatten v
|
||||
let mut v=self.body.velocity;
|
||||
self.contact_constrain_velocity(&mut v);
|
||||
self.body.velocity=v;
|
||||
self.walk.state=WalkEnum::Invalid;
|
||||
},
|
||||
PhysicsInstruction::CollisionEnd(c) => {
|
||||
self.contacts.remove(&c);//remove contact before calling contact_constrain_acceleration
|
||||
let mut a=self.gravity;
|
||||
self.contact_constrain_acceleration(&mut a);
|
||||
self.body.acceleration=a;
|
||||
self.walk.state=WalkEnum::Invalid;
|
||||
//check ground
|
||||
match &c.face {
|
||||
AabbFace::Top => {
|
||||
self.grounded=false;
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
},
|
||||
PhysicsInstruction::SetControlDir(control_dir)=>{
|
||||
self.temp_control_dir=control_dir;
|
||||
self.walk.state=WalkEnum::Invalid;
|
||||
},
|
||||
PhysicsInstruction::StrafeTick => {
|
||||
//let control_dir=self.get_control_dir();//this should respect your mouse interpolation settings
|
||||
let d=self.body.velocity.dot(self.temp_control_dir);
|
||||
if d<self.mv {
|
||||
let mut v=self.body.velocity+(self.mv-d)*self.temp_control_dir;
|
||||
self.contact_constrain_velocity(&mut v);
|
||||
self.body.velocity=v;
|
||||
}
|
||||
}
|
||||
PhysicsInstruction::Jump => {
|
||||
self.grounded=false;//do I need this?
|
||||
let mut v=self.body.velocity+glam::Vec3::new(0.0,0.715588/2.0*100.0,0.0);
|
||||
self.contact_constrain_velocity(&mut v);
|
||||
self.body.velocity=v;
|
||||
self.walk.state=WalkEnum::Invalid;
|
||||
},
|
||||
PhysicsInstruction::ReachWalkTargetVelocity => {
|
||||
//precisely set velocity
|
||||
let mut a=glam::Vec3::ZERO;
|
||||
self.contact_constrain_acceleration(&mut a);
|
||||
self.body.acceleration=a;
|
||||
let mut v=self.walk.target_velocity;
|
||||
self.contact_constrain_velocity(&mut v);
|
||||
self.body.velocity=v;
|
||||
self.walk.state=WalkEnum::Reached;
|
||||
},
|
||||
PhysicsInstruction::RefreshWalkTarget => {
|
||||
//calculate acceleration yada yada
|
||||
if self.grounded{
|
||||
let mut v=self.walk.target_velocity;
|
||||
self.contact_constrain_velocity(&mut v);
|
||||
let mut target_diff=v-self.body.velocity;
|
||||
target_diff.y=0f32;
|
||||
if target_diff==glam::Vec3::ZERO{
|
||||
let mut a=glam::Vec3::ZERO;
|
||||
self.contact_constrain_acceleration(&mut a);
|
||||
self.body.acceleration=a;
|
||||
self.walk.state=WalkEnum::Reached;
|
||||
}else{
|
||||
let accel=self.walk_accel.min(self.gravity.length()*self.friction);
|
||||
let time_delta=target_diff.length()/accel;
|
||||
let mut a=target_diff/time_delta;
|
||||
self.contact_constrain_acceleration(&mut a);
|
||||
self.body.acceleration=a;
|
||||
self.walk.target_time=self.body.time+((time_delta as f64)*1_000_000_000f64) as TIME;
|
||||
self.walk.state=WalkEnum::Transient;
|
||||
}
|
||||
}
|
||||
},
|
||||
PhysicsInstruction::SetWalkTargetVelocity(v) => {
|
||||
self.walk.target_velocity=v;
|
||||
self.walk.state=WalkEnum::Invalid;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
@ -279,11 +279,6 @@ fn start<E: Example>(
|
||||
log::info!("Initializing the example...");
|
||||
let mut example = E::init(&config, &adapter, &device, &queue);
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let mut last_frame_inst = Instant::now();
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let (mut frame_count, mut accum_time) = (0, 0.0);
|
||||
|
||||
log::info!("Entering render loop...");
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
let _ = (&instance, &adapter); // force ownership by the closure
|
||||
@ -364,20 +359,6 @@ fn start<E: Example>(
|
||||
example.move_mouse(delta);
|
||||
},
|
||||
event::Event::RedrawRequested(_) => {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
accum_time += last_frame_inst.elapsed().as_secs_f32();
|
||||
last_frame_inst = Instant::now();
|
||||
frame_count += 1;
|
||||
if frame_count == 100 {
|
||||
println!(
|
||||
"Avg frame time {}ms",
|
||||
accum_time * 1000.0 / frame_count as f32
|
||||
);
|
||||
accum_time = 0.0;
|
||||
frame_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
let frame = match surface.get_current_texture() {
|
||||
Ok(frame) => frame,
|
||||
|
48
src/instruction.rs
Normal file
48
src/instruction.rs
Normal file
@ -0,0 +1,48 @@
|
||||
#[derive(Debug)]
|
||||
pub struct TimedInstruction<I> {
|
||||
pub time: crate::body::TIME,
|
||||
pub instruction: I,
|
||||
}
|
||||
|
||||
pub trait InstructionEmitter<I> {
|
||||
fn next_instruction(&self, time_limit:crate::body::TIME) -> Option<TimedInstruction<I>>;
|
||||
}
|
||||
pub trait InstructionConsumer<I> {
|
||||
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
|
||||
}
|
||||
|
||||
//PROPER PRIVATE FIELDS!!!
|
||||
pub struct InstructionCollector<I> {
|
||||
time: crate::body::TIME,
|
||||
instruction: Option<I>,
|
||||
}
|
||||
impl<I> InstructionCollector<I> {
|
||||
pub fn new(time:crate::body::TIME) -> Self {
|
||||
Self{
|
||||
time,
|
||||
instruction:None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
|
||||
match instruction {
|
||||
Some(unwrap_instruction) => {
|
||||
if unwrap_instruction.time<self.time {
|
||||
self.time=unwrap_instruction.time;
|
||||
self.instruction=Some(unwrap_instruction.instruction);
|
||||
}
|
||||
},
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
pub fn instruction(self) -> Option<TimedInstruction<I>> {
|
||||
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
|
||||
match self.instruction {
|
||||
Some(instruction)=>Some(TimedInstruction{
|
||||
time:self.time,
|
||||
instruction
|
||||
}),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +1,5 @@
|
||||
pub mod framework;
|
||||
pub mod body;
|
||||
pub mod zeroes;
|
||||
pub mod instruction;
|
||||
pub mod load_roblox;
|
||||
|
28
src/load_roblox.rs
Normal file
28
src/load_roblox.rs
Normal file
@ -0,0 +1,28 @@
|
||||
fn class_is_a(class: &str, superclass: &str) -> bool {
|
||||
if class==superclass {
|
||||
return true
|
||||
}
|
||||
let class_descriptor=rbx_reflection_database::get().classes.get(class);
|
||||
if let Some(descriptor) = &class_descriptor {
|
||||
if let Some(class_super) = &descriptor.superclass {
|
||||
return class_is_a(&class_super, superclass)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
pub fn get_objects(buf_thing: std::io::BufReader<&[u8]>, superclass: &str) -> Result<std::vec::Vec<rbx_dom_weak::Instance>, Box<dyn std::error::Error>> {
|
||||
// Using buffered I/O is recommended with rbx_binary
|
||||
let dom = rbx_binary::from_reader(buf_thing)?;
|
||||
|
||||
let mut objects = std::vec::Vec::<rbx_dom_weak::Instance>::new();
|
||||
//move matching instances into objects
|
||||
let (_,mut instances) = dom.into_raw();
|
||||
for (_,instance) in instances.drain() {
|
||||
if class_is_a(instance.class.as_str(), superclass) {
|
||||
objects.push(instance);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(objects)
|
||||
}
|
296
src/main.rs
296
src/main.rs
@ -24,7 +24,7 @@ struct ModelData {
|
||||
entities: Vec<Entity>,
|
||||
}
|
||||
|
||||
struct Model {
|
||||
struct ModelGraphics {
|
||||
transform: glam::Mat4,
|
||||
vertex_buf: wgpu::Buffer,
|
||||
entities: Vec<Entity>,
|
||||
@ -34,20 +34,12 @@ struct Model {
|
||||
|
||||
// Note: we use the Y=up coordinate space in this example.
|
||||
struct Camera {
|
||||
time: Instant,
|
||||
pos: glam::Vec3,
|
||||
vel: glam::Vec3,
|
||||
gravity: glam::Vec3,
|
||||
friction: f32,
|
||||
screen_size: (u32, u32),
|
||||
offset: glam::Vec3,
|
||||
fov: f32,
|
||||
yaw: f32,
|
||||
pitch: f32,
|
||||
controls: u32,
|
||||
mv: f32,
|
||||
grounded: bool,
|
||||
walkspeed: f32,
|
||||
}
|
||||
|
||||
const CONTROL_MOVEFORWARD:u32 = 0b00000001;
|
||||
@ -100,7 +92,7 @@ fn get_control_dir(controls: u32) -> glam::Vec3{
|
||||
}
|
||||
|
||||
impl Camera {
|
||||
fn to_uniform_data(&self) -> [f32; 16 * 3 + 4] {
|
||||
fn to_uniform_data(&self, pos: glam::Vec3) -> [f32; 16 * 3 + 4] {
|
||||
let aspect = self.screen_size.0 as f32 / self.screen_size.1 as f32;
|
||||
let fov = if self.controls&CONTROL_ZOOM==0 {
|
||||
self.fov
|
||||
@ -109,7 +101,7 @@ impl Camera {
|
||||
};
|
||||
let proj = perspective_rh(fov, aspect, 0.5, 1000.0);
|
||||
let proj_inv = proj.inverse();
|
||||
let view = glam::Mat4::from_translation(self.pos+self.offset) * glam::Mat4::from_euler(glam::EulerRot::YXZ, self.yaw, self.pitch, 0f32);
|
||||
let view = glam::Mat4::from_translation(pos+self.offset) * glam::Mat4::from_euler(glam::EulerRot::YXZ, self.yaw, self.pitch, 0f32);
|
||||
let view_inv = view.inverse();
|
||||
|
||||
let mut raw = [0f32; 16 * 3 + 4];
|
||||
@ -122,13 +114,15 @@ impl Camera {
|
||||
}
|
||||
|
||||
pub struct Skybox {
|
||||
start_time: std::time::Instant,
|
||||
camera: Camera,
|
||||
physics: strafe_client::body::PhysicsState,
|
||||
sky_pipeline: wgpu::RenderPipeline,
|
||||
entity_pipeline: wgpu::RenderPipeline,
|
||||
ground_pipeline: wgpu::RenderPipeline,
|
||||
main_bind_group: wgpu::BindGroup,
|
||||
camera_buf: wgpu::Buffer,
|
||||
models: Vec<Model>,
|
||||
models: Vec<ModelGraphics>,
|
||||
depth_view: wgpu::TextureView,
|
||||
staging_belt: wgpu::util::StagingBelt,
|
||||
}
|
||||
@ -178,7 +172,7 @@ fn add_obj(device:&wgpu::Device,modeldatas:& mut Vec<ModelData>,source:&[u8]){
|
||||
for &index in &[0, end_index - 1, end_index] {
|
||||
let vert = poly.0[index];
|
||||
if let Some(&i)=vertex_index.get(&vert){
|
||||
indices.push(i as u16);
|
||||
indices.push(i);
|
||||
}else{
|
||||
let i=vertices.len() as u16;
|
||||
vertices.push(Vertex {
|
||||
@ -236,6 +230,131 @@ impl strafe_client::framework::Example for Skybox {
|
||||
modeldatas[1].transform=glam::Mat4::from_translation(glam::vec3(10.,5.,10.));
|
||||
modeldatas[2].transform=glam::Mat4::from_translation(glam::vec3(-10.,5.,10.));
|
||||
|
||||
let input = std::io::BufReader::new(&include_bytes!("../maps/bhop_easyhop.rbxm")[..]);
|
||||
match strafe_client::load_roblox::get_objects(input, "BasePart") {
|
||||
Ok(objects)=>{
|
||||
for object in objects.iter() {
|
||||
if let (
|
||||
Some(rbx_dom_weak::types::Variant::CFrame(cf)),
|
||||
Some(rbx_dom_weak::types::Variant::Vector3(size)),
|
||||
Some(rbx_dom_weak::types::Variant::Float32(transparency)),
|
||||
) = (
|
||||
object.properties.get("CFrame"),
|
||||
object.properties.get("Size"),
|
||||
object.properties.get("Transparency"),
|
||||
)
|
||||
{
|
||||
if *transparency==1.0 {
|
||||
continue;
|
||||
}
|
||||
//simply draw a box
|
||||
let face_data = [
|
||||
[0.0f32, 0., 1.],
|
||||
[0.0f32, 0., -1.],
|
||||
[1.0f32, 0., 0.],
|
||||
[-1.0f32, 0., 0.],
|
||||
[0.0f32, 1., 0.],
|
||||
[0.0f32, -1., 0.],
|
||||
];
|
||||
let texture_data = [
|
||||
[1.0f32, 0.],
|
||||
[0.0f32, 0.],
|
||||
[0.0f32, 1.],
|
||||
[1.0f32, 1.],
|
||||
];
|
||||
let vertex_data = [
|
||||
// top (0, 0, 1)
|
||||
[-1.0f32, -1., 1.],
|
||||
[1.0f32, -1., 1.],
|
||||
[1.0f32, 1., 1.],
|
||||
[-1.0f32, 1., 1.],
|
||||
// bottom (0, 0, -1)
|
||||
[-1.0f32, 1., -1.],
|
||||
[1.0f32, 1., -1.],
|
||||
[1.0f32, -1., -1.],
|
||||
[-1.0f32, -1., -1.],
|
||||
// right (1, 0, 0)
|
||||
[1.0f32, -1., -1.],
|
||||
[1.0f32, 1., -1.],
|
||||
[1.0f32, 1., 1.],
|
||||
[1.0f32, -1., 1.],
|
||||
// left (-1, 0, 0)
|
||||
[-1.0f32, -1., 1.],
|
||||
[-1.0f32, 1., 1.],
|
||||
[-1.0f32, 1., -1.],
|
||||
[-1.0f32, -1., -1.],
|
||||
// front (0, 1, 0)
|
||||
[1.0f32, 1., -1.],
|
||||
[-1.0f32, 1., -1.],
|
||||
[-1.0f32, 1., 1.],
|
||||
[1.0f32, 1., 1.],
|
||||
// back (0, -1, 0)
|
||||
[1.0f32, -1., 1.],
|
||||
[-1.0f32, -1., 1.],
|
||||
[-1.0f32, -1., -1.],
|
||||
[1.0f32, -1., -1.],
|
||||
];
|
||||
let mut indices = Vec::new();
|
||||
let mut vertices = Vec::new();
|
||||
let mut vertex_index = std::collections::HashMap::<usize,u16>::new();
|
||||
for face in 0..6 {
|
||||
for end_index in 2..4 {
|
||||
for &index in &[0, end_index - 1, end_index] {
|
||||
let vert = face*4+index;
|
||||
let unique_id=(vert * 1<<0) + (index * 1<<8) + (face * 1<<16);
|
||||
if let Some(&i)=vertex_index.get(&unique_id){
|
||||
indices.push(i);
|
||||
}else{
|
||||
let i=vertices.len() as u16;
|
||||
vertices.push(Vertex {
|
||||
pos: vertex_data[vert],
|
||||
texture: texture_data[index],
|
||||
normal: face_data[face],
|
||||
});
|
||||
vertex_index.insert(unique_id,i);
|
||||
indices.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Index"),
|
||||
contents: bytemuck::cast_slice(&indices),
|
||||
usage: wgpu::BufferUsages::INDEX,
|
||||
});
|
||||
let mut entities = Vec::<Entity>::new();
|
||||
entities.push(Entity {
|
||||
index_buf,
|
||||
index_count: indices.len() as u32,
|
||||
});
|
||||
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Vertex"),
|
||||
contents: bytemuck::cast_slice(&vertices),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
modeldatas.push(ModelData {
|
||||
transform: glam::Mat4::from_translation(
|
||||
glam::Vec3::new(cf.position.x,cf.position.y,cf.position.z)
|
||||
)
|
||||
* glam::Mat4::from_mat3(
|
||||
glam::Mat3::from_cols(
|
||||
glam::Vec3::new(cf.orientation.x.x,cf.orientation.y.x,cf.orientation.z.x),
|
||||
glam::Vec3::new(cf.orientation.x.y,cf.orientation.y.y,cf.orientation.z.y),
|
||||
glam::Vec3::new(cf.orientation.x.z,cf.orientation.y.z,cf.orientation.z.z),
|
||||
),
|
||||
)
|
||||
* glam::Mat4::from_scale(
|
||||
glam::Vec3::new(size.x,size.y,size.z)/2.0
|
||||
),
|
||||
vertex_buf,
|
||||
entities,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => println!("lmao err {:?}", e),
|
||||
}
|
||||
|
||||
let main_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
entries: &[
|
||||
@ -290,28 +409,69 @@ impl strafe_client::framework::Example for Skybox {
|
||||
});
|
||||
|
||||
let camera = Camera {
|
||||
time: Instant::now(),
|
||||
pos: glam::Vec3::new(5.0,0.0,5.0),
|
||||
vel: glam::Vec3::new(0.0,0.0,0.0),
|
||||
gravity: glam::Vec3::new(0.0,-100.0,0.0),
|
||||
friction: 90.0,
|
||||
screen_size: (config.width, config.height),
|
||||
offset: glam::Vec3::new(0.0,4.5,0.0),
|
||||
offset: glam::Vec3::new(0.0,4.5-2.5,0.0),
|
||||
fov: 1.0, //fov_slope = tan(fov_y/2)
|
||||
pitch: 0.0,
|
||||
yaw: 0.0,
|
||||
mv: 2.7,
|
||||
controls:0,
|
||||
grounded: true,
|
||||
walkspeed: 18.0,
|
||||
};
|
||||
let camera_uniforms = camera.to_uniform_data();
|
||||
let physics = strafe_client::body::PhysicsState {
|
||||
body: strafe_client::body::Body::with_pva(glam::vec3(0.0,50.0,0.0),glam::vec3(0.0,0.0,0.0),glam::vec3(0.0,-100.0,0.0)),
|
||||
time: 0,
|
||||
tick: 0,
|
||||
strafe_tick_num: 100,//100t
|
||||
strafe_tick_den: 1_000_000_000,
|
||||
gravity: glam::vec3(0.0,-100.0,0.0),
|
||||
friction: 1.2,
|
||||
walk_accel: 90.0,
|
||||
mv: 2.7,
|
||||
grounded: false,
|
||||
jump_trying: false,
|
||||
temp_control_dir: glam::Vec3::ZERO,
|
||||
walkspeed: 18.0,
|
||||
contacts: std::collections::HashSet::new(),
|
||||
models_cringe_clone: modeldatas.iter().map(|m|strafe_client::body::Model::new(m.transform)).collect(),
|
||||
walk: strafe_client::body::WalkState::new(),
|
||||
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
||||
};
|
||||
|
||||
let camera_uniforms = camera.to_uniform_data(physics.body.extrapolated_position(0));
|
||||
let camera_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Camera"),
|
||||
contents: bytemuck::cast_slice(&camera_uniforms),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
|
||||
//drain the modeldata vec so entities can be /moved/ to models.entities
|
||||
let mut models = Vec::<ModelGraphics>::with_capacity(modeldatas.len());
|
||||
for (i,modeldata) in modeldatas.drain(..).enumerate() {
|
||||
let model_uniforms = get_transform_uniform_data(&modeldata.transform);
|
||||
let model_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||
contents: bytemuck::cast_slice(&model_uniforms),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
let model_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &model_bind_group_layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: model_buf.as_entire_binding(),
|
||||
},
|
||||
],
|
||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||
});
|
||||
//all of these are being moved here
|
||||
models.push(ModelGraphics{
|
||||
transform: modeldata.transform,
|
||||
vertex_buf:modeldata.vertex_buf,
|
||||
entities: modeldata.entities,
|
||||
bind_group: model_bind_group,
|
||||
model_buf,
|
||||
})
|
||||
}
|
||||
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: None,
|
||||
bind_group_layouts: &[&main_bind_group_layout, &model_bind_group_layout],
|
||||
@ -507,39 +667,12 @@ impl strafe_client::framework::Example for Skybox {
|
||||
label: Some("Camera"),
|
||||
});
|
||||
|
||||
//drain the modeldata vec so entities can be /moved/ to models.entities
|
||||
let mut models = Vec::<Model>::with_capacity(modeldatas.len());
|
||||
for (i,modeldata) in modeldatas.drain(..).enumerate() {
|
||||
let model_uniforms = get_transform_uniform_data(&modeldata.transform);
|
||||
let model_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some(format!("Model{}",i).as_str()),
|
||||
contents: bytemuck::cast_slice(&model_uniforms),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
let model_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &model_bind_group_layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: model_buf.as_entire_binding(),
|
||||
},
|
||||
],
|
||||
label: Some(format!("Model{}",i).as_str()),
|
||||
});
|
||||
//all of these are being moved here
|
||||
models.push(Model{
|
||||
transform: modeldata.transform,
|
||||
vertex_buf:modeldata.vertex_buf,
|
||||
entities: modeldata.entities,
|
||||
bind_group: model_bind_group,
|
||||
model_buf,
|
||||
})
|
||||
}
|
||||
|
||||
let depth_view = Self::create_depth_texture(config, device);
|
||||
|
||||
Skybox {
|
||||
start_time: Instant::now(),
|
||||
camera,
|
||||
physics,
|
||||
sky_pipeline,
|
||||
entity_pipeline,
|
||||
ground_pipeline,
|
||||
@ -625,44 +758,45 @@ impl strafe_client::framework::Example for Skybox {
|
||||
queue: &wgpu::Queue,
|
||||
_spawner: &strafe_client::framework::Spawner,
|
||||
) {
|
||||
let time = Instant::now();
|
||||
|
||||
//physique
|
||||
let dt=(time-self.camera.time).as_secs_f32();
|
||||
self.camera.time=time;
|
||||
let camera_mat=glam::Mat3::from_euler(glam::EulerRot::YXZ,self.camera.yaw,0f32,0f32);
|
||||
let camera_mat=glam::Mat3::from_rotation_y(self.camera.yaw);
|
||||
let control_dir=camera_mat*get_control_dir(self.camera.controls&(CONTROL_MOVELEFT|CONTROL_MOVERIGHT|CONTROL_MOVEFORWARD|CONTROL_MOVEBACK)).normalize_or_zero();
|
||||
let d=self.camera.vel.dot(control_dir);
|
||||
if d<self.camera.mv {
|
||||
self.camera.vel+=(self.camera.mv-d)*control_dir;
|
||||
|
||||
let time=self.start_time.elapsed().as_nanos() as i64;
|
||||
|
||||
self.physics.run(time);
|
||||
|
||||
//ALL OF THIS IS TOTALLY WRONG!!!
|
||||
let walk_target_velocity=self.physics.walkspeed*control_dir;
|
||||
//autohop (already pressing spacebar; the signal to begin trying to jump is different)
|
||||
if self.physics.grounded&&walk_target_velocity!=self.physics.walk.target_velocity {
|
||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
||||
time,
|
||||
instruction:strafe_client::body::PhysicsInstruction::SetWalkTargetVelocity(walk_target_velocity)
|
||||
});
|
||||
}
|
||||
self.camera.vel+=self.camera.gravity*dt;
|
||||
self.camera.pos+=self.camera.vel*dt;
|
||||
if self.camera.pos.y<0.0{
|
||||
self.camera.pos.y=0.0;
|
||||
self.camera.vel.y=0.0;
|
||||
self.camera.grounded=true;
|
||||
|
||||
if control_dir!=self.physics.temp_control_dir {
|
||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
||||
time,
|
||||
instruction:strafe_client::body::PhysicsInstruction::SetControlDir(control_dir)
|
||||
});
|
||||
}
|
||||
if self.camera.grounded&&(self.camera.controls&CONTROL_JUMP)!=0 {
|
||||
self.camera.grounded=false;
|
||||
self.camera.vel+=glam::Vec3::new(0.0,0.715588/2.0*100.0,0.0);
|
||||
}
|
||||
if self.camera.grounded {
|
||||
let applied_friction=self.camera.friction*dt;
|
||||
let targetv=control_dir*self.camera.walkspeed;
|
||||
let diffv=targetv-self.camera.vel;
|
||||
if applied_friction*applied_friction<diffv.length_squared() {
|
||||
self.camera.vel+=applied_friction*diffv.normalize();
|
||||
} else {
|
||||
self.camera.vel=targetv;
|
||||
}
|
||||
|
||||
self.physics.jump_trying=self.camera.controls&CONTROL_JUMP!=0;
|
||||
//autohop (already pressing spacebar; the signal to begin trying to jump is different)
|
||||
if self.physics.grounded&&self.physics.jump_trying {
|
||||
//scroll will be implemented with InputInstruction::Jump(true) but it blocks setting self.jump_trying=true
|
||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
||||
time,
|
||||
instruction:strafe_client::body::PhysicsInstruction::Jump
|
||||
});
|
||||
}
|
||||
|
||||
let mut encoder =
|
||||
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||
|
||||
// update rotation
|
||||
let camera_uniforms = self.camera.to_uniform_data();
|
||||
let camera_uniforms = self.camera.to_uniform_data(self.physics.body.extrapolated_position(time));
|
||||
self.staging_belt
|
||||
.write_buffer(
|
||||
&mut encoder,
|
||||
|
8
src/sweep.rs
Normal file
8
src/sweep.rs
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
//something that implements body + hitbox + transform can predict collision
|
||||
impl crate::sweep::PredictCollision for Model {
|
||||
fn predict_collision(&self,other:&Model) -> Option<crate::event::EventStruct> {
|
||||
//math!
|
||||
None
|
||||
}
|
||||
}
|
27
src/zeroes.rs
Normal file
27
src/zeroes.rs
Normal file
@ -0,0 +1,27 @@
|
||||
//find roots of polynomials
|
||||
pub fn zeroes2(a0:f32,a1:f32,a2:f32) -> Vec<f32>{
|
||||
if a2==0f32{
|
||||
return zeroes1(a0, a1);
|
||||
}
|
||||
let mut radicand=a1*a1-4f32*a2*a0;
|
||||
if 0f32<radicand {
|
||||
radicand=radicand.sqrt();
|
||||
if 0f32<a2 {
|
||||
return vec![(-a1-radicand)/(2f32*a2),(-a1+radicand)/(2f32*a2)];
|
||||
} else {
|
||||
return vec![(-a1+radicand)/(2f32*a2),(-a1-radicand)/(2f32*a2)];
|
||||
}
|
||||
} else if radicand==0f32 {
|
||||
return vec![-a1/(2f32*a2)];
|
||||
} else {
|
||||
return vec![];
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn zeroes1(a0:f32,a1:f32) -> Vec<f32> {
|
||||
if a1==0f32{
|
||||
return vec![];
|
||||
} else {
|
||||
return vec![-a0/a1];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user