DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
effect.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3
4#include "effect.hpp"
5
6#include <libgraph.h>
7#include <libvu0.h>
8
9#include "mathutil.hpp"
10#include "mglib.hpp"
11#include "rect.hpp"
12#include "snd.hpp"
13
15 if (texture == NULL) {
16 return;
17 }
18
19 position[3] = 1.0f;
20 int top_left[4];
21 int bottom_right[4];
22
23 if (MGRotTransPers3DSprite(top_left, bottom_right, position, half_width, half_height, 0) == 0) {
24 return;
25 }
26
27 sceGsAlpha alpha = mgAlpha;
28
29 if (alpha_blend > 0) {
30 alpha.bits.a = 0;
31 alpha.bits.b = 2;
32 alpha.bits.c = 0;
33 alpha.bits.d = 1;
34 MGSetGsALPHA(&alpha);
35 }
36
37 if (disable_z_write != 0) {
38 sceGsZbuf zbuffer = mgZBuffer;
39 zbuffer.bits.zmsk = 1;
40 MGSetGsZBUF(&zbuffer);
41 }
42
43 set3DSprite(GetVif1Packet(), texture, texel, top_left, bottom_right, &colour);
44
45 if (alpha_blend != 0) {
46 MGSetGsALPHA(&mgAlpha);
47 }
48
49 if (disable_z_write != 0) {
50 MGSetGsZBUF(&mgZBuffer);
51 }
52}
53
55 texture = NULL;
56 texel = CRect_i_(0, 0, 0, 0);
57 colour.a = 128;
58 colour.g = 128;
59 colour.b = 128;
60 colour.r = 128;
61 alpha_blend = false;
62 disable_z_write = false;
63}
64
66 active = true;
67 frame = 0;
68 draw_mode = (s16) parameters->draw_mode;
69 lifetime = (s16) parameters->lifetime;
72 width = parameters->width;
73 height = parameters->height;
74 sceVu0CopyVector(position, parameters->position);
75 position[3] = 1.0f;
76 sceVu0CopyVector(velocity, parameters->velocity);
77 sceVu0CopyVector(acceleration, parameters->acceleration);
78 sceVu0CopyVector(position_oscillation_scale, parameters->position_oscillation_scale);
79 sceVu0CopyVector(position_oscillation_rate, parameters->position_oscillation_rate);
80 sceVu0CopyVector(scale, parameters->scale);
81 sceVu0CopyVector(scale_velocity, parameters->scale_velocity);
82 sceVu0CopyVector(scale_oscillation_scale, parameters->scale_oscillation_scale);
83 sceVu0CopyVector(scale_oscillation_rate, parameters->scale_oscillation_rate);
84 opacity_mode = parameters->opacity_mode;
85 render_flags = parameters->render_flags;
86 texture = parameters->texture;
87 texel = parameters->texel;
88 texture_frames = parameters->texture_frames;
90
91 switch (opacity_mode) {
92 case EFFECT_OPACITY_CONSTANT:
93 opacity = parameters->opacity;
94 opacity_step = 0.0f;
95 break;
96 case EFFECT_OPACITY_FADE_IN:
97 opacity = parameters->opacity;
98 opacity_step = (1.0f - parameters->opacity) / (float) lifetime;
99 break;
100 case EFFECT_OPACITY_FADE_OUT:
101 opacity = parameters->opacity;
102 opacity_step = -parameters->opacity / (float) lifetime;
103 break;
104 }
105}
106
107void CEffect::Step(int unused) {
108 if (active == 0) {
109 return;
110 }
111
112 frame++;
113
114 if (frame > lifetime) {
115 frame = 0;
116 active = false;
117 }
118
119 sceVu0AddVector(position, position, velocity);
120 sceVu0AddVector(velocity, velocity, acceleration);
121
122 if ((position_oscillation_flags & 1) != 0) {
123 float phase = (float) frame;
124
125 if (position_oscillation_scale[0] > 0.0f) {
127 }
128
129 if (position_oscillation_scale[1] > 0.0f) {
131 }
132
133 if (position_oscillation_scale[2] > 0.0f) {
135 }
136 }
137
138 scale[0] += scale_velocity[0];
139 scale[1] += scale_velocity[1];
140
141 if ((scale_oscillation_flags & 1) != 0) {
142 float phase = (float) frame;
143
144 if (scale_oscillation_scale[0] > 0.0f) {
145 scale[0] += scale_oscillation_scale[0] * Sinf(phase * scale_oscillation_rate[0]);
146 }
147
148 if (scale_oscillation_scale[1] > 0.0f) {
149 scale[1] += scale_oscillation_scale[1] * Sinf(phase * scale_oscillation_rate[1]);
150 }
151 }
152
154
155 if (opacity < 0.0f) {
156 opacity = 0.0f;
157 }
158
159 if (opacity > 1.0f) {
160 opacity = 1.0f;
161 }
162}
163
165 if (active == 0 || texture == NULL) {
166 return;
167 }
168
169 position[3] = 1.0f;
170 float sprite_width = scale[0] * width;
171 float sprite_height = scale[1] * height;
172 int top_left[4];
173 int bottom_right[4];
174 int screen[4][4];
175 float corner[4][4];
176
177 if (draw_mode != 0) {
178 for (int i = 0; i < 4; i++) {
179 sceVu0CopyVector(corner[i], position);
180 }
181
182 corner[0][0] -= sprite_width / 2.0f;
183 corner[0][2] -= sprite_height / 2.0f;
184 corner[1][0] += sprite_width / 2.0f;
185 corner[1][2] -= sprite_height / 2.0f;
186 corner[2][0] -= sprite_width / 2.0f;
187 corner[2][2] += sprite_height / 2.0f;
188 corner[3][0] += sprite_width / 2.0f;
189 corner[3][2] += sprite_height / 2.0f;
190
191 for (int i = 0; i < 4; i++) {
192 if (MGRotTransPers(screen[i], corner[i], 0) == 0) {
193 return;
194 }
195 }
196 } else if (MGRotTransPers3DSprite(top_left, bottom_right, position, sprite_width, sprite_height, 0) == 0) {
197 return;
198 }
199
200 if (render_flags != 0) {
201 sceGsZbuf zbuffer = mgZBuffer;
202 sceGsAlpha alpha = mgAlpha;
203 zbuffer.bits.zmsk = 1;
204 MGSetGsZBUF(&zbuffer);
205
206 if ((render_flags & 1) != 0) {
207 alpha.bits.a = 0;
208 alpha.bits.b = 2;
209 alpha.bits.c = 0;
210 alpha.bits.d = 1;
211 }
212
213 if ((render_flags & 2) != 0) {
214 alpha.bits.a = 2;
215 alpha.bits.b = 0;
216 alpha.bits.c = 0;
217 alpha.bits.d = 1;
218 }
219
220 MGSetGsALPHA(&alpha);
221 }
222
223 // Texture changes lag their corresponding source rectangle by one draw.
224 CTexture *draw_texture = texture;
225 CRect_i_ draw_texel = texel;
226 CEffectTextureFrame *animation;
227
228 if (texture_frames != NULL) {
229 int animation_frame = frame;
230
231 if (texture_frame_period > 0) {
232 animation_frame %= texture_frame_period;
233 }
234
235 for (animation = texture_frames; animation != NULL; animation = animation->next) {
236 if (animation_frame < animation->end_frame) {
237 texture = animation->texture;
238 draw_texel = animation->texel;
239 break;
240 }
241 }
242 }
243
244 spRGBA colour = {0x68, 0x80, 0x80, (int) (opacity * 128.0f)};
245
246 if (draw_mode != 0) {
247 set3DSprite(GetVif1Packet(), draw_texture, draw_texel, screen[0], screen[1], screen[2], screen[3], &colour);
248 } else {
249 set3DSprite(GetVif1Packet(), draw_texture, draw_texel, top_left, bottom_right, &colour);
250 }
251
252 if (render_flags != 0) {
253 MGSetGsZBUF(NULL);
254 MGSetGsALPHA(NULL);
255 }
256}
257
258void CEffectParam::Initialize() {
259 lifetime = 0;
260 draw_mode = 0;
263 opacity_mode = EFFECT_OPACITY_CONSTANT;
264 opacity = 1.0f;
265 render_flags = 0;
266 width = height = 0.0f;
267 position[0] = position[1] = position[2] = position[3] = 0.0f;
268 sceVu0CopyVector(velocity, position);
269 sceVu0CopyVector(acceleration, position);
270 sceVu0CopyVector(position_oscillation_scale, position);
271 sceVu0CopyVector(position_oscillation_rate, position);
272 scale[0] = scale[1] = 1.0f;
273 sceVu0CopyVector(scale_velocity, position);
274 sceVu0CopyVector(scale_oscillation_scale, position);
275 sceVu0CopyVector(scale_oscillation_rate, position);
276 texture = NULL;
277 texel = CRect_i_(0, 0, 0, 0);
279 texture_frames = NULL;
280}
281
283 active = false;
284 frame = 0;
285 lifetime = 0;
286 draw_mode = 0;
289 opacity_mode = EFFECT_OPACITY_CONSTANT;
290 opacity = 1.0f;
291 render_flags = 0;
292 opacity_step = 0.0f;
293 width = height = 0.0f;
294 position[0] = position[1] = position[2] = position[3] = 0.0f;
295 sceVu0CopyVector(velocity, position);
296 sceVu0CopyVector(acceleration, position);
297 sceVu0CopyVector(position_oscillation_scale, position);
298 sceVu0CopyVector(position_oscillation_rate, position);
299 scale[0] = scale[1] = 1.0f;
300 sceVu0CopyVector(scale_velocity, position);
301 sceVu0CopyVector(scale_oscillation_scale, position);
302 sceVu0CopyVector(scale_oscillation_rate, position);
303 texture = NULL;
304 texel = CRect_i_(0, 0, 0, 0);
305 texture_frames = NULL;
307}
CRect_i_ texel
Definition effect.hpp:170
void Initialize()
Definition effect.cpp:54
float position[4]
Definition effect.hpp:165
float half_width
Definition effect.hpp:166
int disable_z_write
Definition effect.hpp:173
int alpha_blend
Definition effect.hpp:172
float half_height
Definition effect.hpp:167
spRGBA colour
Definition effect.hpp:171
void Draw()
Definition effect.cpp:14
CTexture * texture
Definition effect.hpp:168
sceVu0FVECTOR position
Definition op_a.cpp:149
int draw_mode
Definition effect.hpp:44
float scale_velocity[4]
Definition effect.hpp:54
float scale_oscillation_scale[4]
Definition effect.hpp:55
int position_oscillation_flags
Definition op_a.cpp:145
float height
Definition op_a.cpp:147
float acceleration[4]
Definition effect.hpp:50
CRect< int > texel
Definition op_a.cpp:164
float width
Definition effect.hpp:42
float position_oscillation_rate[4]
Definition effect.hpp:52
float position_oscillation_scale[4]
Definition effect.hpp:51
float scale[4]
Definition effect.hpp:53
float scale_oscillation_rate[4]
Definition effect.hpp:56
int render_flags
Definition op_a.cpp:161
float velocity[4]
Definition effect.hpp:49
CEffectTextureFrame * texture_frames
Definition effect.hpp:62
float opacity
Definition op_a.cpp:162
int texture_frame_period
Definition op_a.cpp:166
int opacity_mode
Definition op_a.cpp:160
int lifetime
Definition op_a.cpp:144
CTexture * texture
Definition op_a.cpp:163
int scale_oscillation_flags
Definition effect.hpp:45
CTexture * texture
Definition effect.hpp:111
float scale_oscillation_scale[4]
Definition effect.hpp:105
float height
Definition effect.hpp:89
s16 frame
Definition effect.hpp:85
float acceleration[4]
Definition effect.hpp:96
float velocity[4]
Definition effect.hpp:95
float width
Definition effect.hpp:88
float opacity_step
Definition effect.hpp:109
int position_oscillation_flags
Definition effect.hpp:90
int render_flags
Definition effect.hpp:110
float opacity
Definition effect.hpp:108
s16 draw_mode
Definition effect.hpp:87
void Step(int unused)
Definition effect.cpp:107
float scale_oscillation_rate[4]
Definition effect.hpp:106
float scale[4]
Definition effect.hpp:103
int scale_oscillation_flags
Definition effect.hpp:99
float scale_velocity[4]
Definition effect.hpp:104
int opacity_mode
Definition effect.hpp:107
CRect_i_ texel
Definition effect.hpp:115
void Initialize()
Definition effect.cpp:282
float position[4]
Definition effect.hpp:94
CEffectTextureFrame * texture_frames
Definition effect.hpp:116
void Draw()
Definition effect.cpp:164
s16 lifetime
Definition effect.hpp:86
int texture_frame_period
Definition effect.hpp:117
void SetEffect(CEffectParam *parameters)
Definition effect.cpp:65
s16 active
Definition effect.hpp:84
float position_oscillation_scale[4]
Definition effect.hpp:97
float position_oscillation_rate[4]
Definition effect.hpp:98
CEffectTextureFrame * next
Definition effect.hpp:30
CTexture * texture
Definition effect.hpp:26
u8 b
Definition rect.hpp:48
u8 g
Definition rect.hpp:47
u8 a
Definition rect.hpp:49
u8 r
Definition rect.hpp:46