-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Objective Simple text pipeline benchmark. It's quite expensive but current examples don't capture the performance of `queue_text` as it only runs on changes to the text.
- Loading branch information
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//! Text pipeline benchmark. | ||
//! | ||
//! Continuously recomputes a large `Text` component with 100 sections. | ||
use bevy::{ | ||
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, | ||
prelude::*, | ||
text::{BreakLineOn, Text2dBounds}, | ||
window::{PresentMode, WindowPlugin}, | ||
}; | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins.set(WindowPlugin { | ||
primary_window: Some(Window { | ||
present_mode: PresentMode::Immediate, | ||
..default() | ||
}), | ||
..default() | ||
})) | ||
.add_plugin(FrameTimeDiagnosticsPlugin::default()) | ||
.add_plugin(LogDiagnosticsPlugin::default()) | ||
.add_startup_system(spawn) | ||
.add_system(update_text_bounds) | ||
.run(); | ||
} | ||
|
||
fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) { | ||
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, | ||
linebreak_behaviour: BreakLineOn::AnyCharacter, | ||
}, | ||
..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; | ||
} | ||
} |