diff --git a/stella/src/common/Snapshot.cxx b/stella/src/common/Snapshot.cxx index 38f3962f8..0e7febfb1 100644 --- a/stella/src/common/Snapshot.cxx +++ b/stella/src/common/Snapshot.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Snapshot.cxx,v 1.19 2008-03-30 15:01:38 stephena Exp $ +// $Id: Snapshot.cxx,v 1.20 2008-05-20 13:42:50 stephena Exp $ //============================================================================ #include @@ -38,7 +38,7 @@ void Snapshot::savePNG(FrameBuffer& framebuffer, const Properties& props, try { // Make sure we have a 'clean' image, with no onscreen messages - framebuffer.hideMessage(); + framebuffer.enableMessages(false); // Get actual image dimensions. which are not always the same // as the framebuffer dimensions @@ -105,6 +105,8 @@ void Snapshot::savePNG(FrameBuffer& framebuffer, const Properties& props, if(compmem) delete[] compmem; out.close(); + // Re-enabled old messages + framebuffer.enableMessages(true); framebuffer.showMessage("Snapshot saved"); } catch(const char *msg) diff --git a/stella/src/emucore/EventHandler.cxx b/stella/src/emucore/EventHandler.cxx index cf42d8208..11858ddbe 100644 --- a/stella/src/emucore/EventHandler.cxx +++ b/stella/src/emucore/EventHandler.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: EventHandler.cxx,v 1.223 2008-05-16 12:17:22 stephena Exp $ +// $Id: EventHandler.cxx,v 1.224 2008-05-20 13:42:50 stephena Exp $ //============================================================================ #include @@ -428,6 +428,9 @@ void EventHandler::poll(uInt32 time) myOSystem->console().togglePhosphor(); break; + case SDLK_l: + myOSystem->frameBuffer().toggleFrameStats(); + break; #if 0 // FIXME - these will be removed when a UI is added for event recording case SDLK_e: // Alt-e starts/stops event recording diff --git a/stella/src/emucore/FrameBuffer.cxx b/stella/src/emucore/FrameBuffer.cxx index 8741802d6..0f3250b82 100644 --- a/stella/src/emucore/FrameBuffer.cxx +++ b/stella/src/emucore/FrameBuffer.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBuffer.cxx,v 1.128 2008-05-19 21:16:58 stephena Exp $ +// $Id: FrameBuffer.cxx,v 1.129 2008-05-20 13:42:50 stephena Exp $ //============================================================================ #include @@ -45,7 +45,8 @@ FrameBuffer::FrameBuffer(OSystem* osystem) myUsePhosphor(false), myPhosphorBlend(77), myInitializedCount(0), - myPausedCount(0) + myPausedCount(0), + myFrameStatsEnabled(false) { } @@ -124,6 +125,18 @@ void FrameBuffer::update() // And update the screen drawMediaSource(); + // Show frame statistics + if(myFrameStatsEnabled) + { + // FIXME - sizes hardcoded for now; fix during UI refactoring + uInt32 scanlines = myOSystem->console().mediaSource().scanlines(); + float fps = (scanlines <= 285 ? 15720.0 : 15600.0) / scanlines; + char msg[30]; + sprintf(msg, "%u LINES %2.2f FPS", scanlines, fps); + fillRect(3, 3, 95, 9, kBGColor); + drawString(&myOSystem->font(), msg, 3, 3, 95, kBtnTextColor, kTextAlignCenter); + } + break; // S_EMULATE } @@ -261,12 +274,36 @@ void FrameBuffer::showMessage(const string& message, MessagePosition position, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FrameBuffer::hideMessage() +void FrameBuffer::toggleFrameStats() { - // Erase old messages on the screen - if(myMessage.counter > 0) + showFrameStats(!myOSystem->settings().getBool("stats")); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FrameBuffer::showFrameStats(bool enable) +{ + myOSystem->settings().setBool("stats", enable); + myFrameStatsEnabled = enable; + myOSystem->eventHandler().refreshDisplay(true); // Do this twice for + myOSystem->eventHandler().refreshDisplay(true); // double-buffered modes +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FrameBuffer::enableMessages(bool enable) +{ + if(enable) { + // Only re-anable frame stats if they were already enabled before + myFrameStatsEnabled = myOSystem->settings().getBool("stats"); + } + else + { + // Temporarily disable frame stats + myFrameStatsEnabled = false; + + // Erase old messages on the screen myMessage.counter = 0; + myOSystem->eventHandler().refreshDisplay(true); // Do this twice for myOSystem->eventHandler().refreshDisplay(true); // double-buffered modes } diff --git a/stella/src/emucore/FrameBuffer.hxx b/stella/src/emucore/FrameBuffer.hxx index d244cc9df..61fd8fd36 100644 --- a/stella/src/emucore/FrameBuffer.hxx +++ b/stella/src/emucore/FrameBuffer.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBuffer.hxx,v 1.94 2008-03-13 22:58:06 stephena Exp $ +// $Id: FrameBuffer.hxx,v 1.95 2008-05-20 13:42:50 stephena Exp $ //============================================================================ #ifndef FRAMEBUFFER_HXX @@ -101,7 +101,7 @@ enum { All GUI elements (ala ScummVM) are drawn here as well. @author Stephen Anthony - @version $Id: FrameBuffer.hxx,v 1.94 2008-03-13 22:58:06 stephena Exp $ + @version $Id: FrameBuffer.hxx,v 1.95 2008-05-20 13:42:50 stephena Exp $ */ class FrameBuffer { @@ -146,9 +146,20 @@ class FrameBuffer int color = kTextColorHi); /** - Hides any onscreen messages. + Toggles showing or hiding framerate statistics. */ - void hideMessage(); + void toggleFrameStats(); + + /** + Shows a message containing frame statistics for the current frame. + */ + void showFrameStats(bool enable); + + /** + Enable/disable any pending messages. Disabled messages aren't removed + from the message queue; they're just not redrawn into the framebuffer. + */ + void enableMessages(bool enable); /** Returns the current width of the framebuffer *before* any scaling. @@ -520,7 +531,7 @@ class FrameBuffer void setWindowIcon(); /** - Set the icon for the main SDL window. + Draw pending messages. */ void drawMessage(); @@ -570,6 +581,10 @@ class FrameBuffer }; Message myMessage; + // Used to show frame statistics (scanline count and framerate) + Message myFrameStats; + bool myFrameStatsEnabled; + // The list of all available video modes for this framebuffer VideoModeList myWindowedModeList; VideoModeList myFullscreenModeList; diff --git a/stella/src/emucore/OSystem.cxx b/stella/src/emucore/OSystem.cxx index 96528a962..5df73a728 100644 --- a/stella/src/emucore/OSystem.cxx +++ b/stella/src/emucore/OSystem.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: OSystem.cxx,v 1.126 2008-05-19 21:16:58 stephena Exp $ +// $Id: OSystem.cxx,v 1.127 2008-05-20 13:42:50 stephena Exp $ //============================================================================ #include @@ -358,6 +358,7 @@ bool OSystem::createFrameBuffer(bool showmessage) break; } } + myFrameBuffer->showFrameStats(mySettings->getBool("stats")); return true; } diff --git a/stella/src/emucore/Settings.cxx b/stella/src/emucore/Settings.cxx index 1ed41a130..9978cfbbf 100644 --- a/stella/src/emucore/Settings.cxx +++ b/stella/src/emucore/Settings.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Settings.cxx,v 1.144 2008-05-16 12:04:34 stephena Exp $ +// $Id: Settings.cxx,v 1.145 2008-05-20 13:42:50 stephena Exp $ //============================================================================ #include @@ -101,6 +101,7 @@ Settings::Settings(OSystem* osystem) setInternal("showinfo", "false"); setInternal("tiafloat", "true"); setInternal("avoxport", ""); + setInternal("stats", "false"); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -327,6 +328,7 @@ void Settings::usage() << " -autoslot <1|0> Automatically switch to next save slot when state saving\n" << " -ssdir The directory to save snapshot files to\n" << " -sssingle <1|0> Generate single snapshot instead of many\n" + << " -stats <1|0> Show scanline and framerate info during emulation\n" << endl << " -listrominfo Display contents of stella.pro, one line per ROM entry\n" << " -rominfo Display detailed information for the given ROM\n" diff --git a/stella/src/gui/DialogContainer.cxx b/stella/src/gui/DialogContainer.cxx index bd1c33750..30890b99b 100644 --- a/stella/src/gui/DialogContainer.cxx +++ b/stella/src/gui/DialogContainer.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: DialogContainer.cxx,v 1.42 2008-05-11 21:18:35 stephena Exp $ +// $Id: DialogContainer.cxx,v 1.43 2008-05-20 13:42:50 stephena Exp $ //============================================================================ #include "OSystem.hxx" @@ -137,7 +137,7 @@ void DialogContainer::reStack() addDialog(myBaseDialog); // Erase any previous messages - myOSystem->frameBuffer().hideMessage(); + myOSystem->frameBuffer().enableMessages(false); // Reset all continuous events reset();