DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
mapparts.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3
4#include "mapparts.hpp"
5
6#include <libvu0.h>
7
8#include "collision.hpp"
9#include "editpartsinfo.hpp"
10#include "frame.hpp"
11#include "framevu1.hpp"
12#include "mathutil.hpp"
13#include "mglib.hpp"
14#include "objanime.hpp"
15
16void CMapParts::GetPosition(float *out_position) {
17 sceVu0CopyVector(out_position, this->pos);
18}
19
20void CMapParts::SetPosition(float *position) {
21 sceVu0CopyVector(this->pos, position);
22}
23
24void CMapParts::SetPosition(float x, float y, float z) {
25 this->pos[0] = x;
26 this->pos[1] = y;
27 this->pos[2] = z;
28}
29
30void CMapParts::SetRotation(float x, float y, float z) {
31 this->rotation.x = x;
32 this->rotation.y = y;
33 this->rotation.z = z;
34}
35
36void CMapParts::SetRotY(int direction) {
37 float angle;
38 float zero = 0.0f;
39
40 // A part faces one of four directions, so each step is a quarter turn.
41 this->rot_y = direction;
42 angle = 0.5f * (PI * direction);
43 SetRotation(zero, angle, 0.0f);
44}
45
47 return this->rot_y;
48}
49
51 int i;
52
53 CMapObject::Initialize();
54 this->info = NULL;
55 this->preview_frame = 0;
56 this->blocked_preview_frame = 0;
57 this->ripple_frame = NULL;
58 this->unk_1D4 = 0;
59 this->unit_size = 0.0f;
60 this->rot_y = 0;
61 this->def_parts_no = 0;
63 this->parts_no = this->area = -1;
64 this->lift = 0.0f;
65 this->draw_distance = -1.0f;
66
67 for (i = 0; i < MAP_PARTS_EFFECT_MAX; i++) {
68 this->effect_on[i] = 0;
69 this->effect[i] = NULL;
70 }
71
72 this->func_count = 0;
73 this->func_data = 0;
74}
75
79
80void CMapParts::FrameObjectOnOff(char *name, int on) {
81 CFrame *found;
82
84
85 if (this->ripple_frame != NULL) {
86 found = this->ripple_frame->SearchFrame(name);
87
88 if (found != NULL) {
89 found->attr.draw_on = on;
90 }
91 }
92}
93
95 EDITPARTS_INFO *parts_info;
96
97 parts_info = this->info;
98
99 if (parts_info == NULL) {
100 return 1;
101 }
102
103 // A part that faces east or west covers the grid the other way round.
104 if (this->rot_y % 2) {
105 return parts_info->height;
106 }
107
108 return parts_info->width;
109}
110
112 EDITPARTS_INFO *parts_info;
113
114 parts_info = this->info;
115
116 if (parts_info == NULL) {
117 return 1;
118 }
119
120 if (this->rot_y % 2) {
121 return parts_info->width;
122 }
123
124 return parts_info->height;
125}
126
127int CMapParts::GetInfoData(int x, int y) {
128 int width;
129 int height;
130 int value;
131
132 if (this->info == NULL) {
133 return 0;
134 }
135
136 value = 0;
137 width = GetWidth();
138 height = GetHeight();
139
140 // Every direction reads the same grid, from the corner that the direction
141 // puts first and along the axis that it puts first.
142 switch (this->rot_y) {
143 case -1:
144 value = this->info->header->cell[y + height * (width - x - 1)];
145 break;
146 case 0:
147 value = this->info->header->cell[x + y * width];
148 break;
149 case 1:
150 value = this->info->header->cell[x * height + (height - y) - 1];
151 break;
152 case 2:
153 value = this->info->header->cell[(width - x) + width * (height - y - 1) - 1];
154 break;
155 }
156
157 return value;
158}
159
161 int i;
162 short cell;
163
164 if (this->info == NULL) {
165 return 0;
166 }
167
168 if (this->info->header == NULL) {
169 return 0;
170 }
171
172 for (i = 0; i < this->info->width * this->info->height; i++) {
173 cell = this->info->header->cell[i];
174
175 if (cell != 0 && cell < 0x80) {
176 return 1;
177 }
178 }
179
180 return 0;
181}
182
184 int i;
185 short cell;
186
187 if (this->info == NULL) {
188 return 0;
189 }
190
191 if (this->info->header == NULL) {
192 return 0;
193 }
194
195 for (i = 0; i < this->info->width * this->info->height; i++) {
196 cell = this->info->header->cell[i];
197
198 if (cell != 0 && cell == 0x81) {
199 return 1;
200 }
201 }
202
203 return 0;
204}
205
207 float world[4][4];
208 sceVu0FVECTOR min;
209 sceVu0FVECTOR max;
210
211 // The extent of the part is held in its own axes, so it takes the
212 // position and the angle of the part before it meets the box.
213 RotMatrixY(world, this->rotation.y);
214 sceVu0CopyVector(world[3], this->pos);
215 world[3][3] = 1.0f;
216 this->bound.min[3] = 1.0f;
217 this->bound.max[3] = 1.0f;
218 sceVu0ApplyMatrix(max, world, this->bound.max);
219 sceVu0ApplyMatrix(min, world, this->bound.min);
220 VectorMaxMin(max, min, max, min);
221
222 if (max[0] < box->min[0]) {
223 return 0;
224 }
225
226 if (max[2] < box->min[2]) {
227 return 0;
228 }
229
230 if (min[0] > box->max[0]) {
231 return 0;
232 }
233
234 if (min[2] > box->max[2]) {
235 return 0;
236 }
237
238 return 1;
239}
240
242 float world[4][4];
243 sceVu0FVECTOR corner[4];
244 sceVu0FVECTOR max;
245 sceVu0FVECTOR min;
246
247 RotMatrixY(world, this->rotation.y);
248
249 // All four corners take part, so that a part turned away from the axes
250 // still meets the box on the ground it really covers.
251 sceVu0CopyVector(corner[0], this->bound.min);
252 sceVu0CopyVector(corner[1], this->bound.min);
253 sceVu0CopyVector(corner[2], this->bound.max);
254 sceVu0CopyVector(corner[3], this->bound.max);
255 corner[1][2] = this->bound.max[2];
256 corner[2][2] = this->bound.min[2];
257
258 sceVu0CopyVector(world[3], this->pos);
259 world[3][3] = 1.0f;
260 this->bound.min[3] = 1.0f;
261 this->bound.max[3] = 1.0f;
262 sceVu0ApplyMatrix(corner[0], world, corner[0]);
263 sceVu0ApplyMatrix(corner[1], world, corner[1]);
264 sceVu0ApplyMatrix(corner[2], world, corner[2]);
265 sceVu0ApplyMatrix(corner[3], world, corner[3]);
266 VectorMaxMin(max, min, corner[0], corner[1], corner[2], corner[3]);
267
268 if (max[0] < box->min[0]) {
269 return 0;
270 }
271
272 if (max[2] < box->min[2]) {
273 return 0;
274 }
275
276 if (min[0] > box->max[0]) {
277 return 0;
278 }
279
280 if (min[2] > box->max[2]) {
281 return 0;
282 }
283
284 return 1;
285}
286
287void CMapParts::DrawLOD(float *distance, int lowest, int highest, int *out_level) {
288 sceVu0FVECTOR saved_pos;
289 sceVu0FVECTOR lifted_pos;
290 sceVu0FVECTOR eye;
291 sceVu0FVECTOR saved_rotation;
292 float depth;
293
294 if (this->handle < 0) {
295 return;
296 }
297
298 if (this->draw_on == 0) {
299 return;
300 }
301
302 sceVu0CopyVector(saved_pos, this->pos);
303 sceVu0CopyVector(saved_rotation, (float *) &this->rotation);
304 sceVu0CopyVector(lifted_pos, saved_pos);
305
306 // A part that asks for a lift stands a little above the ground, by less
307 // the further it is from the eye, so that it does not cut into what it
308 // stands on.
309 if (this->lift > 0.0f) {
310 lifted_pos[3] = 1.0f;
311 sceVu0ApplyMatrix(eye, mgRenderInfo.view_scaled, lifted_pos);
312 depth = eye[2] / 1000.0f;
313
314 if (depth < 0.1f) {
315 depth = 0.02f;
316 }
317
318 if (depth > 2.0f) {
319 depth = 2.0f;
320 }
321
322 if (this->lift > 1.0f) {
323 lifted_pos[1] += 0.1f;
324 } else {
325 lifted_pos[1] += depth * this->lift;
326 }
327 }
328
329 sceVu0CopyVector(this->pos, lifted_pos);
330 sceVu0CopyVector((float *) &this->rotation, saved_rotation);
331 CObjectFrame::DrawLOD(distance, lowest, highest, out_level);
332 sceVu0CopyVector(this->pos, saved_pos);
333}
334
335void CMapParts::DrawParts(float time, float *distance, int lowest, int highest, int *out_level) {
336 sceVu0FVECTOR ambient;
337 sceVu0FVECTOR saved_ambient;
338 float light_direction[4][4];
339 float light_colour[4][4];
340 float saved_light_colour[4][4];
341 float saved_light_direction[4][4];
342 sceVu0FVECTOR part_pos;
343 sceVu0FVECTOR part_rotation;
344 float parts_distance[4];
345 sceVu0FVECTOR effect_pos;
346 sceVu0FVECTOR direction;
347 int lit;
348 int light;
349 int i;
350 EDIT_EFFECT_INFO *effect_info;
351 float extent;
352
353 if (this->draw_on == 0) {
354 return;
355 }
356
357 lit = 0;
358 light = 3;
359
360 // A part that covers more ground goes to a coarser level of detail later,
361 // so that its size rather than its distance decides.
362 extent = this->bound.max[0] - this->bound.min[0];
363 extent += this->bound.max[2] - this->bound.min[2];
364 extent *= 0.25f;
365
366 for (i = 0; i < 4; i++) {
367 parts_distance[i] = extent + distance[i];
368 }
369
370 for (i = 0; i < MAP_PARTS_EFFECT_MAX; i++) {
371 if (this->effect_on[i] < 0) {
372 break;
373 }
374
375 if (this->effect_on[i] == 0) {
376 continue;
377 }
378
379 effect_info = this->effect[i];
380
381 if (effect_info == NULL) {
382 continue;
383 }
384
385 if (effect_info->kind != EDIT_EFFECT_UNK_5) {
386 continue;
387 }
388
389 if (!CheckEditEffect(effect_info, time)) {
390 continue;
391 }
392
393 if (effect_info->frame == NULL) {
394 continue;
395 }
396
397 // The first effect that lights the part takes the lights that the
398 // scene had, so that the last one can put them back.
399 if (!lit) {
400 MGGetAmbient(ambient);
401 MGGetPLight(light_direction, light_colour);
402 sceVu0CopyMatrix(saved_light_colour, light_colour);
403 sceVu0CopyMatrix(saved_light_direction, light_direction);
404 sceVu0CopyVector(saved_ambient, ambient);
405 sceVu0CopyVector(part_pos, this->pos);
406 sceVu0CopyVector(part_rotation, (float *) &this->rotation);
407
408 if (this->frame[0] != NULL) {
409 this->frame[0]->SetPosition(part_pos);
410 this->frame[0]->SetRotation(part_rotation[0], part_rotation[1], part_rotation[2]);
411 }
412
413 lit = 1;
414 }
415
416 effect_info->frame->GetWorldPosition(effect_pos, effect_info->offset);
417 sceVu0SubVector(direction, effect_pos, part_pos);
418 sceVu0Normalize(direction, direction);
419 light_direction[0][light] = direction[0];
420 light_direction[1][light] = direction[1];
421 light_direction[2][light] = direction[2];
422 light_colour[light][0] = effect_info->colour[0];
423 light_colour[light][1] = effect_info->colour[1];
424 light_colour[light][2] = effect_info->colour[2];
425 light_colour[light][3] = 128.0f;
426
427 light--;
428
429 if (light < 0) {
430 break;
431 }
432 }
433
434 if (lit) {
435 MGSetPLight(light_direction, light_colour);
436 }
437
438 CMapParts::DrawLOD(parts_distance, lowest, highest, out_level);
439
440 if (lit) {
441 MGSetAmbient(saved_ambient);
442 MGSetPLight(saved_light_direction, saved_light_colour);
443 }
444}
445
446void CMapParts::DrawEffect(CCamera *camera, float time, CEffectGroup *group) {
447 sceVu0FVECTOR part_pos;
448 sceVu0FVECTOR part_rotation;
449 int i;
450 EDIT_EFFECT_INFO *effect_info;
451
452 if (this->handle < 0) {
453 return;
454 }
455
456 if (this->draw_on == 0) {
457 return;
458 }
459
460 for (i = 0; i < MAP_PARTS_EFFECT_MAX; i++) {
461 if (this->effect_on[i] < 0) {
462 break;
463 }
464
465 if (this->effect_on[i] == 0) {
466 continue;
467 }
468
469 effect_info = this->effect[i];
470
471 if (effect_info == NULL) {
472 continue;
473 }
474
475 if (!CheckEditEffect(effect_info, time)) {
476 continue;
477 }
478
479 sceVu0CopyVector(part_pos, this->pos);
480 sceVu0CopyVector(part_rotation, (float *) &this->rotation);
481
482 if (this->frame[0] != NULL) {
483 this->frame[0]->SetPosition(part_pos);
484 this->frame[0]->SetRotation(part_rotation[0], part_rotation[1], part_rotation[2]);
485 }
486
487 DrawEditEffect(effect_info, camera, group);
488 }
489}
sceVu0FVECTOR min
Definition collision.hpp:29
sceVu0FVECTOR max
Definition collision.hpp:28
short draw_on
Definition frame.hpp:27
CFrameAttr attr
Definition frame.hpp:65
int handle
Definition op_b.cpp:96
virtual void FrameObjectOnOff(char *name, int on)
Definition mapobject.cpp:27
s32 parts_no
Definition mapparts.hpp:51
s32 func_count
Definition mapparts.hpp:58
virtual void SetPosition(float *position)
Definition mapparts.cpp:20
int ChangeDigData()
Definition mapparts.cpp:183
int GetHeight()
Definition mapparts.cpp:111
void SetRotY(int direction)
Definition mapparts.cpp:36
float lift
Definition mapparts.hpp:62
s32 func_data
Definition mapparts.hpp:59
CFrame * ripple_frame
Definition mapparts.hpp:56
s32 def_parts_no
Definition mapparts.hpp:60
s32 subtype
Definition mapparts.hpp:61
void Initialize()
Definition mapparts.cpp:50
int CheckBox2(CBoxVu0 *box)
Definition mapparts.cpp:241
int GetWidth()
Definition mapparts.cpp:94
float unit_size
Definition mapparts.hpp:69
virtual void SetRotation(float x, float y, float z)
Definition mapparts.cpp:30
CBoxVu0 bound
Definition mapparts.hpp:67
int CheckBox(CBoxVu0 *box)
Definition mapparts.cpp:206
s32 preview_frame
Definition mapparts.hpp:54
void DrawParts(float time, float *distance, int lowest, int highest, int *out_level)
Definition mapparts.cpp:335
s32 blocked_preview_frame
Definition mapparts.hpp:55
virtual void FrameObjectOnOff(char *name, int on)
Definition mapparts.cpp:80
int GetRotY()
Definition mapparts.cpp:46
int ChangeAltData()
Definition mapparts.cpp:160
void GetPosition(float *out_position)
Definition mapparts.cpp:16
float draw_distance
Definition mapparts.hpp:63
EDIT_EFFECT_INFO * effect[MAP_PARTS_EFFECT_MAX]
Definition mapparts.hpp:73
void DrawEffect(CCamera *camera, float time, CEffectGroup *group)
Definition mapparts.cpp:446
int GetInfoData(int x, int y)
Definition mapparts.cpp:127
EDITPARTS_INFO * info
Definition mapparts.hpp:57
s32 effect_on[MAP_PARTS_EFFECT_MAX]
Definition mapparts.hpp:72
virtual void DrawLOD(float *distance, int lowest, int highest, int *out_level)
Definition mapparts.cpp:287
virtual void DrawLOD(float *distance, int lowest, int highest, int *out_level)
CFrameVu1 * frame[4]
Definition op_b.cpp:76
s32 draw_on
Definition op_b.cpp:78
CVector3_f_ rotation
Definition object.hpp:23
float pos[4]
Definition object.hpp:18
#define MAP_PARTS_EFFECT_MAX
Definition mapparts.hpp:39
@ MAP_PARTS_SUBTYPE_NONE
Definition mapparts.hpp:18
EPARTS_INFO_HEADER * header
sceVu0FVECTOR offset
Definition objanime.hpp:171
sceVu0FVECTOR colour
Definition objanime.hpp:173
sceVu0FMATRIX view_scaled