From f9595b11fc2bef08d84a00b81f9b2884f77897b0 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 26 Dec 2014 23:18:54 +0200 Subject: ZVISION: Add an FPS timer (accessible with F10, or the "FRAME" cheat) --- engines/zvision/core/events.cpp | 18 +++++++++++++----- engines/zvision/zvision.cpp | 19 ++++++++++++++++++- engines/zvision/zvision.h | 7 +++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/engines/zvision/core/events.cpp b/engines/zvision/core/events.cpp index 4438474078..7804130e2a 100644 --- a/engines/zvision/core/events.cpp +++ b/engines/zvision/core/events.cpp @@ -158,15 +158,18 @@ void ZVision::cheatCodes(uint8 key) { } } - if (checkCode("FRAME")) - _renderManager->showDebugMsg(Common::String::format("FPS: ???, not implemented")); + if (checkCode("FRAME")) { + Common::String fpsStr = Common::String::format("FPS: %d", getFPS()); + _renderManager->showDebugMsg(fpsStr); + } + + if (checkCode("COMPUTERARCH")) + _renderManager->showDebugMsg("COMPUTERARCH: var-viewer not implemented"); + // This cheat essentially toggles the GOxxxx cheat below if (checkCode("XYZZY")) _scriptManager->setStateValue(StateKey_DebugCheats, 1 - _scriptManager->getStateValue(StateKey_DebugCheats)); - if (checkCode("COMPUTERARCH")) - _renderManager->showDebugMsg(Common::String::format("COMPUTERARCH: var-viewer not implemented")); - if (_scriptManager->getStateValue(StateKey_DebugCheats) == 1) if (checkCode("GO????")) _scriptManager->changeLocation(getBufferedKey(3), @@ -240,6 +243,11 @@ void ZVision::processEvents() { _scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2; break; + case Common::KEYCODE_F10: { + Common::String fpsStr = Common::String::format("FPS: %d", getFPS()); + _renderManager->showDebugMsg(fpsStr); + } + break; default: break; } diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index b3fc02ee15..615574bbcd 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -101,7 +101,9 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _frameRenderDelay(2), _keyboardVelocity(0), _mouseVelocity(0), - _videoIsPlaying(false) { + _videoIsPlaying(false), + _renderedFrameCount(0), + _fps(0) { debug(1, "ZVision::ZVision"); @@ -130,6 +132,8 @@ ZVision::~ZVision() { delete _rnd; delete _midiManager; + getTimerManager()->removeTimerProc(&fpsTimerCallback); + // Remove all of our debug levels DebugMan.clearAllDebugChannels(); } @@ -214,6 +218,9 @@ void ZVision::initialize() { // Create debugger console. It requires GFX to be initialized _console = new Console(this); _doubleFPS = ConfMan.getBool("doublefps"); + + // Initialize FPS timer callback + getTimerManager()->installTimerProc(&fpsTimerCallback, 1000000, this, "zvisionFPS"); } Common::Error ZVision::run() { @@ -246,6 +253,7 @@ Common::Error ZVision::run() { // Update the screen if (canRender()) { _system->updateScreen(); + _renderedFrameCount++; } else { _frameRenderDelay--; } @@ -291,4 +299,13 @@ bool ZVision::canRender() { return _frameRenderDelay <= 0; } +void ZVision::fpsTimerCallback(void *refCon) { + ((ZVision *)refCon)->fpsTimer(); +} + +void ZVision::fpsTimer() { + _fps = _renderedFrameCount; + _renderedFrameCount = 0; +} + } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 6664d0cd5d..5482060cd0 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -119,6 +119,8 @@ private: Common::Event _event; int _frameRenderDelay; + int _renderedFrameCount; + int _fps; int16 _mouseVelocity; int16 _keyboardVelocity; bool _doubleFPS; @@ -197,6 +199,11 @@ public: void setRenderDelay(uint); bool canRender(); + static void fpsTimerCallback(void *refCon); + void fpsTimer(); + int getFPS() const { + return _fps; + } void loadSettings(); void saveSettings(); -- cgit v1.2.3