DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
character.cpp
1/* Retail compiled this unit before anything had passed two doubles to a helper,
2 * so only $a0 was marked read at a helper call and SetEvent's loop counter
3 * could take $a1. See re/ai/compiler/leaked_state.md; without this the counter
4 * lands in $a2. Ignored by mwcc, read by scripts/build/statefix.py. */
5#pragma helper_mask_gpr 0x10
6#pragma helper_mask_fpr 0x1000
7#pragma name_counter 648
8
9#include "character.hpp"
10
11#include <libvu0.h>
12
13#include <cstring>
14
15#include "chararead.hpp"
16#include "cloth.hpp"
17#include "frame.hpp"
18#include "gameutil.hpp"
19#include "mathutil.hpp"
20#include "mglib.hpp"
21#include "snd.hpp"
22#include "texture.hpp"
23
24/* External */
25
26/* sbss */
28
29/* data */
30
31#include "textureanime.hpp"
32#include "visualvu1.hpp"
33
34void zcross(float z, float *from, float *to, float *out) {
35 float dz;
36 float t;
37 float dy;
38 float dx;
39
40 // Where the line between the two points crosses the plane at z.
41 dx = to[0] - from[0];
42 dy = to[1] - from[1];
43 dz = to[2] - from[2];
44 t = (z - from[2]) / dz;
45 out[0] = from[0] + t * dx;
46 out[1] = from[1] + t * dy;
47 out[2] = z;
48 out[3] = 1.0f;
49}
50
58int scissior(float out[][4], float first[][4], float second[][4], float near_z) {
59 float first_distance[4];
60 float second_distance[4];
61 int count;
62 int first_front;
63 int second_front;
64 int first_behind;
65 int second_behind;
66 int first_crosses;
67 int pair_crosses;
68 int second_crosses;
69 int i;
70 int crossing_count;
71
72 count = 0;
73 first_front = 0;
74 second_front = 0;
75 first_behind = 0;
76 second_behind = 0;
77 first_crosses = 0;
78 pair_crosses = 0;
79 second_crosses = 0;
80
81 for (i = 0; i < 3; i++) {
82 first_distance[i] = first[i][2] - near_z;
83 second_distance[i] = second[i][2] - near_z;
84
85 if (!(first_distance[i] <= 0.0f)) {
86 first_front++;
87 } else {
88 first_behind++;
89 }
90
91 if (!(second_distance[i] <= 0.0f)) {
92 second_front++;
93 } else {
94 second_behind++;
95 }
96 }
97
98 if (first_distance[0] * first_distance[1] < 0.0f) {
99 first_crosses++;
100 }
101
102 if (first_distance[1] * first_distance[2] < 0.0f) {
103 first_crosses++;
104 }
105
106 if (first_distance[2] * first_distance[0] < 0.0f) {
107 first_crosses++;
108 }
109
110 if (second_distance[0] * second_distance[1] < 0.0f) {
111 second_crosses++;
112 }
113
114 if (second_distance[1] * second_distance[2] < 0.0f) {
115 second_crosses++;
116 }
117
118 if (second_distance[2] * second_distance[0] < 0.0f) {
119 second_crosses++;
120 }
121
122 if (first_distance[0] * second_distance[0] < 0.0f) {
123 pair_crosses++;
124 }
125
126 if (first_distance[1] * second_distance[1] < 0.0f) {
127 pair_crosses++;
128 }
129
130 if (first_distance[2] * second_distance[2] < 0.0f) {
131 pair_crosses++;
132 }
133
134 crossing_count = first_crosses + second_crosses + pair_crosses;
135
136 if (crossing_count == 0) {
137 for (int j = 0; j < 5; j++) {
138 *(u_long128 *) out[j] = *(u_long128 *) first[0];
139 }
140
141 return 0;
142 }
143
144 if (crossing_count == 4 && pair_crosses == 0) {
145 if (first_distance[0] * first_distance[1] < 0.0f) {
146 zcross(near_z, first[0], first[1], out[count++]);
147 }
148
149 if (first_distance[1] * first_distance[2] < 0.0f) {
150 zcross(near_z, first[1], first[2], out[count++]);
151 }
152
153 if (first_distance[2] * first_distance[0] < 0.0f) {
154 zcross(near_z, first[2], first[0], out[count++]);
155 }
156
157 if (second_distance[0] * second_distance[2] < 0.0f) {
158 zcross(near_z, second[0], second[2], out[count++]);
159 }
160
161 if (second_distance[2] * second_distance[1] < 0.0f) {
162 zcross(near_z, second[2], second[1], out[count++]);
163 }
164
165 if (second_distance[1] * second_distance[0] < 0.0f) {
166 zcross(near_z, second[1], second[0], out[count++]);
167 }
168 } else if (crossing_count == 3 || crossing_count == 4) {
169 if (first_distance[0] * second_distance[0] < 0.0f) {
170 zcross(near_z, first[0], second[0], out[count++]);
171 }
172
173 if (first_distance[0] * first_distance[1] < 0.0f) {
174 zcross(near_z, first[0], first[1], out[count++]);
175 }
176
177 if (second_distance[0] * second_distance[1] < 0.0f) {
178 zcross(near_z, second[0], second[1], out[count++]);
179 }
180
181 if (first_distance[1] * second_distance[1] < 0.0f) {
182 zcross(near_z, first[1], second[1], out[count++]);
183 }
184
185 if (second_distance[1] * second_distance[2] < 0.0f) {
186 zcross(near_z, second[1], second[2], out[count++]);
187 }
188
189 if (first_distance[1] * first_distance[2] < 0.0f) {
190 zcross(near_z, first[1], first[2], out[count++]);
191 }
192
193 if (first_distance[2] * second_distance[2] < 0.0f) {
194 zcross(near_z, first[2], second[2], out[count++]);
195 }
196
197 if (first_distance[2] * first_distance[0] < 0.0f) {
198 zcross(near_z, first[2], first[0], out[count++]);
199 }
200
201 if (second_distance[2] * second_distance[0] < 0.0f) {
202 zcross(near_z, second[2], second[0], out[count++]);
203 }
204 } else if (crossing_count == 5) {
205 int vertex = 0;
206 int on_second = 0;
207
208 if (first_distance[0] * second_distance[0] < 0.0f) {
209 zcross(near_z, first[0], second[0], out[count++]);
210 } else if (first_distance[1] * second_distance[1] < 0.0f) {
211 zcross(near_z, first[1], second[1], out[count++]);
212 vertex = 1;
213 } else if (first_distance[2] * second_distance[2] < 0.0f) {
214 zcross(near_z, first[2], second[2], out[count++]);
215 vertex = 2;
216 }
217
218 for (int side = 0; side < 3; side++) {
219 int next = vertex + 1;
220
221 if (next > 2) {
222 next = 0;
223 }
224
225 if (on_second == 0) {
226 if (first_distance[vertex] * first_distance[next] < 0.0f) {
227 zcross(near_z, first[vertex], first[next], out[count++]);
228 on_second = 0;
229 }
230
231 if (second_distance[vertex] * second_distance[next] < 0.0f) {
232 zcross(near_z, second[vertex], second[next], out[count++]);
233 on_second = 1;
234 }
235 } else {
236 if (second_distance[vertex] * second_distance[next] < 0.0f) {
237 zcross(near_z, second[vertex], second[next], out[count++]);
238 on_second = 1;
239 }
240
241 if (first_distance[vertex] * first_distance[next] < 0.0f) {
242 zcross(near_z, first[vertex], first[next], out[count++]);
243 on_second = 0;
244 }
245 }
246
247 vertex++;
248
249 if (vertex > 2) {
250 vertex = 0;
251 }
252 }
253 } else {
254 printf("%d*******\n", crossing_count);
255 }
256
257 if (count == 0) {
258 for (int j = 0; j < 5; j++) {
259 *(u_long128 *) out[j] = *(u_long128 *) first[0];
260 }
261 } else {
262 for (int j = count; j < 5; j++) {
263 *(u_long128 *) out[j] = *(u_long128 *) out[j - count];
264 }
265 }
266
267 return count;
268}
269
270void CVisualVu1::SetMDTDataAddress(unsigned int *data) {
271}
272
273unsigned int *CVisualVu1::GetMDTDataAddress() {
274 return NULL;
275}
276
278 int i;
279
280 for (i = 0; i < CHARA_POINT_LIGHT_MAX; i++) {
281 this->point_light[i].used = 0;
282 this->point_light[i].source_w = -1.0f;
283 }
284}
285
286int CCharacter::SetPointLight(float *pos, float inner_range, float outer_range, float red, float green, float blue, float alpha) {
287 int i;
288
289 // The light goes into the first slot that is free.
290 for (i = 0; i < CHARA_POINT_LIGHT_MAX; i++) {
291 if (this->point_light[i].used == 0) {
292 this->point_light[i].used = 1;
293 sceVu0CopyVector(this->point_light[i].pos, pos);
294 this->point_light[i].source_w = pos[3];
295 this->point_light[i].inner_range = inner_range;
296 this->point_light[i].outer_range = outer_range;
297 this->point_light[i].colour[0] = red;
298 this->point_light[i].colour[1] = green;
299 this->point_light[i].colour[2] = blue;
300 this->point_light[i].colour[3] = alpha;
301 return 1;
302 }
303 }
304
305 return 0;
306}
307
309 this->tex_anime.Initialize(data, count);
310}
311
315
317 this->tex_anime.TexAnime(step);
318}
319
321 this->tex_anime.Enable(no);
322}
323
325 this->tex_anime.Disable(no);
326}
327
328int CCharacter::SetFootSound(float left_frame, float right_frame, int motion_no) {
329 CHARA_FOOT_SOUND *sound;
330 int i;
331
332 // One sound for each foot, each in the first slot that is free.
333 for (i = 0; i < CHARA_FOOT_SOUND_MAX; i++) {
334 sound = &this->foot_sound[i];
335
336 if ((float) sound->frame < 0.0f) {
337 sound->frame = (int) left_frame;
338 sound->foot = 0;
339 sound->motion_no = motion_no;
340 break;
341 }
342 }
343
344 for (i = 0; i < CHARA_FOOT_SOUND_MAX; i++) {
345 sound = &this->foot_sound[i];
346
347 if ((float) sound->frame < 0.0f) {
348 sound->frame = (int) right_frame;
349 sound->foot = 1;
350 sound->motion_no = motion_no;
351 break;
352 }
353 }
354
355 return 1;
356}
357
359 this->foot_sound_id = id;
360}
361
363 this->foot_sound_enable = on;
364}
365
367 this->event_enable = on;
368}
369
370void CCharacter::SetEvent(float frame, int kind, int no, int motion_no) {
372 int i;
373
374 for (i = 0; i < CHARA_EVENT_MAX; i++) {
375 event = &this->event[i];
376
377 if ((float) event->frame < 0.0f) {
378 event->frame = (int) frame;
379 event->kind = kind;
380 event->no = no;
381 event->motion_no = motion_no;
382 break;
383 }
384 }
385}
386
387void CCharacter::ClearEvent(int motion_no) {
388 int i;
389
390 // A motion below zero clears every event rather than one motion\'s own.
391 for (i = 0; i < CHARA_EVENT_MAX; i++) {
392 if (motion_no < 0 || this->event[i].motion_no == motion_no) {
393 this->event[i].no = -1;
394 this->event[i].frame = -1;
395 this->event[i].unk_10 = 0;
396 }
397 }
398}
399
401 int i;
402
403 for (i = 0; i < CHARA_MOTION_MAX; i++) {
404 if (this->motion[i] != NULL) {
405 this->motion[i]->state.camera = camera;
406 }
407 }
408}
409
410tagMOTION_TYPE *CCharacter::GetMotionParam(int motion_no, int *out_index, int *out_start, int *out_end, int *out_set) {
411 int index;
412 int i;
413 tagMOTION_TYPE *found;
414
415 index = -1;
416 found = NULL;
417
418 // The motion numbers of the sets run one after another, so the set that
419 // holds the number is the one whose range covers it.
420 for (i = 0; i < CHARA_MOTION_MAX; i++) {
421 if (this->motion[i] != NULL) {
422 if (this->motion_start[i] > motion_no) {
423 continue;
424 }
425
426 if (!(motion_no < this->motion_end[i])) {
427 continue;
428 }
429
430 index = motion_no - this->motion_start[i];
431 found = this->motion[i];
432
433 if (out_start != NULL) {
434 *out_start = this->motion_start[i];
435 }
436
437 if (out_end != NULL) {
438 *out_end = this->motion_end[i];
439 }
440
441 if (out_set != NULL) {
442 *out_set = i;
443 }
444
445 break;
446 }
447 }
448
449 if (index < 0) {
450 return NULL;
451 }
452
453 *out_index = index;
454 return found;
455}
456
459 int index;
460
461 motion = GetMotionParam(motion_no, &index, NULL, NULL, NULL);
462
463 if (motion == NULL) {
464 return NULL;
465 }
466
467 if (motion->motion_info == NULL) {
468 return NULL;
469 }
470
471 return &motion->motion_info[index];
472}
473
476 int index;
477
478 motion = GetMotionParam(this->motion_no, &index, NULL, NULL, NULL);
479
480 if (motion != NULL) {
481 return motion->state.time;
482 }
483
484 return 0.0f;
485}
486
488 int index;
489 int set_no;
491 float old_time;
492#ifdef PAL
493 float step;
494#endif
495 float new_time;
496 float saved_speed;
497 float saved_blend_step;
498 float delta;
499 float abs_delta;
500 MOTION_INFO *motion_info;
501 CHARA_FOOT_SOUND *sound;
503 int foot_sound_enabled;
504 sceVu0FVECTOR position;
505
506 this->motion_state = 0;
507
508 if (this->motion_no < 0) {
509 return;
510 }
511
512 index = -1;
513 motion = GetMotionParam(this->motion_no, &index, NULL, NULL, &set_no);
514
515 if (motion == NULL) {
516 return;
517 }
518
519 if (motion->motion_info == NULL) {
520 return;
521 }
522
523 old_time = motion->state.time;
524 this->motion_state = 2;
525 motion_info = &motion->motion_info[index];
526
527#ifdef PAL
528 // The step the motion advances by this frame, once the character's own speed overrides it.
529 step = motion_info->speed;
530
531 if (this->motion_speed > 0.0f) {
532 step = this->motion_speed;
533 }
534
535 if (motion_info != NULL) {
536 if (old_time >= (float) motion_info->start && (float) motion_info->end - step - 0.01f <= old_time) {
537 this->motion_state = 3;
538 }
539 }
540#else
541 if (motion_info != NULL) {
542 if (old_time >= (float) motion_info->start && old_time <= (float) motion_info->end && (float) motion_info->end - motion_info->speed - 0.01f <= old_time) {
543 this->motion_state = 3;
544 }
545 }
546#endif
547
548 motion->state.motion_no = index;
549
551 if (this->motion_no == 1 || this->motion_no == 2) {
552 motion->state.next_frame = NextMotionTime_GET_EX(motion->motion_info, &motion->state);
553 motion->state.next_frame += 2;
554 } else {
556 this->motion_state = 1;
557 }
558 }
559
560 saved_speed = motion->motion_info[index].speed;
561 saved_blend_step = motion->state.blend_step;
562
563 if (this->motion_speed > 0.0f) {
564 motion->motion_info[index].speed = this->motion_speed;
565 }
566
567 if ((this->motion_flags & 1) || MotionStopFlag) {
568 motion->motion_info[index].speed = 0.0f;
569 motion->state.blend_step = 0.0f;
570 }
571
572 if (this->motion_flags & 2) {
573#ifdef PAL
574 if (!(motion->state.time + step < (float) motion->motion_info[index].end)) {
575#else
576 if (!(motion->state.time + saved_speed + 0.01f < (float) motion->motion_info[index].end)) {
577#endif
578 motion->motion_info[index].speed = 0.0f;
579 }
580 }
581
582 if (this->motion_flags & 4) {
583 motion->state.blend_step = 1.0f;
586 motion->state.time = (float) motion->motion_info[index].start;
587 }
588
589 this->motion_flags &= ~4;
590 SetMotionEX(this->frame, motion, motion->motion_info, &motion->state, motion->frame_info);
591
592 if (motion->motion_info != NULL) {
593 motion->motion_info[index].speed = saved_speed;
594 motion->state.blend_step = saved_blend_step;
595 }
596
597 if (this->fade_out != 0) {
598 this->fade[0] -= 0.08f;
599
600 if (this->fade[0] < this->fade[3]) {
601 this->fade[0] = this->fade[3];
602 }
603 } else {
604 this->fade[0] += 0.08f;
605
606 if (this->fade[0] > 1.0f) {
607 this->fade[0] = 1.0f;
608 }
609 }
610
611 if (this->ground_ambient_no >= 0 && this->ground_ambient_no < 2) {
612 for (int j = 0; j < 3; j++) {
613 if (this->ground_ambient[this->ground_ambient_no][j] > this->ambient_tint[j]) {
614 this->ambient_tint[j] += 10.0f;
615
616 if (this->ground_ambient[this->ground_ambient_no][j] < this->ambient_tint[j]) {
617 this->ambient_tint[j] = this->ground_ambient[this->ground_ambient_no][j];
618 }
619 }
620
621 if (this->ground_ambient[this->ground_ambient_no][j] < this->ambient_tint[j]) {
622 this->ambient_tint[j] -= 10.0f;
623
624 if (this->ground_ambient[this->ground_ambient_no][j] > this->ambient_tint[j]) {
625 this->ambient_tint[j] = this->ground_ambient[this->ground_ambient_no][j];
626 }
627 }
628 }
629 } else {
630 for (int j = 0; j < 3; j++) {
631 this->ambient_tint[j] -= 10.0f;
632
633 if (this->ambient_tint[j] < 0.0f) {
634 this->ambient_tint[j] = 0.0f;
635 }
636 }
637 }
638
639 new_time = motion->state.time;
640 GetWorldPosition(position);
641 delta = old_time - new_time;
642 abs_delta = delta < 0.0f ? -delta : delta;
643
644 if (abs_delta < 1.0f) {
645 for (int i = 0; i < CHARA_FOOT_SOUND_MAX && this->foot_sound_enable != 0 && this->foot_sound_id >= 0 && this->foot_sound_wait == 0; i++) {
646 sound = &this->foot_sound[i];
647
648 if ((float) sound->frame >= 0.0f && sound->motion_no == set_no && (float) sound->frame >= old_time && (float) sound->frame < new_time) {
649 SndPlayFootSound(this->foot_sound_id, sound->foot, position);
650 this->foot_sound_wait = 5;
651 }
652 }
653 }
654
655 delta = delta < 0.0f ? -delta : delta;
656
657 if (delta < 1.0f) {
658 for (int i = 0; i < CHARA_EVENT_MAX && this->event_enable != 0; i++) {
659 event = &this->event[i];
660
661 if ((float) event->frame < 0.0f || event->motion_no != set_no || (float) event->frame < old_time || (float) event->frame >= new_time) {
662 continue;
663 }
664
665 switch (event->kind) {
667 foot_sound_enabled = this->foot_sound_enable;
668
669 if (foot_sound_enabled != 0) {
670 SndPlayFootSound(this->foot_sound_id, event->no, position);
671 }
672
673 break;
675 SndSePlay(event->no, -1, 0);
676 break;
677 }
678 }
679 }
680
681 this->foot_sound_wait--;
682
683 if (this->foot_sound_wait < 0) {
684 this->foot_sound_wait = 0;
685 }
686}
687
689 int index;
690 int i;
692 tagMOTION_TYPE *shadow;
693 int motion_no;
694 int start;
695 float speed;
696
697 motion_no = this->motion_no;
698
699 if (motion_no < 0) {
700 return;
701 }
702
703 index = -1;
704 shadow = NULL;
705
706 for (i = 0; i < CHARA_MOTION_MAX; i++) {
707 if (this->motion[i] == NULL) {
708 continue;
709 }
710
711 start = this->motion_start[i];
712
713 if (start > motion_no) {
714 continue;
715 }
716
717 if (motion_no >= this->motion_end[i]) {
718 continue;
719 }
720
721 index = motion_no - start;
722 shadow = this->shadow_motion[i];
723 motion = this->motion[i];
724 }
725
726 if (shadow == NULL) {
727 return;
728 }
729
730 if (index < 0) {
731 return;
732 }
733
734 if (motion->motion_info == NULL || shadow->motion_info == NULL) {
735 return;
736 }
737
738 speed = motion->motion_info[index].speed;
739
740 if ((this->motion_flags & 1) || MotionStopFlag) {
741 shadow->motion_info[index].speed = 0.0f;
742 }
743
744 if (this->motion_flags & 2) {
745 // The shadow stops on the last frame rather than running past it.
746 if (!(shadow->state.time + speed + 0.001f < (float) shadow->motion_info[index].end)) {
747 shadow->motion_info[index].speed = 0.0f;
748 }
749 }
750
751 if (this->shadow_frame == NULL) {
752 return;
753 }
754
755 // The shadow plays the motion of the model, at the frame the model stands on.
756 shadow->state.time = motion->state.time;
759 shadow->state.blend = motion->state.blend;
764 SetMotionEX(this->shadow_frame, shadow, shadow->motion_info, &shadow->state, shadow->frame_info);
765 shadow->motion_info[index].speed = speed;
766}
767
768void CCharacter::ClothStep(int step) {
769 sceVu0FVECTOR world_pos;
770 CFrame *root;
771 int i;
772
773 if (MotionStopFlag != 0) {
774 return;
775 }
776
777 sceVu0CopyVector(world_pos, this->pos);
778
779 if (this->frame != NULL) {
780 this->frame->SetPosition(this->pos[0], this->pos[1], this->pos[2]);
781 this->frame->SetRotation(this->rotation.x, this->rotation.y, this->rotation.z);
782 root = this->frame->parent;
783
784 if (root != NULL) {
785 this->pos[3] = 1.0f;
786 root->GetWorldPosition(world_pos, this->pos);
787 }
788 }
789
790 for (i = 0; i < CHARA_CLOTH_MAX; i++) {
791 if (this->cloth[i] != NULL) {
792 this->cloth[i]->wind = (void *) this->wind;
793 this->cloth[i]->floor_y = world_pos[1];
794 this->cloth[i]->Step(step);
795 }
796 }
797}
798
799void CCharacter::ClothFloor(int floor) {
800 int i;
801
802 for (i = 0; i < CHARA_CLOTH_MAX; i++) {
803 if (this->cloth[i] != NULL) {
804 this->cloth[i]->floor_on = floor;
805 }
806 }
807}
808
809void CCharacter::SetPosition(float x, float y, float z) {
810 CObject::SetPosition(x, y, z);
811
812 if (this->frame != NULL) {
813 this->frame->SetPosition(x, y, z);
814 }
815
816 if (this->shadow_frame != NULL) {
817 this->shadow_frame->SetPosition(x, y, z);
818 }
819}
820
821void CCharacter::GetWorldPosition(float *out_position) {
822 GetPosition(out_position);
823 out_position[3] = 1.0f;
824
825 if (this->frame->parent != NULL) {
826 this->frame->parent->GetWorldPosition(out_position, out_position);
827 }
828}
829
830void CCharacter::GetPosition(float *out_position) {
831 sceVu0CopyVector(out_position, this->pos);
832}
833
834void CCharacter::SetPosition(float *position) {
835 CCharacter::SetPosition(position[0], position[1], position[2]);
836}
837
839 CCharacter::SetPosition(position.x, position.y, position.z);
840}
841
842void CCharacter::SetRotation(float x, float y, float z) {
843 CObject::SetRotation(x, y, z);
844
845 if (this->frame != NULL) {
846 this->frame->SetRotation(x, y, z);
847 }
848
849 if (this->shadow_frame != NULL) {
850 this->shadow_frame->SetRotation(x, y, z);
851 }
852}
853
857
861
862void CCharacter::SetScale(float x, float y, float z) {
863 CObject::SetScale(x, y, z);
864
865 if (this->frame != NULL) {
866 this->frame->SetScale(x, y, z);
867 }
868
869 if (this->shadow_frame != NULL) {
870 this->shadow_frame->SetScale(x, y, z);
871 }
872}
873
876}
877
879 sceVu0FVECTOR ambient;
880 sceVu0FVECTOR saved_ambient;
881 float light_direction[4][4];
882 float light_colour[4][4];
883 float saved_light_colour[4][4];
884 float saved_light_direction[4][4];
885 sceVu0FVECTOR pos;
886 sceVu0FVECTOR direction;
887 int fading;
888 int light_slot;
889 int i;
890 int colour_no;
891 int cloth_no;
892 float distance;
893 float level;
894
895 if (this->frame != NULL) {
896 this->frame->SetPosition(this->pos[0], this->pos[1], this->pos[2]);
897 this->frame->SetRotation(this->rotation.x, this->rotation.y, this->rotation.z);
898 this->frame->SetScale(this->scale[0], this->scale[1], this->scale[2]);
899 }
900
901 fading = this->fade[0] < 1.0f;
902
903 // The scene keeps the lights it had, so that the character can put them
904 // back once it has drawn.
905 MGGetAmbient(ambient);
906 MGGetPLight(light_direction, light_colour);
907 sceVu0CopyMatrix(saved_light_colour, light_colour);
908 sceVu0CopyMatrix(saved_light_direction, light_direction);
909 sceVu0CopyVector(saved_ambient, ambient);
910
911 light_slot = 3;
912
913 for (i = 0; i < CHARA_POINT_LIGHT_MAX; i++) {
914 // Only a light_slot that the scene leaves free can take one of its own.
915 if (saved_light_direction[0][light_slot] != 0.0f) {
916 break;
917 }
918
919 if (saved_light_direction[1][light_slot] != 0.0f) {
920 break;
921 }
922
923 if (saved_light_direction[2][light_slot] != 0.0f) {
924 break;
925 }
926
927 if (this->point_light[i].used == 0) {
928 continue;
929 }
930
932 sceVu0SubVector(direction, this->point_light[i].pos, pos);
933 distance = DistVector(direction);
934
935 if (!(distance <= this->point_light[i].outer_range)) {
936 continue;
937 }
938
939 sceVu0Normalize(direction, direction);
940 light_direction[0][light_slot] = direction[0];
941 light_direction[1][light_slot] = direction[1];
942 light_direction[2][light_slot] = direction[2];
943
944 // The light_slot gives its whole colour up to the inner range and fades
945 // away over the rest.
946 level = 1.0f;
947
948 if (!(distance <= this->point_light[i].inner_range)) {
949 level = level - (distance - this->point_light[i].inner_range) / (this->point_light[i].outer_range - this->point_light[i].inner_range);
950 }
951
952 light_colour[light_slot][0] = this->point_light[i].colour[0] * level;
953 light_colour[light_slot][1] = this->point_light[i].colour[1] * level;
954 light_colour[light_slot][2] = this->point_light[i].colour[2] * level;
955 light_colour[light_slot][3] = this->point_light[i].colour[3];
956
957 light_slot--;
958
959 if (light_slot <= 2) {
960 break;
961 }
962 }
963
964 if (fading) {
965 sceVu0ScaleVectorXYZ(ambient, ambient, this->fade[0]);
966
967 for (colour_no = 0; colour_no < 4; colour_no++) {
968 sceVu0ScaleVectorXYZ(light_colour[colour_no], light_colour[colour_no], this->fade[0]);
969 }
970 }
971
972 ambient[0] += this->ambient_offset[0] + this->ambient_tint[0];
973 ambient[1] += this->ambient_offset[1] + this->ambient_tint[1];
974 ambient[2] += this->ambient_offset[2] + this->ambient_tint[2];
975
976 if (!(this->ambient_offset[3] < 0.0f)) {
977 ambient[3] = this->ambient_offset[3];
978 }
979
980 MGSetAmbient(ambient);
981 MGSetPLight(light_direction, light_colour);
982 MGDraw(this->frame);
983
984 for (cloth_no = 0; cloth_no < CHARA_CLOTH_MAX; cloth_no++) {
985 if (this->cloth[cloth_no] != NULL) {
986 this->cloth[cloth_no]->Draw();
987 }
988 }
989
990 MGSetAmbient(saved_ambient);
991 MGSetPLight(saved_light_direction, saved_light_colour);
992}
993
995 sceVu0FVECTOR transform;
996
997 if (this->shadow_frame == NULL) {
998 return;
999 }
1000
1001 sceVu0FVECTOR light_direction = {0.0f, 1.0f, 0.0f, 0.0f};
1002
1003 this->shadow_frame->SetScale(this->scale[0], this->scale[1], this->scale[2]);
1004 GetRotation(transform);
1005
1006 CFrame *shadow = this->shadow_frame;
1007 shadow->SetRotation(transform[0], transform[1], transform[2]);
1008 GetPosition(transform);
1009 this->shadow_frame->SetPosition(transform);
1010 // The shadow lies below the feet rather than inside the model.
1011 transform[1] -= 12.8f;
1012 MGDrawShadowFast(this->shadow_frame, transform, light_direction);
1013}
1014
1015void CCharacter::LoadPackData(unsigned int *pack, char *name, CDataAlloc2<1> *model_alloc, CDataAlloc2<1> *texture_alloc) {
1016 LoadPackData(pack, name, model_alloc, model_alloc, texture_alloc);
1017}
1018
1019void CCharacter::LoadPackData(unsigned int *pack, char *name, CDataAlloc2<1> *model_alloc, CDataAlloc2<1> *motion_alloc, CDataAlloc2<1> *texture_alloc) {
1020 ReadInfo(this, pack, name, model_alloc, motion_alloc, texture_alloc, 0, NULL, 0, 0);
1021}
1022
1023void CCharacter::LoadPackData2(unsigned int *pack, char *name, CDataAlloc2<1> *alloc, int texture_block_no, CDataAlloc2<1> *image_alloc, int visual_type) {
1024 ReadInfo(this, pack, name, alloc, alloc, alloc, texture_block_no, image_alloc, visual_type, 0);
1025}
1026
1027void CCharacter::LoadPackData3(unsigned int *pack, char *name, CDataAlloc2<1> *alloc, int texture_block_no, CDataAlloc2<1> *image_alloc, int keep_textures, int visual_type) {
1028 ReadInfo(this, pack, name, alloc, alloc, alloc, texture_block_no, image_alloc, visual_type, keep_textures);
1029}
1030
1032 LOADTEXTURE_INFO2 info[2];
1033
1034 if (this->config != NULL) {
1035 this->tex_anime.LoadCFGFile(this->config, this->config_size);
1036 }
1037
1038 // A block that the character loaded textures into goes back to what the
1039 // character alone asks for.
1040 if (this->images[1] != 0 || this->images[2] != 0 || this->images[3] != 0) {
1041 info[0].block_no = block_no;
1042 info[0].mipmap = false;
1043 info[0].name = (char *) this->images[0];
1044 info[1].block_no = 0;
1045 info[1].mipmap = false;
1046 info[1].name = NULL;
1047 TexManager.DeleteTextureBlock(block_no);
1048 TexManager.LoadTextureBlockEX(block_no, info);
1049 }
1050}
1051
1053 int i;
1054
1055 // The first set is the one the character was loaded with; the rest come
1056 // from packs that a caller added, and go with them.
1057 for (i = 1; i < CHARA_MOTION_MAX; i++) {
1058 this->motion[i] = NULL;
1059 this->shadow_motion[i] = NULL;
1060 this->motion_start[i] = -1;
1061 this->motion_end[i] = -1;
1062 }
1063}
1064
1066 CObject::Initialize(1.0f);
1067 this->frame = NULL;
1068 this->motion_no = 0;
1069 this->shadow_frame = NULL;
1070 this->motion_speed = -1.0f;
1071 this->frame_info = 0;
1072 this->shadow_frame_info = 0;
1073 this->motion_type.motion_info = NULL;
1074 this->unk_C6C = 0;
1075 this->motion_type.unk_78 = 0;
1076 this->motion_type.frame_info = NULL;
1077 this->motion_type.unk_6C = 0;
1078 this->motion_type.unk_68 = 0;
1079 this->motion_type.unk_70 = 0;
1080 this->motion_type.unk_74 = 0;
1081 this->shadow_motion_type = this->motion_type;
1082 this->shadow_motion_type.frame_info = NULL;
1083 this->motion_flags = 0;
1084
1085 this->cloth = this->cloth_buf;
1086
1087 for (int j = 0; j < CHARA_CLOTH_MAX; j++) {
1088 this->cloth[j] = NULL;
1089 }
1090
1091 this->wind = 0;
1092
1093 for (int i = 0; i < CHARA_MOTION_MAX; i++) {
1094 this->motion[i] = NULL;
1095 this->shadow_motion[i] = NULL;
1096 this->motion_start[i] = -1;
1097 this->motion_end[i] = -1;
1098 memset(this->motion_storage[i].storage, 0, sizeof(this->motion_storage[i].storage));
1099 memset(this->shadow_motion_storage[i].storage, 0, sizeof(this->shadow_motion_storage[i].storage));
1100 }
1101
1102 this->body_width = 7.0f;
1103 this->body_height = 17.0f;
1104 this->body_depth = 60.0f;
1105 this->fade_out = 0;
1106 this->fade[0] = 1.0f;
1107 this->fade[1] = 0.0f;
1108 this->fade[2] = 0.0f;
1109 this->fade[3] = 0.7f;
1110 this->ambient_offset[0] = 0.0f;
1111 this->ambient_offset[1] = 0.0f;
1112 this->ambient_offset[2] = 0.0f;
1113 this->ambient_offset[3] = -1.0f;
1114
1115 sceVu0FVECTOR zero = {0.0f, 0.0f, 0.0f, 0.0f};
1116
1117 for (int i = 0; i < 2; i++) {
1118 sceVu0CopyVector(this->ground_ambient[i], zero);
1119 }
1120
1121 sceVu0CopyVector(this->ambient_tint, zero);
1122
1123 // The first set of motions is the one the model was loaded with.
1124 this->motion[0] = &this->motion_type;
1125 this->shadow_motion[0] = &this->shadow_motion_type;
1126 this->motion_start[0] = 0;
1127 this->motion_end[0] = 256;
1128
1129 for (int j = 0; j < 16; j++) {
1130 this->unk_1068[j].unk_04 = -1.0f;
1131 this->unk_1068[j].unk_00 = -1;
1132 this->unk_1068[j].unk_0C = 0;
1133 }
1134
1135 for (int j = 0; j < CHARA_FOOT_SOUND_MAX; j++) {
1136 this->foot_sound[j].foot = -1;
1137 this->foot_sound[j].frame = -1;
1138 }
1139
1140 this->foot_sound_wait = 0;
1141 this->foot_sound_id = 0;
1142 this->foot_sound_enable = 1;
1143 ClearEvent(-1);
1144 this->event_enable = 1;
1145 this->motion_state = 0;
1146 this->config = NULL;
1148}
1149
1152}
1153
1156 this->unk_11B0 = 0;
1157 this->unk_11B4 = 0;
1158 this->unk_11B8 = 0;
1159 this->unk_11C0 = 0;
1160 this->unk_11C4 = 0;
1161 this->unk_11C8 = 0;
1162 this->unk_11CC = 0;
1163}
#define CHARA_EVENT_MAX
Definition character.hpp:43
#define CHARA_MOTION_MAX
Definition character.hpp:35
#define CHARA_CLOTH_MAX
Definition character.hpp:39
@ CHARA_EVENT_SOUND_EFFECT
Definition character.hpp:24
@ CHARA_EVENT_FOOT_SOUND
Definition character.hpp:23
#define CHARA_FOOT_SOUND_MAX
Definition character.hpp:41
#define CHARA_POINT_LIGHT_MAX
Definition character.hpp:37
CCloth ** cloth
void TexAnimeOn(int no)
virtual void GetWorldPosition(float *out_position)
CFrame * frame
virtual void GetPosition(float *out_position)
virtual void LoadPackData2(unsigned int *pack, char *name, CDataAlloc2< 1 > *alloc, int texture_block_no, CDataAlloc2< 1 > *image_alloc, int visual_type)
void ClearEvent(int motion_no)
MOTION_INFO * GetMotionInfo(int motion_no)
void ClearPointLight()
void DeleteExtendMotion()
virtual void LoadPackData(unsigned int *pack, char *name, CDataAlloc2< 1 > *model_alloc, CDataAlloc2< 1 > *texture_alloc)
void SetEvent(float frame, int kind, int no, int motion_no)
tagMOTION_TYPE * GetMotionParam(int motion_no, int *out_index, int *out_start, int *out_end, int *out_set)
virtual void SetScale(float x, float y, float z)
virtual void LoadPackData3(unsigned int *pack, char *name, CDataAlloc2< 1 > *alloc, int texture_block_no, CDataAlloc2< 1 > *image_alloc, int keep_textures, int visual_type)
CCloth * cloth_buf[8]
void InitializeTexAnime(CTexAnimeData *data, int count)
CFakePointLight point_light[CHARA_POINT_LIGHT_MAX]
void SetFootSoundID(int id)
void SetMotionCamera(CCamera *camera)
virtual void Step()
sceVu0FVECTOR ambient_offset
void EventEnable(int on)
tagMOTION_TYPE * shadow_motion[CHARA_MOTION_MAX]
sceVu0FVECTOR ground_ambient[2]
MotionParam shadow_motion_storage[CHARA_MOTION_MAX]
CHARA_FOOT_SOUND foot_sound[CHARA_FOOT_SOUND_MAX]
virtual void ShadowStep()
s32 foot_sound_id
tagMOTION_TYPE motion_type
float fade[4]
void ClearTexAnime()
s32 motion_end[CHARA_MOTION_MAX]
static s32 MotionStopFlag
CHARA_EVENT event[CHARA_EVENT_MAX]
tagMOTION_TYPE shadow_motion_type
virtual void SetRotation(float x, float y, float z)
void FootSoundEnable(int on)
void TextureAnime(int step)
char * config
virtual void ClothFloor(int floor)
void DeleteExtendTexture(int block_no)
virtual void DrawShadow()
s32 ground_ambient_no
virtual void Initialize()
CFrame * shadow_frame
void TexAnimeOff(int no)
MotionParam motion_storage[CHARA_MOTION_MAX]
u_int * images[4]
float body_height
s32 foot_sound_enable
tagFRAME_INF * shadow_frame_info
float body_depth
s32 foot_sound_wait
CTextureAnime tex_anime
int SetFootSound(float left_frame, float right_frame, int motion_no)
float motion_speed
float GetNowTime()
virtual void Draw()
sceVu0FVECTOR ambient_tint
s32 motion_start[CHARA_MOTION_MAX]
float body_width
virtual void SetPosition(float x, float y, float z)
int SetPointLight(float *pos, float inner_range, float outer_range, float red, float green, float blue, float alpha)
tagMOTION_TYPE * motion[CHARA_MOTION_MAX]
virtual void ClothStep(int step)
tagFRAME_INF * frame_info
int floor_on
Definition cloth.hpp:32
float floor_y
Definition cloth.hpp:33
void Draw()
Definition cloth.cpp:19
void Step(int step)
Definition cloth.cpp:144
void * wind
Definition cloth.hpp:34
CFrame * parent
Definition frame.hpp:66
virtual void Initialize()
virtual void Draw()
float scale[4]
Definition object.hpp:26
CVector3_f_ rotation
Definition object.hpp:23
void Initialize(float mass)
Definition object.cpp:184
virtual void SetScale(float x, float y, float z)
Definition object.cpp:162
virtual CVector3_f_ * GetRotation()
Definition object.cpp:150
virtual void SetPosition(CVector3_f_ position)
Definition object.cpp:38
virtual void SetRotation(CVector3_f_ rotation)
Definition object.cpp:66
float pos[4]
Definition object.hpp:18
void Initialize(CTexAnimeData *records, int count)
void Disable(int group)
void Enable(int group)
void TexAnime(int texture_block)
void LoadCFGFile(char *script, int script_size)
unsigned int next_frame
Definition gameutil.hpp:192
CCamera * camera
Definition gameutil.hpp:196
unsigned int frame
Definition gameutil.hpp:191
float blend_step
Definition gameutil.hpp:190
MOTION_INFO * motion_info
Definition gameutil.hpp:275
tagFRAME_INF * frame_info
Definition gameutil.hpp:274
MOTION_STATE state
Definition gameutil.hpp:273