mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
f18f28874a
# Objective - Better consistency with `add_systems`. - Deprecating `add_plugin` in favor of a more powerful `add_plugins`. - Allow passing `Plugin` to `add_plugins`. - Allow passing tuples to `add_plugins`. ## Solution - `App::add_plugins` now takes an `impl Plugins` parameter. - `App::add_plugin` is deprecated. - `Plugins` is a new sealed trait that is only implemented for `Plugin`, `PluginGroup` and tuples over `Plugins`. - All examples, benchmarks and tests are changed to use `add_plugins`, using tuples where appropriate. --- ## Changelog ### Changed - `App::add_plugins` now accepts all types that implement `Plugins`, which is implemented for: - Types that implement `Plugin`. - Types that implement `PluginGroup`. - Tuples (up to 16 elements) over types that implement `Plugins`. - Deprecated `App::add_plugin` in favor of `App::add_plugins`. ## Migration Guide - Replace `app.add_plugin(plugin)` calls with `app.add_plugins(plugin)`. --------- Co-authored-by: Carter Anderson <mcanders1@gmail.com>
72 lines
2.2 KiB
Rust
72 lines
2.2 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},
|
|
};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
DefaultPlugins.set(WindowPlugin {
|
|
primary_window: Some(Window {
|
|
present_mode: PresentMode::Immediate,
|
|
..default()
|
|
}),
|
|
..default()
|
|
}),
|
|
FrameTimeDiagnosticsPlugin,
|
|
LogDiagnosticsPlugin::default(),
|
|
))
|
|
.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: 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_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;
|
|
}
|
|
}
|