
# Objective The migration process for `bevy_color` (#12013) will be fairly involved: there will be hundreds of affected files, and a large number of APIs. ## Solution To allow us to proceed granularly, we're going to keep both `bevy_color::Color` (new) and `bevy_render::Color` (old) around until the migration is complete. However, simply doing this directly is confusing! They're both called `Color`, making it very hard to tell when a portion of the code has been ported. As discussed in #12056, by renaming the old `Color` type, we can make it easier to gradually migrate over, one API at a time. ## Migration Guide THIS MIGRATION GUIDE INTENTIONALLY LEFT BLANK. This change should not be shipped to end users: delete this section in the final migration guide! --------- Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com>
80 lines
2.6 KiB
Rust
80 lines
2.6 KiB
Rust
//! Text pipeline benchmark.
|
|
//!
|
|
//! Continuously recomputes a large `Text` component with 100 sections.
|
|
|
|
use bevy::{
|
|
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
|
prelude::*,
|
|
text::{BreakLineOn, Text2dBounds},
|
|
window::{PresentMode, WindowPlugin, WindowResolution},
|
|
winit::{UpdateMode, WinitSettings},
|
|
};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
DefaultPlugins.set(WindowPlugin {
|
|
primary_window: Some(Window {
|
|
present_mode: PresentMode::AutoNoVsync,
|
|
resolution: WindowResolution::new(1920.0, 1080.0)
|
|
.with_scale_factor_override(1.0),
|
|
..default()
|
|
}),
|
|
..default()
|
|
}),
|
|
FrameTimeDiagnosticsPlugin,
|
|
LogDiagnosticsPlugin::default(),
|
|
))
|
|
.insert_resource(WinitSettings {
|
|
focused_mode: UpdateMode::Continuous,
|
|
unfocused_mode: UpdateMode::Continuous,
|
|
})
|
|
.add_systems(Startup, spawn)
|
|
.add_systems(Update, update_text_bounds)
|
|
.run();
|
|
}
|
|
|
|
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: LegacyColor::BLUE,
|
|
},
|
|
},
|
|
TextSection {
|
|
value: "pipeline".repeat(i),
|
|
style: TextStyle {
|
|
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
|
|
font_size: (4 + i % 11) as f32,
|
|
color: LegacyColor::YELLOW,
|
|
},
|
|
},
|
|
]
|
|
})
|
|
.collect::<Vec<_>>();
|
|
commands.spawn(Text2dBundle {
|
|
text: Text {
|
|
sections,
|
|
justify: JustifyText::Center,
|
|
linebreak_behavior: 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;
|
|
}
|
|
}
|