diff options
author | Filippos Karapetis | 2014-12-26 13:14:24 +0200 |
---|---|---|
committer | Filippos Karapetis | 2014-12-26 13:14:24 +0200 |
commit | eea1ee445fcac7ecc53e31d258aac697d6b242f1 (patch) | |
tree | 2caaf9a3201cc4abfd80b6d5fdc20d04d0a7cac9 /engines | |
parent | e8820d26e7d673f96c416f93dd16811107e94cb4 (diff) | |
download | scummvm-rg350-eea1ee445fcac7ecc53e31d258aac697d6b242f1.tar.gz scummvm-rg350-eea1ee445fcac7ecc53e31d258aac697d6b242f1.tar.bz2 scummvm-rg350-eea1ee445fcac7ecc53e31d258aac697d6b242f1.zip |
ZVISION: Move more graphics code out of the main engine code
Diffstat (limited to 'engines')
-rw-r--r-- | engines/zvision/core/events.cpp | 17 | ||||
-rw-r--r-- | engines/zvision/graphics/render_manager.cpp | 133 | ||||
-rw-r--r-- | engines/zvision/graphics/render_manager.h | 4 | ||||
-rw-r--r-- | engines/zvision/scripting/actions.cpp | 5 | ||||
-rw-r--r-- | engines/zvision/scripting/script_manager.cpp | 5 | ||||
-rw-r--r-- | engines/zvision/zvision.cpp | 155 | ||||
-rw-r--r-- | engines/zvision/zvision.h | 17 |
7 files changed, 167 insertions, 169 deletions
diff --git a/engines/zvision/core/events.cpp b/engines/zvision/core/events.cpp index 70fd425949..5f29a6879c 100644 --- a/engines/zvision/core/events.cpp +++ b/engines/zvision/core/events.cpp @@ -30,6 +30,7 @@ #include "zvision/scripting/script_manager.h" #include "zvision/scripting/menu.h" #include "zvision/sound/zork_raw.h" +#include "zvision/text/string_manager.h" #include "common/events.h" #include "common/system.h" @@ -70,19 +71,19 @@ void ZVision::shortKeys(Common::Event event) { if (event.kbd.hasFlags(Common::KBD_CTRL)) { switch (event.kbd.keycode) { case Common::KEYCODE_s: - if (getMenuBarEnable() & kMenubarSave) + if (_menu->getEnable() & kMenubarSave) _scriptManager->changeLocation('g', 'j', 's', 'e', 0); break; case Common::KEYCODE_r: - if (getMenuBarEnable() & kMenubarRestore) + if (_menu->getEnable() & kMenubarRestore) _scriptManager->changeLocation('g', 'j', 'r', 'e', 0); break; case Common::KEYCODE_p: - if (getMenuBarEnable() & kMenubarSettings) + if (_menu->getEnable() & kMenubarSettings) _scriptManager->changeLocation('g', 'j', 'p', 'e', 0); break; case Common::KEYCODE_q: - if (getMenuBarEnable() & kMenubarExit) + if (_menu->getEnable() & kMenubarExit) ifQuit(); break; default: @@ -482,4 +483,12 @@ uint8 ZVision::getZvisionKey(Common::KeyCode scummKeyCode) { return 0; } +bool ZVision::ifQuit() { + if (_renderManager->askQuestion(_stringManager->getTextLine(StringManager::ZVISION_STR_EXITPROMT))) { + quitGame(); + return true; + } + return false; +} + } // End of namespace ZVision diff --git a/engines/zvision/graphics/render_manager.cpp b/engines/zvision/graphics/render_manager.cpp index 35e3b89b09..0a48ae6c16 100644 --- a/engines/zvision/graphics/render_manager.cpp +++ b/engines/zvision/graphics/render_manager.cpp @@ -1091,4 +1091,137 @@ void RenderManager::showDebugMsg(const Common::String &msg, int16 delay) { deleteSubArea(msgid, delay); } +void RenderManager::updateRotation() { + int16 _velocity = _engine->getMouseVelocity() + _engine->getKeyboardVelocity(); + ScriptManager *scriptManager = _engine->getScriptManager(); + + if (_doubleFPS) + _velocity /= 2; + + if (_velocity) { + RenderTable::RenderState renderState = _renderTable.getRenderState(); + if (renderState == RenderTable::PANORAMA) { + int16 startPosition = scriptManager->getStateValue(StateKey_ViewPos); + + int16 newPosition = startPosition + (_renderTable.getPanoramaReverse() ? -_velocity : _velocity); + + int16 zeroPoint = _renderTable.getPanoramaZeroPoint(); + if (startPosition >= zeroPoint && newPosition < zeroPoint) + scriptManager->setStateValue(StateKey_Rounds, scriptManager->getStateValue(StateKey_Rounds) - 1); + if (startPosition <= zeroPoint && newPosition > zeroPoint) + scriptManager->setStateValue(StateKey_Rounds, scriptManager->getStateValue(StateKey_Rounds) + 1); + + int16 screenWidth = getBkgSize().x; + if (screenWidth) + newPosition %= screenWidth; + + if (newPosition < 0) + newPosition += screenWidth; + + setBackgroundPosition(newPosition); + } else if (renderState == RenderTable::TILT) { + int16 startPosition = scriptManager->getStateValue(StateKey_ViewPos); + + int16 newPosition = startPosition + _velocity; + + int16 screenHeight = getBkgSize().y; + int16 tiltGap = _renderTable.getTiltGap(); + + if (newPosition >= (screenHeight - tiltGap)) + newPosition = screenHeight - tiltGap; + if (newPosition <= tiltGap) + newPosition = tiltGap; + + setBackgroundPosition(newPosition); + } + } +} + +void RenderManager::checkBorders() { + RenderTable::RenderState renderState = _renderTable.getRenderState(); + if (renderState == RenderTable::PANORAMA) { + int16 startPosition = _engine->getScriptManager()->getStateValue(StateKey_ViewPos); + + int16 newPosition = startPosition; + + int16 screenWidth = getBkgSize().x; + + if (screenWidth) + newPosition %= screenWidth; + + if (newPosition < 0) + newPosition += screenWidth; + + if (startPosition != newPosition) + setBackgroundPosition(newPosition); + } else if (renderState == RenderTable::TILT) { + int16 startPosition = _engine->getScriptManager()->getStateValue(StateKey_ViewPos); + + int16 newPosition = startPosition; + + int16 screenHeight = getBkgSize().y; + int16 tiltGap = _renderTable.getTiltGap(); + + if (newPosition >= (screenHeight - tiltGap)) + newPosition = screenHeight - tiltGap; + if (newPosition <= tiltGap) + newPosition = tiltGap; + + if (startPosition != newPosition) + setBackgroundPosition(newPosition); + } +} + +void RenderManager::rotateTo(int16 _toPos, int16 _time) { + if (_renderTable.getRenderState() != RenderTable::PANORAMA) + return; + + if (_time == 0) + _time = 1; + + int32 maxX = getBkgSize().x; + int32 curX = getCurrentBackgroundOffset(); + int32 dx = 0; + + if (curX == _toPos) + return; + + if (curX > _toPos) { + if (curX - _toPos > maxX / 2) + dx = (_toPos + (maxX - curX)) / _time; + else + dx = -(curX - _toPos) / _time; + } else { + if (_toPos - curX > maxX / 2) + dx = -((maxX - _toPos) + curX) / _time; + else + dx = (_toPos - curX) / _time; + } + + _engine->stopClock(); + + for (int16 i = 0; i <= _time; i++) { + if (i == _time) + curX = _toPos; + else + curX += dx; + + if (curX < 0) + curX = maxX - curX; + else if (curX >= maxX) + curX %= maxX; + + setBackgroundPosition(curX); + + prepareBackground(); + renderSceneToScreen(); + + _system->updateScreen(); + + _system->delayMillis(500 / _time); + } + + _engine->startClock(); +} + } // End of namespace ZVision diff --git a/engines/zvision/graphics/render_manager.h b/engines/zvision/graphics/render_manager.h index dbaa8fdc50..30e51456e9 100644 --- a/engines/zvision/graphics/render_manager.h +++ b/engines/zvision/graphics/render_manager.h @@ -340,6 +340,10 @@ public: 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); + + void checkBorders(); + void rotateTo(int16 to, int16 time); + void updateRotation(); }; } // End of namespace ZVision diff --git a/engines/zvision/scripting/actions.cpp b/engines/zvision/scripting/actions.cpp index c26a93f529..7c3463b6d0 100644 --- a/engines/zvision/scripting/actions.cpp +++ b/engines/zvision/scripting/actions.cpp @@ -30,6 +30,7 @@ #include "zvision/sound/zork_raw.h" #include "zvision/video/zork_avi_decoder.h" #include "zvision/file/save_manager.h" +#include "zvision/scripting/menu.h" #include "zvision/scripting/sidefx/timer_node.h" #include "zvision/scripting/sidefx/music_node.h" #include "zvision/scripting/sidefx/syncsound_node.h" @@ -439,7 +440,7 @@ ActionMenuBarEnable::ActionMenuBarEnable(ZVision *engine, int32 slotkey, const C } bool ActionMenuBarEnable::execute() { - _engine->menuBarEnable(_menus); + _engine->getMenuHandler()->setEnable(_menus); return true; } @@ -819,7 +820,7 @@ ActionRotateTo::ActionRotateTo(ZVision *engine, int32 slotkey, const Common::Str } bool ActionRotateTo::execute() { - _engine->rotateTo(_toPos, _time); + _engine->getRenderManager()->rotateTo(_toPos, _time); return true; } diff --git a/engines/zvision/scripting/script_manager.cpp b/engines/zvision/scripting/script_manager.cpp index 2a4aa5fed0..1a2b8362f5 100644 --- a/engines/zvision/scripting/script_manager.cpp +++ b/engines/zvision/scripting/script_manager.cpp @@ -29,6 +29,7 @@ #include "zvision/graphics/cursors/cursor_manager.h" #include "zvision/file/save_manager.h" #include "zvision/scripting/actions.h" +#include "zvision/scripting/menu.h" #include "zvision/scripting/sidefx/timer_node.h" #include "common/algorithm.h" @@ -583,7 +584,7 @@ void ScriptManager::ChangeLocationReal() { _referenceTable.clear(); addPuzzlesToReferenceTable(universe); - _engine->menuBarEnable(0xFFFF); + _engine->getMenuHandler()->setEnable(0xFFFF); if (_nextLocation.world != _currentLocation.world) { cleanScriptScope(nodeview); @@ -652,7 +653,7 @@ void ScriptManager::ChangeLocationReal() { execScope(nodeview); } - _engine->checkBorders(); + _engine->getRenderManager()->checkBorders(); } void ScriptManager::serialize(Common::WriteStream *stream) { diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 575a7af6ab..bd215f4f62 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -232,7 +232,7 @@ Common::Error ZVision::run() { _cursorManager->setItemID(_scriptManager->getStateValue(StateKey_InventoryItem)); processEvents(); - updateRotation(); + _renderManager->updateRotation(); _scriptManager->update(deltaTime); _menu->process(deltaTime); @@ -244,7 +244,7 @@ Common::Error ZVision::run() { _renderManager->renderSceneToScreen(); // Update the screen - if (_frameRenderDelay <= 0) { + if (canRender()) { _system->updateScreen(); } else { _frameRenderDelay--; @@ -291,155 +291,4 @@ bool ZVision::canRender() { return _frameRenderDelay <= 0; } -void ZVision::updateRotation() { - int16 _velocity = _mouseVelocity + _keyboardVelocity; - - if (_doubleFPS) - _velocity /= 2; - - if (_velocity) { - RenderTable::RenderState renderState = _renderManager->getRenderTable()->getRenderState(); - if (renderState == RenderTable::PANORAMA) { - int16 startPosition = _scriptManager->getStateValue(StateKey_ViewPos); - - int16 newPosition = startPosition + (_renderManager->getRenderTable()->getPanoramaReverse() ? -_velocity : _velocity); - - int16 zeroPoint = _renderManager->getRenderTable()->getPanoramaZeroPoint(); - if (startPosition >= zeroPoint && newPosition < zeroPoint) - _scriptManager->setStateValue(StateKey_Rounds, _scriptManager->getStateValue(StateKey_Rounds) - 1); - if (startPosition <= zeroPoint && newPosition > zeroPoint) - _scriptManager->setStateValue(StateKey_Rounds, _scriptManager->getStateValue(StateKey_Rounds) + 1); - - int16 screenWidth = _renderManager->getBkgSize().x; - if (screenWidth) - newPosition %= screenWidth; - - if (newPosition < 0) - newPosition += screenWidth; - - _renderManager->setBackgroundPosition(newPosition); - } else if (renderState == RenderTable::TILT) { - int16 startPosition = _scriptManager->getStateValue(StateKey_ViewPos); - - int16 newPosition = startPosition + _velocity; - - int16 screenHeight = _renderManager->getBkgSize().y; - int16 tiltGap = _renderManager->getRenderTable()->getTiltGap(); - - if (newPosition >= (screenHeight - tiltGap)) - newPosition = screenHeight - tiltGap; - if (newPosition <= tiltGap) - newPosition = tiltGap; - - _renderManager->setBackgroundPosition(newPosition); - } - } -} - -void ZVision::checkBorders() { - RenderTable::RenderState renderState = _renderManager->getRenderTable()->getRenderState(); - if (renderState == RenderTable::PANORAMA) { - int16 startPosition = _scriptManager->getStateValue(StateKey_ViewPos); - - int16 newPosition = startPosition; - - int16 screenWidth = _renderManager->getBkgSize().x; - - if (screenWidth) - newPosition %= screenWidth; - - if (newPosition < 0) - newPosition += screenWidth; - - if (startPosition != newPosition) - _renderManager->setBackgroundPosition(newPosition); - } else if (renderState == RenderTable::TILT) { - int16 startPosition = _scriptManager->getStateValue(StateKey_ViewPos); - - int16 newPosition = startPosition; - - int16 screenHeight = _renderManager->getBkgSize().y; - int16 tiltGap = _renderManager->getRenderTable()->getTiltGap(); - - if (newPosition >= (screenHeight - tiltGap)) - newPosition = screenHeight - tiltGap; - if (newPosition <= tiltGap) - newPosition = tiltGap; - - if (startPosition != newPosition) - _renderManager->setBackgroundPosition(newPosition); - } -} - -void ZVision::rotateTo(int16 _toPos, int16 _time) { - if (_renderManager->getRenderTable()->getRenderState() != RenderTable::PANORAMA) - return; - - if (_time == 0) - _time = 1; - - int32 maxX = _renderManager->getBkgSize().x; - int32 curX = _renderManager->getCurrentBackgroundOffset(); - int32 dx = 0; - - if (curX == _toPos) - return; - - if (curX > _toPos) { - if (curX - _toPos > maxX / 2) - dx = (_toPos + (maxX - curX)) / _time; - else - dx = -(curX - _toPos) / _time; - } else { - if (_toPos - curX > maxX / 2) - dx = -((maxX - _toPos) + curX) / _time; - else - dx = (_toPos - curX) / _time; - } - - _clock.stop(); - - for (int16 i = 0; i <= _time; i++) { - if (i == _time) - curX = _toPos; - else - curX += dx; - - if (curX < 0) - curX = maxX - curX; - else if (curX >= maxX) - curX %= maxX; - - _renderManager->setBackgroundPosition(curX); - - _renderManager->prepareBackground(); - _renderManager->renderSceneToScreen(); - - _system->updateScreen(); - - _system->delayMillis(500 / _time); - } - - _clock.start(); -} - -void ZVision::menuBarEnable(uint16 menus) { - if (_menu) - _menu->setEnable(menus); -} - -uint16 ZVision::getMenuBarEnable() { - if (_menu) - return _menu->getEnable(); - return 0; -} - -bool ZVision::ifQuit() { - if (_renderManager->askQuestion(_stringManager->getTextLine(StringManager::ZVISION_STR_EXITPROMT))) { - quitGame(); - return true; - } - return false; -} - } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 848b278f69..dc1ac1b8cb 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -155,12 +155,21 @@ public: MidiManager *getMidiManager() const { return _midiManager; } + MenuHandler *getMenuHandler() const { + return _menu; + } Common::RandomSource *getRandomSource() const { return _rnd; } ZVisionGameId getGameId() const { return _gameDescription->gameId; } + int16 getKeyboardVelocity() const { + return _keyboardVelocity; + } + int16 getMouseVelocity() const { + return _mouseVelocity; + } uint8 getZvisionKey(Common::KeyCode scummKeyCode); @@ -184,8 +193,6 @@ public: void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true, Subtitle *sub = NULL); Video::VideoDecoder *loadAnimation(const Common::String &fileName); - void rotateTo(int16 to, int16 time); - Common::String generateSaveFileName(uint slot); Common::String generateAutoSaveFileName(); @@ -195,13 +202,8 @@ public: void loadSettings(); void saveSettings(); - void menuBarEnable(uint16 menus); - uint16 getMenuBarEnable(); - bool ifQuit(); - void checkBorders(); - // Engine features bool hasFeature(EngineFeature f) const; bool canLoadGameStateCurrently(); @@ -218,7 +220,6 @@ private: void processEvents(); void onMouseMove(const Common::Point &pos); - void updateRotation(); void registerDefaultSettings(); void shortKeys(Common::Event); |