1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/* 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 centerX, int16 centerY, float ampl, float waveln, float spd):
Effect(engine, key, region, ported) {
_frame = 0;
_frameCount = frames;
_ampls.resize(_frameCount);
_halfWidth = _region.width() / 2;
_halfHeight = _region.height() / 2;
int32 frmsize = _halfWidth * _halfHeight;
float phase = 0;
int16 quarterWidth = _halfWidth / 2;
int16 quarterHeight = _halfHeight / 2;
for (int16 i = 0; i < _frameCount; i++) {
_ampls[i].resize(frmsize);
for (int16 y = 0; y < _halfHeight; y++)
for (int16 x = 0; x < _halfWidth; x++) {
int16 dx = (x - quarterWidth);
int16 dy = (y - quarterHeight);
_ampls[i][x + y * _halfWidth] = ampl * sin(sqrt(dx * dx / (float)centerX + dy * dy / (float)centerY) / (-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 < _halfHeight; y++) {
uint16 *abc = (uint16 *)_surface.getBasePtr(0, y);
uint16 *abc2 = (uint16 *)_surface.getBasePtr(0, _halfHeight + y);
uint16 *abc3 = (uint16 *)_surface.getBasePtr(_halfWidth, y);
uint16 *abc4 = (uint16 *)_surface.getBasePtr(_halfWidth, _halfHeight + y);
for (int16 x = 0; x < _halfWidth; x++) {
int8 amnt = _ampls[_frame][x + _halfWidth * y];
int16 nX = x + amnt;
int16 nY = y + amnt;
if (nX < 0)
nX = 0;
if (nX >= _region.width())
nX = _region.width() - 1;
if (nY < 0)
nY = 0;
if (nY >= _region.height())
nY = _region.height() - 1;
*abc = *(const uint16 *)srcSubRect.getBasePtr(nX, nY);
nX = x + amnt + _halfWidth;
nY = y + amnt;
if (nX < 0)
nX = 0;
if (nX >= _region.width())
nX = _region.width() - 1;
if (nY < 0)
nY = 0;
if (nY >= _region.height())
nY = _region.height() - 1;
*abc3 = *(const uint16 *)srcSubRect.getBasePtr(nX, nY);
nX = x + amnt;
nY = y + amnt + _halfHeight;
if (nX < 0)
nX = 0;
if (nX >= _region.width())
nX = _region.width() - 1;
if (nY < 0)
nY = 0;
if (nY >= _region.height())
nY = _region.height() - 1;
*abc2 = *(const uint16 *)srcSubRect.getBasePtr(nX, nY);
nX = x + amnt + _halfWidth;
nY = y + amnt + _halfHeight;
if (nX < 0)
nX = 0;
if (nX >= _region.width())
nX = _region.width() - 1;
if (nY < 0)
nY = 0;
if (nY >= _region.height())
nY = _region.height() - 1;
*abc4 = *(const uint16 *)srcSubRect.getBasePtr(nX, nY);
abc++;
abc2++;
abc3++;
abc4++;
}
}
return &_surface;
}
void WaveFx::update() {
_frame = (_frame + 1) % _frameCount;
}
} // End of namespace ZVision
|