Qt:
- Add fps counter - Minor code cleanup - Linux: DEFINES cleanup
This commit is contained in:
parent
f09b93c62a
commit
83ebb04cc2
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QSize>
|
||||
#include <QAction>
|
||||
#include <QActionGroup>
|
||||
#include <QLabel>
|
||||
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue