DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
dataset.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 199
4
5#include "dataset.hpp"
6
7#include <eekernel.h>
8#include <libvu0.h>
9
10#include <cstdio>
11#include <cstring>
12
13#include "boxvu0.hpp"
14#include "collisionmdt.hpp"
15#include "dataalloc.hpp"
16#include "frame.hpp"
17#include "framevu1.hpp"
18#include "mathutil.hpp"
19#include "mds.hpp"
20#include "mdt.hpp"
21#include "mglib.hpp"
22#include "visual.hpp"
23
24void CCollisionMDT::Initialize() {
25 model = 0;
26 mesh = 0;
27 mesh_count = 0;
28}
29
30u_int *read_buffer;
31CDataAlloc2<1> *WorkBuffer;
32CDataAlloc2<1> *ActiveData;
33
34CDataAlloc2<1> VisualData(-1);
35CDataAlloc2<1> MotionData(-1);
36CDataAlloc2<1> TextureData(-1);
37CDataAlloc2<1> WaterData(-1);
38CDataAlloc2<1> VariousData(-1);
39CDataAlloc2<1> ActiveData0(-1);
40CDataAlloc2<1> ActiveData1(-1);
41CDataAlloc<1, 1690000> GlobalDataBuffer;
42CDataAlloc2<1> workbuffer(-1);
43#ifndef PORT
44void InitializeDataBuffer() {
45 GlobalDataBuffer.used = 0;
46 memset(&GlobalDataBuffer.block[GlobalDataBuffer.used], 0, 1690000 * 16);
47
48 GlobalDataBuffer.Alloc64(10);
49 asm {
50 paddub $4, $2, $0
51 sw $4, WaterData
52 }
53 WaterData.limit = 10;
54 WaterData.used = 0;
55
56 GlobalDataBuffer.Alloc64(25000);
57 asm {
58 paddub $4, $2, $0
59 sw $4, ActiveData0
60 }
61 ActiveData0.limit = 25000;
62 ActiveData0.used = 0;
63
64 GlobalDataBuffer.Alloc64(25000);
65 asm {
66 paddub $4, $2, $0
67 sw $4, ActiveData1
68 }
69 ActiveData1.limit = 25000;
70
71 WaterData.used = 0;
72 ActiveData0.used = 0;
73 ActiveData1.used = 0;
74}
75#endif
76void SetDataBuffer(CDataAlloc2<1> *arena, int quads) {
77 arena->base = GlobalDataBuffer.Alloc64(quads);
78 arena->limit = quads;
79 arena->used = 0;
80}
81
82void SetPacketReadBuffer(int packet_quads, int read_quads) {
83 u_long128 *packet_buffer0;
84 u_long128 *packet_buffer1;
85
86 read_buffer = (u_int *) GlobalDataBuffer.Alloc64(read_quads);
87 packet_buffer0 = (u_long128 *) GlobalDataBuffer.Alloc64(packet_quads);
88 packet_buffer1 = (u_long128 *) GlobalDataBuffer.Alloc64(packet_quads);
89 MGInitVif1Packet(packet_buffer0, packet_buffer1);
90 workbuffer.base = GlobalDataBuffer.Alloc64(2048);
91 workbuffer.limit = 2048;
92 WorkBuffer = &workbuffer;
93 WorkBuffer->used = 0;
94 printf("%d/%d\n", GlobalDataBuffer.used, 1690000);
95}
96#ifndef PORT
97void BufferAllClear() {
98 GlobalDataBuffer.used = 0;
99 asm {
100 lw $2, GlobalDataBuffer+27040000
101 sll $3, $2, 4
102 la $2, GlobalDataBuffer
103 addu $2, $2, $3
104 paddub $4, $0, $0
105 beq $0, $0, clear_test
106clear_loop:
107 sq $0, 0($2)
108 addiu $2, $2, 16
109 addiu $4, $4, 1
110clear_test:
111 lui $3, 0x19
112 ori $3, $3, 0xc990
113 slt $3, $4, $3
114 bne $3, $0, clear_loop
115 }
116
117 VisualData.base = GlobalDataBuffer.Alloc64(600000);
118 VisualData.limit = 600000;
119 VisualData.used = 0;
120
121 MotionData.base = GlobalDataBuffer.Alloc64(200000);
122 MotionData.limit = 200000;
123 MotionData.used = 0;
124
125 TextureData.base = GlobalDataBuffer.Alloc64(300000);
126 TextureData.limit = 300000;
127 TextureData.used = 0;
128
129 WaterData.base = GlobalDataBuffer.Alloc64(90000);
130 WaterData.limit = 90000;
131 WaterData.used = 0;
132
133 ActiveData0.base = GlobalDataBuffer.Alloc64(25000);
134 ActiveData0.limit = 25000;
135 ActiveData0.used = 0;
136
137 ActiveData1.base = GlobalDataBuffer.Alloc64(25000);
138 ActiveData1.limit = 25000;
139 ActiveData1.used = 0;
140
141 read_buffer = (u_int *) GlobalDataBuffer.Alloc64(100000);
142 workbuffer.base = GlobalDataBuffer.Alloc64(4096);
143 workbuffer.limit = 4096;
144 WorkBuffer = &workbuffer;
145 WorkBuffer->used = 0;
146
147 u_long128 *packet_buffer0 = (u_long128 *) GlobalDataBuffer.Alloc64(50000);
148 u_long128 *packet_buffer1 = (u_long128 *) GlobalDataBuffer.Alloc64(50000);
149 MGInitVif1Packet(packet_buffer0, packet_buffer1);
150
151 WaterData.used = 0;
152 ActiveData0.used = 0;
153 ActiveData1.used = 0;
154}
155#endif
156static int htoi(char *text) {
157 char *cursor;
158 int len;
159 int value;
160 int i;
161 int place;
162 int ch;
163 int digit;
164
165 cursor = text;
166 len = 0;
167 value = 0;
168
169 while (*cursor++ != '\0') {
170 len++;
171 }
172
173 place = 1;
174
175 for (i = 0; i < len; i++) {
176 ch = (unsigned char) text[len - i - 1];
177 digit = 0;
178
179 if (ch >= '0' && ch <= '9') {
180 digit = ch - '0';
181 }
182
183 if (ch >= 'a' && ch <= 'f') {
184 digit = ch - 'a' + 10;
185 }
186
187 if (ch >= 'A' && ch <= 'F') {
188 digit = ch - 'A' + 10;
189 }
190
191 value += digit * place;
192 place <<= 4;
193 }
194
195 return value;
196}
197
198void SetFrameAttr(CFrame *frame, int recurse) {
199 int has_codes;
200 char *cursor;
201 char blend_code[3];
202 CFrame *child;
203
204 frame->attr.clip_enable = true;
205 frame->attr.clip_depth = 150.0f;
206 has_codes = 1;
207 cursor = frame->name;
208
209 if (*cursor == '\0') {
210 has_codes = 0;
211 }
212
213 cursor++;
214
215 for (;;) {
216 if (*cursor == '\0') {
217 has_codes = 0;
218 break;
219 }
220
221 if (*cursor == '_' && cursor[-1] == '_') {
222 break;
223 }
224
225 cursor++;
226 }
227
228 while (has_codes) {
229 if (*cursor == '\0') {
230 break;
231 }
232
233 switch (*cursor) {
234 case 'c':
235 case 'C':
236 frame->attr.use_color = true;
237 frame->attr.color[0] = 128.0f;
238 frame->attr.color[1] = 128.0f;
239 frame->attr.color[2] = 128.0f;
240 frame->attr.color[3] = 128.0f;
241 break;
242 case 'n':
243 case 'N':
244 frame->attr.clip_enable = false;
245 break;
246 case 'a':
247 case 'A':
248 blend_code[0] = cursor[1];
249 cursor += 2;
250 blend_code[1] = *cursor;
251 blend_code[2] = '\0';
252
253 if (blend_code[0] >= 'a' && blend_code[0] <= 'z') {
254 blend_code[0] -= 32;
255 }
256
257 if (blend_code[1] >= 'a' && blend_code[1] <= 'z') {
258 blend_code[1] -= 32;
259 }
260
261 if (blend_code[0] == 'P' && blend_code[1] == 'P') {
262 frame->attr.blend_mode = 1;
263 } else if (blend_code[0] == 'N' && blend_code[1] == 'N') {
264 frame->attr.blend_mode = -1;
265 } else {
266 frame->attr.alpha_ref = htoi(blend_code);
267 }
268
269 break;
270 case 'z':
271 case 'Z':
272 frame->attr.depth_write = false;
273 break;
274 case 'f':
275 case 'F':
276 frame->attr.fog_enable = false;
277 break;
278 case 's':
279 case 'S':
280 frame->attr.program_option = 1;
281 break;
282 case 'm':
283 case 'M':
284 frame->attr.eye_relative = true;
285 break;
286 case 'b':
287 case 'B':
288 cursor++;
289
290 if (*cursor == '\0') {
291 cursor--;
292 break;
293 }
294
295 if (*cursor == 'Y' || *cursor == 'y') {
296 frame->attr.billboard = 2;
297 }
298
299 if (*cursor == 'A' || *cursor == 'a') {
300 frame->attr.billboard = 3;
301 }
302
303 break;
304 case 't':
305 case 'T':
306 frame->attr.ambient_boost = true;
307 break;
308 case 'o':
309 case 'O':
310 frame->attr.ignore_depth = true;
311 break;
312 case 'v':
313 case 'V':
314 frame->attr.draw_on = 2;
315 frame->flags = 2;
316 break;
317 }
318
319 cursor++;
320 }
321
322 if (recurse) {
323 for (child = frame->child; child != 0; child = child->brother) {
324 SetFrameAttr(child, recurse);
325 }
326 }
327}
328
329int dset_mds_packet;
330int dset_mds_objnum;
331
332/* One edge of a shadow model while the pairing pass is running. The pass is over pairs, so an edge
333 already matched is skipped rather than removed, and the pointer is where the answer is written
334 back into the model itself. */
336 short v0;
337 short v1;
338 short done;
340};
341
342static void ArrangeShadowMDT(u_int *data);
343static void CreateBBox(CBox3<float> *box, sceVu0FVECTOR *vertex, int num);
344
345/* A scene file turned into frames. Every object of the file gets one, in the file's own order, so
346 that a parent index is an index into the array being built; an object whose name marks it as a
347 locator gets a frame and nothing else. */
348CFrameVu1 *LoadMDSFile(u_int *data, CDataAlloc2<1> *alloc, int attr, char **double_names, char **retain_names) {
349 /* Declared in this order because it is what lays them out in small data, and every reference
350 to either is a displacement off $gp that the order decides. */
351 static int flag;
352 static char init;
353
354 u_int i;
355 char **double_entry;
356 char **retain_entry;
357 float sx;
358 float sy;
359 float sz;
360 float rx;
361 float ry;
362 float rz;
363 MDS_HEADER *header;
364 MDS_OBJECT *object;
365 CFrameVu1 *node;
366 CFrameVu1 *frames;
367 CVisualMDTVu1 *visual;
368 u_long128 *block;
369 float *extremes[2];
370 sceVu0FMATRIX matrix;
371 int j;
372 int k;
373 int saved_attr;
374
375 if (!data) {
376 return 0;
377 }
378
379 /* The file is read into place by whoever loaded it and everything inside is addressed as
380 quadwords from its front, so a misaligned block would mislay all of it. */
381 if ((int) data % 16) {
382 printf("address error!! %d \n", data);
383 }
384
385 FlushCache(0);
386
387 if (!init) {
388 flag = 0;
389 init = 1;
390 }
391
392 header = (MDS_HEADER *) data;
393 data += sizeof(MDS_HEADER) / sizeof(u_int);
394
395 dset_mds_packet = 0;
396 dset_mds_objnum = header->object_num;
397
398 block = (u_long128 *) alloc->Alloc(header->object_num * sizeof(CFrameVu1) / 16);
399 frames = new (block) CFrameVu1[header->object_num];
400
401 for (i = 0; i < header->object_num; i++) {
402 object = (MDS_OBJECT *) data;
403 data += sizeof(MDS_OBJECT) / sizeof(u_int);
404
405 if (memcmp(object->name, "func_", 5) == 0) {
406 continue;
407 }
408
409 node = &frames[i];
410 node->Initialize();
411 sz = sy = sx = 1.0f;
412 node->SetScale(sx, sy, sz);
413 rx = ry = rz = 0.0f;
414 node->SetRotation(rx, ry, rz);
415 node->SetPosition(0.0f, 0.0f, 0.0f);
416
417 for (j = 0; j < 4; j++) {
418 for (k = 0; k < 4; k++) {
419 matrix[k][j] = object->matrix[k][j];
420 }
421 }
422
423 strcpy(node->name, object->name);
424 node->SetTransMatrix(matrix);
425 SetFrameAttr(node, 0);
426
427 if (object->parent < 0) {
428 node->SetParent(0);
429 } else {
430 node->SetParent(&frames[object->parent]);
431 }
432
433 if (object->data_ofs) {
434 MDT_HEADER *model = (MDT_HEADER *) ((char *) header + object->data_ofs);
435
436 sceVu0FVECTOR *vertex = (sceVu0FVECTOR *) ((char *) model + model->vertex_ofs);
437 int vertex_num = model->vertex_num;
438
439 CreateBBox((CBox3<float> *) node->max, vertex, vertex_num);
440
441 extremes[0] = node->min;
442 extremes[1] = node->max;
443
444 for (j = 0; j < 8; j++) {
445 node->corner[j][3] = 1.0f;
446 node->corner[j][0] = extremes[(j & 1) != 0][0];
447 node->corner[j][1] = extremes[(j & 2) != 0][1];
448 node->corner[j][2] = extremes[(j & 4) != 0][2];
449 }
450
451 saved_attr = attr;
452 double_entry = double_names;
453
454 if (double_entry) {
455 while (*double_entry) {
456 if (FrameNameComp(node->name, *double_entry)) {
457 attr |= 2;
458 attr |= 4;
459 break;
460 }
461
462 double_entry++;
463 }
464 }
465
466 retain_entry = retain_names;
467
468 if (retain_entry) {
469 while (*retain_entry) {
470 if (FrameNameComp(node->name, *retain_entry)) {
471 attr |= 2;
472 break;
473 }
474
475 retain_entry++;
476 }
477 }
478
479 visual = CreateVisual((u_int *) ((char *) header + object->data_ofs), alloc, attr);
480
481 if (attr & 2) {
482 node->SetVisual(visual);
483 } else {
484 node->SetVisual(visual);
485 }
486
487 attr = saved_attr;
488 }
489 }
490
491 flag = 1;
492 return frames;
493}
494
495/* One model file turned into the object that draws it. Which of the three kinds it becomes is the
496 attribute's business, and so is whether the model file is kept beside the built block and whether
497 a second block is built so that the drawing has two to alternate between. */
498CVisualMDTVu1 *CreateVisual(u_int *data, CDataAlloc2<1> *alloc, int attr) {
499 CVisualMDTVu1 *visual;
500 u_int *copy;
501
502 if (!data) {
503 return 0;
504 }
505
506 if (attr & 2) {
507 if (attr & 8) {
508 visual = new ((u_long128 *) alloc->Alloc(3)) CVisualShadow;
509 } else {
510 visual = new ((u_long128 *) alloc->Alloc(3)) CVisualMDTVu1;
511 }
512 } else {
513 if (attr & 8) {
514 visual = new ((u_long128 *) alloc->Alloc(3)) CVisualShadow;
515 } else {
516 visual = (CVisualMDTVu1 *) new ((u_long128 *) alloc->Alloc(2)) CVisualVu1;
517 }
518 }
519
520 visual->Initialize();
521 alloc->Align64();
522
523 /* The block is written where the allocator would hand out next and reserved afterwards, since
524 only the visual knows how much of it the model needed. */
525 if (attr & 8) {
526 ((CVisualShadow *) visual)
527 ->CreateVUdataShadow((u_int *) (alloc->base + alloc->used * 16), data);
528 visual->vu_data_buffer[0] = visual->vu_data;
529 visual->vu_data_buffer[1] = visual->vu_data;
530 ArrangeShadowMDT(data);
531 } else {
532 visual->CreateVUdataFromMDT((u_int *) (alloc->base + alloc->used * 16), data, 0, 0);
533 }
534
535 alloc->Alloc(visual->vu_size);
536 dset_mds_packet += visual->vu_size;
537 alloc->Align64();
538
539 if (attr & 2) {
540 alloc->Align64();
541 copy = (u_int *) alloc->Alloc((((MDT_HEADER *) data)->size >> 4) + 1);
542 memcpy(copy, data, ((MDT_HEADER *) data)->size);
543
544 if (attr & 2) {
545 visual->SetMDTDataAddress(copy);
546 }
547
548 if (attr & 0x10) {
549 visual->copy_on_draw = true;
550 }
551
552 if ((attr & 4) && !(attr & 0x10)) {
553 alloc->Align64();
554
555 if (attr & 8) {
556 visual->vu_data_buffer[0] = visual->vu_data;
557 ((CVisualShadow *) visual)
558 ->CreateVUdataShadow((u_int *) (alloc->base + alloc->used * 16), data);
559 } else {
560 visual->vu_data_buffer[0] = visual->vu_data;
561 visual->CreateVUdataFromMDT((u_int *) (alloc->base + alloc->used * 16), data, 0, 0);
562 }
563
564 alloc->Alloc(visual->vu_size);
565 visual->vu_data_buffer[1] = visual->vu_data;
566 } else {
567 visual->vu_data_buffer[0] = visual->vu_data;
568 visual->vu_data_buffer[1] = visual->vu_data;
569 }
570 }
571
572 alloc->Align64();
573 return visual;
574}
575
576/* Which of a shadow model's edges lie on its silhouette, decided once here rather than per frame.
577 Every edge of every triangle is listed with the plane normal of the triangle it came from; two
578 edges that are the same pair of corners in opposite order belong to the two triangles that share
579 them, and if those two face nearly the same way the edge is interior and is switched off in the
580 model itself. What is left switched on is the outline. */
581static void ArrangeShadowMDT(u_int *data) {
582 SHADOW_EDGE edges[1024];
583 sceVu0FVECTOR normals[1024];
584 sceVu0FVECTOR side0;
585 sceVu0FVECTOR side1;
586 sceVu0FVECTOR face;
587
588 sceVu0FVECTOR *vertex;
589 MDT_HEADER *model;
590 MDT_SHADOW *mesh;
591 MDT_SSHAPE *shape;
592 int edge_count;
593 int i;
594 int j;
595 MDT_SVERTEX *corner;
596 int shape_num;
597 int index_count;
598 int k;
599 int m;
600
601 model = (MDT_HEADER *) data;
602 mesh = (MDT_SHADOW *) ((char *) model + model->mesh_ofs);
603 vertex = (sceVu0FVECTOR *) ((char *) model + model->vertex_ofs);
604
605 shape_num = mesh->shape_num;
606 shape = mesh->shape;
607 edge_count = 0;
608
609 for (i = 0; i < shape_num; i++) {
610 index_count = shape->index_num;
611 corner = shape->vertex;
612
613 for (j = 0; j < index_count / 3; j++) {
614 sceVu0SubVector(side0, vertex[corner[1].index], vertex[corner[0].index]);
615 sceVu0SubVector(side1, vertex[corner[2].index], vertex[corner[0].index]);
616 sceVu0OuterProduct(face, side0, side1);
617 sceVu0Normalize(normals[edge_count], face);
618 sceVu0CopyVector(normals[edge_count + 1], normals[edge_count]);
619 sceVu0CopyVector(normals[edge_count + 2], normals[edge_count]);
620
621 edges[edge_count].v0 = corner[0].index;
622 edges[edge_count].v1 = corner[1].index;
623 edges[edge_count].done = 0;
624 edges[edge_count].edge_flag = &corner[0].edge;
625 corner[0].edge = false;
626 edge_count++;
627
628 edges[edge_count].v0 = corner[1].index;
629 edges[edge_count].v1 = corner[2].index;
630 edges[edge_count].done = 0;
631 edges[edge_count].edge_flag = &corner[1].edge;
632 corner[1].edge = false;
633 edge_count++;
634
635 edges[edge_count].v0 = corner[2].index;
636 edges[edge_count].v1 = corner[0].index;
637 edges[edge_count].done = 0;
638 edges[edge_count].edge_flag = &corner[2].edge;
639 corner[2].edge = false;
640 edge_count++;
641
642 if (edge_count > 1020) {
643 printf("shadow initialize failed\n");
644
645 while (1)
646 ;
647 }
648
649 corner += 3;
650 }
651
652 shape = (MDT_SSHAPE *) corner;
653 }
654
655 for (k = 0; k < edge_count - 1; k++) {
656 if (edges[k].done) {
657 continue;
658 }
659
660 for (m = k + 1; m < edge_count; m++) {
661 if (edges[m].done) {
662 continue;
663 }
664
665 if (edges[k].v0 != edges[m].v1) {
666 continue;
667 }
668
669 if (edges[k].v1 != edges[m].v0) {
670 continue;
671 }
672
673 if (DistVector(normals[k], normals[m]) < 0.0008f) {
674 edges[k].done = 1;
675 *edges[k].edge_flag = 1;
676 edges[m].done = 1;
677 *edges[m].edge_flag = 1;
678 break;
679 }
680 }
681 }
682}
683
684/* The four detail levels of one object, loaded as four scenes. A level the caller has no file for
685 leaves a null behind rather than a scene with nothing in it. */
686void LoadMDSFileLOD(CFrameVu1 **frame, u_int **data, CDataAlloc2<1> *alloc, int attr) {
687 int i;
688
689 for (i = 0; i < 4; i++) {
690 if (!data[i]) {
691 frame[i] = 0;
692 } else {
693 frame[i] = LoadMDSFile(data[i], alloc, attr, 0, 0);
694 }
695 }
696}
697
698/* A collision scene turned into frames. It is the scene loader with the drawing left out: the same
699 file shape and the same parenting, but every object carries a shape to be asked questions of
700 rather than geometry to be drawn, and nothing scales or positions a frame because the transform
701 the file carries is the whole of it. */
702CFrameVu1 *LoadCollisionFile(u_int *data, CDataAlloc2<1> *alloc) {
703 CFrameVu1 *frames;
704 u_int i;
705 u_int *cursor;
706 MDS_HEADER *header;
707 MDS_OBJECT *object;
708 CFrameVu1 *node;
709 u_long128 *block;
710 float *extremes[2];
711 sceVu0FMATRIX matrix;
712 int j;
713 int k;
714 int corner;
715
716 cursor = data;
717 header = (MDS_HEADER *) data;
718 cursor += sizeof(MDS_HEADER) / sizeof(u_int);
719
720 if (!((MDS_HEADER *) data)->object_num) {
721 return 0;
722 }
723
724 block = (u_long128 *) alloc->Alloc(((MDS_HEADER *) data)->object_num * sizeof(CFrameVu1) / 16);
725 frames = new (block) CFrameVu1[header->object_num];
726
727 for (i = 0; i < header->object_num; i++) {
728 object = (MDS_OBJECT *) cursor;
729 cursor += sizeof(MDS_OBJECT) / sizeof(u_int);
730
731 node = &frames[i];
732 node->Initialize();
733
734 for (j = 0; j < 4; j++) {
735 for (k = 0; k < 4; k++) {
736 matrix[k][j] = object->matrix[k][j];
737 }
738 }
739
740 strcpy(node->name, object->name);
741 node->SetTransMatrix(matrix);
742
743 if (object->parent < 0) {
744 node->SetParent(0);
745 } else {
746 node->SetParent(&frames[object->parent]);
747 }
748
749 if (object->data_ofs) {
750 MDT_HEADER *model = (MDT_HEADER *) ((char *) header + object->data_ofs);
751
752 node->SetCollision(CreateCollisionMDT((u_int *) model, alloc));
753 sceVu0FVECTOR *vertex = (sceVu0FVECTOR *) ((char *) model + model->vertex_ofs);
754 int vertex_num = model->vertex_num;
755
756 CreateBBox((CBox3<float> *) node->max, vertex, vertex_num);
757
758 extremes[0] = node->min;
759 extremes[1] = node->max;
760
761 for (corner = 0; corner < 8; corner++) {
762 node->corner[corner][3] = 1.0f;
763 node->corner[corner][0] = extremes[(corner & 1) != 0][0];
764 node->corner[corner][1] = extremes[(corner & 2) != 0][1];
765 node->corner[corner][2] = extremes[(corner & 4) != 0][2];
766 }
767 }
768 }
769
770 return frames;
771}
772
773/* One model file turned into the shape a frame answers about. The file is copied into the block
774 first, because everything the collision holds points into that copy and the caller's own is not
775 expected to outlive the load; the triangles are then built out of it with the bound of each
776 beside it, which is what lets a box query reject one without reading a vertex. */
777CCollisionMDT *CreateCollisionMDT(u_int *data, CDataAlloc2<1> *alloc) {
778 u_long128 *info;
779 MDT_HEADER *model;
780 u_long128 *vertex;
781 MDT_CPOLY *poly;
782 u_int i;
783 u_int poly_count;
784 CCollisionMDT *collision;
785 MDT_HEADER *source;
786 MDT_CPOLY_SET *poly_set;
787 CCPolyBox *built;
788 int index;
789
790 source = (MDT_HEADER *) data;
791 model = (MDT_HEADER *) alloc->Alloc64((((MDT_HEADER *) data)->size >> 4) + 1);
792 memcpy(model, source, source->size);
793
794 collision = new ((u_long128 *) alloc->Alloc(4)) CCollisionMDT;
795 collision->model = model;
796 collision->CreateBBox();
797
798 vertex = (u_long128 *) ((char *) model + model->vertex_ofs);
799 info = (u_long128 *) ((char *) model + model->info_ofs);
800 poly_set = &((MDT_COLLISION *) ((char *) model + model->mesh_ofs))->set;
801 poly = poly_set->poly;
802
803 built = (CCPolyBox *) alloc->Alloc(poly_set->num * sizeof(CCPolyBox) / 16);
804
805 for (i = 0; i < (poly_count = poly_set->num); i++) {
806 *(u_long128 *) built[i].poly.vertex[0] = vertex[poly->vertex[0]];
807 *(u_long128 *) built[i].poly.vertex[1] = vertex[poly->vertex[1]];
808 *(u_long128 *) built[i].poly.vertex[2] = vertex[poly->vertex[2]];
809
810 index = poly->info_index;
811
812 if (!model->info_ofs || index < 0) {
813 memset(&built[i].poly.info, 0, 16);
814 } else {
815 *(u_long128 *) &built[i].poly.info = info[index];
816 }
817
818 poly++;
819
820 VectorMaxMin(built[i].box.max, built[i].box.min, built[i].poly.vertex[0], built[i].poly.vertex[1], built[i].poly.vertex[2]);
821 PlaneNormal(built[i].poly.normal, built[i].poly.vertex[0], built[i].poly.vertex[1], built[i].poly.vertex[2]);
822 }
823
824 collision->mesh = built;
825 collision->mesh_count = poly_count;
826 return collision;
827}
828
829/* A scene loaded into the allocator every scene without one of its own goes into. */
830CFrameVu1 *LoadMDSFile(u_int *data, int attr, int unused) {
831 return LoadMDSFile(data, &VisualData, attr, 0, 0);
832}
833
834/* The extent of a run of points, which is a model's bound when the points are its vertices. A model
835 with no vertex array at all answers an empty bound rather than reading one. */
836static void CreateBBox(CBox3<float> *box, sceVu0FVECTOR *vertex, int num) {
837 int i;
838
839 if (!vertex) {
840 box->max[0] = box->min[0] = 0.0f;
841 box->max[1] = box->min[1] = 0.0f;
842 box->max[2] = box->min[2] = 0.0f;
843 return;
844 }
845
846 box->max[0] = vertex[0][0];
847 box->max[1] = vertex[0][1];
848 box->max[2] = vertex[0][2];
849 box->min[0] = vertex[0][0];
850 box->min[1] = vertex[0][1];
851 box->min[2] = vertex[0][2];
852
853 for (i = 0; i < num; i++) {
854 if (box->max[0] < vertex[0][0]) {
855 box->max[0] = vertex[0][0];
856 }
857
858 if (box->max[1] < vertex[0][1]) {
859 box->max[1] = vertex[0][1];
860 }
861
862 if (box->max[2] < vertex[0][2]) {
863 box->max[2] = vertex[0][2];
864 }
865
866 if (box->min[0] > vertex[0][0]) {
867 box->min[0] = vertex[0][0];
868 }
869
870 if (box->min[1] > vertex[0][1]) {
871 box->min[1] = vertex[0][1];
872 }
873
874 if (box->min[2] > vertex[0][2]) {
875 box->min[2] = vertex[0][2];
876 }
877
878 vertex++;
879 }
880}
881
882/* A subtree copied into an allocator, node by node. Each copy is constructed where the allocator
883 hands out next and then assigned from its original, so what a node carries travels with it and
884 what ties it to its neighbours does not — the parenting is redone from the copies as the walk
885 descends. */
886CFrameVu1 *CopyFrameVu1(CFrameVu1 *frame, CDataAlloc2<1> *alloc) {
887 CFrame *first_child;
888 CFrame *child;
889 CFrameVu1 *copy;
890
891 if (!frame) {
892 return 0;
893 }
894
895 copy = new ((u_long128 *) alloc->Alloc(sizeof(CFrameVu1) / 16)) CFrameVu1;
896 copy->Initialize();
897 *copy = *frame;
898
899 first_child = frame->child;
900
901 for (child = first_child; child; child = child->brother) {
902 CopyFrameVu1((CFrameVu1 *) child, alloc)->SetParent(copy);
903 }
904
905 return copy;
906}
907
908/* The same over frames that draw nothing. */
909CFrame *CopyFrame(CFrame *frame, CDataAlloc2<1> *alloc) {
910 CFrame *first_child;
911 CFrame *child;
912 CFrame *copy;
913
914 if (!frame) {
915 return 0;
916 }
917
918 copy = new ((u_long128 *) alloc->Alloc(sizeof(CFrame) / 16)) CFrame;
919 copy->Initialize();
920 *copy = *frame;
921
922 first_child = frame->child;
923
924 for (child = first_child; child; child = child->brother) {
925 CopyFrame(child, alloc)->SetParent(copy);
926 }
927
928 return copy;
929}
930
931void LoadLODData(CFrameVu1 **frame, char **name, u_int *data, int attr) {
932}
933
934/* A collision scene loaded into the allocator every scene without one of its own goes into. */
935CFrameVu1 *LoadCollisionFile(u_int *data) {
936 return LoadCollisionFile(data, &VisualData);
937}
938
939int CCollision::GetPolygon(int index, sceVu0FMATRIX v0, sceVu0FMATRIX v1, sceVu0FMATRIX v2) {
940 return 0;
941}
942
943int CCollision::GetMaxY(float *position) {
944 return 0;
945}
946
947int CCollision::Intersection(float *from, float *to, float *hit) {
948 return 0;
949}
950
951int CCollision::PickUpNearPoly(CCPoly *poly) {
952 return 0;
953}
954
955int CCollision::PickUpNearPoly(CCPoly *poly, const CBoxVu0 &box) {
956 return 0;
957}
958
959int CCollision::PickUpNearPoly(CCPoly *poly, float *position, float radius) {
960 return 0;
961}
962
963void CCollision::Initialize() {
964}
T max[4]
Definition boxvu0.hpp:16
T min[4]
Definition boxvu0.hpp:17
CCPolyBox * mesh
Definition collision.hpp:99
MDT_HEADER * model
Definition collision.hpp:98
u_char * base
Definition dataalloc.hpp:24
u_long128 block[1690000]
Definition dataalloc.hpp:92
short draw_on
Definition frame.hpp:27
char clip_enable
Definition frame.hpp:29
short alpha_ref
Definition frame.hpp:43
sceVu0FVECTOR color
Definition frame.hpp:39
char ignore_depth
Definition frame.hpp:46
char ambient_boost
Definition frame.hpp:41
short billboard
Definition frame.hpp:48
float clip_depth
Definition frame.hpp:28
char program_option
Definition frame.hpp:32
char use_color
Definition frame.hpp:38
short eye_relative
Definition frame.hpp:47
char depth_write
Definition frame.hpp:45
char fog_enable
Definition frame.hpp:33
short blend_mode
Definition frame.hpp:44
virtual void Initialize()
Definition frame.cpp:1341
void SetVisual(CVisualVu1 *visual)
Definition frame.cpp:1333
int flags
Definition frame.hpp:60
sceVu0FVECTOR corner[8]
Definition frame.hpp:64
char name[32]
Definition frame.hpp:68
CFrameAttr attr
Definition frame.hpp:65
sceVu0FVECTOR min
Definition frame.hpp:63
sceVu0FVECTOR max
Definition frame.hpp:62
CFrame * child
Definition frame.hpp:69
CFrame * brother
Definition frame.hpp:70
u_int * vu_data_buffer[2]
Definition visual.hpp:147
virtual void SetMDTDataAddress(u_int *data)
virtual void Initialize()
u_int * vu_data
Definition visual.hpp:74
int CreateVUdataFromMDT(u_int *block, u_int *data, int unknown0, int unknown1)
u_int vu_size
Definition visual.hpp:75
unsigned int object_num
Definition mds.hpp:22
int data_ofs
Definition mds.hpp:34
int parent
Definition mds.hpp:35
char name[32]
Definition mds.hpp:33
MDT_CPOLY poly[1]
Definition mdt.hpp:50
unsigned int num
Definition mdt.hpp:49
int vertex[3]
Definition mdt.hpp:39
int info_index
Definition mdt.hpp:40
int vertex_ofs
Definition mdt.hpp:14
int mesh_ofs
Definition mdt.hpp:19
int vertex_num
Definition mdt.hpp:13
unsigned int size
Definition mdt.hpp:12
int info_ofs
Definition mdt.hpp:21
MDT_SSHAPE shape[1]
Definition mdt.hpp:87
int shape_num
Definition mdt.hpp:85
MDT_SVERTEX vertex[1]
Definition mdt.hpp:77
int index_num
Definition mdt.hpp:75
int index
Definition mdt.hpp:65
int edge
Definition mdt.hpp:67
int * edge_flag
Definition dataset.cpp:339