2020-04-05 21:12:14 +00:00
|
|
|
mod diagnostic;
|
2020-04-04 19:43:16 +00:00
|
|
|
pub mod diagnostics;
|
2020-04-05 21:12:14 +00:00
|
|
|
pub use diagnostic::*;
|
2020-03-27 22:03:47 +00:00
|
|
|
|
2020-04-06 23:15:59 +00:00
|
|
|
use bevy_app::{AppBuilder, AppPlugin};
|
2020-04-30 23:13:21 +00:00
|
|
|
use diagnostics::{
|
|
|
|
frame_time_diagnostic_system, print_diagnostics_system, setup_frame_time_diagnostic_system,
|
|
|
|
PrintDiagnosticsState,
|
|
|
|
};
|
|
|
|
use legion::prelude::IntoSystem;
|
2020-04-05 21:12:14 +00:00
|
|
|
use std::time::Duration;
|
2020-03-27 22:03:47 +00:00
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
pub struct DiagnosticsPlugin {
|
|
|
|
pub print_wait_duration: Duration,
|
|
|
|
pub print_diagnostics: bool,
|
|
|
|
pub add_defaults: bool,
|
2020-03-27 22:03:47 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
impl Default for DiagnosticsPlugin {
|
|
|
|
fn default() -> Self {
|
|
|
|
DiagnosticsPlugin {
|
|
|
|
print_wait_duration: Duration::from_secs_f64(1.0),
|
|
|
|
print_diagnostics: false,
|
|
|
|
add_defaults: true,
|
2020-03-27 22:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
impl AppPlugin for DiagnosticsPlugin {
|
2020-04-06 03:19:02 +00:00
|
|
|
fn build(&self, app: &mut AppBuilder) {
|
2020-05-01 20:12:47 +00:00
|
|
|
app.init_resource::<Diagnostics>();
|
2020-04-05 21:12:14 +00:00
|
|
|
if self.add_defaults {
|
2020-04-30 23:13:21 +00:00
|
|
|
app.add_startup_system(setup_frame_time_diagnostic_system.system())
|
|
|
|
.add_system(frame_time_diagnostic_system.system());
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
2020-03-27 22:03:47 +00:00
|
|
|
|
2020-04-05 21:12:14 +00:00
|
|
|
if self.print_diagnostics {
|
2020-04-30 23:13:21 +00:00
|
|
|
app.add_resource(PrintDiagnosticsState::new(self.print_wait_duration))
|
|
|
|
.add_system(print_diagnostics_system.system());
|
2020-03-27 22:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-04 19:43:16 +00:00
|
|
|
}
|