DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
textureanime.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#include "textureanime.hpp"
4
5#include <cstring>
6
7#include "mglib.hpp"
8#include "rect.hpp"
9#include "scriptinterpreter.hpp"
10#include "texture.hpp"
11
13CTextureAnime *pTexAnime;
14int now_group;
15
16static void CommandTEX_ANIME(void **arguments);
17static void CommandTEX_ANIME_DATA(void **arguments);
18static void CommandTEX_ANIME_DATA2(void **arguments);
19static void CommandTEX_SCROLL_DATA(void **arguments);
20static void CommandTEX_ANIME_END(void **arguments);
21
23 if (texture != NULL) {
24 block = texture->block;
25 width = texture->width;
26 height = texture->height;
27 bpp = texture->bpp;
28 tex0 = texture->tex0;
29 tex1 = texture->tex1;
30 }
31}
32
36
38 kind = -1;
39 group = 0;
40 duration = 0;
41 memset(&first_texture, 0, sizeof(first_texture));
43 memset(&second_texture, 0, sizeof(second_texture));
45 source_height = 0;
46 source_width = 0;
47 source_y = 0;
48 source_x = 0;
49 dest_y = 0;
50 dest_x = 0;
51 scroll_y = 0.0f;
52 scroll_x = 0.0f;
53 scroll_y_step = 0.0f;
54 scroll_x_step = 0.0f;
55 next = NULL;
56 linked_group = -1;
57}
58
59void CTextureAnime::TexAnime(int texture_block) {
60 int x;
61 int height;
62 int width;
63 int y;
64 int to_x;
65 int to_y;
66 int scroll_x;
67 int scroll_y;
68 int group;
69
70 sceVif1PkCnt(Vif1Packet, 0);
71 sceVif1PkOpenDirectCode(Vif1Packet, 0);
72 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &GiftagAD);
73 sceVif1PkAddGsAD(Vif1Packet, 0x3F, 0);
74 sceVif1PkCloseGifTag(Vif1Packet);
75 sceVif1PkCloseDirectCode(Vif1Packet);
76
77 for (int i = 0; i < 24; i++) {
78 if (enabled[i] != 0 && current[i] != NULL && current[i]->linked_group >= 0) {
79 Enable(current[i]->linked_group);
80 }
81 }
82
83 for (group = 0; group < 24; group++) {
84 if (enabled[group] == 0 || current[group] == NULL || current[group]->first_texture.block != texture_block || current[group]->second_texture.block != texture_block) {
85 continue;
86 }
87
88 CTexAnimeData *record = current[group];
89
90 for (;;) {
91 if (record->kind == 0) {
92 MGMoveImage((sceGsTex0 *) &record->first_texture.tex0, CRect_i_(record->source_x, record->source_y, record->source_width, record->source_height), (sceGsTex0 *) &record->second_texture.tex0, record->dest_x, record->dest_y, 0);
93
94 if (record->source_width == record->first_texture.width && record->source_height == record->first_texture.height && record->first_texture.bpp == 1) {
95 sceGsTex0 clut_source;
96 sceGsTex0 clut_destination;
97
98 clut_source.bits.tbp0 = ((sceGsTex0 *) &record->first_texture.tex0)->bits.cbp;
99 clut_source.bits.tbw = 1;
100 clut_source.bits.psm = ((sceGsTex0 *) &record->first_texture.tex0)->bits.cpsm;
101 clut_destination.bits.tbp0 = ((sceGsTex0 *) &record->second_texture.tex0)->bits.cbp;
102 clut_destination.bits.tbw = 1;
103 clut_destination.bits.psm = ((sceGsTex0 *) &record->second_texture.tex0)->bits.cpsm;
104 MGMoveImage(&clut_source, CRect_i_(0, 0, 16, 16), &clut_destination, 0, 0, 0);
105 }
106 }
107
108 if (record->kind == 1) {
109 scroll_x = (int) record->scroll_x;
110 scroll_y = (int) record->scroll_y;
111
112 x = record->source_x + scroll_x;
113 y = record->source_y + scroll_y;
114 width = record->source_width - scroll_x;
115 height = record->source_height - scroll_y;
116 to_x = record->dest_x;
117 to_y = record->dest_y;
118
119 if (width > 0 && height > 0) {
120 MGMoveImage((sceGsTex0 *) &record->first_texture.tex0, CRect_i_(x, y, width, height), (sceGsTex0 *) &record->second_texture.tex0, to_x, to_y, 0);
121 }
122
123 x = record->source_x + scroll_x;
124 y = record->source_y;
125 width = record->source_width - scroll_x;
126 height = scroll_y;
127 to_x = record->dest_x;
128 to_y = record->dest_y + record->source_height - scroll_y;
129
130 if (width > 0 && height > 0) {
131 MGMoveImage((sceGsTex0 *) &record->first_texture.tex0, CRect_i_(x, y, width, height), (sceGsTex0 *) &record->second_texture.tex0, to_x, to_y, 0);
132 }
133
134 x = record->source_x;
135 y = record->source_y + scroll_y;
136 width = scroll_x;
137 height = record->source_height - scroll_y;
138 to_x = record->dest_x + record->source_width - scroll_x;
139 to_y = record->dest_y;
140
141 if (width > 0 && height > 0) {
142 MGMoveImage((sceGsTex0 *) &record->first_texture.tex0, CRect_i_(x, y, width, height), (sceGsTex0 *) &record->second_texture.tex0, to_x, to_y, 0);
143 }
144
145 x = record->source_x;
146 y = record->source_y;
147 width = scroll_x;
148 height = scroll_y;
149 // Unlike the other pieces of the wrapped scroll, retail places this one from source_x rather than dest_x.
150 to_x = record->source_x + record->source_width - scroll_x;
151 to_y = record->dest_y + record->source_height - scroll_y;
152
153 if (width > 0 && height > 0) {
154 MGMoveImage((sceGsTex0 *) &record->first_texture.tex0, CRect_i_(x, y, width, height), (sceGsTex0 *) &record->second_texture.tex0, to_x, to_y, 0);
155 }
156 }
157
158 if (record->kind == 1 && CTextureAnime::stop_anime == 0) {
159 if (record->scroll_x_step != 0.0f) {
160 float scroll = record->scroll_x + record->scroll_x_step;
161 record->scroll_x = scroll;
162
163 if (scroll >= record->source_width) {
164 record->scroll_x = scroll - record->source_width;
165 }
166
167 if (record->scroll_x < 0.0f) {
168 record->scroll_x = record->source_width + record->scroll_x;
169 }
170 }
171
172 if (record->scroll_y_step != 0.0f) {
173 float scroll = record->scroll_y + record->scroll_y_step;
174 record->scroll_y = scroll;
175
176 if (scroll >= record->source_height) {
177 record->scroll_y = scroll - record->source_height;
178 }
179
180 if (record->scroll_y < 0.0f) {
181 record->scroll_y = record->source_height + record->scroll_y;
182 }
183 }
184 }
185
186 if (record->duration != 0 || record->next == NULL) {
187 break;
188 }
189
190 record = record->next;
191 }
192
193 if (CTextureAnime::stop_anime == 0) {
194 frame[group]++;
195 }
196
197 if (record->duration < 0) {
198 frame[group] = 0;
199 } else if (frame[group] > record->duration) {
200 frame[group] = 0;
201 current[group] = current[group]->next;
202
203 if (current[group] == NULL) {
204 current[group] = first[group];
205 }
206 }
207 }
208
209 sceVif1PkCnt(Vif1Packet, 0);
210 sceVif1PkOpenDirectCode(Vif1Packet, 0);
211 sceVif1PkOpenGifTag(Vif1Packet, *(u_long128 *) &GiftagAD);
212 sceVif1PkAddGsAD(Vif1Packet, 0x3F, 0);
213 sceVif1PkCloseGifTag(Vif1Packet);
214 sceVif1PkCloseDirectCode(Vif1Packet);
215}
216
217void CTextureAnime::Initialize(CTexAnimeData *records, int count) {
218 data = records;
219 data_count = count;
220
221 for (int group = 0; group < 24; group++) {
222 first[group] = 0;
223 current[group] = 0;
224 last[group] = 0;
225 frame[group] = 0;
226 enabled[group] = 0;
227 }
228}
229
231 Initialize(records, count);
232}
233
235 if (data == NULL) {
236 return NULL;
237 }
238
239 CTexAnimeData *record = data;
240
241 for (int i = 0; i < data_count; i++, record++) {
242 if (record->kind == -1) {
243 return record;
244 }
245 }
246
247 return NULL;
248}
249
251 if (group < 0 || group >= 24) {
252 return NULL;
253 }
254
255 CTexAnimeData *record = NewTexAnimeData();
256
257 if (record == NULL) {
258 return NULL;
259 }
260
261 record->Initialize();
262
263 if (last[group] != NULL) {
264 last[group]->next = record;
265 }
266
267 last[group] = record;
268 record->next = NULL;
269
270 if (current[group] == NULL) {
271 current[group] = record;
272 }
273
274 if (first[group] == NULL) {
275 first[group] = record;
276 }
277
278 return record;
279}
280
282 CTexAnimeData *record = NewTexAnimeGroupData(source->group);
283
284 if (record == NULL) {
285 return 0;
286 }
287
288 record->kind = source->kind;
289 record->group = source->group;
290 record->duration = source->duration;
291 record->linked_group = source->linked_group;
292 record->first_texture = source->first_texture;
293 record->second_texture = source->second_texture;
294 record->source_x = source->source_x;
295 record->source_y = record->first_texture.height - source->source_y - source->source_height;
296 record->source_width = source->source_width;
297 record->source_height = source->source_height;
298 record->dest_x = source->dest_x;
299 record->dest_y = record->second_texture.height - source->dest_y - source->source_height;
300 record->scroll_x_step = source->scroll_x_step;
301 record->scroll_y_step = source->scroll_y_step;
302 return 1;
303}
304
306 for (int group = 0; group < 24; group++) {
307 Disable(group);
308 }
309}
310
311void CTextureAnime::Enable(int group) {
312 if (group < 0 || group >= 24) {
313 return;
314 }
315
316 enabled[group] = 1;
317}
318
319void CTextureAnime::Disable(int group) {
320 if (group < 0 || group >= 24) {
321 return;
322 }
323
324 enabled[group] = 0;
325 current[group] = first[group];
326 frame[group] = 0;
327}
328
330static TAG_PARAM Command[5] = {
331 {"TEX_ANIME", {1, 1, -1} },
332 {"TEX_ANIME_DATA", {0, 1, 1, 1, 1, 0, 1, 1, 1, 1, -1} },
333 {"TEX_ANIME_DATA2", {0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, -1}},
334 {"TEX_SCROLL_DATA", {0, 1, 1, 1, 1, 0, 1, 1, 2, 2, 1, 1, -1} },
335 {"TEX_ANIME_END", {-1} },
336};
337
339static void (*CommandExe[5])(void **arguments) = {
340 CommandTEX_ANIME,
341 CommandTEX_ANIME_DATA,
342 CommandTEX_ANIME_DATA2,
343 CommandTEX_SCROLL_DATA,
344 CommandTEX_ANIME_END,
345};
346
347void CTextureAnime::LoadCFGFile(char *script, int script_size) {
348 pTexAnime = this;
349 now_group = 0;
350 DisableAll();
351
352 CScriptInterpreter interpreter;
353 interpreter.SetScript(script, script_size);
354 interpreter.SetTAG((TAG_PARAM *) Command, 5);
355 int command;
356
357 for (;;) {
358 command = interpreter.GetNextTAG();
359
360 if (command < 0) {
361 break;
362 }
363
364 CommandExe[command](interpreter.arguments);
365 }
366}
367
375static void CommandTEX_ANIME(void **arguments) {
376 now_group = *(int *) arguments[0];
377
378 if (*(int *) arguments[1] != 0) {
379 pTexAnime->Enable(now_group);
380 return;
381 }
382
383 pTexAnime->Disable(now_group);
384}
385
393static void CommandTEX_ANIME_DATA(void **arguments) {
394 CTexAnimeData record;
395 record.group = (s16) now_group;
396 record.kind = 0;
397 char *first_name = (char *) arguments[0];
398 record.source_x = *(s16 *) arguments[1];
399 record.source_y = *(s16 *) arguments[2];
400 record.source_width = *(s16 *) arguments[3];
401 record.source_height = *(s16 *) arguments[4];
402 char *second_name = (char *) arguments[5];
403 record.dest_x = *(s16 *) arguments[6];
404 record.dest_y = *(s16 *) arguments[7];
405 record.duration = *(s16 *) arguments[8];
406
407 if (*(int *) arguments[9] != 0) {
408 record.duration = -1;
409 }
410
411 CTexture *first_texture = TexManager.GetTexture(first_name, -1);
412 CTexture *second_texture = TexManager.GetTexture(second_name, -1);
413 memset(&record.first_texture, 0, sizeof(record.first_texture));
414 record.first_texture.block = -1;
415 memset(&record.second_texture, 0, sizeof(record.second_texture));
416 record.second_texture.block = -1;
417
418 if (first_texture != NULL && second_texture != NULL) {
419 record.first_texture.Copy(first_texture);
420 record.second_texture.Copy(second_texture);
421 pTexAnime->EnterTexAnime(&record);
422 }
423}
424
432static void CommandTEX_ANIME_DATA2(void **arguments) {
433 CTexAnimeData record;
434 record.group = (s16) now_group;
435 record.kind = 0;
436 char *first_name = (char *) arguments[0];
437 record.source_x = *(s16 *) arguments[1];
438 record.source_y = *(s16 *) arguments[2];
439 record.source_width = *(s16 *) arguments[3];
440 record.source_height = *(s16 *) arguments[4];
441 char *second_name = (char *) arguments[5];
442 record.dest_x = *(s16 *) arguments[6];
443 record.dest_y = *(s16 *) arguments[7];
444 record.duration = *(s16 *) arguments[8];
445 int hold = *(int *) arguments[9];
446 record.linked_group = *(s16 *) arguments[10];
447
448 if (hold != 0) {
449 record.duration = -1;
450 }
451
452 CTexture *first_texture = TexManager.GetTexture(first_name, -1);
453 CTexture *second_texture = TexManager.GetTexture(second_name, -1);
454
455 if (first_texture != NULL && second_texture != NULL) {
456 record.first_texture.Copy(first_texture);
457 record.second_texture.Copy(second_texture);
458 pTexAnime->EnterTexAnime(&record);
459 }
460}
461
469static void CommandTEX_SCROLL_DATA(void **arguments) {
470 CTexAnimeData record;
471 record.group = (s16) now_group;
472 record.kind = 1;
473 char *first_name = (char *) arguments[0];
474 record.source_x = *(s16 *) arguments[1];
475 record.source_y = *(s16 *) arguments[2];
476 record.source_width = *(s16 *) arguments[3];
477 record.source_height = *(s16 *) arguments[4];
478 char *second_name = (char *) arguments[5];
479 record.dest_x = *(s16 *) arguments[6];
480 record.dest_y = *(s16 *) arguments[7];
481 record.scroll_x_step = *(float *) arguments[8];
482 record.scroll_y_step = *(float *) arguments[9];
483 record.duration = *(s16 *) arguments[10];
484
485 if (*(int *) arguments[11] != 0) {
486 record.duration = -1;
487 }
488
489 CTexture *first_texture = TexManager.GetTexture(first_name, -1);
490 CTexture *second_texture = TexManager.GetTexture(second_name, -1);
491
492 if (first_texture != NULL && second_texture != NULL) {
493 record.first_texture.Copy(first_texture);
494 record.second_texture.Copy(second_texture);
495 pTexAnime->EnterTexAnime(&record);
496 }
497}
498
506static void CommandTEX_ANIME_END(void **arguments) {
507}
void SetScript(char *script, int script_size)
void SetTAG(TAG_PARAM *tags, int count)
CTextureTexAnime second_texture
CTextureTexAnime first_texture
CTexAnimeData * next
void Initialize(CTexAnimeData *records, int count)
void Disable(int group)
CTexAnimeData * NewTexAnimeData()
CTexAnimeData * current[24]
CTextureAnime(CTexAnimeData *records=0, int count=0)
CTexAnimeData * NewTexAnimeGroupData(int group)
CTexAnimeData * last[24]
CTexAnimeData * first[24]
void Enable(int group)
void TexAnime(int texture_block)
int EnterTexAnime(CTexAnimeData *source)
void LoadCFGFile(char *script, int script_size)
static s32 stop_anime
CTexAnimeData * data
short height
Definition texture.hpp:54
short bpp
Definition texture.hpp:55
short block
Definition texture.hpp:52
short width
Definition texture.hpp:53
u_long tex1
Definition texture.hpp:58
u_long tex0
Definition texture.hpp:57
void Copy(CTexture *texture)