Add performance stats overlay in status bar

Show FPS, frame time, visible/total objects, and visible/total
triangles in the status bar. Toggled via Settings > Show Performance
Stats, persisted in app settings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-04-11 20:05:50 +10:00
parent bfac12dbe7
commit 6f6bebf387
8 changed files with 84 additions and 0 deletions
+21
View File
@@ -18,6 +18,7 @@
********************************************************************************/
#include "MainWindow.h"
#include "AppSettings.h"
#include "SettingsWindow.h"
#include <QApplication>
@@ -43,6 +44,23 @@ MainWindow::MainWindow(QWidget* parent)
QMessageBox::warning(this, "Error", msg);
}, Qt::QueuedConnection);
connect(viewport_, &ViewportWindow::frameStatsUpdated, this, [this](const ViewportWindow::FrameStats& s) {
if (!stats_label_->isVisible()) return;
stats_label_->setText(
QString("%1 fps | %2 ms | %3/%4 obj | %5/%6 tri")
.arg(s.fps, 0, 'f', 1)
.arg(s.frame_time_ms, 0, 'f', 1)
.arg(s.visible_objects)
.arg(s.total_objects)
.arg(s.visible_triangles)
.arg(s.total_triangles));
});
connect(&AppSettings::instance(), &AppSettings::showStatsChanged, this, [this](bool show) {
stats_label_->setVisible(show);
if (!show) stats_label_->clear();
});
connect(&element_poll_timer_, &QTimer::timeout, this, &MainWindow::pollNewElements);
element_poll_timer_.setInterval(100);
@@ -91,7 +109,10 @@ void MainWindow::setupUi() {
progress_bar_->setMaximumWidth(200);
progress_bar_->setVisible(false);
status_label_ = new QLabel("Ready");
stats_label_ = new QLabel();
stats_label_->setVisible(AppSettings::instance().showStats());
statusBar()->addWidget(status_label_, 1);
statusBar()->addPermanentWidget(stats_label_);
statusBar()->addPermanentWidget(progress_bar_);
}