@@ -703,11 +703,12 @@ void Console::Run()
703703{
704704 Timer clockTimer;
705705 Timer lastFrameTimer;
706+ double frameDurations[60 ] = {};
707+ uint32_t frameDurationIndex = 0 ;
706708 double targetTime;
707709 double lastFrameMin = 9999 ;
708710 double lastFrameMax = 0 ;
709711 uint32_t lastFrameNumber = -1 ;
710- uint32_t lastPauseFrame = 0 ;
711712 double lastDelay = GetFrameDelay ();
712713
713714 _runLock.Acquire ();
@@ -762,7 +763,6 @@ void Console::Run()
762763 // This can happen when something slows the emulator down severely (or when breaking execution in VS when debugging Mesen itself, etc.)
763764 clockTimer.Reset ();
764765 targetTime = 0 ;
765- lastPauseFrame = _ppu->GetFrameCount ();
766766
767767 _resetRunTimers = false ;
768768 lastDelay = delay;
@@ -772,12 +772,16 @@ void Console::Run()
772772
773773 bool displayDebugInfo = _settings->CheckFlag (EmulationFlags::DisplayDebugInfo);
774774 if (displayDebugInfo) {
775- DisplayDebugInformation (clockTimer, lastFrameTimer, lastFrameMin, lastFrameMax, lastPauseFrame);
775+ double lastFrameTime = lastFrameTimer.GetElapsedMS ();
776+ lastFrameTimer.Reset ();
777+ frameDurations[frameDurationIndex] = lastFrameTime;
778+ frameDurationIndex = (frameDurationIndex + 1 ) % 60 ;
779+
780+ DisplayDebugInformation (lastFrameTime, lastFrameMin, lastFrameMax, frameDurations);
776781 if (_slave) {
777- _slave->DisplayDebugInformation (clockTimer, lastFrameTimer, lastFrameMin, lastFrameMax, lastPauseFrame );
782+ _slave->DisplayDebugInformation (lastFrameTime, lastFrameMin, lastFrameMax, frameDurations );
778783 }
779784 }
780- lastFrameTimer.Reset ();
781785
782786 // Sleep until we're ready to start the next frame
783787 clockTimer.WaitUntil (targetTime);
@@ -1039,7 +1043,6 @@ void Console::LoadState(istream &loadStream, uint32_t stateVersion)
10391043
10401044 _debugHud->ClearScreen ();
10411045 _notificationManager->SendNotification (ConsoleNotificationType::StateLoaded);
1042- _resetRunTimers = true ;
10431046 UpdateNesModel (false );
10441047 }
10451048}
@@ -1454,7 +1457,7 @@ void Console::DebugProcessVramWriteOperation(uint16_t addr, uint8_t & value)
14541457#endif
14551458}
14561459
1457- void Console::DisplayDebugInformation (Timer &clockTimer, Timer &lastFrameTimer, double &lastFrameMin, double &lastFrameMax, uint32_t lastPauseFrame )
1460+ void Console::DisplayDebugInformation (double lastFrame, double &lastFrameMin, double &lastFrameMax, double frameDurations[ 60 ] )
14581461{
14591462 AudioStatistics stats = _soundMixer->GetStatistics ();
14601463
@@ -1479,12 +1482,15 @@ void Console::DisplayDebugInformation(Timer &clockTimer, Timer &lastFrameTimer,
14791482 _debugHud->DrawRectangle (132 , 8 , 115 , 49 , 0xFFFFFF , false , 1 , startFrame);
14801483 _debugHud->DrawString (134 , 10 , " Video Stats" , 0xFFFFFF , 0xFF000000 , 1 , startFrame);
14811484
1485+ double totalDuration = 0 ;
1486+ for (int i = 0 ; i < 60 ; i++) {
1487+ totalDuration += frameDurations[i];
1488+ }
1489+
14821490 ss = std::stringstream ();
1483- ss << " FPS: " << std::fixed << std::setprecision (4 ) << ((startFrame - lastPauseFrame) / (clockTimer. GetElapsedMS () / 1000 ));
1491+ ss << " FPS: " << std::fixed << std::setprecision (4 ) << (1000 / (totalDuration/ 60 ));
14841492 _debugHud->DrawString (134 , 21 , ss.str (), 0xFFFFFF , 0xFF000000 , 1 , startFrame);
14851493
1486- double lastFrame = lastFrameTimer.GetElapsedMS ();
1487-
14881494 ss = std::stringstream ();
14891495 ss << " Last Frame: " << std::fixed << std::setprecision (2 ) << lastFrame << " ms" ;
14901496 _debugHud->DrawString (134 , 30 , ss.str (), 0xFFFFFF , 0xFF000000 , 1 , startFrame);
0 commit comments