Unified
Split
Showing
with
304 additions
and 295 deletions.
- +45 −9 engines/zvision/core/events.cpp
- +213 −2 engines/zvision/graphics/render_manager.cpp
- +11 −1 engines/zvision/graphics/render_manager.h
- +3 −2 engines/zvision/scripting/actions.cpp
- +1 −1 engines/zvision/scripting/controls/input_control.cpp
- +4 −3 engines/zvision/scripting/controls/save_control.cpp
- +3 −2 engines/zvision/scripting/script_manager.cpp
- +6 −261 engines/zvision/zvision.cpp
- +18 −14 engines/zvision/zvision.h
| @@ -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" | ||
| @@ -39,23 +40,50 @@ | ||
|
|
||
| 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) { | ||
| 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: | ||
| @@ -70,11 +98,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 +129,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 +159,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????")) | ||
| @@ -455,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 | ||
| @@ -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,214 @@ 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); | ||
| } | ||
|
|
||
| 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 | ||
| @@ -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 @@ class RenderManager { | ||
| // Visual effects list | ||
| EffectsList _effects; | ||
|
|
||
| bool _doubleFPS; | ||
|
|
||
| public: | ||
| void initialize(); | ||
| @@ -334,6 +335,15 @@ class RenderManager { | ||
| // 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); | ||
|
|
||
| void checkBorders(); | ||
| void rotateTo(int16 to, int16 time); | ||
| void updateRotation(); | ||
| }; | ||
|
|
||
| } // End of namespace ZVision | ||
Oops, something went wrong.