Skip to content

Commit

Permalink
remove randomness
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Aug 1, 2023
1 parent 37188de commit 66a5fba
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
8 changes: 4 additions & 4 deletions examples/3d/spotlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy::{
pbr::NotShadowCaster,
prelude::*,
};
use rand::{thread_rng, Rng};
use rand::{rngs::StdRng, Rng, SeedableRng};

fn main() {
App::new()
Expand Down Expand Up @@ -40,10 +40,10 @@ fn setup(
});

// cubes
let mut rng = thread_rng();
for _ in 0..100 {
let mut rng = StdRng::seed_from_u64(19878367467713);
for _ in 0..40 {
let x = rng.gen_range(-5.0..5.0);
let y = rng.gen_range(-5.0..5.0);
let y = rng.gen_range(0.0..3.0);
let z = rng.gen_range(-5.0..5.0);
commands.spawn((
PbrBundle {
Expand Down
30 changes: 14 additions & 16 deletions examples/async_tasks/external_source_external_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use bevy::prelude::*;
// Using crossbeam_channel instead of std as std `Receiver` is `!Sync`
use crossbeam_channel::{bounded, Receiver};
use rand::Rng;
use rand::{rngs::StdRng, Rng, SeedableRng};
use std::time::{Duration, Instant};

fn main() {
Expand All @@ -25,17 +25,19 @@ fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());

let (tx, rx) = bounded::<u32>(10);
std::thread::spawn(move || loop {
// Everything here happens in another thread
// This is where you could connect to an external data source
let mut rng = rand::thread_rng();
let start_time = Instant::now();
let duration = Duration::from_secs_f32(rng.gen_range(0.0..0.2));
while start_time.elapsed() < duration {
// Spinning for 'duration', simulating doing hard work!
}
std::thread::spawn(move || {
let mut rng = StdRng::seed_from_u64(19878367467713);
loop {
// Everything here happens in another thread
// This is where you could connect to an external data source
let start_time = Instant::now();
let duration = Duration::from_secs_f32(rng.gen_range(0.0..0.2));
while start_time.elapsed() < duration {
// Spinning for 'duration', simulating doing hard work!
}

tx.send(rng.gen_range(0..2000)).unwrap();
tx.send(rng.gen_range(0..2000)).unwrap();
}
});

commands.insert_resource(StreamReceiver(rx));
Expand All @@ -59,11 +61,7 @@ fn spawn_text(mut commands: Commands, mut reader: EventReader<StreamEvent>) {
commands.spawn(Text2dBundle {
text: Text::from_section(event.0.to_string(), text_style.clone())
.with_alignment(TextAlignment::Center),
transform: Transform::from_xyz(
per_frame as f32 * 100.0 + rand::thread_rng().gen_range(-40.0..40.0),
300.0,
0.0,
),
transform: Transform::from_xyz(per_frame as f32 * 100.0, 300.0, 0.0),
..default()
});
}
Expand Down
4 changes: 2 additions & 2 deletions examples/ecs/iter_combinations.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Shows how to iterate over combinations of query results.
use bevy::{pbr::AmbientLight, prelude::*};
use rand::{thread_rng, Rng};
use rand::{rngs::StdRng, Rng, SeedableRng};

const DELTA_TIME: f32 = 0.01;

Expand Down Expand Up @@ -56,7 +56,7 @@ fn generate_bodies(
let color_range = 0.5..1.0;
let vel_range = -0.5..0.5;

let mut rng = thread_rng();
let mut rng = StdRng::seed_from_u64(19878367467713);
for _ in 0..NUM_BODIES {
let radius: f32 = rng.gen_range(0.1..0.7);
let mass_value = radius.powi(3) * 10.;
Expand Down
5 changes: 3 additions & 2 deletions examples/ecs/parallel_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
use bevy::ecs::query::BatchingStrategy;
use bevy::prelude::*;
use rand::random;
use rand::{rngs::StdRng, Rng, SeedableRng};

#[derive(Component, Deref)]
struct Velocity(Vec2);

fn spawn_system(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
let texture = asset_server.load("branding/icon.png");
let mut rng = StdRng::seed_from_u64(19878367467713);
for _ in 0..128 {
commands.spawn((
SpriteBundle {
texture: texture.clone(),
transform: Transform::from_scale(Vec3::splat(0.1)),
..default()
},
Velocity(20.0 * Vec2::new(random::<f32>() - 0.5, random::<f32>() - 0.5)),
Velocity(20.0 * Vec2::new(rng.gen::<f32>() - 0.5, rng.gen::<f32>() - 0.5)),
));
}
}
Expand Down

0 comments on commit 66a5fba

Please sign in to comment.