Skip to content

Commit

Permalink
many_glyphs recompute-text option (bevyengine#8499)
Browse files Browse the repository at this point in the history
# Objective

Add a commandline argument to the `many_glyphs` that forces the
recomputation of all the text every frame.
  • Loading branch information
ickshonpe authored Apr 26, 2023
1 parent c324b90 commit 323705e
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions examples/stress_tests/many_glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
//!
//! Creates a `Text` with a single `TextSection` containing `100_000` glyphs,
//! and renders it with the UI in a white color and with Text2d in a red color.
//!
//! To recompute all text each frame run
//! `cargo run --example many_glyphs --release recompute-text`
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
Expand All @@ -10,18 +13,23 @@ use bevy::{
};

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::Immediate,
..default()
}),
let mut app = App::new();
app.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::Immediate,
..default()
}))
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::default())
.add_systems(Startup, setup)
.run();
}),
..default()
}))
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::default())
.add_systems(Startup, setup);

if std::env::args().any(|arg| arg == "recompute-text") {
app.add_systems(Update, force_text_recomputation);
}

app.run();
}

fn setup(mut commands: Commands) {
Expand Down Expand Up @@ -73,3 +81,9 @@ fn setup(mut commands: Commands) {
..Default::default()
});
}

fn force_text_recomputation(mut text_query: Query<&mut Text>) {
for mut text in &mut text_query {
text.set_changed();
}
}

0 comments on commit 323705e

Please sign in to comment.