From 83ebb04cc2009581f0d73cc34124c285f7414cce Mon Sep 17 00:00:00 2001 From: alvinwong Date: Tue, 18 Mar 2014 13:19:23 +0000 Subject: [PATCH] Qt: - Add fps counter - Minor code cleanup - Linux: DEFINES cleanup --- desmume/src/qt/project/core/core.pro | 33 ------------------- desmume/src/qt/project/frontend/main.cpp | 1 + desmume/src/qt/project/frontend/mainloop.cpp | 23 +++++++++++++ desmume/src/qt/project/frontend/mainloop.h | 6 ++++ .../src/qt/project/frontend/ui/mainwindow.cpp | 14 ++++++-- .../src/qt/project/frontend/ui/mainwindow.h | 6 ++-- 6 files changed, 45 insertions(+), 38 deletions(-) diff --git a/desmume/src/qt/project/core/core.pro b/desmume/src/qt/project/core/core.pro index d3771c602..89fb9e85e 100644 --- a/desmume/src/qt/project/core/core.pro +++ b/desmume/src/qt/project/core/core.pro @@ -63,41 +63,8 @@ win32 { DEFINES += \ HOST_LINUX=1 \ - PACKAGE_NAME=\\\"desmume\\\" \ - PACKAGE_TARNAME=\\\"desmume\\\" \ - PACKAGE_VERSION=\\\"svn\\\" \ - PACKAGE_STRING=\\\"desmume\ svn\\\" \ - PACKAGE_BUGREPORT=\\\"\\\" \ - PACKAGE_URL=\\\"\\\" \ - PACKAGE=\\\"desmume\\\" \ - VERSION=\\\"svn\\\" \ - STDC_HEADERS=1 \ - HAVE_SYS_TYPES_H=1 \ - HAVE_SYS_STAT_H=1 \ - HAVE_STDLIB_H=1 \ - HAVE_STRING_H=1 \ - HAVE_MEMORY_H=1 \ - HAVE_STRINGS_H=1 \ - HAVE_INTTYPES_H=1 \ - HAVE_STDINT_H=1 \ - HAVE_UNISTD_H=1 \ HAVE_LIBZ=1 \ - HAVE_GL_GL_H=1 \ - HAVE_GL_GLU_H=1 \ - HAVE_LIBDL=1 \ - HAVE_LIBGL=1 \ - HAVE_GL_GLX_H=1 \ - HAVE_GL_GLX=1 \ - GLADEUI_UNINSTALLED_DIR=\\\"/home/alvin/src/desmume-svn-code/src/gtk-glade/glade/\\\" \ - GTKGLEXT_AVAILABLE=1 \ HAVE_LIBAGG=1 \ - GETTEXT_PACKAGE=\\\"desmume\\\" \ - HAVE_LOCALE_H=1 \ - HAVE_LC_MESSAGES=1 \ - HAVE_BIND_TEXTDOMAIN_CODESET=1 \ - HAVE_GETTEXT=1 \ - HAVE_DCGETTEXT=1 \ - ENABLE_NLS=1 \ HAVE_JIT=1 \ _GNU_SOURCE=1 \ _REENTRANT diff --git a/desmume/src/qt/project/frontend/main.cpp b/desmume/src/qt/project/frontend/main.cpp index 55da8b5c2..34788e907 100644 --- a/desmume/src/qt/project/frontend/main.cpp +++ b/desmume/src/qt/project/frontend/main.cpp @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) { QObject::connect(desmume::qt::ds::video, &desmume::qt::Video::screenBufferUpdated, &w, &desmume::qt::MainWindow::screenBufferUpdate); QObject::connect(&mainLoop, &desmume::qt::MainLoop::screenRedrawRequested, &w, &desmume::qt::MainWindow::screenRedraw); + QObject::connect(&mainLoop, &desmume::qt::MainLoop::fpsUpdated, &w, &desmume::qt::MainWindow::fpsUpdate); return a.exec(); } diff --git a/desmume/src/qt/project/frontend/mainloop.cpp b/desmume/src/qt/project/frontend/mainloop.cpp index b5cafdbe8..ade2e9858 100644 --- a/desmume/src/qt/project/frontend/mainloop.cpp +++ b/desmume/src/qt/project/frontend/mainloop.cpp @@ -33,6 +33,9 @@ MainLoop::MainLoop(QObject *parent) , mLoopInitialized(false) , mFrameMod3(0) , mNextFrameTimeNs(0) + , mFpsCounter(0) + , mFps(0) + , mNextFpsCountTime(0) { } @@ -40,6 +43,10 @@ void MainLoop::kickStart() { mBasicTimer->start(100, this); } +int MainLoop::fps() { + return mFps; +} + void MainLoop::timerEvent(QTimerEvent* event) { loop(); } @@ -52,6 +59,9 @@ void MainLoop::loop() { mTime->start(); mNextFrameTimeNs = 0; mFrameMod3 = 0; + mFpsCounter = 0; + mFps = 0; + mNextFpsCountTime = 1000; } // ---- Time keeping ---- @@ -86,6 +96,9 @@ void MainLoop::loop() { mBasicTimer->start(0, this); } + // Count the fps + countFps(mTime->elapsed()); + //qDebug("Accumulative: %lld", mTime->elapsed()); // ---- Real action ---- @@ -104,5 +117,15 @@ void MainLoop::loop() { //this->screenRedrawRequested(false); } +void MainLoop::countFps(qint64 thisFrameTime) { + mFpsCounter += 1; + if (thisFrameTime >= mNextFpsCountTime) { + mNextFpsCountTime = thisFrameTime + 1000; + mFps = mFpsCounter; + mFpsCounter = 0; + this->fpsUpdated(mFps); + } +} + } /* namespace qt */ } /* namespace desmume */ diff --git a/desmume/src/qt/project/frontend/mainloop.h b/desmume/src/qt/project/frontend/mainloop.h index 84f9689c7..bdaf549f4 100644 --- a/desmume/src/qt/project/frontend/mainloop.h +++ b/desmume/src/qt/project/frontend/mainloop.h @@ -34,15 +34,21 @@ class MainLoop : public QObject { bool mLoopInitialized; int mFrameMod3; qint64 mNextFrameTimeNs; + int mFpsCounter; + int mFps; + qint64 mNextFpsCountTime; void loop(); + void countFps(qint64 thisFrameTime); protected: void timerEvent(QTimerEvent* event); public: explicit MainLoop(QObject* parent = 0); void kickStart(); + int fps(); signals: void screenRedrawRequested(bool immediate); + void fpsUpdated(int fps); private slots: diff --git a/desmume/src/qt/project/frontend/ui/mainwindow.cpp b/desmume/src/qt/project/frontend/ui/mainwindow.cpp index cdac5d71f..26d7f7a7d 100644 --- a/desmume/src/qt/project/frontend/ui/mainwindow.cpp +++ b/desmume/src/qt/project/frontend/ui/mainwindow.cpp @@ -36,6 +36,7 @@ namespace qt { MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) + , mFpsLabel(NULL) { ui->setupUi(this); this->populateVideoFilterMenu(); @@ -52,7 +53,7 @@ void MainWindow::populateVideoFilterMenu() { videoFilterActionGroup = new QActionGroup(this); for (int i = 0; i < VideoFilterTypeIDCount; i++) { const VideoFilterAttributes& filter = VideoFilterAttributesList[i]; - QAction *act = new QAction(this); + QAction *act = new QAction(videoFilterActionGroup); act->setObjectName(QStringLiteral("actionVideoFilter") + filter.typeString); act->setCheckable(true); act->setData(i); @@ -62,7 +63,6 @@ void MainWindow::populateVideoFilterMenu() { } else { act->setText(filter.typeString); } - videoFilterActionGroup->addAction(act); ui->menuVideoFilter->addAction(act); } connect(videoFilterActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(videoFilterActionGroup_triggered(QAction*))); @@ -85,6 +85,16 @@ void MainWindow::screenRedraw(bool immediate) { } } +void MainWindow::fpsUpdate(int fps) { + QString fpsText = QStringLiteral("%1 fps").arg(fps); + if (mFpsLabel == NULL) { + mFpsLabel = new QLabel(fpsText, ui->statusBar); + ui->statusBar->addPermanentWidget(mFpsLabel); + } else { + mFpsLabel->setText(fpsText); + } +} + void MainWindow::keyPressEvent(QKeyEvent *event) { if (!keyboard.keyPress(event->key())) { QMainWindow::keyPressEvent(event); diff --git a/desmume/src/qt/project/frontend/ui/mainwindow.h b/desmume/src/qt/project/frontend/ui/mainwindow.h index f1502718f..4b9b46040 100644 --- a/desmume/src/qt/project/frontend/ui/mainwindow.h +++ b/desmume/src/qt/project/frontend/ui/mainwindow.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace desmume { namespace qt { @@ -37,6 +38,7 @@ class MainWindow : public QMainWindow { Q_OBJECT QActionGroup* videoFilterActionGroup; + QLabel* mFpsLabel; void populateVideoFilterMenu(); protected: void keyPressEvent(QKeyEvent *event); @@ -48,17 +50,15 @@ public: public slots: void screenBufferUpdate(unsigned int *buf, const QSize &size, qreal scale); void screenRedraw(bool immediate); + void fpsUpdate(int fps); private slots: void on_actionQuit_triggered(); void videoFilterActionGroup_triggered(QAction* action); void on_actionConfigureControls_triggered(); void on_actionPause_toggled(bool checked); - void on_actionOpenROM_triggered(); - void on_actionAboutQt_triggered(); - void on_action_AboutDeSmuME_triggered(); private: