diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index c0cafb029..016ba103f 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -46,7 +46,10 @@ FrameBuffer::FrameBuffer(OSystem& osystem) : myOSystem(osystem), myInitializedCount(0), myPausedCount(0), - myCurrentModeList(nullptr) + myCurrentModeList(nullptr), + myTotalTime(0), + myTotalFrames(0), + myLastRunFrameRate(0) { myMsg.surface = myStatsMsg.surface = nullptr; myStatsEnabled = myMsg.enabled = myStatsMsg.enabled = false; @@ -230,7 +233,7 @@ FBInitStatus FrameBuffer::createDisplay(const string& title, // Create surfaces for TIA statistics and general messages myStatsMsg.color = kColorInfo; myStatsMsg.w = infoFont().getMaxCharWidth() * 30 + 2; - myStatsMsg.h = (infoFont().getFontHeight() + 2) * 2; + myStatsMsg.h = (infoFont().getFontHeight() + 2) * 3; if(!myStatsMsg.surface) { @@ -285,35 +288,10 @@ void FrameBuffer::update() // Show frame statistics if(myStatsMsg.enabled) - { - const ConsoleInfo& info = myOSystem.console().about(); - char msg[30]; - uInt32 color; - - myStatsMsg.surface->invalidate(); - string bsinfo = info.BankSwitch + - (myOSystem.settings().getBool("dev.settings") ? "| Developer" : "| Player"); - // draw shadowed text - color = myOSystem.console().tia().scanlinesLastFrame() != myLastScanlines ? kDbgColorRed : myStatsMsg.color; - std::snprintf(msg, 30, "%3u", myOSystem.console().tia().scanlinesLastFrame()); - myStatsMsg.surface->drawString(infoFont(), msg, 1, 1, - myStatsMsg.w, color, TextAlign::Left, 0, true, kBGColor); - color = myOSystem.console().getFramerate() != myLastFrameRate ? kDbgColorRed : myStatsMsg.color; - std::snprintf(msg, 30, "@ %3.2ffps", myOSystem.console().getFramerate()); - myStatsMsg.surface->drawString(infoFont(), msg, 1 + infoFont().getStringWidth("262 "), 1, - myStatsMsg.w, color, TextAlign::Left, 0, true, kBGColor); - std::snprintf(msg, 30, "=> %s", info.DisplayFormat.c_str()); - myStatsMsg.surface->drawString(infoFont(), msg, 1+ infoFont().getStringWidth("262 @ 60.00fps "), 1, - myStatsMsg.w, myStatsMsg.color, TextAlign::Left, 0, true, kBGColor); - - myStatsMsg.surface->drawString(infoFont(), bsinfo, 1, 15, - myStatsMsg.w, myStatsMsg.color, TextAlign::Left, 0, true, kBGColor); - myStatsMsg.surface->setDirty(); - myStatsMsg.surface->setDstPos(myImageRect.x() + 1, myImageRect.y() + 1); - myStatsMsg.surface->render(); - } + drawFrameStats(); + else + myLastFrameRate = myOSystem.console().getFramerate(); myLastScanlines = myOSystem.console().tia().scanlinesLastFrame(); - myLastFrameRate = myOSystem.console().getFramerate(); myPausedCount = 0; break; // EventHandlerState::EMULATION } @@ -399,6 +377,61 @@ void FrameBuffer::showMessage(const string& message, MessagePosition position, myMsg.enabled = true; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FrameBuffer::drawFrameStats() +{ + const ConsoleInfo& info = myOSystem.console().about(); + char msg[30]; + uInt32 color; + + myStatsMsg.surface->invalidate(); + string bsinfo = info.BankSwitch + + (myOSystem.settings().getBool("dev.settings") ? "| Developer" : "| Player"); + // draw shadowed text + color = myOSystem.console().tia().scanlinesLastFrame() != myLastScanlines ? kDbgColorRed : myStatsMsg.color; + std::snprintf(msg, 30, "%3u", myOSystem.console().tia().scanlinesLastFrame()); + myStatsMsg.surface->drawString(infoFont(), msg, 1, 1, + myStatsMsg.w, color, TextAlign::Left, 0, true, kBGColor); + // draw framerate + float frameRate; + if(myOSystem.settings().getInt("framerate") == 0) + { + // if 'Auto' is selected, draw the calculated framerate + frameRate = myOSystem.console().getFramerate(); + } + else + { + // if 'Auto' is not selected, draw the effective framerate + const TimingInfo& ti = myOSystem.timingInfo(); + if(ti.totalFrames - myTotalFrames >= myLastFrameRate) + { + frameRate = 1000000.0 * (ti.totalFrames - myTotalFrames) / (ti.totalTime - myTotalTime); + if(frameRate > myOSystem.console().getFramerate() + 1) + frameRate = 1; + myTotalFrames = ti.totalFrames; + myTotalTime = ti.totalTime; + } + else + frameRate = myLastFrameRate; + } + color = frameRate != myLastFrameRate ? kDbgColorRed : myStatsMsg.color; + myLastFrameRate = frameRate; + std::snprintf(msg, 30, "@%6.2ffps", frameRate); + myStatsMsg.surface->drawString(infoFont(), msg, 1 + infoFont().getStringWidth("262 "), 1, + myStatsMsg.w, color, TextAlign::Left, 0, true, kBGColor); + std::snprintf(msg, 30, "=> %s", info.DisplayFormat.c_str()); + myStatsMsg.surface->drawString(infoFont(), msg, 1 + infoFont().getStringWidth("262 @ 60.00fps "), 1, + myStatsMsg.w, myStatsMsg.color, TextAlign::Left, 0, true, kBGColor); + + myStatsMsg.surface->drawString(infoFont(), bsinfo, 1, 15, + myStatsMsg.w, myStatsMsg.color, TextAlign::Left, 0, true, kBGColor); + + myStatsMsg.surface->setDirty(); + myStatsMsg.surface->setDstPos(myImageRect.x() + 1, myImageRect.y() + 1); + myStatsMsg.surface->render(); + +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameBuffer::toggleFrameStats() { diff --git a/src/emucore/FrameBuffer.hxx b/src/emucore/FrameBuffer.hxx index 472213b3c..f5d6580fd 100644 --- a/src/emucore/FrameBuffer.hxx +++ b/src/emucore/FrameBuffer.hxx @@ -458,6 +458,9 @@ class FrameBuffer string myScreenTitle; private: + // Draws the frame stats overlay + void drawFrameStats(); + // Indicates the number of times the framebuffer was initialized uInt32 myInitializedCount; @@ -512,8 +515,7 @@ class FrameBuffer bool myStatsEnabled; uInt32 myLastScanlines; float myLastFrameRate; - - + bool myGrabMouse; // The list of all available video modes for this framebuffer @@ -533,6 +535,10 @@ class FrameBuffer // Holds UI palette data (standard and classic colours) static uInt32 ourGUIColors[3][kNumColors-256]; + uInt64 myTotalTime; + uInt64 myTotalFrames; + float myLastRunFrameRate; + private: // Following constructors and assignment operators not supported FrameBuffer() = delete; diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 95175dc67..2a5704382 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -633,7 +633,7 @@ void OSystem::mainLoop() // for that and reset the timers when appropriate if((myTimingInfo.virt - myTimingInfo.current) > (myTimePerFrame << 1)) { - myTimingInfo.start = myTimingInfo.current = myTimingInfo.virt = getTicks(); + myTimingInfo.current = myTimingInfo.virt = getTicks(); } if(myTimingInfo.current < myTimingInfo.virt)