many_glyphs recompute-text option (#8499)

# Objective

Add a commandline argument to the `many_glyphs` that forces the
recomputation of all the text every frame.
This commit is contained in:
ickshonpe 2023-04-26 22:05:01 +01:00 committed by GitHub
parent c324b90ffe
commit 323705e0ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,9 @@
//! //!
//! Creates a `Text` with a single `TextSection` containing `100_000` glyphs, //! 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. //! 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::{ use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*, prelude::*,
@ -10,18 +13,23 @@ use bevy::{
}; };
fn main() { fn main() {
App::new() let mut app = App::new();
.add_plugins(DefaultPlugins.set(WindowPlugin { app.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window { primary_window: Some(Window {
present_mode: PresentMode::Immediate, present_mode: PresentMode::Immediate,
..default()
}),
..default() ..default()
})) }),
.add_plugin(FrameTimeDiagnosticsPlugin::default()) ..default()
.add_plugin(LogDiagnosticsPlugin::default()) }))
.add_systems(Startup, setup) .add_plugin(FrameTimeDiagnosticsPlugin::default())
.run(); .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) { fn setup(mut commands: Commands) {
@ -73,3 +81,9 @@ fn setup(mut commands: Commands) {
..Default::default() ..Default::default()
}); });
} }
fn force_text_recomputation(mut text_query: Query<&mut Text>) {
for mut text in &mut text_query {
text.set_changed();
}
}