From c496c0f281465ac741181ab105f113a6f98a8bcf Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Fri, 3 Jul 2020 21:52:27 -0400 Subject: [PATCH] Added logic to increase/decrease emulation speed via hotkeys using QTimer system. Bug fix for = key Qt to SDL mapping. --- src/drivers/Qt/GameApp.cpp | 8 ++++++++ src/drivers/Qt/GameApp.h | 4 ++++ src/drivers/Qt/keyscan.cpp | 2 +- src/drivers/Qt/main.cpp | 13 ++++++++----- src/drivers/Qt/sdl-throttle.cpp | 12 ++++++++++-- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/drivers/Qt/GameApp.cpp b/src/drivers/Qt/GameApp.cpp index dbbbb27b..bd811408 100644 --- a/src/drivers/Qt/GameApp.cpp +++ b/src/drivers/Qt/GameApp.cpp @@ -40,6 +40,14 @@ gameWin_t::~gameWin_t(void) delete viewport; } +void gameWin_t::setCyclePeriodms( int ms ) +{ + // If timer is already running, it will be restarted. + gameTimer->start( ms ); + + //printf("Period Set to: %i ms \n", ms ); +} + void gameWin_t::closeEvent(QCloseEvent *event) { //printf("Main Window Close Event\n"); diff --git a/src/drivers/Qt/GameApp.h b/src/drivers/Qt/GameApp.h index ddd624d1..570ef6e8 100644 --- a/src/drivers/Qt/GameApp.h +++ b/src/drivers/Qt/GameApp.h @@ -30,6 +30,8 @@ class gameWin_t : public QMainWindow gameViewGL_t *viewport; //gameViewSDL_t *viewport; + void setCyclePeriodms( int ms ); + protected: QMenu *fileMenu; QMenu *optMenu; @@ -65,4 +67,6 @@ class gameWin_t : public QMainWindow }; +extern gameWin_t *gameWindow; + #endif diff --git a/src/drivers/Qt/keyscan.cpp b/src/drivers/Qt/keyscan.cpp index 389ac66a..da2b4982 100644 --- a/src/drivers/Qt/keyscan.cpp +++ b/src/drivers/Qt/keyscan.cpp @@ -758,7 +758,7 @@ SDL_Keycode convQtKey2SDLKeyCode( Qt::Key q ) s = SDLK_LESS; break; case Key_Equal: - s = SDLK_LESS; + s = SDLK_EQUALS; break; case Key_Greater: s = SDLK_GREATER; diff --git a/src/drivers/Qt/main.cpp b/src/drivers/Qt/main.cpp index 6c16f142..28e4d882 100644 --- a/src/drivers/Qt/main.cpp +++ b/src/drivers/Qt/main.cpp @@ -3,18 +3,21 @@ #include "Qt/GameApp.h" #include "Qt/fceuWrapper.h" +gameWin_t *gameWindow = NULL; + int main( int argc, char *argv[] ) { QApplication app(argc, argv); - gameWin_t win; + + gameWindow = new gameWin_t(); fceuWrapperInit( argc, argv ); - win.resize( 512, 512 ); - win.show(); + gameWindow->resize( 512, 512 ); + gameWindow->show(); - win.viewport->init(); + gameWindow->viewport->init(); - return app.exec(); + return app.exec(); } diff --git a/src/drivers/Qt/sdl-throttle.cpp b/src/drivers/Qt/sdl-throttle.cpp index 6af554fb..f6a52eb3 100644 --- a/src/drivers/Qt/sdl-throttle.cpp +++ b/src/drivers/Qt/sdl-throttle.cpp @@ -3,6 +3,7 @@ #include "Qt/sdl.h" #include "Qt/throttle.h" +#include "Qt/GameApp.h" static const double Slowest = 0.015625; // 1/64x speed (around 1 fps on NTSC) static const double Fastest = 32; // 32x speed (around 1920 fps on NTSC) @@ -10,7 +11,7 @@ static const double Normal = 1.0; // 1x speed (around 60 fps on NTSC) static uint64 Lasttime, Nexttime; static double desired_frametime = (1.0 / 60.099823); -static int InFrame; +static int InFrame = 0; double g_fpsScale = Normal; // used by sdl.cpp bool MaxSpeed = false; @@ -32,12 +33,19 @@ RefreshThrottleFPS() { double hz; int32_t fps = FCEUI_GetDesiredFPS(); // Do >> 24 to get in Hz + int32_t T; hz = ( ((double)fps) / 16777216.0 ); desired_frametime = 1.0 / ( hz * g_fpsScale ); - printf("FrameTime: %llu %llu %f %lf \n", fps, fps >> 24, hz, desired_frametime ); + T = (int32_t)( desired_frametime * 1000.0 ); + + if ( T < 0 ) T = 1; + + //printf("FrameTime: %llu %llu %f %lf \n", fps, fps >> 24, hz, desired_frametime ); + + gameWindow->setCyclePeriodms( T ); Lasttime=0; Nexttime=0;