Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update text stress tests #4

Merged
merged 6 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/stress_tests/many_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn main() {
}

if args.recompute_text {
app.add_systems(Update, |mut text_query: Query<&mut Text>| {
app.add_systems(Update, |mut text_query: Query<&mut TextNEW>| {
text_query
.iter_mut()
.for_each(|mut text| text.set_changed());
Expand Down Expand Up @@ -262,8 +262,8 @@ fn spawn_button(

if spawn_text {
builder.with_children(|parent| {
parent.spawn(TextBundle::from_section(
format!("{column}, {row}"),
parent.spawn((
TextNEW(format!("{column}, {row}")),
TextStyle {
font_size: FONT_SIZE,
color: Color::srgb(0.2, 0.2, 0.2),
Expand Down
61 changes: 33 additions & 28 deletions examples/stress_tests/many_glyphs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Simple text rendering benchmark.
//!
//! Creates a `Text` with a single `TextSection` containing `100_000` glyphs,
//! Creates a text block with a single span 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
Expand Down Expand Up @@ -45,17 +45,15 @@ fn setup(mut commands: Commands) {
warn!(include_str!("warning_string.txt"));

commands.spawn(Camera2dBundle::default());
let mut text = Text {
sections: vec![TextSection {
value: "0123456789".repeat(10_000),
style: TextStyle {
font_size: 4.,
..default()
},
}],
let text_string = "0123456789".repeat(10_000);
let text_style = TextStyle {
font_size: 4.,
..Default::default()
};
let text_block = TextBlock {
justify: JustifyText::Left,
linebreak: LineBreak::AnyCharacter,
..default()
..Default::default()
};

commands
Expand All @@ -69,28 +67,35 @@ fn setup(mut commands: Commands) {
..default()
})
.with_children(|commands| {
commands.spawn(TextBundle {
text: text.clone(),
style: Style {
width: Val::Px(1000.),
commands
.spawn(NodeBundle {
style: Style {
width: Val::Px(1000.),
..Default::default()
},
..Default::default()
},
..Default::default()
});
})
.with_child((
TextNEW(text_string.clone()),
text_style.clone(),
text_block.clone(),
));
});

text.sections[0].style.color = RED.into();

commands.spawn(Text2dBundle {
text,
text_anchor: bevy::sprite::Anchor::Center,
text_2d_bounds: TextBounds::new_horizontal(1000.),
..Default::default()
});
commands.spawn((
Text2d::new(text_string),
TextStyle {
color: RED.into(),
..text_style
},
bevy::sprite::Anchor::Center,
TextBounds::new_horizontal(1000.),
text_block,
));
}

fn force_text_recomputation(mut text_query: Query<&mut Text>) {
for mut text in &mut text_query {
text.set_changed();
fn force_text_recomputation(mut text_query: Query<&mut TextBlock>) {
for mut block in &mut text_query {
block.set_changed();
}
}
72 changes: 42 additions & 30 deletions examples/stress_tests/text_pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Text pipeline benchmark.
//!
//! Continuously recomputes a large `Text` component with 100 sections.
//! Continuously recomputes a large block of text with 100 text spans.

use bevy::{
color::palettes::basic::{BLUE, YELLOW},
Expand Down Expand Up @@ -39,37 +39,49 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
warn!(include_str!("warning_string.txt"));

commands.spawn(Camera2dBundle::default());
let sections = (1..=50)
.flat_map(|i| {
[
TextSection {
value: "text".repeat(i),
style: TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: (4 + i % 10) as f32,
color: BLUE.into(),
},

let make_spans = |i| {
[
(
"text".repeat(i),
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: (4 + i % 10) as f32,
color: BLUE.into(),
..Default::default()
},
TextSection {
value: "pipeline".repeat(i),
style: TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: (4 + i % 11) as f32,
color: YELLOW.into(),
},
),
(
"pipeline".repeat(i),
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: (4 + i % 11) as f32,
color: YELLOW.into(),
},
]
})
.collect::<Vec<_>>();
commands.spawn(Text2dBundle {
text: Text {
sections,
justify: JustifyText::Center,
linebreak: LineBreak::AnyCharacter,
..default()
},
..Default::default()
});
),
]
};

let [t1, p1] = make_spans(1);
commands
.spawn((
Text2d::new(t1.0),
t1.1,
TextBlock {
justify: JustifyText::Center,
linebreak: LineBreak::AnyCharacter,
..Default::default()
},
TextBounds::default(),
))
.with_children(|parent| {
parent.spawn((TextSpan2d(p1.0), p1.1));
for i in 2..=50 {
let [t, p] = make_spans(i);
parent.spawn((TextSpan2d(t.0), t.1));
parent.spawn((TextSpan2d(p.0), p.1));
}
});
}

// changing the bounds of the text will cause a recomputation
Expand Down
Loading