Skip to content

Commit

Permalink
feat(performance-matrix): color code FPS values based on thresholds
Browse files Browse the repository at this point in the history
Color-code the FPS readings in the performance matrix plugin to provide
visually clear feedback regarding the frame rate status. Green indicates
good performance (above 60 FPS), yellow represents acceptable performance
(30 to 60 FPS), and red signifies poor performance (below 30 FPS).
  • Loading branch information
ShenMian committed Jun 19, 2024
1 parent 390e162 commit b9e395b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/plugins/performance_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ impl PerformanceBundle {
};
PerformanceBundle {
text: TextBundle::from_sections([
text_section(Color::GREEN.with_a(ALPHA), "FPS : "),
text_section(Color::CYAN.with_a(ALPHA), ""),
text_section(Color::GREEN.with_a(ALPHA), "FPS(SMA): "),
text_section(Color::CYAN.with_a(ALPHA), ""),
text_section(Color::GREEN.with_a(ALPHA), "FPS(EMA): "),
text_section(Color::CYAN.with_a(ALPHA), ""),
text_section(Color::CYAN.with_a(ALPHA), "FPS : "),
text_section(Color::default().with_a(ALPHA), ""),
text_section(Color::CYAN.with_a(ALPHA), "FPS(SMA): "),
text_section(Color::default().with_a(ALPHA), ""),
text_section(Color::CYAN.with_a(ALPHA), "FPS(EMA): "),
text_section(Color::default().with_a(ALPHA), ""),
])
.with_style(Style {
position_type: PositionType::Absolute,
Expand All @@ -64,13 +64,22 @@ fn update_performance_matrix(
let mut text = query.single_mut();
if let Some(fps) = diagnostics.get(&FrameTimeDiagnosticsPlugin::FPS) {
if let Some(raw) = fps.value() {
text.sections[1].value = format!("{raw:.2}\n");
update_fps(raw, &mut text.sections[1]);
}
if let Some(sma) = fps.average() {
text.sections[3].value = format!("{sma:.2}\n");
update_fps(sma, &mut text.sections[3]);
}
if let Some(ema) = fps.smoothed() {
text.sections[5].value = format!("{ema:.2}\n");
update_fps(ema, &mut text.sections[5]);
}
}
}

fn update_fps(value: f64, section: &mut TextSection) {
section.value = format!("{value:.2}\n");
section.style.color = match value {
v if v < 30.0 => Color::RED,
v if v < 60.0 => Color::YELLOW,
_ => Color::GREEN,
};
}

0 comments on commit b9e395b

Please sign in to comment.