FPS counter is back

This commit is contained in:
Arisotura
2020-04-27 23:58:29 +02:00
parent a8aa834c16
commit 0913576ef5
2 changed files with 28 additions and 11 deletions

View File

@ -60,6 +60,9 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent)
{ {
EmuStatus = 0; EmuStatus = 0;
EmuRunning = 2; EmuRunning = 2;
RunningSomething = false;
connect(this, SIGNAL(windowTitleChange(QString)), mainWindow, SLOT(onTitleUpdate(QString)));
} }
void EmuThread::run() void EmuThread::run()
@ -102,8 +105,6 @@ void EmuThread::run()
u32 nsamples = 0; u32 nsamples = 0;
char melontitle[100]; char melontitle[100];
SDL_mutex* titlemutex = SDL_CreateMutex();
void* titledata[2] = {melontitle, titlemutex};
while (EmuRunning != 0) while (EmuRunning != 0)
{ {
@ -207,6 +208,7 @@ void EmuThread::run()
uiAreaQueueRedrawAll(MainDrawArea);*/ uiAreaQueueRedrawAll(MainDrawArea);*/
mainWindow->update(); mainWindow->update();
bool fastforward = false;
/*bool fastforward = HotkeyDown(HK_FastForward); /*bool fastforward = HotkeyDown(HK_FastForward);
if (Config::AudioSync && !fastforward) if (Config::AudioSync && !fastforward)
@ -218,7 +220,7 @@ void EmuThread::run()
if (ret == SDL_MUTEX_TIMEDOUT) break; if (ret == SDL_MUTEX_TIMEDOUT) break;
} }
SDL_UnlockMutex(AudioSyncLock); SDL_UnlockMutex(AudioSyncLock);
} }*/
float framerate = (1000.0f * nlines) / (60.0f * 263.0f); float framerate = (1000.0f * nlines) / (60.0f * 263.0f);
@ -265,11 +267,9 @@ void EmuThread::run()
if (framerate < 1) fpstarget = 999; if (framerate < 1) fpstarget = 999;
else fpstarget = 1000.0f/framerate; else fpstarget = 1000.0f/framerate;
SDL_LockMutex(titlemutex);
sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget); sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget);
SDL_UnlockMutex(titlemutex); changeWindowTitle(melontitle);
uiQueueMain(UpdateWindowTitle, titledata); }
}*/
} }
else else
{ {
@ -297,14 +297,15 @@ void EmuThread::run()
EmuStatus = EmuRunning; EmuStatus = EmuRunning;
sprintf(melontitle, "melonDS " MELONDS_VERSION);
changeWindowTitle(melontitle);
SDL_Delay(100); SDL_Delay(100);
} }
} }
EmuStatus = 0; EmuStatus = 0;
SDL_DestroyMutex(titlemutex);
//if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); //if (Screen_UseGL) uiGLMakeContextCurrent(GLContext);
NDS::DeInit(); NDS::DeInit();
@ -321,6 +322,11 @@ void EmuThread::run()
//if (Screen_UseGL) uiGLMakeContextCurrent(NULL); //if (Screen_UseGL) uiGLMakeContextCurrent(NULL);
} }
void EmuThread::changeWindowTitle(char* title)
{
emit windowTitleChange(QString(title));
}
void EmuThread::emuRun() void EmuThread::emuRun()
{ {
EmuRunning = 1; EmuRunning = 1;
@ -460,6 +466,12 @@ void MainWindow::onOpenFile()
} }
void MainWindow::onTitleUpdate(QString title)
{
setWindowTitle(title);
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
srand(time(NULL)); srand(time(NULL));
@ -623,8 +635,6 @@ int main(int argc, char** argv)
} }
#endif #endif
RunningSomething = false;
mainWindow = new MainWindow(); mainWindow = new MainWindow();
mainWindow->show(); mainWindow->show();

View File

@ -33,12 +33,17 @@ class EmuThread : public QThread
public: public:
explicit EmuThread(QObject* parent = nullptr); explicit EmuThread(QObject* parent = nullptr);
void changeWindowTitle(char* title);
// to be called from the UI thread // to be called from the UI thread
void emuRun(); void emuRun();
void emuPause(bool refresh); void emuPause(bool refresh);
void emuUnpause(); void emuUnpause();
void emuStop(); void emuStop();
signals:
void windowTitleChange(QString title);
private: private:
volatile int EmuStatus; volatile int EmuStatus;
int PrevEmuStatus; int PrevEmuStatus;
@ -73,6 +78,8 @@ public:
private slots: private slots:
void onOpenFile(); void onOpenFile();
void onTitleUpdate(QString title);
private: private:
MainWindowPanel* panel; MainWindowPanel* panel;
}; };