diff --git a/Cargo.lock b/Cargo.lock index fb9f9ce..674d23d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -509,7 +509,19 @@ checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.13.3+wasi-0.2.2", + "windows-targets 0.52.4", ] [[package]] @@ -643,23 +655,24 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.170" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" [[package]] name = "lighthouse-client" -version = "3.0.1" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27c65998e9183705cbf7d742ef40b1bd315aac704e651b01fc9fd1cd39d9036" +checksum = "ea076326c3e309733b8822750a1e91443f34dff7062969753340ad33fd10abc4" dependencies = [ "async-tungstenite", "futures", "lighthouse-protocol", - "rand", + "rand 0.8.5", "rmp-serde", "serde", "serde_with", + "stream-guard", "thiserror", "tokio", "tracing", @@ -667,11 +680,11 @@ dependencies = [ [[package]] name = "lighthouse-protocol" -version = "3.0.1" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad904b463b1c4bd22249207abaeb3134b92e39ecf6665f73c8693ec378b9c8e2" +checksum = "e4d754a4949fad89b1b3481ab407c8ec06820887eb481042596c62d6f5db8fef" dependencies = [ - "rand", + "rand 0.8.5", "rmpv", "serde", "serde_with", @@ -685,14 +698,14 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lisnake" -version = "1.0.3" +version = "2.0.0" dependencies = [ "anyhow", "clap", "dotenvy", "futures", "lighthouse-client", - "rand", + "rand 0.9.0", "tokio", "tracing", "tracing-subscriber", @@ -735,7 +748,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] @@ -859,6 +872,26 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pin-project" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -914,8 +947,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.3", + "zerocopy", ] [[package]] @@ -925,7 +969,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.3", ] [[package]] @@ -934,7 +988,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.12", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.1", ] [[package]] @@ -1187,6 +1250,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "stream-guard" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1d822c252e766a20acaa3e39f9001cadbd91c05b913e716bf184879204bdcb4" +dependencies = [ + "futures", + "pin-project", +] + [[package]] name = "strsim" version = "0.10.0" @@ -1408,7 +1481,7 @@ dependencies = [ "httparse", "log", "native-tls", - "rand", + "rand 0.8.5", "sha1", "thiserror", "url", @@ -1489,6 +1562,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi" +version = "0.13.3+wasi-0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2" +dependencies = [ + "wit-bindgen-rt", +] + [[package]] name = "wasm-bindgen" version = "0.2.92" @@ -1705,3 +1787,32 @@ name = "windows_x86_64_msvc" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + +[[package]] +name = "wit-bindgen-rt" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c" +dependencies = [ + "bitflags 2.5.0", +] + +[[package]] +name = "zerocopy" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf01143b2dd5d134f11f545cf9f1431b13b749695cb33bcce051e7568f99478" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712c8386f4f4299382c9abee219bee7084f78fb939d88b6840fcc1320d5f6da2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 48ffaa5..026edf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lisnake" -version = "1.0.3" +version = "2.0.0" description = "Snake for Project Lighthouse" edition = "2021" license = "MIT" @@ -13,8 +13,8 @@ anyhow = "1.0.81" clap = { version = "4.5.3", features = ["derive", "env"] } dotenvy = "0.15.7" futures = "0.3.30" -lighthouse-client = "3.0.1" -rand = "0.8.5" +lighthouse-client = "4.0.0" +rand = "0.9.0" tokio = { version = "1.36.0", features = ["rt", "macros", "time"] } tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "std"] } diff --git a/src/main.rs b/src/main.rs index 430857a..f9b94e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ async fn main() -> Result<()> { let auth = Authentication::new(&args.username, &args.token); let state = Arc::new(Mutex::new(State::new())); - let mut lh = Lighthouse::connect_with_tokio_to(&args.url, auth).await?; + let lh = Lighthouse::connect_with_tokio_to(&args.url, auth).await?; info!("Connected to the Lighthouse server"); let stream = lh.stream_model().await?; diff --git a/src/model/snake.rs b/src/model/snake.rs index bbad238..8d14bbd 100644 --- a/src/model/snake.rs +++ b/src/model/snake.rs @@ -6,13 +6,13 @@ use crate::constants::SNAKE_COLOR; #[derive(Debug, PartialEq, Eq, Clone)] pub struct Snake { - fields: VecDeque, - dir: Delta, + fields: VecDeque>, + dir: Delta, } impl Snake { pub fn from_initial_length(length: usize) -> Self { - let mut pos: Pos = LIGHTHOUSE_RECT.sample_random().unwrap(); + let mut pos: Pos = LIGHTHOUSE_RECT.sample_random().unwrap(); let dir = Delta::random_cardinal(); let mut fields = VecDeque::new(); @@ -24,9 +24,9 @@ impl Snake { Self { fields, dir } } - pub fn head(&self) -> Pos { *self.fields.front().unwrap() } + pub fn head(&self) -> Pos { *self.fields.front().unwrap() } - pub fn back(&self) -> Pos { *self.fields.back().unwrap() } + pub fn back(&self) -> Pos { *self.fields.back().unwrap() } pub fn grow(&mut self) { self.fields.push_back(LIGHTHOUSE_RECT.wrap(self.back() - self.dir)); @@ -42,7 +42,7 @@ impl Snake { self.fields.iter().collect::>().len() < self.fields.len() } - pub fn rotate_head(&mut self, dir: Delta) { + pub fn rotate_head(&mut self, dir: Delta) { self.dir = dir; } @@ -56,7 +56,7 @@ impl Snake { self.fields.len() } - pub fn random_fruit_pos(&self) -> Option { + pub fn random_fruit_pos(&self) -> Option> { let fields = self.fields.iter().collect::>(); if fields.len() >= LIGHTHOUSE_SIZE { None diff --git a/src/model/state.rs b/src/model/state.rs index 3c55e0a..d412301 100644 --- a/src/model/state.rs +++ b/src/model/state.rs @@ -8,7 +8,7 @@ use super::Snake; #[derive(Debug, PartialEq, Eq, Clone)] pub struct State { pub snake: Snake, - pub fruit: Pos, + pub fruit: Pos, } impl State { diff --git a/src/updater.rs b/src/updater.rs index 2a562c3..72977e4 100644 --- a/src/updater.rs +++ b/src/updater.rs @@ -8,7 +8,7 @@ use tracing::debug; use crate::{constants::UPDATE_INTERVAL, model::State}; -pub async fn run(mut lh: Lighthouse, shared_state: Arc>) -> Result<()> { +pub async fn run(lh: Lighthouse, shared_state: Arc>) -> Result<()> { loop { // Update the snake and render it let frame = {