2023-03-04 12:29:08 +00:00
|
|
|
//! Text pipeline benchmark.
|
|
|
|
//!
|
|
|
|
//! Continuously recomputes a large `Text` component with 100 sections.
|
|
|
|
|
|
|
|
use bevy::{
|
|
|
|
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
|
|
|
prelude::*,
|
|
|
|
text::{BreakLineOn, Text2dBounds},
|
2023-11-09 22:05:32 +00:00
|
|
|
window::{PresentMode, WindowPlugin, WindowResolution},
|
2023-03-04 12:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::new()
|
2023-06-21 20:51:03 +00:00
|
|
|
.add_plugins((
|
|
|
|
DefaultPlugins.set(WindowPlugin {
|
|
|
|
primary_window: Some(Window {
|
2023-07-21 20:15:13 +00:00
|
|
|
present_mode: PresentMode::AutoNoVsync,
|
2023-11-09 22:05:32 +00:00
|
|
|
resolution: WindowResolution::new(1920.0, 1080.0)
|
|
|
|
.with_scale_factor_override(1.0),
|
2023-06-21 20:51:03 +00:00
|
|
|
..default()
|
|
|
|
}),
|
2023-03-04 12:29:08 +00:00
|
|
|
..default()
|
|
|
|
}),
|
2023-06-21 20:51:03 +00:00
|
|
|
FrameTimeDiagnosticsPlugin,
|
|
|
|
LogDiagnosticsPlugin::default(),
|
|
|
|
))
|
2023-03-18 01:45:34 +00:00
|
|
|
.add_systems(Startup, spawn)
|
|
|
|
.add_systems(Update, update_text_bounds)
|
2023-03-04 12:29:08 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
|
2023-04-24 14:35:03 +00:00
|
|
|
warn!(include_str!("warning_string.txt"));
|
|
|
|
|
2023-03-04 12:29:08 +00:00
|
|
|
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: Color::BLUE,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TextSection {
|
|
|
|
value: "pipeline".repeat(i),
|
|
|
|
style: TextStyle {
|
|
|
|
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
|
|
|
|
font_size: (4 + i % 11) as f32,
|
|
|
|
color: Color::YELLOW,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
commands.spawn(Text2dBundle {
|
|
|
|
text: Text {
|
|
|
|
sections,
|
|
|
|
alignment: TextAlignment::Center,
|
2023-04-05 21:25:53 +00:00
|
|
|
linebreak_behavior: BreakLineOn::AnyCharacter,
|
2023-03-04 12:29:08 +00:00
|
|
|
},
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// changing the bounds of the text will cause a recomputation
|
|
|
|
fn update_text_bounds(time: Res<Time>, mut text_bounds_query: Query<&mut Text2dBounds>) {
|
|
|
|
let width = (1. + time.elapsed_seconds().sin()) * 600.0;
|
|
|
|
for mut text_bounds in text_bounds_query.iter_mut() {
|
|
|
|
text_bounds.size.x = width;
|
|
|
|
}
|
|
|
|
}
|