/* 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/graphics/effects/wave.h" #include "zvision/zvision.h" #include "zvision/graphics/render_manager.h" namespace ZVision { WaveFx::WaveFx(ZVision *engine, uint32 key, Common::Rect region, bool ported, int16 frames, int16 s_x, int16 s_y, float ampl, float waveln, float spd): Effect(engine, key, region, ported) { _frame = 0; _frame_cnt = frames; _ampls.resize(_frame_cnt); _hw = _region.width() / 2; _hh = _region.height() / 2; int32 frmsize = _hw * _hh; float phase = 0; int16 w_4 = _hw / 2; int16 h_4 = _hh / 2; for (int16 i = 0; i < _frame_cnt; i++) { _ampls[i].resize(frmsize); for (int16 y = 0; y < _hh; y++) for (int16 x = 0; x < _hw; x++) { int16 dx = (x - w_4); int16 dy = (y - h_4); _ampls[i][x + y * _hw] = ampl * sin(sqrt(dx * dx / (float)s_x + dy * dy / (float)s_y) / (-waveln * 3.1415926) + phase); } phase += spd; } } WaveFx::~WaveFx() { for (uint16 i = 0; i < _ampls.size(); i++) _ampls[i].clear(); _ampls.clear(); } const Graphics::Surface *WaveFx::draw(const Graphics::Surface &srcSubRect) { for (int16 y = 0; y < _hh; y++) { uint16 *abc = (uint16 *)_surface.getBasePtr(0, y); uint16 *abc2 = (uint16 *)_surface.getBasePtr(0, _hh + y); uint16 *abc3 = (uint16 *)_surface.getBasePtr(_hw, y); uint16 *abc4 = (uint16 *)_surface.getBasePtr(_hw, _hh + y); for (int16 x = 0; x < _hw; x++) { int8 amnt = _ampls[_frame][x + _hw * y]; int16 n_x = x + amnt; int16 n_y = y + amnt; if (n_x < 0) n_x = 0; if (n_x >= _region.width()) n_x = _region.width() - 1; if (n_y < 0) n_y = 0; if (n_y >= _region.height()) n_y = _region.height() - 1; *abc = *(const uint16 *)srcSubRect.getBasePtr(n_x, n_y); n_x = x + amnt + _hw; n_y = y + amnt; if (n_x < 0) n_x = 0; if (n_x >= _region.width()) n_x = _region.width() - 1; if (n_y < 0) n_y = 0; if (n_y >= _region.height()) n_y = _region.height() - 1; *abc3 = *(const uint16 *)srcSubRect.getBasePtr(n_x, n_y); n_x = x + amnt; n_y = y + amnt + _hh; if (n_x < 0) n_x = 0; if (n_x >= _region.width()) n_x = _region.width() - 1; if (n_y < 0) n_y = 0; if (n_y >= _region.height()) n_y = _region.height() - 1; *abc2 = *(const uint16 *)srcSubRect.getBasePtr(n_x, n_y); n_x = x + amnt + _hw; n_y = y + amnt + _hh; if (n_x < 0) n_x = 0; if (n_x >= _region.width()) n_x = _region.width() - 1; if (n_y < 0) n_y = 0; if (n_y >= _region.height()) n_y = _region.height() - 1; *abc4 = *(const uint16 *)srcSubRect.getBasePtr(n_x, n_y); abc++; abc2++; abc3++; abc4++; } } return &_surface; } void WaveFx::update() { _frame = (_frame + 1) % _frame_cnt; } } // End of namespace ZVision