diff --git a/engines/zvision/graphics/render_manager.cpp b/engines/zvision/graphics/render_manager.cpp index 0aa062214f6..ce1962a8ee6 100644 --- a/engines/zvision/graphics/render_manager.cpp +++ b/engines/zvision/graphics/render_manager.cpp @@ -1046,4 +1046,8 @@ EffectMap *RenderManager::makeEffectMap(const Graphics::Surface &surf, uint16 tr return newMap; } +void RenderManager::markDirty() { + _bkgDirtyRect = Common::Rect(_bkgWidth, _bkgHeight); +} + } // End of namespace ZVision diff --git a/engines/zvision/graphics/render_manager.h b/engines/zvision/graphics/render_manager.h index 665a27bf646..e0fc5c248c9 100644 --- a/engines/zvision/graphics/render_manager.h +++ b/engines/zvision/graphics/render_manager.h @@ -281,6 +281,8 @@ public: EffectMap *makeEffectMap(const Graphics::Surface &surf, uint16 transp); Common::Rect bkgRectToScreen(const Common::Rect &src); + + void markDirty(); }; } // End of namespace ZVision diff --git a/engines/zvision/graphics/render_table.cpp b/engines/zvision/graphics/render_table.cpp index 9bf40d37452..aeba729196f 100644 --- a/engines/zvision/graphics/render_table.cpp +++ b/engines/zvision/graphics/render_table.cpp @@ -264,4 +264,22 @@ float RenderTable::getTiltGap() { return _tiltOptions.gap; } +float RenderTable::getAngle() { + if (_renderState == TILT) + return _tiltOptions.fieldOfView; + else if (_renderState == PANORAMA) + return _panoramaOptions.fieldOfView; + else + return 1.0; +} + +float RenderTable::getLinscale() { + if (_renderState == TILT) + return _tiltOptions.linearScale; + else if (_renderState == PANORAMA) + return _panoramaOptions.linearScale; + else + return 1.0; +} + } // End of namespace ZVision diff --git a/engines/zvision/graphics/render_table.h b/engines/zvision/graphics/render_table.h index a268ee615fe..7153738c6f5 100644 --- a/engines/zvision/graphics/render_table.h +++ b/engines/zvision/graphics/render_table.h @@ -81,6 +81,8 @@ public: void setTiltReverse(bool reverse); float getTiltGap(); + float getAngle(); + float getLinscale(); private: void generatePanoramaLookupTable(); diff --git a/engines/zvision/scripting/actions.cpp b/engines/zvision/scripting/actions.cpp index 2464f54861c..9733c5cae82 100644 --- a/engines/zvision/scripting/actions.cpp +++ b/engines/zvision/scripting/actions.cpp @@ -33,6 +33,7 @@ #include "zvision/scripting/sidefx/music_node.h" #include "zvision/scripting/sidefx/syncsound_node.h" #include "zvision/scripting/sidefx/animation_node.h" +#include "zvision/scripting/sidefx/distort_node.h" #include "zvision/scripting/sidefx/ttytext_node.h" #include "zvision/scripting/sidefx/region_node.h" #include "zvision/scripting/controls/titler_control.h" @@ -192,6 +193,28 @@ bool ActionDisplayMessage::execute() { return true; } +////////////////////////////////////////////////////////////////////////////// +// ActionDistort +////////////////////////////////////////////////////////////////////////////// + +ActionDistort::ActionDistort(ZVision *engine, int32 slotkey, const Common::String &line) : + ResultAction(engine, slotkey) { + sscanf(line.c_str(), "%hd %hd %f %f %f %f", &_distSlot, &_speed, &_st_angl, &_en_angl, &_st_lin, &_en_lin); +} + +ActionDistort::~ActionDistort() { + _engine->getScriptManager()->killSideFx(_distSlot); +} + +bool ActionDistort::execute() { + if (_engine->getScriptManager()->getSideFX(_distSlot)) + return true; + + _engine->getScriptManager()->addSideFX(new DistortNode(_engine, _distSlot, _speed, _st_angl, _en_angl, _st_lin, _en_lin)); + + return true; +} + ////////////////////////////////////////////////////////////////////////////// // ActionEnableControl ////////////////////////////////////////////////////////////////////////////// diff --git a/engines/zvision/scripting/actions.h b/engines/zvision/scripting/actions.h index b3c46d16ce0..f51847ed05d 100644 --- a/engines/zvision/scripting/actions.h +++ b/engines/zvision/scripting/actions.h @@ -202,9 +202,16 @@ public: class ActionDistort : public ResultAction { public: ActionDistort(ZVision *engine, int32 slotkey, const Common::String &line); + ~ActionDistort(); bool execute(); private: + int16 _distSlot; + int16 _speed; + float _st_angl; + float _en_angl; + float _st_lin; + float _en_lin; }; class ActionEnableControl : public ResultAction { diff --git a/engines/zvision/scripting/scr_file_handling.cpp b/engines/zvision/scripting/scr_file_handling.cpp index 8140d09a6ae..df60b0b8d4a 100644 --- a/engines/zvision/scripting/scr_file_handling.cpp +++ b/engines/zvision/scripting/scr_file_handling.cpp @@ -242,7 +242,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (act.matchString("dissolve", true)) { // TODO: Implement ActionDissolve } else if (act.matchString("distort", true)) { - // TODO: Implement ActionDistort + actionList.push_back(new ActionDistort(_engine, slot, args)); } else if (act.matchString("enable_control", true)) { actionList.push_back(new ActionEnableControl(_engine, slot, args)); } else if (act.matchString("flush_mouse_events", true)) { diff --git a/engines/zvision/scripting/sidefx/distort_node.cpp b/engines/zvision/scripting/sidefx/distort_node.cpp new file mode 100644 index 00000000000..576a1f8592d --- /dev/null +++ b/engines/zvision/scripting/sidefx/distort_node.cpp @@ -0,0 +1,109 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" + +#include "zvision/scripting/sidefx/distort_node.h" + +#include "zvision/zvision.h" +#include "zvision/scripting/script_manager.h" +#include "zvision/graphics/render_manager.h" +#include "zvision/graphics/render_table.h" + +#include "common/stream.h" + + +namespace ZVision { + +DistortNode::DistortNode(ZVision *engine, uint32 key, int16 speed, float st_angl, float en_angl, float st_lin, float en_lin) + : SideFX(engine, key, SIDEFX_DISTORT) { + + _angle = _engine->getRenderManager()->getRenderTable()->getAngle(); + _linScale = _engine->getRenderManager()->getRenderTable()->getLinscale(); + + _speed = speed; + _incr = true; + _st_angl = st_angl; + _en_angl = en_angl; + _st_lin = st_lin; + _en_lin = en_lin; + + _curFrame = 1.0; + + _diff_angl = en_angl - st_angl; + _diff_lin = en_lin - st_lin; + + _frmSpeed = (float)speed / 15.0; + _frames = ceil((5.0 - _frmSpeed * 2.0) / _frmSpeed); + if (_frames <= 0) + _frames = 1; + + if (_key != StateKey_NotSet) + _engine->getScriptManager()->setStateValue(_key, 1); +} + +DistortNode::~DistortNode() { + setParams(_angle, _linScale); +} + +bool DistortNode::process(uint32 deltaTimeInMillis) { + + float updTime = deltaTimeInMillis / (1000.0 / 60.0); + + if (_incr) + _curFrame += updTime; + else + _curFrame -= updTime; + + if (_curFrame < 1.0) { + _curFrame = 1.0; + _incr = true; + } else if (_curFrame > _frames) { + _curFrame = _frames; + _incr = false; + } + + float diff = (1.0 / (5.0 - (_curFrame * _frmSpeed))) / (5.0 - _frmSpeed); + + + setParams(_st_angl + diff * _diff_angl, _st_lin + diff * _diff_lin); + + return false; +} + +void DistortNode::setParams(float angl, float linScale) { + RenderTable *table = _engine->getRenderManager()->getRenderTable(); + if (table->getRenderState() == RenderTable::PANORAMA) { + table->setPanoramaFoV(angl); + table->setPanoramaScale(linScale); + table->generateRenderTable(); + _engine->getRenderManager()->markDirty(); + } else if (table->getRenderState() == RenderTable::TILT) { + table->setTiltFoV(angl); + table->setTiltScale(linScale); + table->generateRenderTable(); + _engine->getRenderManager()->markDirty(); + } +} + + +} // End of namespace ZVision diff --git a/engines/zvision/scripting/sidefx/distort_node.h b/engines/zvision/scripting/sidefx/distort_node.h new file mode 100644 index 00000000000..cba9c5eff24 --- /dev/null +++ b/engines/zvision/scripting/sidefx/distort_node.h @@ -0,0 +1,63 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ZVISION_DISTORT_NODE_H +#define ZVISION_DISTORT_NODE_H + +#include "zvision/scripting/sidefx.h" + +namespace ZVision { + +class ZVision; + +class DistortNode : public SideFX { +public: + DistortNode(ZVision *engine, uint32 key, int16 speed, float st_angl, float en_angl, float st_lin, float en_lin); + ~DistortNode(); + + bool process(uint32 deltaTimeInMillis); + +private: + int16 _speed; + float _st_angl; + float _en_angl; + float _st_lin; + float _en_lin; + + float _frmSpeed; + float _diff_angl; + float _diff_lin; + bool _incr; + int16 _frames; + + float _curFrame; + + float _angle; + float _linScale; + +private: + void setParams(float angl, float linScale); +}; + +} // End of namespace ZVision + +#endif