2020-05-18 01:09:29 +00:00
|
|
|
use bevy::{
|
|
|
|
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
|
|
|
|
prelude::*,
|
|
|
|
};
|
2020-05-13 20:09:32 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::build()
|
|
|
|
.add_default_plugins()
|
2020-05-18 01:09:29 +00:00
|
|
|
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
2020-05-14 00:31:56 +00:00
|
|
|
.add_startup_system(setup.system())
|
2020-06-17 20:27:10 +00:00
|
|
|
.add_system(text_update_system.system())
|
2020-05-13 20:09:32 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-05-18 01:09:29 +00:00
|
|
|
fn text_update_system(diagnostics: Res<Diagnostics>, mut label: ComMut<Label>) {
|
2020-05-18 21:53:57 +00:00
|
|
|
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
|
|
|
|
if let Some(average) = fps.average() {
|
2020-06-20 19:39:12 +00:00
|
|
|
label.text = format!("FPS: {:.2}", average);
|
2020-05-18 21:53:57 +00:00
|
|
|
}
|
2020-05-18 01:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-13 20:09:32 +00:00
|
|
|
|
2020-05-18 01:09:29 +00:00
|
|
|
fn setup(command_buffer: &mut CommandBuffer, asset_server: Res<AssetServer>) {
|
|
|
|
let font_handle = asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap();
|
2020-05-14 00:31:56 +00:00
|
|
|
command_buffer
|
2020-05-13 20:09:32 +00:00
|
|
|
.build()
|
|
|
|
// 2d camera
|
2020-06-25 18:21:56 +00:00
|
|
|
.entity_with(OrthographicCameraComponents::ui())
|
2020-05-13 20:09:32 +00:00
|
|
|
// texture
|
2020-06-25 18:21:56 +00:00
|
|
|
.entity_with(LabelComponents {
|
2020-05-13 20:09:32 +00:00
|
|
|
node: Node::new(
|
2020-05-18 01:09:29 +00:00
|
|
|
Anchors::TOP_LEFT,
|
|
|
|
Margins::new(0.0, 250.0, 0.0, 60.0),
|
2020-05-13 20:09:32 +00:00
|
|
|
),
|
2020-05-18 01:09:29 +00:00
|
|
|
label: Label {
|
|
|
|
text: "FPS:".to_string(),
|
|
|
|
font: font_handle,
|
2020-06-14 01:53:31 +00:00
|
|
|
style: TextStyle {
|
|
|
|
font_size: 60.0,
|
|
|
|
color: Color::WHITE,
|
|
|
|
},
|
2020-05-18 01:09:29 +00:00
|
|
|
},
|
2020-05-13 20:09:32 +00:00
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
}
|