ZVISION: Implement action:distort and distort sidefx node

This commit is contained in:
Marisa-Chan 2014-10-23 17:09:58 +07:00
parent 8e9d201cc3
commit 678f47f043
9 changed files with 229 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -81,6 +81,8 @@ public:
void setTiltReverse(bool reverse);
float getTiltGap();
float getAngle();
float getLinscale();
private:
void generatePanoramaLookupTable();

View File

@ -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
//////////////////////////////////////////////////////////////////////////////

View File

@ -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 {

View File

@ -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)) {

View File

@ -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

View File

@ -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