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>
33 lines
1.2 KiB
Rust
33 lines
1.2 KiB
Rust
//! This example illustrates how to create a custom diagnostic.
|
|
|
|
use bevy::{
|
|
diagnostic::{Diagnostic, DiagnosticId, Diagnostics, LogDiagnosticsPlugin, RegisterDiagnostic},
|
|
prelude::*,
|
|
};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
DefaultPlugins,
|
|
// The "print diagnostics" plugin is optional.
|
|
// It just visualizes our diagnostics in the console.
|
|
LogDiagnosticsPlugin::default(),
|
|
))
|
|
// Diagnostics must be initialized before measurements can be added.
|
|
.register_diagnostic(
|
|
Diagnostic::new(SYSTEM_ITERATION_COUNT, "system_iteration_count", 10)
|
|
.with_suffix(" iterations"),
|
|
)
|
|
.add_systems(Update, my_system)
|
|
.run();
|
|
}
|
|
|
|
// All diagnostics should have a unique DiagnosticId.
|
|
// For each new diagnostic, generate a new random number.
|
|
pub const SYSTEM_ITERATION_COUNT: DiagnosticId =
|
|
DiagnosticId::from_u128(337040787172757619024841343456040760896);
|
|
|
|
fn my_system(mut diagnostics: Diagnostics) {
|
|
// Add a measurement of 10.0 for our diagnostic each time this system runs.
|
|
diagnostics.add_measurement(SYSTEM_ITERATION_COUNT, || 10.0);
|
|
}
|