diff --git a/src/citron/main.cpp b/src/citron/main.cpp index c2cf2d8b0..fccc47bb5 100644 --- a/src/citron/main.cpp +++ b/src/citron/main.cpp @@ -5133,19 +5133,17 @@ void GMainWindow::OnToggleVramOverlay() { } double GMainWindow::GetCurrentFPS() const { - if (!system || !system->IsPoweredOn()) { + if (!this->system || !this->system->IsPoweredOn()) { return 0.0; } - auto results = system->GetAndResetPerfStats(); - return results.average_game_fps; + return last_perf_stats.average_game_fps; } double GMainWindow::GetCurrentFrameTime() const { - if (!system || !system->IsPoweredOn()) { + if (!this->system || !this->system->IsPoweredOn()) { return 0.0; } - auto results = system->GetAndResetPerfStats(); - return results.frametime * 1000.0; // Convert to milliseconds + return last_perf_stats.frametime * 1000.0; } u32 GMainWindow::GetShadersBuilding() const { @@ -5262,11 +5260,10 @@ u64 GMainWindow::GetStagingMemoryUsage() const { } double GMainWindow::GetEmulationSpeed() const { - if (!system || !system->IsPoweredOn()) { + if (!this->system || !this->system->IsPoweredOn()) { return 0.0; } - auto results = system->GetAndResetPerfStats(); - return results.emulation_speed * 100.0; // Convert to percentage + return last_perf_stats.emulation_speed * 100.0; } void GMainWindow::OnAlbum() { @@ -5508,7 +5505,7 @@ void GMainWindow::OnTasStateChanged() { } void GMainWindow::UpdateStatusBar() { - if (emu_thread == nullptr || !system->IsPoweredOn()) { + if (emu_thread == nullptr || !this->system->IsPoweredOn()) { status_bar_update_timer.stop(); return; } @@ -5519,8 +5516,11 @@ void GMainWindow::UpdateStatusBar() { tas_label->clear(); } - auto results = system->GetAndResetPerfStats(); - auto& shader_notify = system->GPU().ShaderNotify(); + // Capture and SAVE the results so the overlay can see them too + last_perf_stats = this->system->GetAndResetPerfStats(); + + const auto& results = last_perf_stats; + auto& shader_notify = this->system->GPU().ShaderNotify(); const int shaders_building = shader_notify.ShadersBuilding(); if (shaders_building > 0) { @@ -5537,8 +5537,8 @@ void GMainWindow::UpdateStatusBar() { if (Settings::values.use_speed_limit.GetValue()) { emu_speed_label->setText(tr("Speed: %1% / %2%") - .arg(results.emulation_speed * 100.0, 0, 'f', 0) - .arg(Settings::values.speed_limit.GetValue())); + .arg(results.emulation_speed * 100.0, 0, 'f', 0) + .arg(Settings::values.speed_limit.GetValue())); } else { emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0)); } diff --git a/src/citron/main.h b/src/citron/main.h index 0fe250a5e..42d14d711 100644 --- a/src/citron/main.h +++ b/src/citron/main.h @@ -20,6 +20,7 @@ #include "citron/compatibility_list.h" #include "citron/hotkeys.h" #include "citron/util/controller_navigation.h" +#include "core/perf_stats.h" #ifdef __unix__ #include @@ -195,6 +196,7 @@ private: void OnSigInterruptNotifierActivated(); void SetGamemodeEnabled(bool state); #endif + Core::PerfStatsResults last_perf_stats{}; Service::AM::FrontendAppletParameters ApplicationAppletParameters(); Service::AM::FrontendAppletParameters LibraryAppletParameters(u64 program_id, Service::AM::AppletId applet_id); std::unique_ptr autoloader_provider; diff --git a/src/citron/util/performance_overlay.cpp b/src/citron/util/performance_overlay.cpp index d41459ef3..ff265f734 100644 --- a/src/citron/util/performance_overlay.cpp +++ b/src/citron/util/performance_overlay.cpp @@ -202,36 +202,24 @@ void PerformanceOverlay::UpdatePerformanceStats() { shaders_building = main_window->GetShadersBuilding(); - static int update_counter = 0; - update_counter++; + current_fps = main_window->GetCurrentFPS(); + current_frame_time = main_window->GetCurrentFrameTime(); + emulation_speed = main_window->GetEmulationSpeed(); - if (update_counter % 2 == 0) { - try { - current_fps = main_window->GetCurrentFPS(); - current_frame_time = main_window->GetCurrentFrameTime(); - emulation_speed = main_window->GetEmulationSpeed(); + // Standard safety checks + if (std::isnan(current_fps) || current_fps < 0.0) current_fps = 0.0; + if (std::isnan(current_frame_time) || current_frame_time < 0.0) current_frame_time = 0.0; + if (std::isnan(emulation_speed) || emulation_speed < 0.0) emulation_speed = 0.0; - if (std::isnan(current_fps) || current_fps < 0.0 || current_fps > 1000.0) current_fps = 60.0; - if (std::isnan(current_frame_time) || current_frame_time < 0.0 || current_frame_time > 100.0) current_frame_time = 16.67; - if (std::isnan(emulation_speed) || emulation_speed < 0.0 || emulation_speed > 1000.0) emulation_speed = 100.0; - - if (current_fps > 0.0) current_frame_time = 1000.0 / current_fps; - } catch (...) {} - } - - if (update_counter % 4 == 0) { + // Update temps every 2 seconds (4 * 500ms) + static int temp_counter = 0; + if (temp_counter++ % 4 == 0) { UpdateHardwareTemperatures(); } - if (std::isnan(current_fps) || current_fps <= 0.0) current_fps = 60.0; - if (std::isnan(current_frame_time) || current_frame_time <= 0.0) current_frame_time = 16.67; - if (std::isnan(emulation_speed) || emulation_speed <= 0.0) emulation_speed = 100.0; - if (current_frame_time > 0.0) AddFrameTime(current_frame_time); fps_color = GetFpsColor(current_fps); - temperature_color = GetTemperatureColor(std::max({cpu_temperature, gpu_temperature, battery_temperature})); - update(); } @@ -386,7 +374,7 @@ void PerformanceOverlay::DrawPerformanceInfo(QPainter& painter) { const int stat_step = painter.fontMetrics().height() + 2; int y_left = (padding / 2) + painter.fontMetrics().ascent(); - int y_right = y_left + 10; + int y_right = y_left + 18; // 1. Draw Title (Left) painter.setFont(title_font);