Skip to content

Commit

Permalink
use seeded random for example font_atlas_debug
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Mar 16, 2024
1 parent 1323de7 commit aea4296
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions examples/ui/font_atlas_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! Bevy uses `FontAtlas`'s under the hood to optimize text rendering.

use bevy::{color::palettes::basic::YELLOW, prelude::*, text::FontAtlasSets};
use rand::{rngs::StdRng, Rng, SeedableRng};

fn main() {
App::new()
Expand Down Expand Up @@ -30,6 +31,9 @@ impl Default for State {
}
}

#[derive(Resource, Deref, DerefMut)]
struct SeededRng(StdRng);

fn atlas_render_system(
mut commands: Commands,
mut state: ResMut<State>,
Expand Down Expand Up @@ -57,10 +61,15 @@ fn atlas_render_system(
}
}

fn text_update_system(mut state: ResMut<State>, time: Res<Time>, mut query: Query<&mut Text>) {
fn text_update_system(
mut state: ResMut<State>,
time: Res<Time>,
mut query: Query<&mut Text>,
mut seeded_rng: ResMut<SeededRng>,
) {
if state.timer.tick(time.delta()).finished() {
for mut text in &mut query {
let c = rand::random::<u8>() as char;
let c = seeded_rng.gen::<u8>() as char;
let string = &mut text.sections[0].value;
if !string.contains(c) {
string.push(c);
Expand Down Expand Up @@ -95,4 +104,5 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut state: ResM
},
));
});
commands.insert_resource(SeededRng(StdRng::seed_from_u64(19878367467713)));
}

0 comments on commit aea4296

Please sign in to comment.