Skip to content

Commit

Permalink
ZVISION: Implement action:rotate_to
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa-Chan committed Nov 7, 2014
1 parent 7151240 commit 0efa1bc
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
15 changes: 15 additions & 0 deletions engines/zvision/scripting/actions.cpp
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions engines/zvision/scripting/actions.h
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion engines/zvision/scripting/scr_file_handling.cpp
Expand Up @@ -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)) {
Expand Down
52 changes: 52 additions & 0 deletions engines/zvision/zvision.cpp
Expand Up @@ -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
2 changes: 2 additions & 0 deletions engines/zvision/zvision.h
Expand Up @@ -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();

Expand Down

0 comments on commit 0efa1bc

Please sign in to comment.