DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
runeffect.cpp
1#include "runeffect.hpp"
2
3#include <libgraph.h>
4#include <libpkt.h>
5
6#include <cmath>
7#include <cstdlib>
8
9#include "mglib.hpp"
10#include "rect.hpp"
11#include "snd.hpp"
12#include "texture.hpp"
13
14float waveAnimeCnt[32];
15int sw;
16
24void blendTextuer(sceVif1Packet *packet, int destination, int width, int format, CTexture *first_texture, const CRect_i_ &first_destination, const CRect_i_ &first_source, CTexture *second_texture, const CRect_i_ &second_destination, const CRect_i_ &second_source) {
25 sceGsTex0 frame;
26 sceGsTest test;
27 sceGsZbuf zbuffer;
28 sceGsAlpha alpha;
29 float q = 1.0f;
30
31 MGGetFBuffTex(&frame);
32 sceVif1PkCnt(packet, 0);
33 sceVif1PkOpenDirectCode(packet, 0);
34 sceVif1PkOpenGifTag(packet, *(u_long128 *) &GiftagAD);
35 sceVif1PkAddGsAD(packet, SCE_GS_TEX1_1, 0x61);
36 sceVif1PkAddGsAD(packet, SCE_GS_TEXFLUSH, 0);
37 sceVif1PkAddGsAD(packet, SCE_GS_TEX0_1, *(u_long *) &frame);
38 sceVif1PkAddGsAD(packet, SCE_GS_FRAME_1, SCE_GS_SET_FRAME(destination >> 5, width, format, 0));
39 test = mgPixelTest;
40 test.bits.ate = 0;
41 test.bits.zte = 1;
42 test.bits.ztst = 1;
43 sceVif1PkAddGsAD(packet, SCE_GS_TEST_1, *(u_long *) &test);
44 zbuffer = mgZBuffer;
45 zbuffer.bits.zmsk = 1;
46 sceVif1PkAddGsAD(packet, SCE_GS_ZBUF_1, *(u_long *) &zbuffer);
47
48 sceVif1PkAddGsAD(packet, SCE_GS_PRIM, 0x106);
49 sceVif1PkAddGsAD(packet, SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(0x80, 0x80, 0x80, 0x80, *(u_int *) &q));
50 sceVif1PkAddGsAD(packet, SCE_GS_TEX0_1, first_texture->tex0);
51 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV(first_source.x << 4, first_source.y << 4));
52 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2((first_destination.x << 4) + 0x6C00, (first_destination.y << 4) + GS_Y_OFFSET, 0, 0));
53 // This pass takes the bottom texel row from x rather than y.
54 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV((first_source.x + first_source.width) << 4, (first_source.x + first_source.height) << 4));
55 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2(((first_destination.x + first_destination.width) << 4) + 0x6C00, ((first_destination.y + first_destination.height) << 4) + GS_Y_OFFSET, 0, 0));
56
57 sceVif1PkAddGsAD(packet, SCE_GS_PRIM, 0x156);
58 sceVif1PkAddGsAD(packet, SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(0x80, 0x80, 0x80, 0x80, *(u_int *) &q));
59 sceVif1PkAddGsAD(packet, SCE_GS_TEX0_1, first_texture->tex0);
60 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV(first_source.x << 4, first_source.y << 4));
61 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2((first_destination.x << 4) + 0x6C00, (first_destination.y << 4) + GS_Y_OFFSET, 0, 0));
62 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV((first_source.x + first_source.width) << 4, (first_source.y + first_source.height) << 4));
63 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2(((first_destination.x + first_destination.width) << 4) + 0x6C00, ((first_destination.y + first_destination.height) << 4) + GS_Y_OFFSET, 0, 0));
64 sceVif1PkAddGsAD(packet, SCE_GS_TEXFLUSH, 0);
65
66 zbuffer = mgZBuffer;
67 zbuffer.bits.zmsk = 1;
68 sceVif1PkAddGsAD(packet, SCE_GS_ZBUF_1, *(u_long *) &zbuffer);
69 alpha = mgAlpha;
70 alpha.bits.a = 1;
71 alpha.bits.b = 2;
72 alpha.bits.c = 0;
73 alpha.bits.d = 0;
74 sceVif1PkAddGsAD(packet, SCE_GS_ALPHA_1, *(u_long *) &alpha);
75
76 sceVif1PkAddGsAD(packet, SCE_GS_PRIM, 0x156);
77 sceVif1PkAddGsAD(packet, SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(0x80, 0x80, 0x80, 0x80, *(u_int *) &q));
78 sceVif1PkAddGsAD(packet, SCE_GS_TEX0_1, second_texture->tex0);
79 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV(second_source.x << 4, second_source.y << 4));
80 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2((second_destination.x << 4) + 0x6C00, (second_destination.y << 4) + GS_Y_OFFSET, 0, 0));
81 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV((second_source.x + second_source.width) << 4, (second_source.y + second_source.height) << 4));
82 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2(((second_destination.x + second_destination.width) << 4) + 0x6C00, ((second_destination.y + second_destination.height) << 4) + GS_Y_OFFSET, 0, 0));
83
84 sceVif1PkAddGsAD(packet, SCE_GS_FRAME_1, SCE_GS_SET_FRAME(frame.TBP0 >> 5, frame.TBW, frame.PSM, 0));
85 sceVif1PkAddGsAD(packet, SCE_GS_TEST_1, *(u_long *) &mgPixelTest);
86 sceVif1PkAddGsAD(packet, SCE_GS_ZBUF_1, *(u_long *) &mgZBuffer);
87 sceVif1PkAddGsAD(packet, SCE_GS_ALPHA_1, *(u_long *) &mgAlpha);
88 sceVif1PkCloseGifTag(packet);
89 sceVif1PkCloseDirectCode(packet);
90}
91
99void initBlendCnt(int count, float scale) {
100 for (int i = 0; i < count; i++) {
101 float degrees = (360.0f / (float) count) * (float) i;
102 float wave = sinf(PI * degrees / 180.0f);
103 waveAnimeCnt[i] = wave * scale;
104 }
105}
106
115void blendTextuerTest(sceVif1Packet *packet, int destination, int width, int format, const CRect_i_ &source, CTexture *texture, const CRect_i_ &texture_destination, const CRect_i_ &texture_source, float depth, float phase) {
116 sceGsTex0 frame;
117 sceGsTest test;
118 sceGsZbuf zbuffer;
119 sceGsAlpha alpha;
120 float q = 1.0f;
121
122 MGGetFBuffTex(&frame);
123 depth /= 10000;
124 sceVif1PkCnt(packet, 0);
125 sceVif1PkOpenDirectCode(packet, 0);
126 sceVif1PkOpenGifTag(packet, *(u_long128 *) &GiftagAD);
127 sceVif1PkAddGsAD(packet, SCE_GS_TEXFLUSH, 0);
128 sceVif1PkAddGsAD(packet, SCE_GS_TEX0_1, *(u_long *) &frame);
129 sceVif1PkAddGsAD(packet, SCE_GS_TEX1_1, 0x61);
130 sceVif1PkAddGsAD(packet, SCE_GS_FRAME_1, SCE_GS_SET_FRAME(destination >> 5, width, format, 0));
131 test = mgPixelTest;
132 test.bits.ate = 0;
133 test.bits.zte = 1;
134 test.bits.ztst = 1;
135 sceVif1PkAddGsAD(packet, SCE_GS_TEST_1, *(u_long *) &test);
136 zbuffer = mgZBuffer;
137 zbuffer.bits.zmsk = 1;
138 sceVif1PkAddGsAD(packet, SCE_GS_ZBUF_1, *(u_long *) &zbuffer);
139
140 int y;
141 int top = 0;
142 int bottom = 0;
143 int count = 0;
144 float amplitude = 0.0f;
145
146 for (y = 0; y < source.height; y += 2) {
147 int index = count + (int) phase;
148
149 if (index >= 8) {
150 index -= 8;
151 }
152
153 int offset = (int) (16.0f * (depth * (amplitude * waveAnimeCnt[index])));
154 bottom += 2;
155 int left = (source.x << 4) + offset;
156
157 if (left < 0) {
158 left = 0;
159 }
160
161 int right = offset + ((source.x + source.width) << 4);
162
163 if (right > 0x27F0) {
164 right = 0x27F0;
165 }
166
167 sceVif1PkAddGsAD(packet, SCE_GS_TEX0_1, *(u_long *) &frame);
168 sceVif1PkAddGsAD(packet, SCE_GS_PRIM, 0x116);
169 sceVif1PkAddGsAD(packet, SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(0x80, 0x80, 0x80, 0x80, *(u_int *) &q));
170 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV(left, (source.y + top) << 4));
171 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2(0x6C00, (y << 4) + GS_Y_OFFSET, 0, 0));
172 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV(right, (source.y + bottom) << 4));
173 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2((source.width << 4) + 0x6C00, ((y + 2) << 4) + GS_Y_OFFSET, 0, 0));
174 top = bottom;
175 count++;
176
177 if (count >= 8) {
178 amplitude = 1.3f * rand() / 2147483648.0f;
179 }
180
181 if (count >= 8) {
182 count = 0;
183 }
184 }
185
186 sceVif1PkAddGsAD(packet, SCE_GS_TEXFLUSH, 0);
187 alpha = mgAlpha;
188 alpha.bits.a = 2;
189 alpha.bits.b = 2;
190 alpha.bits.c = 2;
191 alpha.bits.d = 1;
192 sceVif1PkAddGsAD(packet, SCE_GS_ALPHA_1, *(u_long *) &alpha);
193
194 sceVif1PkAddGsAD(packet, SCE_GS_PRIM, 0x156);
195 sceVif1PkAddGsAD(packet, SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(0x80, 0x80, 0x80, 0x80, *(u_int *) &q));
196 sceVif1PkAddGsAD(packet, SCE_GS_TEX0_1, texture->tex0);
197 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV(texture_source.x << 4, texture_source.y << 4));
198 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2((texture_destination.x << 4) + 0x6C00, (texture_destination.y << 4) + GS_Y_OFFSET, 0, 0));
199 sceVif1PkAddGsAD(packet, SCE_GS_UV, SCE_GS_SET_UV((texture_source.x + texture_source.width) << 4, (texture_source.y + texture_source.height) << 4));
200 sceVif1PkAddGsAD(packet, SCE_GS_XYZF2, SCE_GS_SET_XYZF2(((texture_destination.x + texture_destination.width) << 4) + 0x6C00, ((texture_destination.y + texture_destination.height) << 4) + GS_Y_OFFSET, 0, 0));
201
202 sceVif1PkAddGsAD(packet, SCE_GS_FRAME_1, SCE_GS_SET_FRAME(frame.TBP0 >> 5, frame.TBW, frame.PSM, 0));
203 sceVif1PkAddGsAD(packet, SCE_GS_TEST_1, *(u_long *) &mgPixelTest);
204 sceVif1PkAddGsAD(packet, SCE_GS_ZBUF_1, *(u_long *) &mgZBuffer);
205 sceVif1PkAddGsAD(packet, SCE_GS_ALPHA_1, *(u_long *) &mgAlpha);
206 sceVif1PkAddGsAD(packet, SCE_GS_TEXFLUSH, 0);
207 sceVif1PkCloseGifTag(packet);
208 sceVif1PkCloseDirectCode(packet);
209}
210
218void CRunEffect::Lighting(int enabled) {
219 lighting = enabled;
220}
221
230 int top_left[4];
231 int bottom_right[4];
232 int top_right[4];
233 int bottom_left[4];
234 sceVu0FVECTOR light;
235
236 CTexture *first = TexManager.GetTexture("fx_foot", -1);
237 CTexture *second = TexManager.GetTexture("fx_foot2", -1);
238
239 if (first == NULL || second == NULL) {
240 return;
241 }
242
243 sceVu0FVECTOR normal = {0.0f, 1.0f, 0.0f, 0.0f};
244 MGCalcColor(light, normal);
245 light[0] += 80.0f;
246 light[1] += 60.0f;
247 light[2] += 40.0f;
248
249 if (!(light[0] <= 255.0f)) {
250 light[0] = 255.0f;
251 }
252
253 if (!(light[1] <= 255.0f)) {
254 light[1] = 255.0f;
255 }
256
257 if (!(light[2] <= 255.0f)) {
258 light[2] = 255.0f;
259 }
260
261 spRGBA colour;
262
263 if (lighting != 0) {
264 colour.r = (int) light[0];
265 colour.g = (int) light[1];
266 colour.b = (int) light[2];
267 colour.a = 0x80;
268 } else {
269 colour.r = 0x80;
270 colour.g = 0x80;
271 colour.b = 0x80;
272 colour.a = 0x80;
273 }
274
275 sw ^= 1;
276
277 sceGsZbuf zbuffer = mgZBuffer;
278 zbuffer.bits.zmsk = 1;
279 sceVif1Packet *packet = Vif1Packet;
280 sceVif1PkCnt(packet, 0);
281 sceVif1PkOpenDirectCode(packet, 0);
282 sceVif1PkOpenGifTag(packet, *(u_long128 *) &GiftagAD);
283 sceVif1PkAddGsAD(packet, SCE_GS_ZBUF_1, *(u_long *) &zbuffer);
284 sceVif1PkCloseGifTag(packet);
285 sceVif1PkCloseDirectCode(packet);
286
287 for (int i = 0; i < 8; i++) {
288 if (life[i] == 0) {
289 continue;
290 }
291
292 if (MGRotTransPers3DSprite(top_left, bottom_right, position[i], 12.0f - 0.5f * life[i], 5.5f - 0.25f * life[i], 0) != 1) {
293 continue;
294 }
295
296 top_right[0] = bottom_right[0];
297 top_right[1] = top_left[1];
298 top_right[2] = top_left[2];
299 top_right[3] = top_left[3];
300 bottom_left[0] = top_left[0];
301 bottom_left[1] = bottom_right[1];
302 bottom_left[2] = bottom_right[2];
303 bottom_left[3] = bottom_right[3];
304 colour.a = life[i] * 10;
305
306 if (sw != 0) {
307 set3DSprite(Vif1Packet, first, CRect_i_(0, 0, 0x20, 0x20), top_left, top_right, bottom_left, bottom_right, &colour);
308 } else {
309 set3DSprite(Vif1Packet, second, CRect_i_(0, 0, 0x20, 0x20), top_left, top_right, bottom_left, bottom_right, &colour);
310 }
311 }
312
313 sceVif1PkCnt(packet, 0);
314 sceVif1PkOpenDirectCode(packet, 0);
315 sceVif1PkOpenGifTag(packet, *(u_long128 *) &GiftagAD);
316 sceVif1PkAddGsAD(packet, SCE_GS_ZBUF_1, *(u_long *) &mgZBuffer);
317 sceVif1PkCloseGifTag(packet);
318 sceVif1PkCloseDirectCode(packet);
319}
320
328void CRunEffect::Set(float *origin) {
329 int slot = -1;
330
331 for (int i = 0; i < 8; i++) {
332 if (life[i] == 0) {
333 slot = i;
334 }
335 }
336
337 if (slot != -1) {
338 position[slot][0] = origin[0];
339 position[slot][1] = origin[1];
340 position[slot][2] = origin[2];
341 position[slot][3] = 1.0f;
342 velocity_y[slot] = 0.3f;
343 life[slot] = 16;
344 }
345}
346
355 for (int i = 0; i < 8; i++) {
356 if (life[i] != 0) {
357 life[i]--;
358 velocity_y[i] -= 0.03f;
359 position[i][1] += velocity_y[i];
360 }
361 }
362}
363
372 for (int i = 0; i < 8; i++) {
373 velocity_y[i] = 0.0f;
374 life[i] = 0;
375 }
376
377 lighting = false;
378}
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
void Lighting(int on)
void Step()
int life[8]
Definition runeffect.hpp:47
float velocity_y[8]
Definition runeffect.hpp:46
float position[8][4]
Definition runeffect.hpp:45
void Set(float *position)
void Draw()
u_long tex0
Definition texture.hpp:57
u8 b
Definition rect.hpp:48
u8 g
Definition rect.hpp:47
u8 a
Definition rect.hpp:49
u8 r
Definition rect.hpp:46