diff --git a/Cargo.lock b/Cargo.lock index 82e0a33..bb75f3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,9 +100,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -253,12 +253,6 @@ version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9441c6b2fe128a7c2bf680a44c34d0df31ce09e5b7e401fcca3faa483dbc921" -[[package]] -name = "atomic_refcell" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f2bfe491d41d45507b8431da8274f7feeca64a49e86d980eed2937ec2ff020" - [[package]] name = "autocfg" version = "1.1.0" @@ -395,7 +389,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -442,7 +436,7 @@ checksum = "a44e4e2784a81430199e4157e02903a987a32127c773985506f020e7d501b62e" dependencies = [ "bevy_macro_utils", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -490,14 +484,14 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] name = "bevy_egui" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a73a93a8cf6b8c744281d1b88f5b0fa278d608e909af9bbf4eb491a7cb1ad2c" +checksum = "fb1c1f6ad293c60fd8559c4502cda5e832e92b0e0f3d994929b33f24d4352d70" dependencies = [ "arboard", "bevy", @@ -544,7 +538,7 @@ dependencies = [ "bevy_eventlistener_core", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -665,7 +659,7 @@ checksum = "23ddc18d489b4e57832d4958cde7cd2f349f0ad91e5892ac9e2f2ee16546b981" dependencies = [ "quote", "rustc-hash", - "syn 2.0.37", + "syn 2.0.38", "toml_edit", ] @@ -802,7 +796,7 @@ dependencies = [ "bit-set", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "uuid", ] @@ -865,7 +859,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1034,7 +1028,7 @@ checksum = "5391b242c36f556db01d5891444730c83aa9dd648b6a8fd2b755d22cb3bddb57" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1176,14 +1170,14 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" @@ -1424,18 +1418,18 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "ecolor" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e479a7fa3f23d4e794f8b2f8b3568dd4e47886ad1b12c9c095e141cb591eb63" +checksum = "cfdf4e52dbbb615cfd30cf5a5265335c217b5fd8d669593cea74a517d9c605af" dependencies = [ "bytemuck", ] [[package]] name = "egui" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3aef8ec3ae1b772f340170c65bf27d5b8c28f543a0116c844d2ac08d01123e7" +checksum = "8bd69fed5fcf4fbb8225b24e80ea6193b61e17a625db105ef0c4d71dde6eb8b7" dependencies = [ "ahash", "epaint", @@ -1444,9 +1438,9 @@ dependencies = [ [[package]] name = "emath" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3857d743a6e0741cdd60b622a74c7a36ea75f5f8f11b793b41d905d2c9721a4b" +checksum = "1ef2b29de53074e575c18b694167ccbe6e5191f7b25fe65175a0d905a32eeec0" dependencies = [ "bytemuck", ] @@ -1480,18 +1474,17 @@ checksum = "3fe2568f851fd6144a45fa91cfed8fe5ca8fc0b56ba6797bfc1ed2771b90e37c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] name = "epaint" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09333964d4d57f40a85338ba3ca5ed4716070ab184dcfed966b35491c5c64f3b" +checksum = "58067b840d009143934d91d8dcb8ded054d8301d7c11a517ace0a99bb1e1595e" dependencies = [ "ab_glyph", "ahash", - "atomic_refcell", "bytemuck", "ecolor", "emath", @@ -1571,9 +1564,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -1904,9 +1897,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" dependencies = [ "libc", ] @@ -1954,9 +1947,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libloading" @@ -2231,9 +2224,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] @@ -2277,7 +2270,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -2487,9 +2480,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -2544,14 +2537,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.6" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" +checksum = "d119d7c7ca818f8a53c300863d4f87566aac09943aef5b355bb83969dae75d87" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.9", - "regex-syntax 0.7.5", + "regex-automata 0.4.1", + "regex-syntax 0.8.1", ] [[package]] @@ -2565,13 +2558,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.9" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" +checksum = "465c6fc0621e4abc4187a2bda0937bfd4f722c2730b29562e19689ea796c9a4b" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.5", + "regex-syntax 0.8.1", ] [[package]] @@ -2582,9 +2575,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.5" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +checksum = "56d84fdd47036b038fc80dd333d10b6aab10d5d31f4a366e20014def75328d33" [[package]] name = "renderdoc-sys" @@ -2594,7 +2587,7 @@ checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b" [[package]] name = "rlviser" -version = "0.3.5" +version = "0.4.0" dependencies = [ "bevy", "bevy_asset_loader", @@ -2688,22 +2681,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -2719,9 +2712,9 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b21f559e07218024e7e9f90f96f601825397de0e25420135f7f952453fed0b" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" dependencies = [ "lazy_static", ] @@ -2844,9 +2837,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -2869,9 +2862,9 @@ dependencies = [ [[package]] name = "taffy" -version = "0.3.14" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96ffc872aa6d5b1037b0daf795d7c16defaf2715f1f297475362ad9d30aefb7a" +checksum = "c488aa2bf4bb0cafed312e0876b79a591e3cfa47391f842b7198f9a56547561b" dependencies = [ "arrayvec", "grid", @@ -2925,7 +2918,7 @@ checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -3008,11 +3001,10 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "ee2ef2af84856a50c1d430afce2fdded0a4ec7eda868db86409b4543df0797f9" dependencies = [ - "cfg-if", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -3020,20 +3012,20 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable", @@ -3210,7 +3202,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-shared", ] @@ -3244,7 +3236,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3340,9 +3332,9 @@ dependencies = [ [[package]] name = "webbrowser" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2c79b77f525a2d670cb40619d7d9c673d09e0666f72c591ebd7861f84a87e57" +checksum = "82b2391658b02c27719fc5a0a73d6e696285138e8b12fba9d4baa70451023c71" dependencies = [ "core-foundation", "home", @@ -3718,9 +3710,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.5.15" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 1a6ae7b..8896182 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -version = "0.3.5" +version = "0.4.0" name = "rlviser" edition = "2021" publish = false @@ -9,7 +9,7 @@ publish = false [dependencies] bevy_asset_loader = "0.17.0" bevy_atmosphere = "0.7.0" -bevy_egui = "0.21.0" +bevy_egui = "0.22.0" bevy_eventlistener = "0.3.0" bevy_framepace = { version = "0.13.2", default-features = false } bevy_mod_picking = { version = "0.15.0", default-features = false, features = ["backend_raycast"]} diff --git a/src/assets.rs b/src/assets.rs index b34bb16..30a2fda 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -238,7 +238,7 @@ fn retreive_material(name: &str, asset_server: &AssetServer, base_color: Color) }; let props = format!("./assets/{pre_path}.props.txt"); - let Ok(props_file) = fs::read_to_string(&props) else { + let Ok(props_file) = fs::read_to_string(props) else { error!("Failed to read {path} ({name})"); return None; }; diff --git a/src/bytes.rs b/src/bytes.rs index d809696..a0f12ca 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -1,11 +1,8 @@ -use bevy::{ - math::{Mat3A as RotMat, Vec3A as Vec3}, - prelude::Quat, -}; +use bevy::math::{Mat3A as RotMat, Vec3A as Vec3}; use crate::rocketsim::{ - BallHitInfo, BallState, BoostPad, BoostPadState, CarConfig, CarControls, CarInfo, CarState, GameState, Team, - WheelPairConfig, + BallHitInfo, BallState, BoostPad, BoostPadState, CarConfig, CarControls, CarInfo, CarState, GameState, HeatseekerInfo, + Team, WheelPairConfig, }; trait ToBytesExact: FromBytesExact { @@ -36,12 +33,25 @@ impl ToBytesExact<{ Self::NUM_BYTES }> for RotMat { } } +impl ToBytesExact<{ Self::NUM_BYTES }> for HeatseekerInfo { + fn to_bytes(&self) -> [u8; Self::NUM_BYTES] { + let mut bytes = [0; Self::NUM_BYTES]; + bytes[..f32::NUM_BYTES].copy_from_slice(&self.y_target_dir.to_le_bytes()); + bytes[f32::NUM_BYTES..f32::NUM_BYTES * 2].copy_from_slice(&self.cur_target_speed.to_le_bytes()); + bytes[f32::NUM_BYTES * 2..].copy_from_slice(&self.time_since_hit.to_le_bytes()); + bytes + } +} + impl ToBytesExact<{ Self::NUM_BYTES }> for BallState { fn to_bytes(&self) -> [u8; Self::NUM_BYTES] { let mut bytes = [0; Self::NUM_BYTES]; bytes[..Vec3::NUM_BYTES].copy_from_slice(&self.pos.to_bytes()); - bytes[Vec3::NUM_BYTES..Vec3::NUM_BYTES * 2].copy_from_slice(&self.vel.to_bytes()); - bytes[Vec3::NUM_BYTES * 2..].copy_from_slice(&self.ang_vel.to_bytes()); + bytes[Vec3::NUM_BYTES + RotMat::NUM_BYTES..Vec3::NUM_BYTES * 2 + RotMat::NUM_BYTES] + .copy_from_slice(&self.vel.to_bytes()); + bytes[Vec3::NUM_BYTES * 2 + RotMat::NUM_BYTES..Vec3::NUM_BYTES * 3 + RotMat::NUM_BYTES] + .copy_from_slice(&self.ang_vel.to_bytes()); + bytes[Vec3::NUM_BYTES * 2 + RotMat::NUM_BYTES..].copy_from_slice(&self.hs_info.to_bytes()); bytes } } @@ -261,10 +271,6 @@ impl ToBytes for GameState { bytes.extend(&(self.pads.len() as u32).to_le_bytes()); bytes.extend(&(self.cars.len() as u32).to_le_bytes()); bytes.extend(self.ball.to_bytes()); - bytes.extend(self.ball_rot.x.to_le_bytes()); - bytes.extend(self.ball_rot.y.to_le_bytes()); - bytes.extend(self.ball_rot.z.to_le_bytes()); - bytes.extend(self.ball_rot.w.to_le_bytes()); bytes.extend(self.pads.iter().flat_map(ToBytesExact::<{ BoostPad::NUM_BYTES }>::to_bytes)); bytes.extend(self.cars.iter().flat_map(ToBytesExact::<{ CarInfo::NUM_BYTES }>::to_bytes)); @@ -330,15 +336,32 @@ impl FromBytesExact for RotMat { } } +impl FromBytesExact for HeatseekerInfo { + const NUM_BYTES: usize = f32::NUM_BYTES * 3; + + #[inline] + fn from_bytes(bytes: &[u8]) -> Self { + Self { + y_target_dir: f32::from_bytes(&bytes[..f32::NUM_BYTES]), + cur_target_speed: f32::from_bytes(&bytes[f32::NUM_BYTES..f32::NUM_BYTES * 2]), + time_since_hit: f32::from_bytes(&bytes[f32::NUM_BYTES * 2..]), + } + } +} + impl FromBytesExact for BallState { - const NUM_BYTES: usize = Vec3::NUM_BYTES * 3; + const NUM_BYTES: usize = Vec3::NUM_BYTES * 3 + RotMat::NUM_BYTES + HeatseekerInfo::NUM_BYTES; #[inline] fn from_bytes(bytes: &[u8]) -> Self { Self { pos: Vec3::from_bytes(&bytes[..Vec3::NUM_BYTES]), - vel: Vec3::from_bytes(&bytes[Vec3::NUM_BYTES..Vec3::NUM_BYTES * 2]), - ang_vel: Vec3::from_bytes(&bytes[Vec3::NUM_BYTES * 2..]), + rot_mat: RotMat::from_bytes(&bytes[Vec3::NUM_BYTES..Vec3::NUM_BYTES + RotMat::NUM_BYTES]), + vel: Vec3::from_bytes(&bytes[Vec3::NUM_BYTES + RotMat::NUM_BYTES..Vec3::NUM_BYTES * 2 + RotMat::NUM_BYTES]), + ang_vel: Vec3::from_bytes( + &bytes[Vec3::NUM_BYTES * 2 + RotMat::NUM_BYTES..Vec3::NUM_BYTES * 3 + RotMat::NUM_BYTES], + ), + hs_info: HeatseekerInfo::from_bytes(&bytes[Vec3::NUM_BYTES * 3 + RotMat::NUM_BYTES..]), } } } @@ -587,7 +610,6 @@ impl FromBytes for GameState { fn get_num_bytes(bytes: &[u8]) -> usize { Self::MIN_NUM_BYTES + BallState::NUM_BYTES - + f32::NUM_BYTES * 4 + Self::read_num_pads(bytes) * BoostPad::NUM_BYTES + Self::read_num_cars(bytes) * CarInfo::NUM_BYTES } @@ -618,36 +640,12 @@ impl FromBytes for GameState { tick_count: Self::read_tick_count(bytes), tick_rate: Self::read_tick_rate(bytes), ball: BallState::from_bytes(&bytes[Self::MIN_NUM_BYTES..Self::MIN_NUM_BYTES + BallState::NUM_BYTES]), - ball_rot: Quat::from_xyzw( - f32::from_bytes( - &bytes[Self::MIN_NUM_BYTES + BallState::NUM_BYTES - ..Self::MIN_NUM_BYTES + BallState::NUM_BYTES + f32::NUM_BYTES], - ), - f32::from_bytes( - &bytes[Self::MIN_NUM_BYTES + BallState::NUM_BYTES + f32::NUM_BYTES - ..Self::MIN_NUM_BYTES + BallState::NUM_BYTES + f32::NUM_BYTES * 2], - ), - f32::from_bytes( - &bytes[Self::MIN_NUM_BYTES + BallState::NUM_BYTES + f32::NUM_BYTES * 2 - ..Self::MIN_NUM_BYTES + BallState::NUM_BYTES + f32::NUM_BYTES * 3], - ), - f32::from_bytes( - &bytes[Self::MIN_NUM_BYTES + BallState::NUM_BYTES + f32::NUM_BYTES * 3 - ..Self::MIN_NUM_BYTES + BallState::NUM_BYTES + f32::NUM_BYTES * 4], - ), - ), - pads: bytes[Self::MIN_NUM_BYTES + BallState::NUM_BYTES + f32::NUM_BYTES * 4 - ..Self::MIN_NUM_BYTES - + BallState::NUM_BYTES - + f32::NUM_BYTES * 4 - + Self::read_num_pads(bytes) * BoostPad::NUM_BYTES] + pads: bytes[Self::MIN_NUM_BYTES + BallState::NUM_BYTES + ..Self::MIN_NUM_BYTES + BallState::NUM_BYTES + Self::read_num_pads(bytes) * BoostPad::NUM_BYTES] .chunks_exact(BoostPad::NUM_BYTES) .map(BoostPad::from_bytes) .collect(), - cars: bytes[Self::MIN_NUM_BYTES - + BallState::NUM_BYTES - + f32::NUM_BYTES * 4 - + Self::read_num_pads(bytes) * BoostPad::NUM_BYTES..] + cars: bytes[Self::MIN_NUM_BYTES + BallState::NUM_BYTES + Self::read_num_pads(bytes) * BoostPad::NUM_BYTES..] .chunks_exact(CarInfo::NUM_BYTES) .map(CarInfo::from_bytes) .collect(), diff --git a/src/gui.rs b/src/gui.rs index 0a6b4ee..9ed45b4 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -127,7 +127,7 @@ impl Default for Options { } impl Options { - const FILE_NAME: &str = "settings.txt"; + const FILE_NAME: &'static str = "settings.txt"; #[inline] fn default_read_file() -> Self { diff --git a/src/main.rs b/src/main.rs index a1c68f1..5ad8755 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![warn(clippy::all)] + mod assets; mod bytes; mod camera; diff --git a/src/rocketsim.rs b/src/rocketsim.rs index bb4ff59..95ba943 100644 --- a/src/rocketsim.rs +++ b/src/rocketsim.rs @@ -13,20 +13,44 @@ pub struct BallHitInfo { pub tick_count_when_extra_impulse_applied: u64, } +#[derive(Clone, Copy, Debug)] +pub struct HeatseekerInfo { + /// Which net the ball should seek towards; + /// When 0, no net + pub y_target_dir: f32, + pub cur_target_speed: f32, + pub time_since_hit: f32, +} + +impl Default for HeatseekerInfo { + #[inline] + fn default() -> Self { + Self { + y_target_dir: 0., + cur_target_speed: 2900., + time_since_hit: 0., + } + } +} + #[derive(Clone, Copy, Debug)] pub struct BallState { pub pos: Vec3, + pub rot_mat: RotMat, pub vel: Vec3, pub ang_vel: Vec3, + pub hs_info: HeatseekerInfo, } impl Default for BallState { #[inline] fn default() -> Self { Self { - pos: Vec3::new(0., 0., 92.), + pos: Vec3::new(0., 0., 93.15), + rot_mat: RotMat::IDENTITY, vel: Vec3::ZERO, ang_vel: Vec3::ZERO, + hs_info: HeatseekerInfo::default(), } } } @@ -129,7 +153,6 @@ pub struct GameState { pub tick_count: u64, pub tick_rate: f32, pub ball: BallState, - pub ball_rot: Quat, pub pads: Box<[BoostPad]>, pub cars: Box<[CarInfo]>, } diff --git a/src/udp.rs b/src/udp.rs index d3996de..4f5a6ef 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -98,22 +98,6 @@ impl ToBevyMat for Mat3A { } } -trait ToBevyQuat { - fn to_bevy(self) -> Quat; -} - -impl ToBevyQuat for Quat { - #[inline] - fn to_bevy(self) -> Quat { - // In RocketSim, the Z axis is up, but in Bevy, the Z and Y axis are swapped - // We also need to rotate 90 degrees around the X axis and 180 degrees around the Y axis - Self::from_axis_angle(Vec3::Y, PI) - * Self::from_axis_angle(Vec3::X, PI / 2.) - * self - * Self::from_mat3a(&Mat3A::from_cols(Vec3A::X, -Vec3A::Z, Vec3A::Y)) - } -} - const NUM_CAR_BODIES: usize = 6; const CAR_BODIES: [&str; NUM_CAR_BODIES] = [ @@ -409,7 +393,7 @@ fn update_ball( Color::rgb(0.5, 0.5, amount.max(0.5)) }; - transform.rotation = state.ball_rot.to_bevy(); + transform.rotation = state.ball.rot_mat.to_bevy(); } const MIN_DIST_FROM_BALL: f32 = 200.;