diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index f4dd30c..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "lldb", - "request": "launch", - "name": "Debug game", - "cargo": { - "args": ["build"] - }, - "args": ["--seed=gargamel"], - "cwd": "${workspaceFolder}", - "env": { - "CARGO_MANIFEST_DIR": "${workspaceFolder}", - "LD_LIBRARY_PATH": "${workspaceFolder}/target/debug/deps:${env:HOME}/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" - }, - "presentation": { - "hidden": false, - "group": "run", - "order": 1 - } - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug peer", - "cargo": { - "args": ["build"] - }, - "args": ["--port=25566", "--connect=[::1]:25565"], - "cwd": "${workspaceFolder}", - "env": { - "CARGO_MANIFEST_DIR": "${workspaceFolder}", - "LD_LIBRARY_PATH": "${workspaceFolder}/target/debug/deps:${env:HOME}/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" - }, - "presentation": { - "hidden": false, - "group": "run", - "order": 2 - } - } - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json index 0390453..bc89a82 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,19 +1,8 @@ { - "files.readonlyFromPermissions": true, - "files.readonlyInclude": { - "**/.rustup/**": true, - "**/.cargo/registry/**": true, - "**/.cargo/git/**": true, - "**/.local/share/cargo/registry/**": true, - "**/.local/share/cargo/git/**": true - }, "[rust]": { "editor.defaultFormatter": "rust-lang.rust-analyzer", "editor.formatOnSave": true }, - "rust-analyzer.cargo.extraEnv": { - "RUSTFLAGS": "-Clinker=clang -Clink-arg=-fuse-ld=lld" - }, "rust-analyzer.check.command": "clippy", // "check", // "rust-analyzer.cargo.targetDir": true, "cSpell.words": [ @@ -24,7 +13,6 @@ "PRNG", "recip", "respawns", - "Seedable", "timestep", "timesteps", "winit", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1062be3..155290c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,12 +2,18 @@ "version": "2.0.0", "tasks": [ { - "label": "Build", + "label": "Launch", "type": "cargo", - "command": "build", + "command": "run", + "args": ["--", "--seed", "gargamel"], + "options": { + "env": { + "RUST_BACKTRACE": "full" + } + }, "presentation": { "echo": true, - "reveal": "silent", + "reveal": "always", "focus": false, "panel": "dedicated", "showReuseMessage": false, diff --git a/src/game/seed.rs b/src/game/seed.rs index af8ee58..0119b8b 100644 --- a/src/game/seed.rs +++ b/src/game/seed.rs @@ -1,18 +1,11 @@ use std::hash::{DefaultHasher, Hash, Hasher}; use bevy::prelude::*; -use rand::random; /// Value with which to initialize the PRNG #[derive(Clone, Resource)] pub struct Seed(u64); -impl Seed { - pub fn random() -> Self { - Self(random()) - } -} - impl From for Seed { /// Attempt to parse as an integer, fall back to hashing string fn from(value: String) -> Self { diff --git a/src/game/setup.rs b/src/game/setup.rs index 55ed28b..2ca871c 100644 --- a/src/game/setup.rs +++ b/src/game/setup.rs @@ -8,13 +8,12 @@ use bevy::{ }, prelude::*, }; -use rand::{Rng as _, SeedableRng}; -use wyrand::WyRand; +use bevy_rand::prelude::{GlobalEntropy, WyRand}; +use rand::Rng as _; use super::{ objects::{Ball, Player, Radius, Wall}, rng::thread_rng, - seed::Seed, }; const BALL_COUNT: u8 = 32; @@ -26,8 +25,7 @@ const DIMENSION_SIZES: Range = 500.0..2000.0; pub struct PlayableArea(f32, f32); /// Initialize deterministic values -pub fn setup_from_seed(mut commands: Commands, seed: Res) { - let mut rng = WyRand::from_seed(seed.clone().into()); +pub fn setup_from_seed(mut commands: Commands, mut rng: GlobalEntropy) { commands.insert_resource(PlayableArea( rng.random_range(DIMENSION_SIZES), rng.random_range(DIMENSION_SIZES), diff --git a/src/lib.rs b/src/lib.rs index 18a8234..90a14b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,7 @@ -use std::net::SocketAddr; - use avian2d::{math::Vector, prelude::*}; use bevy::{input::common_conditions::input_pressed, prelude::*}; -use clap::{Args, Parser}; +use bevy_rand::prelude::{EntropyPlugin, WyRand}; +use clap::Parser; mod game; use game::{ @@ -16,25 +15,14 @@ use game::{ #[derive(Parser)] #[command(version, about)] pub struct AppSettings { - #[command(flatten)] - source: Source, - - #[arg(short, long, default_value = "25565")] - port: u16, -} - -#[derive(Args)] -#[group(required = false, multiple = false)] -struct Source { - #[arg(short, long)] - seed: Option, - #[arg(short, long)] - connect: Option, + #[arg(short, long, default_value = ":)")] + pub seed: Seed, } impl Plugin for AppSettings { fn build(&self, app: &mut App) { app.insert_resource(Gravity(Vector::ZERO)) + .insert_resource(self.seed.clone()) .add_plugins(( DefaultPlugins.set(WindowPlugin { primary_window: Window { @@ -46,6 +34,7 @@ impl Plugin for AppSettings { ..default() }), PhysicsPlugins::default().with_length_unit(50.0), + EntropyPlugin::::with_seed(self.seed.clone().into()), )) .add_systems( Startup, @@ -64,13 +53,5 @@ impl Plugin for AppSettings { ), ) .add_systems(PostUpdate, move_camera); - if let Some(ref seed) = self.source.seed { - app.insert_resource(seed.clone()); - } else if let Some(ref peer) = self.source.connect { - println!("{peer}"); - todo!("Handle connecting to peer and retrieving seed"); - } else { - app.insert_resource(Seed::random()); - } } }