Add CLI for networking

This commit is contained in:
Michael Bradley 2025-05-24 13:22:47 -04:00
parent 62da4093ea
commit b7804bd547
Signed by: MichaelBradley
SSH key fingerprint: SHA256:o/aaeYtRubILK7OYYjYP12DmU7BsPUhKji1AgaQ+ge4
3 changed files with 37 additions and 9 deletions

View file

@ -1,11 +1,18 @@
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<String> for Seed {
/// Attempt to parse as an integer, fall back to hashing string
fn from(value: String) -> Self {

View file

@ -8,12 +8,13 @@ use bevy::{
},
prelude::*,
};
use bevy_rand::prelude::{GlobalEntropy, WyRand};
use rand::Rng as _;
use rand::{Rng as _, SeedableRng};
use wyrand::WyRand;
use super::{
objects::{Ball, Player, Radius, Wall},
rng::thread_rng,
seed::Seed,
};
const BALL_COUNT: u8 = 32;
@ -25,7 +26,8 @@ const DIMENSION_SIZES: Range<f32> = 500.0..2000.0;
pub struct PlayableArea(f32, f32);
/// Initialize deterministic values
pub fn setup_from_seed(mut commands: Commands, mut rng: GlobalEntropy<WyRand>) {
pub fn setup_from_seed(mut commands: Commands, seed: Res<Seed>) {
let mut rng = WyRand::from_seed(seed.clone().into());
commands.insert_resource(PlayableArea(
rng.random_range(DIMENSION_SIZES),
rng.random_range(DIMENSION_SIZES),