From 7d16e06c9ffafdecf5bc79c947a41c04252d383e Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sun, 13 Apr 2025 17:18:10 +0200 Subject: [PATCH] use perf-ui plugin to show more performance stats --- Cargo.lock | 54 ++++++++++++++++++++++ Cargo.toml | 1 + src/fps_counter.rs | 112 ++++++++++++++++++++++++--------------------- 3 files changed, 116 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f1fb0b..52c84f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,6 +145,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + [[package]] name = "android_log-sys" version = "0.3.2" @@ -1474,6 +1480,18 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chrono" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-link", +] + [[package]] name = "clang-sys" version = "1.8.1" @@ -2339,6 +2357,30 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core 0.61.0", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "image" version = "0.25.6" @@ -2421,6 +2463,17 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +[[package]] +name = "iyes_perf_ui" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4720bd0aedf593bca8017d5a6aac0210a80d38e2d84f37bcfadcd99ab1258951" +dependencies = [ + "bevy", + "chrono", + "num-traits", +] + [[package]] name = "jni" version = "0.21.1" @@ -2582,6 +2635,7 @@ name = "logisim" version = "0.1.0" dependencies = [ "bevy", + "iyes_perf_ui", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0f3864b..fabe759 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] bevy = { version = "0.15.0", features = ["bevy_dev_tools"] } +iyes_perf_ui = "0.4.0" diff --git a/src/fps_counter.rs b/src/fps_counter.rs index 759e53a..6d58af3 100644 --- a/src/fps_counter.rs +++ b/src/fps_counter.rs @@ -1,63 +1,73 @@ use bevy::{ - dev_tools::fps_overlay::{FpsOverlayConfig, FpsOverlayPlugin}, + // dev_tools::fps_overlay::{FpsOverlayConfig, FpsOverlayPlugin}, prelude::*, - text::FontSmoothing, }; -struct OverlayColor; -impl OverlayColor { - const RED: Color = Color::srgb(1.0, 0.0, 0.0); - const GREEN: Color = Color::srgb(0.0, 1.0, 0.0); -} +use iyes_perf_ui::PerfUiPlugin; +use iyes_perf_ui::prelude::*; + +// struct OverlayColor; +// impl OverlayColor { +// const RED: Color = Color::srgb(1.0, 0.0, 0.0); +// const GREEN: Color = Color::srgb(0.0, 1.0, 0.0); +// } pub struct FpsCounterPlugin; impl Plugin for FpsCounterPlugin { fn build(&self, app: &mut App) { - app.add_plugins(FpsOverlayPlugin { - config: FpsOverlayConfig { - text_config: TextFont { - font_size: 42.0, - ..default() - }, - text_color: OverlayColor::RED, - enabled: true, - }, - }) + app + // app.add_plugins(FpsOverlayPlugin { + // config: FpsOverlayConfig { + // text_config: TextFont { + // font_size: 42.0, + // ..default() + // }, + // text_color: OverlayColor::RED, + // enabled: true, + // }, + // }) + .add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin) + .add_plugins(bevy::diagnostic::EntityCountDiagnosticsPlugin) + .add_plugins(bevy::diagnostic::SystemInformationDiagnosticsPlugin) + .add_plugins(bevy::render::diagnostic::RenderDiagnosticsPlugin) + .add_plugins(PerfUiPlugin) .add_systems(Startup, setup) - .add_systems(Update, customize_config); + // .add_systems(Update, customize_config) + ; } } fn setup(mut commands: Commands) { - commands.spawn(( - Text::new(concat!( - "Press 1 to toggle the overlay color.\n", - "Press 2 to decrease the overlay size.\n", - "Press 3 to increase the overlay size.\n", - "Press 4 to toggle the overlay visibility.", - )), - Node { - position_type: PositionType::Absolute, - bottom: Val::Px(12.0), - left: Val::Px(12.0), - ..default() - }, - )); -} -fn customize_config(input: Res>, mut overlay: ResMut) { - if input.just_pressed(KeyCode::Digit1) { - // Changing resource will affect overlay - if overlay.text_color == OverlayColor::GREEN { - overlay.text_color = OverlayColor::RED; - } else { - overlay.text_color = OverlayColor::GREEN; - } - } - if input.just_pressed(KeyCode::Digit2) { - overlay.text_config.font_size -= 2.0; - } - if input.just_pressed(KeyCode::Digit3) { - overlay.text_config.font_size += 2.0; - } - if input.just_pressed(KeyCode::Digit4) { - overlay.enabled = !overlay.enabled; - } + commands.spawn(PerfUiAllEntries::default()); + // commands.spawn(( + // Text::new(concat!( + // "Press 1 to toggle the overlay color.\n", + // "Press 2 to decrease the overlay size.\n", + // "Press 3 to increase the overlay size.\n", + // "Press 4 to toggle the overlay visibility.", + // )), + // Node { + // position_type: PositionType::Absolute, + // bottom: Val::Px(12.0), + // left: Val::Px(12.0), + // ..default() + // }, + // )); } +// fn customize_config(input: Res>, mut overlay: ResMut) { +// if input.just_pressed(KeyCode::Digit1) { +// // Changing resource will affect overlay +// if overlay.text_color == OverlayColor::GREEN { +// overlay.text_color = OverlayColor::RED; +// } else { +// overlay.text_color = OverlayColor::GREEN; +// } +// } +// if input.just_pressed(KeyCode::Digit2) { +// overlay.text_config.font_size -= 2.0; +// } +// if input.just_pressed(KeyCode::Digit3) { +// overlay.text_config.font_size += 2.0; +// } +// if input.just_pressed(KeyCode::Digit4) { +// overlay.enabled = !overlay.enabled; +// } +// }