Skip to content

Commit

Permalink
ZVISION: Add an FPS timer (accessible with F10, or the "FRAME" cheat)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegr committed Dec 26, 2014
1 parent 19ce38d commit f9595b1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
18 changes: 13 additions & 5 deletions engines/zvision/core/events.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}
Expand Down
19 changes: 18 additions & 1 deletion engines/zvision/zvision.cpp
Expand Up @@ -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");

Expand Down Expand Up @@ -130,6 +132,8 @@ ZVision::~ZVision() {
delete _rnd;
delete _midiManager;

getTimerManager()->removeTimerProc(&fpsTimerCallback);

// Remove all of our debug levels
DebugMan.clearAllDebugChannels();
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -246,6 +253,7 @@ Common::Error ZVision::run() {
// Update the screen
if (canRender()) {
_system->updateScreen();
_renderedFrameCount++;
} else {
_frameRenderDelay--;
}
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions engines/zvision/zvision.h
Expand Up @@ -119,6 +119,8 @@ class ZVision : public Engine {
Common::Event _event;

int _frameRenderDelay;
int _renderedFrameCount;
int _fps;
int16 _mouseVelocity;
int16 _keyboardVelocity;
bool _doubleFPS;
Expand Down Expand Up @@ -197,6 +199,11 @@ class ZVision : public Engine {

void setRenderDelay(uint);
bool canRender();
static void fpsTimerCallback(void *refCon);
void fpsTimer();
int getFPS() const {
return _fps;
}

void loadSettings();
void saveSettings();
Expand Down

0 comments on commit f9595b1

Please sign in to comment.