Skip to content

Commit

Permalink
ZVISION: Implement action:distort and distort sidefx node
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa-Chan committed Oct 23, 2014
1 parent 8e9d201 commit 678f47f
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 1 deletion.
4 changes: 4 additions & 0 deletions engines/zvision/graphics/render_manager.cpp
Expand Up @@ -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
2 changes: 2 additions & 0 deletions engines/zvision/graphics/render_manager.h
Expand Up @@ -281,6 +281,8 @@ class RenderManager {
EffectMap *makeEffectMap(const Graphics::Surface &surf, uint16 transp);

Common::Rect bkgRectToScreen(const Common::Rect &src);

void markDirty();
};

} // End of namespace ZVision
Expand Down
18 changes: 18 additions & 0 deletions engines/zvision/graphics/render_table.cpp
Expand Up @@ -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
2 changes: 2 additions & 0 deletions engines/zvision/graphics/render_table.h
Expand Up @@ -81,6 +81,8 @@ class RenderTable {
void setTiltReverse(bool reverse);

float getTiltGap();
float getAngle();
float getLinscale();

private:
void generatePanoramaLookupTable();
Expand Down
23 changes: 23 additions & 0 deletions engines/zvision/scripting/actions.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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
//////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 7 additions & 0 deletions engines/zvision/scripting/actions.h
Expand Up @@ -202,9 +202,16 @@ class ActionDissolve : public ResultAction {
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 {
Expand Down
2 changes: 1 addition & 1 deletion engines/zvision/scripting/scr_file_handling.cpp
Expand Up @@ -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)) {
Expand Down
109 changes: 109 additions & 0 deletions 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
63 changes: 63 additions & 0 deletions 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

0 comments on commit 678f47f

Please sign in to comment.