Qt: Fix FPS counter on Windows
Vicki Pfau vi@endrift.com
Sun, 30 Sep 2018 16:14:17 -0700
3 files changed,
12 insertions(+),
24 deletions(-)
M
CHANGES
→
CHANGES
@@ -113,6 +113,7 @@ - Wii: Fix drawing caching regression (fixes mgba.io/i/1185)
- Switch: Fix incorrect mapping for fast forward cap - GB, GBA: Fix broken opposing button filter (fixes mgba.io/i/1191) - Qt: Fix jumbled background when paused + - Qt: Fix FPS counter on Windows Misc: - mGUI: Add SGB border configuration option - mGUI: Add support for different settings types
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -138,13 +138,11 @@ setCentralWidget(m_screenWidget);
connect(this, &Window::shutdown, m_logView, &QWidget::hide); connect(&m_fpsTimer, &QTimer::timeout, this, &Window::showFPS); - connect(&m_frameTimer, &QTimer::timeout, this, &Window::delimitFrames); connect(&m_focusCheck, &QTimer::timeout, this, &Window::focusCheck); connect(&m_inputController, &InputController::profileLoaded, m_shortcutController, &ShortcutController::loadProfile); m_log.setLevels(mLOG_WARN | mLOG_ERROR | mLOG_FATAL); m_fpsTimer.setInterval(FPS_TIMER_INTERVAL); - m_frameTimer.setInterval(FRAME_LIST_INTERVAL); m_focusCheck.setInterval(200); m_shortcutController->setConfigController(m_config);@@ -773,7 +771,6 @@ m_videoLayers->clear();
m_audioChannels->clear(); m_fpsTimer.stop(); - m_frameTimer.stop(); m_focusCheck.stop(); emit paused(false);@@ -903,19 +900,8 @@ dialog->show();
} void Window::recordFrame() { - if (m_frameList.isEmpty()) { - m_frameList.append(1); - } else { - ++m_frameList.back(); - } -} - -void Window::delimitFrames() { - if (m_frameList.size() >= FRAME_LIST_SIZE) { - m_frameCounter -= m_frameList.takeAt(0); - } - m_frameCounter += m_frameList.back(); - m_frameList.append(0); + m_frameList.append(m_frameTimer.nsecsElapsed()); + m_frameTimer.restart(); } void Window::showFPS() {@@ -923,7 +909,12 @@ if (m_frameList.isEmpty()) {
updateTitle(); return; } - float fps = m_frameCounter * 10000.f / (FRAME_LIST_INTERVAL * (m_frameList.size() - 1)); + qint64 total = 0; + for (qint64 t : m_frameList) { + total += t; + } + double fps = (m_frameList.size() * 1e10) / total; + m_frameList.clear(); fps = round(fps) / 10.f; updateTitle(fps); }@@ -1655,7 +1646,6 @@ ConfigOption* showFps = m_config->addOption("showFps");
showFps->connect([this](const QVariant& value) { if (!value.toInt()) { m_fpsTimer.stop(); - m_frameTimer.stop(); updateTitle(); } else if (m_controller) { m_fpsTimer.start();
M
src/platform/qt/Window.h
→
src/platform/qt/Window.h
@@ -7,6 +7,7 @@ #pragma once
#include <QAction> #include <QDateTime> +#include <QElapsedTimer> #include <QList> #include <QMainWindow> #include <QTimer>@@ -132,7 +133,6 @@ void tryMakePortable();
void mustRestart(); void recordFrame(); - void delimitFrames(); void showFPS(); void focusCheck();@@ -140,8 +140,6 @@ void updateFrame();
private: static const int FPS_TIMER_INTERVAL = 2000; - static const int FRAME_LIST_INTERVAL = 100; - static const int FRAME_LIST_SIZE = 40; void setupMenu(QMenuBar*); void openStateWindow(LoadSave);@@ -189,10 +187,9 @@ WindowBackground* m_screenWidget;
QPixmap m_logo{":/res/mgba-1024.png"}; ConfigController* m_config; InputController m_inputController; - QList<int> m_frameList; - int m_frameCounter = 0; + QList<qint64> m_frameList; + QElapsedTimer m_frameTimer; QTimer m_fpsTimer; - QTimer m_frameTimer; QList<QString> m_mruFiles; QMenu* m_mruMenu = nullptr; QMenu* m_videoLayers;