mirror of https://github.com/stella-emu/stella.git
benchmark: frame stats now display real frame rate when 'Auto' is not selected
This commit is contained in:
parent
0906997d82
commit
b111a8c127
|
@ -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();
|
||||
}
|
||||
myLastScanlines = myOSystem.console().tia().scanlinesLastFrame();
|
||||
drawFrameStats();
|
||||
else
|
||||
myLastFrameRate = myOSystem.console().getFramerate();
|
||||
myLastScanlines = myOSystem.console().tia().scanlinesLastFrame();
|
||||
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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -513,7 +516,6 @@ class FrameBuffer
|
|||
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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue