Skip to content

Commit

Permalink
Adding explanation to seeded rng used in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
andristarr committed Mar 20, 2024
1 parent f38895a commit bb8ec67
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/3d/spotlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ fn setup(
));

// cubes

// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut rng = StdRng::seed_from_u64(19878367467713);
let cube_mesh = meshes.add(Cuboid::new(0.5, 0.5, 0.5));
let blue = materials.add(Color::srgb_u8(124, 144, 255));
Expand Down
1 change: 1 addition & 0 deletions examples/animation/custom_skinned_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fn setup(

let mesh = meshes.add(mesh);

// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut rng = StdRng::seed_from_u64(42);

for i in -5..5 {
Expand Down
3 changes: 2 additions & 1 deletion examples/async_tasks/external_source_external_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());

let (tx, rx) = bounded::<u32>(10);
std::thread::spawn(move || {
std::thread::spawn(move || {
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut rng = StdRng::seed_from_u64(19878367467713);
loop {
// Everything here happens in another thread
Expand Down
1 change: 1 addition & 0 deletions examples/ecs/iter_combinations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn generate_bodies(
let color_range = 0.5..1.0;
let vel_range = -0.5..0.5;

// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut rng = StdRng::seed_from_u64(19878367467713);
for _ in 0..NUM_BODIES {
let radius: f32 = rng.gen_range(0.1..0.7);
Expand Down
2 changes: 2 additions & 0 deletions examples/ecs/parallel_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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");

// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut rng = StdRng::seed_from_u64(19878367467713);
for _ in 0..128 {
commands.spawn((
Expand Down
2 changes: 1 addition & 1 deletion examples/games/alien_cake_addict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn setup_cameras(mut commands: Commands, mut game: ResMut<Game>) {

fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMut<Game>) {
let mut rng = if std::env::var("GITHUB_ACTIONS") == Ok("true".to_string()) {
// Make the game play out the same way every time, this is useful for testing purposes.
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
StdRng::seed_from_u64(19878367467713)
} else {
StdRng::from_entropy()
Expand Down
1 change: 1 addition & 0 deletions examples/gizmos/axes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut rng = StdRng::seed_from_u64(19878367467713);

// Lights...
Expand Down
4 changes: 4 additions & 0 deletions examples/stress_tests/bevymark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ fn setup(
quad: meshes
.add(Rectangle::from_size(Vec2::splat(BIRD_TEXTURE_SIZE as f32)))
.into(),
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
color_rng: StdRng::seed_from_u64(42),
material_rng: StdRng::seed_from_u64(42),
velocity_rng: StdRng::seed_from_u64(42),
Expand Down Expand Up @@ -304,6 +305,7 @@ fn mouse_handler(
mut wave: Local<usize>,
) {
if rng.is_none() {
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
*rng = Some(StdRng::seed_from_u64(42));
}
let rng = rng.as_mut().unwrap();
Expand Down Expand Up @@ -537,6 +539,7 @@ fn counter_system(
}

fn init_textures(textures: &mut Vec<Handle<Image>>, args: &Args, images: &mut Assets<Image>) {
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut color_rng = StdRng::seed_from_u64(42);
while textures.len() < args.material_texture_count {
let pixel = [color_rng.gen(), color_rng.gen(), color_rng.gen(), 255];
Expand Down Expand Up @@ -572,6 +575,7 @@ fn init_materials(
texture: textures.first().cloned(),
}));

// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut color_rng = StdRng::seed_from_u64(42);
let mut texture_rng = StdRng::seed_from_u64(42);
materials.extend(
Expand Down
3 changes: 3 additions & 0 deletions examples/stress_tests/many_cubes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fn setup(
let material_textures = init_textures(args, images);
let materials = init_materials(args, &material_textures, material_assets);

// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut material_rng = StdRng::seed_from_u64(42);
match args.layout {
Layout::Sphere => {
Expand Down Expand Up @@ -202,6 +203,7 @@ fn setup(
}

fn init_textures(args: &Args, images: &mut Assets<Image>) -> Vec<Handle<Image>> {
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut color_rng = StdRng::seed_from_u64(42);
let color_bytes: Vec<u8> = (0..(args.material_texture_count * 4))
.map(|i| if (i % 4) == 3 { 255 } else { color_rng.gen() })
Expand Down Expand Up @@ -246,6 +248,7 @@ fn init_materials(
..default()
}));

// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut color_rng = StdRng::seed_from_u64(42);
let mut texture_rng = StdRng::seed_from_u64(42);
materials.extend(
Expand Down
1 change: 1 addition & 0 deletions examples/transforms/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
let mut seeded_rng = StdRng::seed_from_u64(19878367467712);

// A camera looking at the origin
Expand Down
1 change: 1 addition & 0 deletions examples/ui/font_atlas_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut state: ResM
},
));
});
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
commands.insert_resource(SeededRng(StdRng::seed_from_u64(19878367467713)));
}

0 comments on commit bb8ec67

Please sign in to comment.