From 0efa1bc5606c9fd984df077d55cf93a7903f5f67 Mon Sep 17 00:00:00 2001 From: Marisa-Chan Date: Fri, 7 Nov 2014 10:25:11 +0600 Subject: [PATCH] ZVISION: Implement action:rotate_to --- engines/zvision/scripting/actions.cpp | 15 ++++++ engines/zvision/scripting/actions.h | 10 ++++ .../zvision/scripting/scr_file_handling.cpp | 2 +- engines/zvision/zvision.cpp | 52 +++++++++++++++++++ engines/zvision/zvision.h | 2 + 5 files changed, 80 insertions(+), 1 deletion(-) diff --git a/engines/zvision/scripting/actions.cpp b/engines/zvision/scripting/actions.cpp index 9733c5cae82d..2754a3967608 100644 --- a/engines/zvision/scripting/actions.cpp +++ b/engines/zvision/scripting/actions.cpp @@ -612,6 +612,21 @@ bool ActionRandom::execute() { return true; } +////////////////////////////////////////////////////////////////////////////// +// ActionRotateTo +////////////////////////////////////////////////////////////////////////////// + +ActionRotateTo::ActionRotateTo(ZVision *engine, int32 slotkey, const Common::String &line) : + ResultAction(engine, slotkey) { + sscanf(line.c_str(), "%d, %d", &_toPos, &_time); +} + +bool ActionRotateTo::execute() { + _engine->rotateTo(_toPos, _time); + + return true; +} + ////////////////////////////////////////////////////////////////////////////// // ActionSetPartialScreen diff --git a/engines/zvision/scripting/actions.h b/engines/zvision/scripting/actions.h index f51847ed05d1..6a200198b737 100644 --- a/engines/zvision/scripting/actions.h +++ b/engines/zvision/scripting/actions.h @@ -360,6 +360,16 @@ class ActionRandom : public ResultAction { ValueSlot *_max; }; +class ActionRotateTo : public ResultAction { +public: + ActionRotateTo(ZVision *engine, int32 slotkey, const Common::String &line); + bool execute(); + +private: + int32 _toPos; + int32 _time; +}; + class ActionSetPartialScreen : public ResultAction { public: ActionSetPartialScreen(ZVision *engine, int32 slotkey, const Common::String &line); diff --git a/engines/zvision/scripting/scr_file_handling.cpp b/engines/zvision/scripting/scr_file_handling.cpp index df60b0b8d4a1..b16a2d94745c 100644 --- a/engines/zvision/scripting/scr_file_handling.cpp +++ b/engines/zvision/scripting/scr_file_handling.cpp @@ -270,7 +270,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (act.matchString("restore_game", true)) { // TODO: Implement ActionRestoreGame } else if (act.matchString("rotate_to", true)) { - // TODO: Implement ActionRotateTo + actionList.push_back(new ActionRotateTo(_engine, slot, args)); } else if (act.matchString("save_game", true)) { // TODO: Implement ActionSaveGame } else if (act.matchString("set_partial_screen", true)) { diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 41d3eea6aa0f..79f7d74a8d6d 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -402,4 +402,56 @@ void ZVision::updateRotation() { } } +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->prepareBkg(); + _renderManager->renderBackbufferToScreen(); + + _system->updateScreen(); + + _system->delayMillis(500 / _time); + } + + _clock.start(); +} + } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 0bee63945806..e2bde7bd9eb4 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -170,6 +170,8 @@ class ZVision : public Engine { */ void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true, Subtitle *sub = NULL); + void rotateTo(int16 to, int16 time); + Common::String generateSaveFileName(uint slot); Common::String generateAutoSaveFileName();