Make more random
At least, make the stuff that doesn't need to be deterministic non-deterministic
This commit is contained in:
parent
245dfde91e
commit
fc95857824
4 changed files with 18 additions and 12 deletions
|
@ -37,5 +37,5 @@ log = { version = "*", features = [
|
||||||
"max_level_debug",
|
"max_level_debug",
|
||||||
"release_max_level_warn",
|
"release_max_level_warn",
|
||||||
] }
|
] }
|
||||||
rand = { version = "0.9.1", default-features = false, features = ["std"] }
|
rand = { version = "0.9.1", default-features = false, features = ["std", "thread_rng"] }
|
||||||
wyrand = "0.3.2"
|
wyrand = "0.3.2"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod objects;
|
mod objects;
|
||||||
|
mod rng;
|
||||||
pub mod runtime;
|
pub mod runtime;
|
||||||
pub mod seed;
|
pub mod seed;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
|
|
7
src/game/rng.rs
Normal file
7
src/game/rng.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
use rand::random;
|
||||||
|
use wyrand::WyRand;
|
||||||
|
|
||||||
|
/// Initialize a `WyRand` using `rand`'s thread-local rng
|
||||||
|
pub fn thread_rng() -> WyRand {
|
||||||
|
WyRand::new(random())
|
||||||
|
}
|
|
@ -9,10 +9,12 @@ use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use bevy_rand::prelude::{GlobalEntropy, WyRand};
|
use bevy_rand::prelude::{GlobalEntropy, WyRand};
|
||||||
use rand::Rng;
|
use rand::Rng as _;
|
||||||
use wyrand::WyRand as LocalRng;
|
|
||||||
|
|
||||||
use super::objects::{Ball, Player, Wall};
|
use super::{
|
||||||
|
objects::{Ball, Player, Wall},
|
||||||
|
rng::thread_rng,
|
||||||
|
};
|
||||||
|
|
||||||
const BALL_COUNT: u8 = 32;
|
const BALL_COUNT: u8 = 32;
|
||||||
const BALL_SIZES: Range<f32> = 10.0..25.0;
|
const BALL_SIZES: Range<f32> = 10.0..25.0;
|
||||||
|
@ -57,7 +59,7 @@ pub fn setup_balls(
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
region: Res<PlayableArea>,
|
region: Res<PlayableArea>,
|
||||||
) {
|
) {
|
||||||
let mut random = LocalRng::new(Default::default());
|
let mut random = thread_rng();
|
||||||
for _ in 0..BALL_COUNT {
|
for _ in 0..BALL_COUNT {
|
||||||
let circle = Circle::new(random.random_range(BALL_SIZES));
|
let circle = Circle::new(random.random_range(BALL_SIZES));
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
@ -66,12 +68,8 @@ pub fn setup_balls(
|
||||||
Mesh2d(meshes.add(circle)),
|
Mesh2d(meshes.add(circle)),
|
||||||
MeshMaterial2d(materials.add(Color::from(RED_400))),
|
MeshMaterial2d(materials.add(Color::from(RED_400))),
|
||||||
Transform::from_xyz(
|
Transform::from_xyz(
|
||||||
random.random_range(
|
random.random::<f32>() * (region.0 - 2.0 * circle.radius) + circle.radius,
|
||||||
(-region.0 / 2.0 + circle.radius)..(region.0 / 2.0 - circle.radius),
|
random.random::<f32>() * (region.1 - 2.0 * circle.radius) + circle.radius,
|
||||||
),
|
|
||||||
random.random_range(
|
|
||||||
(-region.1 / 2.0 + circle.radius)..(region.1 / 2.0 - circle.radius),
|
|
||||||
),
|
|
||||||
0.0,
|
0.0,
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue