@@ -2,103 +2,102 @@ use super::{Diagnostic, DiagnosticId, Diagnostics};
22use bevy_app:: prelude:: * ;
33use bevy_core:: { Time , Timer } ;
44use bevy_ecs:: { IntoSystem , Res , ResMut } ;
5+ use bevy_log:: { debug, info} ;
56use bevy_utils:: Duration ;
67
7- /// An App Plugin that prints diagnostics to the console
8- pub struct PrintDiagnosticsPlugin {
8+ /// An App Plugin that logs diagnostics to the console
9+ pub struct LogDiagnosticsPlugin {
910 pub debug : bool ,
1011 pub wait_duration : Duration ,
1112 pub filter : Option < Vec < DiagnosticId > > ,
1213}
1314
14- /// State used by the [PrintDiagnosticsPlugin ]
15- pub struct PrintDiagnosticsState {
15+ /// State used by the [LogDiagnosticsPlugin ]
16+ struct LogDiagnosticsState {
1617 timer : Timer ,
1718 filter : Option < Vec < DiagnosticId > > ,
1819}
1920
20- impl Default for PrintDiagnosticsPlugin {
21+ impl Default for LogDiagnosticsPlugin {
2122 fn default ( ) -> Self {
22- PrintDiagnosticsPlugin {
23+ LogDiagnosticsPlugin {
2324 debug : false ,
2425 wait_duration : Duration :: from_secs ( 1 ) ,
2526 filter : None ,
2627 }
2728 }
2829}
2930
30- impl Plugin for PrintDiagnosticsPlugin {
31+ impl Plugin for LogDiagnosticsPlugin {
3132 fn build ( & self , app : & mut bevy_app:: AppBuilder ) {
32- app. add_resource ( PrintDiagnosticsState {
33+ app. add_resource ( LogDiagnosticsState {
3334 timer : Timer :: new ( self . wait_duration , true ) ,
3435 filter : self . filter . clone ( ) ,
3536 } ) ;
3637
3738 if self . debug {
3839 app. add_system_to_stage (
3940 stage:: POST_UPDATE ,
40- Self :: print_diagnostics_debug_system . system ( ) ,
41+ Self :: log_diagnostics_debug_system . system ( ) ,
4142 ) ;
4243 } else {
43- app. add_system_to_stage ( stage:: POST_UPDATE , Self :: print_diagnostics_system . system ( ) ) ;
44+ app. add_system_to_stage ( stage:: POST_UPDATE , Self :: log_diagnostics_system . system ( ) ) ;
4445 }
4546 }
4647}
4748
48- impl PrintDiagnosticsPlugin {
49+ impl LogDiagnosticsPlugin {
4950 pub fn filtered ( filter : Vec < DiagnosticId > ) -> Self {
50- PrintDiagnosticsPlugin {
51+ LogDiagnosticsPlugin {
5152 filter : Some ( filter) ,
5253 ..Default :: default ( )
5354 }
5455 }
5556
56- fn print_diagnostic ( diagnostic : & Diagnostic ) {
57+ fn log_diagnostic ( diagnostic : & Diagnostic ) {
5758 if let Some ( value) = diagnostic. value ( ) {
58- print ! ( "{:<65}: {:<10.6}" , diagnostic. name, value) ;
5959 if let Some ( average) = diagnostic. average ( ) {
60- print ! ( " (avg {:.6})" , average) ;
60+ info ! (
61+ "{:<65}: {:<10.6} (avg {:.6})" ,
62+ diagnostic. name, value, average
63+ ) ;
64+ } else {
65+ info ! ( "{:<65}: {:<10.6}" , diagnostic. name, value) ;
6166 }
62-
63- println ! ( "\n " ) ;
6467 }
6568 }
6669
67- pub fn print_diagnostics_system (
68- mut state : ResMut < PrintDiagnosticsState > ,
70+ fn log_diagnostics_system (
71+ mut state : ResMut < LogDiagnosticsState > ,
6972 time : Res < Time > ,
7073 diagnostics : Res < Diagnostics > ,
7174 ) {
7275 if state. timer . tick ( time. delta_seconds ( ) ) . finished ( ) {
73- println ! ( "Diagnostics:" ) ;
74- println ! ( "{}" , "-" . repeat( 93 ) ) ;
7576 if let Some ( ref filter) = state. filter {
7677 for diagnostic in filter. iter ( ) . map ( |id| diagnostics. get ( * id) . unwrap ( ) ) {
77- Self :: print_diagnostic ( diagnostic) ;
78+ Self :: log_diagnostic ( diagnostic) ;
7879 }
7980 } else {
80- for diagnostic in diagnostics. iter ( ) {
81- Self :: print_diagnostic ( diagnostic) ;
81+ for diagnostic in diagnostics. ordered_iter ( ) {
82+ Self :: log_diagnostic ( diagnostic) ;
8283 }
8384 }
8485 }
8586 }
8687
87- pub fn print_diagnostics_debug_system (
88- mut state : ResMut < PrintDiagnosticsState > ,
88+ fn log_diagnostics_debug_system (
89+ mut state : ResMut < LogDiagnosticsState > ,
8990 time : Res < Time > ,
9091 diagnostics : Res < Diagnostics > ,
9192 ) {
9293 if state. timer . tick ( time. delta_seconds ( ) ) . finished ( ) {
93- println ! ( "Diagnostics (Debug):" ) ;
94- println ! ( "{}" , "-" . repeat( 93 ) ) ;
9594 if let Some ( ref filter) = state. filter {
9695 for diagnostic in filter. iter ( ) . map ( |id| diagnostics. get ( * id) . unwrap ( ) ) {
97- println ! ( "{:#?}\n " , diagnostic) ;
96+ debug ! ( "{:#?}\n " , diagnostic) ;
9897 }
9998 } else {
100- for diagnostic in diagnostics. iter ( ) {
101- println ! ( "{:#?}\n " , diagnostic) ;
99+ for diagnostic in diagnostics. ordered_iter ( ) {
100+ debug ! ( "{:#?}\n " , diagnostic) ;
102101 }
103102 }
104103 }
0 commit comments