DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
hitmark.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 1430
4
5#include "hitmark.hpp"
6
7#include <libvu0.h>
8
9#include <cstdlib>
10
11#include "mglib.hpp"
12#include "rect.hpp"
13#include "snd.hpp"
14#include "texture.hpp"
15
16void CHitMark::Set(float *position, float *direction, int kind, float spread, float shrink, float gravity, float speed, int count, float floor_y) {
17 int i;
18
19 SetPosition(position);
20 this->kind = kind;
21 this->spread = spread;
22 this->shrink = shrink;
23 this->gravity = gravity;
24 this->speed = speed;
25 this->floor_y = floor_y;
26
27 // The burst leaves along one direction, at the speed the caller asks for.
28 sceVu0Normalize(direction, direction);
29 direction[0] *= this->speed;
30 direction[1] *= this->speed;
31 direction[2] *= this->speed;
32
33 for (i = 0; i < count; i++) {
34 // Every mark starts a little away from the point of the hit, and
35 // leaves in a direction that is scattered about the one it was given.
36 this->offset[i][0] = rand() / 2147483648.0f - 0.5f;
37 this->offset[i][1] = rand() / 2147483648.0f - 0.5f;
38 this->offset[i][2] = rand() / 2147483648.0f - 0.5f;
39 this->offset[i][3] = 1.0f;
40 this->velocity[i][0] = direction[0] + this->spread * rand() / 2147483648.0f - this->spread / 2.0f;
41 this->velocity[i][1] = direction[0] + this->spread * rand() / 2147483648.0f - this->spread / 2.0f;
42 this->velocity[i][2] = direction[0] + this->spread * rand() / 2147483648.0f - this->spread / 2.0f;
43 this->size[i] = 0.1f + 1.2f * rand() / 2147483648.0f;
44 this->used[i] = 1;
45 }
46
47 this->count = HIT_MARK_MAX;
48}
49
51 int top_left[4];
52 int top_right[4];
53 int bottom_left[4];
54 int bottom_right[4];
55 sceVu0FVECTOR base;
56 sceVu0FVECTOR mark_pos;
57 CTexture *texture;
58 int i;
59
60 if (this->count == 0) {
61 return;
62 }
63
64 sceVu0CopyVector(base, this->pos);
65 texture = TexManager.GetTexture("basefx00", -1);
66
67 for (i = 0; i < this->count; i++) {
68 if (this->used[i] == 0) {
69 continue;
70 }
71
72 mark_pos[0] = base[0] + this->offset[i][0];
73 mark_pos[1] = base[1] + this->offset[i][1];
74 mark_pos[2] = base[2] + this->offset[i][2];
75 mark_pos[3] = 1.0f;
76
77 if (MGRotTransPers3DSprite(top_left, bottom_right, mark_pos, this->size[i], this->size[i] / 2.0f, 0) != 1) {
78 continue;
79 }
80
81 // The two corners that the sprite call gives back are opposite, so the
82 // other two take one part from each.
83 top_right[0] = bottom_right[0];
84 top_right[1] = top_left[1];
85 top_right[2] = top_left[2];
86 bottom_left[0] = top_left[0];
87 bottom_left[1] = bottom_right[1];
88 bottom_left[2] = bottom_right[2];
89
90 switch (this->kind) {
91 case HIT_MARK_HIT: {
92 CRect_i_ rect;
93 rect.x = 0x00;
94 rect.y = 0x00;
95 rect.width = 0x10;
96 rect.height = 0x10;
97 set3DSprite(Vif1Packet, texture, rect, top_left, top_right, bottom_left, bottom_right, 0x80);
98 break;
99 }
100 case HIT_MARK_UNK_1: {
101 CRect_i_ rect;
102 rect.x = 0x30;
103 rect.y = 0x10;
104 rect.width = 0x10;
105 rect.height = 0x10;
106 set3DSprite(Vif1Packet, texture, rect, top_left, top_right, bottom_left, bottom_right, 0x80);
107 break;
108 }
109 case HIT_MARK_GUARD: {
110 CRect_i_ rect;
111 rect.x = 0x40;
112 rect.y = 0x00;
113 rect.width = 0x10;
114 rect.height = 0x10;
115 set3DSprite(Vif1Packet, texture, rect, top_left, top_right, bottom_left, bottom_right, 0x80);
116 break;
117 }
118 case HIT_MARK_UNK_3: {
119 CRect_i_ rect;
120 rect.x = 0x10;
121 rect.y = 0x00;
122 rect.width = 0x20;
123 rect.height = 0x20;
124 set3DSprite(Vif1Packet, texture, rect, top_left, top_right, bottom_left, bottom_right, 0x40);
125 break;
126 }
127 case HIT_MARK_UNK_4: {
128 CRect_i_ rect;
129 rect.x = 0x68;
130 rect.y = 0x20;
131 rect.width = 0x18;
132 rect.height = 0x18;
133 set3DSprite(Vif1Packet, texture, rect, top_left, top_right, bottom_left, bottom_right, 0x80);
134 break;
135 }
136 }
137 }
138}
139
141 sceVu0FVECTOR base;
142 int i;
143
144 sceVu0CopyVector(base, this->pos);
145
146 if (this->count == 0) {
147 return;
148 }
149
150 for (i = 0; i < this->count; i++) {
151 if (this->used[i] == 0) {
152 continue;
153 }
154
155 this->offset[i][0] += this->velocity[i][0];
156 this->offset[i][1] += this->velocity[i][1];
157 this->offset[i][2] += this->velocity[i][2];
158 this->velocity[i][1] -= this->gravity;
159
160 // A mark that reaches the floor bounces off it, and loses most of the
161 // speed it fell with.
162 if (base[1] + this->offset[i][1] <= this->floor_y) {
163 this->velocity[i][1] *= -0.7f;
164 }
165
166 this->size[i] -= this->shrink;
167
168 if (this->size[i] <= 0.1f) {
169 this->used[i] = 0;
170 this->count--;
171 }
172 }
173
174 this->spread -= 0.05f;
175}
176
178 int i;
179
180 for (i = 0; i < HIT_MARK_MAX; i++) {
181 this->used[i] = 0;
182 }
183
184 this->capacity = HIT_MARK_MAX;
185 this->count = 0;
186}
187
189 int top_left[4];
190 int top_right[4];
191 int bottom_left[4];
192 int bottom_right[4];
193 CRect_i_ rect;
194
195 if (this->on == 0) {
196 return;
197 }
198
199 if (MGRotTransPers3DSprite(top_left, bottom_right, this->pos, 5.0f, 2.5f, 0) != 1) {
200 return;
201 }
202
203 if (this->blink != 1) {
204 return;
205 }
206
207 top_right[0] = bottom_right[0];
208 top_right[1] = top_left[1];
209 top_right[2] = top_left[2];
210 bottom_left[0] = top_left[0];
211 bottom_left[1] = bottom_right[1];
212 bottom_left[2] = bottom_right[2];
213
214 rect.x = 0x00;
215 rect.y = 0x20;
216 rect.width = 0x30;
217 rect.height = 0x30;
218 set3DSprite(Vif1Packet, TexManager.GetTexture("basefx00", -1), rect, top_left, top_right, bottom_left, bottom_right, 0x80);
219}
220
222 if (this->on == 0) {
223 return;
224 }
225
226 // The mark shows for four steps and hides for four, so that it blinks.
227 if (this->timer % 4 == 0) {
228 this->blink ^= 1;
229 }
230
231 if (this->timer == 0) {
232 this->on = 0;
233 return;
234 }
235
236 this->timer--;
237}
238
239// The debug overlay's line formats, which DebugInfoMsg points at.
240char DebugInfoMsgMiniMapView[] __attribute__((section(".rodata"))) = "MINI MAP VIEW = %s\n";
241char DebugInfoMsgCollision[] __attribute__((section(".rodata"))) = "COLLISION = %s\n";
242char DebugInfoMsgBgmPlay[] __attribute__((section(".rodata"))) = "BGM PLAY = %s\n";
243char DebugInfoMsgParameter[] __attribute__((section(".rodata"))) = "PARAMETER = %s\n";
244char DebugInfoMsgViewInfo[] __attribute__((section(".rodata"))) = "VIEW INFO = %s\n";
245char DebugInfoMsgUltraMan[] __attribute__((section(".rodata"))) = "UlutraMan = %s\n";
246char DebugInfoMsgReloadEnemy[] __attribute__((section(".rodata"))) = "ReLoadEnemy ID = %d /NUM = %d\n";
247char DebugInfoMsgItemPutZone[] __attribute__((section(".rodata"))) = "Item Put Zone = %s\n";
248char DebugInfoMsgLightMode[] __attribute__((section(".rodata"))) = "Light Mode = %s\n";
249char DebugInfoMsgFloorAtraGet[] __attribute__((section(".rodata"))) = "FLOOR ATRA GET! \n";
250char DebugInfoMsgEventTest[] __attribute__((section(".rodata"))) = "EVENT TEST = %d\n";
251char DebugInfoMsgSetStatus[] __attribute__((section(".rodata"))) = "SET STATUS = %s\n";
252char DebugInfoMsgSePlay[] __attribute__((section(".rodata"))) = "SE PLAY = %d\n";
253char DebugInfoMsgSetChrKey[] __attribute__((section(".rodata"))) = "SET CHRKEY = %d\n";
void Draw()
Definition hitmark.cpp:50
sceVu0FVECTOR velocity[HIT_MARK_MAX]
Definition hitmark.hpp:38
float size[HIT_MARK_MAX]
Definition hitmark.hpp:39
void Initialize()
Definition hitmark.cpp:177
float spread
Definition hitmark.hpp:42
virtual void Step()
Definition hitmark.cpp:140
float gravity
Definition hitmark.hpp:43
s32 count
Definition hitmark.hpp:47
s32 used[HIT_MARK_MAX]
Definition hitmark.hpp:46
sceVu0FVECTOR offset[HIT_MARK_MAX]
Definition hitmark.hpp:37
float shrink
Definition hitmark.hpp:41
float speed
Definition hitmark.hpp:44
s32 kind
Definition hitmark.hpp:48
float floor_y
Definition hitmark.hpp:49
s32 capacity
Definition hitmark.hpp:45
void Set(float *position, float *direction, int kind, float spread, float shrink, float gravity, float speed, int count, float floor_y)
Definition hitmark.cpp:16
float pos[4]
Definition hitmark.hpp:95
virtual void SetPosition(CVector3_f_ position)
Definition object.cpp:38
float pos[4]
Definition object.hpp:18
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
#define HIT_MARK_MAX
Definition hitmark.hpp:29
@ HIT_MARK_GUARD
Definition hitmark.hpp:21
@ HIT_MARK_UNK_1
Definition hitmark.hpp:20
@ HIT_MARK_UNK_3
Definition hitmark.hpp:22
@ HIT_MARK_HIT
Definition hitmark.hpp:19
@ HIT_MARK_UNK_4
Definition hitmark.hpp:23