diff options
author | Filippos Karapetis | 2014-12-26 12:41:36 +0200 |
---|---|---|
committer | Filippos Karapetis | 2014-12-26 12:41:36 +0200 |
commit | 5a72eea2bb102bafb6da112ea90ad1f4af11e1f2 (patch) | |
tree | 5bf667f3b56fb751f1a9d9bd3ea6ce752cc41c61 /engines/zvision | |
parent | 4258750f5025e471ba682945e3091fdaa50c7bc9 (diff) | |
download | scummvm-rg350-5a72eea2bb102bafb6da112ea90ad1f4af11e1f2.tar.gz scummvm-rg350-5a72eea2bb102bafb6da112ea90ad1f4af11e1f2.tar.bz2 scummvm-rg350-5a72eea2bb102bafb6da112ea90ad1f4af11e1f2.zip |
ZVISION: Move some event/rendering code out of the main engine code
Diffstat (limited to 'engines/zvision')
-rw-r--r-- | engines/zvision/core/events.cpp | 37 | ||||
-rw-r--r-- | engines/zvision/graphics/render_manager.cpp | 82 | ||||
-rw-r--r-- | engines/zvision/graphics/render_manager.h | 8 | ||||
-rw-r--r-- | engines/zvision/scripting/controls/save_control.cpp | 7 | ||||
-rw-r--r-- | engines/zvision/zvision.cpp | 108 | ||||
-rw-r--r-- | engines/zvision/zvision.h | 13 |
6 files changed, 133 insertions, 122 deletions
diff --git a/engines/zvision/core/events.cpp b/engines/zvision/core/events.cpp index 227cf213dc..70fd425949 100644 --- a/engines/zvision/core/events.cpp +++ b/engines/zvision/core/events.cpp @@ -39,6 +39,33 @@ namespace ZVision { +void ZVision::pushKeyToCheatBuf(uint8 key) { + for (int i = 0; i < KEYBUF_SIZE - 1; i++) + _cheatBuffer[i] = _cheatBuffer[i + 1]; + + _cheatBuffer[KEYBUF_SIZE - 1] = key; +} + +bool ZVision::checkCode(const char *code) { + int codeLen = strlen(code); + + if (codeLen > KEYBUF_SIZE) + return false; + + for (int i = 0; i < codeLen; i++) + if (code[i] != _cheatBuffer[KEYBUF_SIZE - codeLen + i] && code[i] != '?') + return false; + + return true; +} + +uint8 ZVision::getBufferedKey(uint8 pos) { + if (pos >= KEYBUF_SIZE) + return 0; + else + return _cheatBuffer[KEYBUF_SIZE - pos - 1]; +} + void ZVision::shortKeys(Common::Event event) { if (event.kbd.hasFlags(Common::KBD_CTRL)) { switch (event.kbd.keycode) { @@ -70,11 +97,11 @@ void ZVision::cheatCodes(uint8 key) { if (getGameId() == GID_GRANDINQUISITOR) { if (checkCode("IMNOTDEAF")) { // Unknown cheat - showDebugMsg(Common::String::format("IMNOTDEAF cheat or debug, not implemented")); + _renderManager->showDebugMsg(Common::String::format("IMNOTDEAF cheat or debug, not implemented")); } if (checkCode("3100OPB")) { - showDebugMsg(Common::String::format("Current location: %c%c%c%c", + _renderManager->showDebugMsg(Common::String::format("Current location: %c%c%c%c", _scriptManager->getStateValue(StateKey_World), _scriptManager->getStateValue(StateKey_Room), _scriptManager->getStateValue(StateKey_Node), @@ -101,7 +128,7 @@ void ZVision::cheatCodes(uint8 key) { } if (checkCode("77MASSAVE")) { - showDebugMsg(Common::String::format("Current location: %c%c%c%c", + _renderManager->showDebugMsg(Common::String::format("Current location: %c%c%c%c", _scriptManager->getStateValue(StateKey_World), _scriptManager->getStateValue(StateKey_Room), _scriptManager->getStateValue(StateKey_Node), @@ -131,13 +158,13 @@ void ZVision::cheatCodes(uint8 key) { } if (checkCode("FRAME")) - showDebugMsg(Common::String::format("FPS: ???, not implemented")); + _renderManager->showDebugMsg(Common::String::format("FPS: ???, not implemented")); if (checkCode("XYZZY")) _scriptManager->setStateValue(StateKey_DebugCheats, 1 - _scriptManager->getStateValue(StateKey_DebugCheats)); if (checkCode("COMPUTERARCH")) - showDebugMsg(Common::String::format("COMPUTERARCH: var-viewer not implemented")); + _renderManager->showDebugMsg(Common::String::format("COMPUTERARCH: var-viewer not implemented")); if (_scriptManager->getStateValue(StateKey_DebugCheats) == 1) if (checkCode("GO????")) diff --git a/engines/zvision/graphics/render_manager.cpp b/engines/zvision/graphics/render_manager.cpp index 07ed6d2e2b..35e3b89b09 100644 --- a/engines/zvision/graphics/render_manager.cpp +++ b/engines/zvision/graphics/render_manager.cpp @@ -39,7 +39,7 @@ namespace ZVision { -RenderManager::RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat) +RenderManager::RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat, bool doubleFPS) : _engine(engine), _system(engine->_system), _workingWidth(workingWindow.width()), @@ -51,7 +51,8 @@ RenderManager::RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowH _backgroundWidth(0), _backgroundHeight(0), _backgroundOffset(0), - _renderTable(_workingWidth, _workingHeight) { + _renderTable(_workingWidth, _workingHeight), + _doubleFPS(doubleFPS) { _backgroundSurface.create(_workingWidth, _workingHeight, _pixelFormat); _effectSurface.create(_workingWidth, _workingHeight, _pixelFormat); @@ -1013,4 +1014,81 @@ void RenderManager::bkgFill(uint8 r, uint8 g, uint8 b) { } #endif +void RenderManager::timedMessage(const Common::String &str, uint16 milsecs) { + uint16 msgid = createSubArea(); + updateSubArea(msgid, str); + processSubs(0); + renderSceneToScreen(); + deleteSubArea(msgid, milsecs); +} + +bool RenderManager::askQuestion(const Common::String &str) { + uint16 msgid = createSubArea(); + updateSubArea(msgid, str); + processSubs(0); + renderSceneToScreen(); + _engine->stopClock(); + + int result = 0; + + while (result == 0) { + Common::Event evnt; + while (_engine->getEventManager()->pollEvent(evnt)) { + if (evnt.type == Common::EVENT_KEYDOWN) { + switch (evnt.kbd.keycode) { + case Common::KEYCODE_y: + result = 2; + break; + case Common::KEYCODE_n: + result = 1; + break; + default: + break; + } + } + } + _system->updateScreen(); + if (_doubleFPS) + _system->delayMillis(33); + else + _system->delayMillis(66); + } + deleteSubArea(msgid); + _engine->startClock(); + return result == 2; +} + +void RenderManager::delayedMessage(const Common::String &str, uint16 milsecs) { + uint16 msgid = createSubArea(); + updateSubArea(msgid, str); + processSubs(0); + renderSceneToScreen(); + _engine->stopClock(); + + uint32 stopTime = _system->getMillis() + milsecs; + while (_system->getMillis() < stopTime) { + Common::Event evnt; + while (_engine->getEventManager()->pollEvent(evnt)) { + if (evnt.type == Common::EVENT_KEYDOWN && + (evnt.kbd.keycode == Common::KEYCODE_SPACE || + evnt.kbd.keycode == Common::KEYCODE_RETURN || + evnt.kbd.keycode == Common::KEYCODE_ESCAPE)) + break; + } + _system->updateScreen(); + if (_doubleFPS) + _system->delayMillis(33); + else + _system->delayMillis(66); + } + deleteSubArea(msgid); + _engine->startClock(); +} + +void RenderManager::showDebugMsg(const Common::String &msg, int16 delay) { + uint16 msgid = createSubArea(); + updateSubArea(msgid, msg); + deleteSubArea(msgid, delay); +} + } // End of namespace ZVision diff --git a/engines/zvision/graphics/render_manager.h b/engines/zvision/graphics/render_manager.h index d67ae29a3a..dbaa8fdc50 100644 --- a/engines/zvision/graphics/render_manager.h +++ b/engines/zvision/graphics/render_manager.h @@ -48,7 +48,7 @@ namespace ZVision { class RenderManager { public: - RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat); + RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat, bool doubleFPS); ~RenderManager(); private: @@ -137,6 +137,7 @@ private: // Visual effects list EffectsList _effects; + bool _doubleFPS; public: void initialize(); @@ -334,6 +335,11 @@ public: // Fill background surface by color void bkgFill(uint8 r, uint8 g, uint8 b); #endif + + bool askQuestion(const Common::String &str); + void delayedMessage(const Common::String &str, uint16 milsecs); + void timedMessage(const Common::String &str, uint16 milsecs); + void showDebugMsg(const Common::String &msg, int16 delay = 3000); }; } // End of namespace ZVision diff --git a/engines/zvision/scripting/controls/save_control.cpp b/engines/zvision/scripting/controls/save_control.cpp index 3a4dc47fe8..6cedddffeb 100644 --- a/engines/zvision/scripting/controls/save_control.cpp +++ b/engines/zvision/scripting/controls/save_control.cpp @@ -30,6 +30,7 @@ #include "zvision/text/string_manager.h" #include "zvision/file/save_manager.h" +#include "zvision/graphics/render_manager.h" #include "common/str.h" #include "common/stream.h" @@ -97,18 +98,18 @@ bool SaveControl::process(uint32 deltaTimeInMillis) { if (inp->getText().size() > 0) { bool toSave = true; if (iter->exist) - if (!_engine->askQuestion(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVEEXIST))) + if (!_engine->getRenderManager()->askQuestion(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVEEXIST))) toSave = false; if (toSave) { // FIXME: At this point, the screen shows the save control, so the save game thumbnails will always // show the save control _engine->getSaveManager()->saveGameBuffered(iter->saveId, inp->getText()); - _engine->delayedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVED), 2000); + _engine->getRenderManager()->delayedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVED), 2000); _engine->getScriptManager()->changeLocation(_engine->getScriptManager()->getLastMenuLocation()); } } else { - _engine->timedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVEEMPTY), 2000); + _engine->getRenderManager()->timedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVEEMPTY), 2000); } } else { _engine->getSaveManager()->loadGame(iter->saveId); diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index e9a4486ded..575a7af6ab 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -190,7 +190,7 @@ void ZVision::initialize() { // Create managers _scriptManager = new ScriptManager(this); - _renderManager = new RenderManager(this, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _resourcePixelFormat); + _renderManager = new RenderManager(this, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _resourcePixelFormat, _doubleFPS); _saveManager = new SaveManager(this); _stringManager = new StringManager(this); _cursorManager = new CursorManager(this, _resourcePixelFormat); @@ -265,77 +265,6 @@ Common::Error ZVision::run() { return Common::kNoError; } -bool ZVision::askQuestion(const Common::String &str) { - uint16 msgid = _renderManager->createSubArea(); - _renderManager->updateSubArea(msgid, str); - _renderManager->processSubs(0); - _renderManager->renderSceneToScreen(); - _clock.stop(); - - int result = 0; - - while (result == 0) { - Common::Event evnt; - while (_eventMan->pollEvent(evnt)) { - if (evnt.type == Common::EVENT_KEYDOWN) { - switch (evnt.kbd.keycode) { - case Common::KEYCODE_y: - result = 2; - break; - case Common::KEYCODE_n: - result = 1; - break; - default: - break; - } - } - } - _system->updateScreen(); - if (_doubleFPS) - _system->delayMillis(33); - else - _system->delayMillis(66); - } - _renderManager->deleteSubArea(msgid); - _clock.start(); - return result == 2; -} - -void ZVision::delayedMessage(const Common::String &str, uint16 milsecs) { - uint16 msgid = _renderManager->createSubArea(); - _renderManager->updateSubArea(msgid, str); - _renderManager->processSubs(0); - _renderManager->renderSceneToScreen(); - _clock.stop(); - - uint32 stopTime = _system->getMillis() + milsecs; - while (_system->getMillis() < stopTime) { - Common::Event evnt; - while (_eventMan->pollEvent(evnt)) { - if (evnt.type == Common::EVENT_KEYDOWN && - (evnt.kbd.keycode == Common::KEYCODE_SPACE || - evnt.kbd.keycode == Common::KEYCODE_RETURN || - evnt.kbd.keycode == Common::KEYCODE_ESCAPE)) - break; - } - _system->updateScreen(); - if (_doubleFPS) - _system->delayMillis(33); - else - _system->delayMillis(66); - } - _renderManager->deleteSubArea(msgid); - _clock.start(); -} - -void ZVision::timedMessage(const Common::String &str, uint16 milsecs) { - uint16 msgid = _renderManager->createSubArea(); - _renderManager->updateSubArea(msgid, str); - _renderManager->processSubs(0); - _renderManager->renderSceneToScreen(); - _renderManager->deleteSubArea(msgid, milsecs); -} - void ZVision::pauseEngineIntern(bool pause) { _mixer->pauseAll(pause); @@ -506,44 +435,11 @@ uint16 ZVision::getMenuBarEnable() { } bool ZVision::ifQuit() { - if (askQuestion(_stringManager->getTextLine(StringManager::ZVISION_STR_EXITPROMT))) { + if (_renderManager->askQuestion(_stringManager->getTextLine(StringManager::ZVISION_STR_EXITPROMT))) { quitGame(); return true; } return false; } -void ZVision::pushKeyToCheatBuf(uint8 key) { - for (int i = 0; i < KEYBUF_SIZE - 1; i++) - _cheatBuffer[i] = _cheatBuffer[i + 1]; - - _cheatBuffer[KEYBUF_SIZE - 1] = key; -} - -bool ZVision::checkCode(const char *code) { - int codeLen = strlen(code); - - if (codeLen > KEYBUF_SIZE) - return false; - - for (int i = 0; i < codeLen; i++) - if (code[i] != _cheatBuffer[KEYBUF_SIZE - codeLen + i] && code[i] != '?') - return false; - - return true; -} - -uint8 ZVision::getBufferedKey(uint8 pos) { - if (pos >= KEYBUF_SIZE) - return 0; - else - return _cheatBuffer[KEYBUF_SIZE - pos - 1]; -} - -void ZVision::showDebugMsg(const Common::String &msg, int16 delay) { - uint16 msgid = _renderManager->createSubArea(); - _renderManager->updateSubArea(msgid, msg); - _renderManager->deleteSubArea(msgid, delay); -} - } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index d3beae5e61..848b278f69 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -164,6 +164,14 @@ public: uint8 getZvisionKey(Common::KeyCode scummKeyCode); + void startClock() { + _clock.start(); + } + + void stopClock() { + _clock.stop(); + } + /** * Play a video until it is finished. This is a blocking call. It will call * _clock.stop() when the video starts and _clock.start() when the video finishes. @@ -181,10 +189,6 @@ public: Common::String generateSaveFileName(uint slot); Common::String generateAutoSaveFileName(); - bool askQuestion(const Common::String &str); - void delayedMessage(const Common::String &str, uint16 milsecs); - void timedMessage(const Common::String &str, uint16 milsecs); - void setRenderDelay(uint); bool canRender(); @@ -197,7 +201,6 @@ public: bool ifQuit(); void checkBorders(); - void showDebugMsg(const Common::String &msg, int16 delay = 3000); // Engine features bool hasFeature(EngineFeature f) const; |