Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
stars_shimmer.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
7void stars_shimmer_appendGfx(void* effect);
8
9extern Gfx D_09000F20_338EE0[];
10extern Gfx D_090011C8_339188[];
11extern Gfx D_090011E0_3391A0[];
12extern Gfx D_090011F8_3391B8[];
13extern Gfx D_09001210_3391D0[];
14extern Gfx D_09001228_3391E8[];
15extern Gfx D_09001240_339200[];
16extern Gfx D_09001258_339218[];
17extern Gfx D_09001270_339230[];
18
23
24u8 D_E0044DD0[] = {
25 254, 172, 172,
26 254, 172, 213,
27 254, 180, 154,
28 213, 180, 254,
29 180, 180, 254,
30 180, 221, 254,
31 180, 254, 254,
32 180, 254, 213,
33 180, 254, 180,
34 213, 254, 180,
35 254, 254, 180,
36 254, 213, 172,
37};
38
39u8 D_E0044DF4[] = {
40 30, 60, 90, 100, 104, 106, 108, 110, 112, 113, 113, 110, 107, 103, 0x00, 0x00
41};
42
43u8 D_E0044E04[] = {
44 30, 60, 90, 100, 104, 106, 108, 110, 112, 113, 113, 110, 107, 103, 0x00, 0x00
45};
46
47void stars_shimmer_main(s32 type, f32 x, f32 y, f32 z, f32 arg4, f32 arg5, s32 numParts, s32 arg7) {
49 EffectBlueprint* bpPtr = &bp;
50 EffectInstance* effect;
52 f32 cosTheta;
53 f32 sinTheta;
54 f32 temp_f22;
55 f32 temp_f8;
56 f32 temp_ft;
57 f32 theta;
58 f32 temp5;
59 f32 t3;
60 f32 new_var;
61 s32 i;
62
63 numParts++;
64
65 bpPtr->init = stars_shimmer_init;
68 bpPtr->unk_00 = 0;
69 bpPtr->renderUI = NULL;
70 bpPtr->effectID = EFFECT_STARS_SHIMMER;
71
72 effect = create_effect_instance(bpPtr);
73 effect->numParts = numParts;
74 part = effect->data.starsShimmer = general_heap_malloc(numParts * sizeof(*part));
75 ASSERT(effect->data.starsShimmer != NULL);
76
77 if (type == 6) {
78 part->unk_00 = 1;
79 type = 3;
80 } else {
81 part->unk_00 = 0;
82 }
83 part->pos.x = x;
84 part->pos.y = y;
85 part->pos.z = z;
86 part->lifeTime = 0;
87 part->state = type;
88 part->timeLeft = arg7;
89
90 part++;
91 for (i = 1; i < numParts; i++, part++) {
92 temp_f22 = (360.0f / (numParts - 1)) * i;
93 if (type > 1) {
94 theta = temp_f22 + rand_int(359);
95 } else {
96 theta = temp_f22 + 0.0f;
97 }
98 t3 = (temp_f22 * 10.0f) - 90.0f;
99 sinTheta = sin_deg(theta);
100 cosTheta = cos_deg(theta);
101 temp_f22 = sin_deg(t3);
102 temp_f8 = (arg4 * 0.4) - (arg4 * 0.1 * temp_f22);
103 temp_ft = (arg5 * 0.4) - (arg5 * 0.1 * temp_f22);
104 new_var = 1.0f; // TODO dumb temp and cast later required to match
105 temp5 = (arg5 / (numParts - 1)) * (i - 1);
106
107 part->unk_1C = (u8) new_var;
108 part->lifeTime = 0;
109 part->timeLeft = i + 30;
110
111 switch (type) {
112 case 0:
113 case 1:
114 part->unk_18 = 0;
115 part->pos.z = 0.0f;
116 part->unk_10 = sinTheta * temp_f8;
117 part->unk_14 = cosTheta * temp_ft;
118 break;
119 case 3:
120 part->pos.x = (sinTheta * arg4 * rand_int(100)) * 0.005;
121 part->pos.y = (cosTheta * arg5 * rand_int(100)) * 0.005;
122 part->pos.z = 0.0f;
123
124 part->unk_18 = part->unk_10 = part->unk_14 = 0.0f;
125
126 part->timeLeft += i * 2;
127 break;
128 case 2:
129 case 4:
130 case 5:
131 default:
132 part->unk_10 = sinTheta * temp_f8;
133 part->pos.y = temp5;
134 part->pos.z = cosTheta * temp_f8;
135 part->unk_14 = -rand_int(10) * 0.03f;
136 part->unk_18 = (rand_int(10) * 0.04f) + 0.01;
137 break;
138 }
139 }
140}
141
144
146 StarsShimmerFXData* data = effect->data.starsShimmer;
147 StarsShimmerFXData* it = data;
148 s32 deadParts = 0;
149 s32 state = it->state;
150 s32 lifeTime;
151 s32 i;
152
153 it->timeLeft--;
154 it->lifeTime++;
155 lifeTime = it->lifeTime;
156 if (state == 0 || state == 1 || state == 3 || state >= 10) {
157 if (it->timeLeft < 0) {
158 remove_effect(effect);
159 return;
160 }
161 }
162
163 it++;
164 for (i = 0; i < effect->numParts - 1; i++, it++) {
165 switch (state) {
166 case 0:
167 case 1:
168 it->unk_28 = (lifeTime + i) & 7;
169 it->unk_18 += -0.02;
170 if (lifeTime - 1 < 14) {
171 f32 temp_f0 = (f32) D_E0044DF4[lifeTime - 1] * 0.01;
172
173 it->pos.x = it->unk_10 * temp_f0;
174 it->pos.y = (it->unk_14 * temp_f0) + it->unk_18;
175 it->unk_1C = (f32) D_E0044E04[lifeTime - 1] * 0.01;
176 } else {
177 f32 var_f20 = ((360.0f / (effect->numParts - 1)) * i) + 60.0f;
178
179 if (i % 2 != 0) {
180 var_f20 -= 120.0f;
181 }
182 data->state = 10;
183 it->unk_10 = sin_deg(var_f20);
184 it->unk_14 = cos_deg(var_f20);
185 it->unk_18 = -0.05f;
186 }
187 break;
188 case 10:
189 case 30:
190 it->unk_28 = (lifeTime + i) & 7;
191 it->unk_10 *= 0.96;
192 it->unk_14 *= 0.96;
193 it->unk_14 += it->unk_18;
194 it->unk_1C += (0.1 - it->unk_1C) * 0.1;
195 it->pos.x += it->unk_10;
196 it->pos.y += it->unk_14;
197 break;
198 case 3:
199 it->unk_28 = (lifeTime + i + i) & 7;
200 if (lifeTime - 1 < 14) {
201 it->unk_1C = (f32) D_E0044E04[lifeTime - 1] * 0.01;
202 break;
203 }
204 data->state = 30;
205 break;
206 case 2:
207 case 4:
208 case 5:
209 case 6:
210 case 7:
211 case 8:
212 case 9:
213 case 11:
214 case 12:
215 case 13:
216 case 14:
217 case 15:
218 case 16:
219 case 17:
220 case 18:
221 case 19:
222 case 20:
223 case 21:
224 case 22:
225 case 23:
226 case 24:
227 case 25:
228 case 26:
229 case 27:
230 case 28:
231 case 29:
232 default:
233 it->unk_28 = (lifeTime + i + i) & 7;
234 if (it->timeLeft < 0) {
235 deadParts++;
236 }
237 it->timeLeft--;
238 if ((u32) it->timeLeft > 30) {
239 it->unk_28 = -1;
240 } else {
241 it->lifeTime++;
242 lifeTime = it->lifeTime;
243 if (lifeTime - 1 < 14) {
244 it->unk_1C = (f32) D_E0044E04[lifeTime - 1] * 0.01;
245 if (state == 5) {
246 it->unk_14 += it->unk_18;
247 it->pos.y += it->unk_14;
248 }
249 } else {
250 it->unk_14 += it->unk_18;
251 it->pos.y += it->unk_14;
252 it->unk_1C += (0.1 - it->unk_1C) * 0.1;
253 }
254 if (state == 4) {
255 it->pos.x = (it->unk_10 * sin_deg(lifeTime * 12));
256 it->pos.z = (it->unk_10 * cos_deg(lifeTime * 12));
257 } else {
258 it->pos.x = it->unk_10;
259 }
260 it->unk_14 *= 0.96;
261 }
262 }
263 }
264
265 if (state != 0 && state != 1 && state != 3 && state < 10 && deadParts >= effect->numParts - 1) {
266 remove_effect(effect);
267 }
268}
269
271 RenderTask renderTask;
272 RenderTask* retTask;
273
275 renderTask.appendGfxArg = effect;
276 renderTask.dist = 0;
278
279 retTask = queue_render_task(&renderTask);
280}
281
282void stars_shimmer_appendGfx(void* effect) {
283 Matrix4f sp18, sp58, sp98;
284 StarsShimmerFXData* data = ((EffectInstance*)effect)->data.starsShimmer;
285 s32 state;
286 s32 temp_s4;
287 s32 unk_28;
288 f32 rf, gf, bf;
289 s32 r, g, b;
290 s32 i;
291
292 state = data->state;
293
294 gDPPipeSync(gMainGfxPos++);
295 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
296 gSPDisplayList(gMainGfxPos++, D_09000F20_338EE0);
297
298 temp_s4 = (data->lifeTime - 1) * 3;
299 guTranslateF(sp18, data->pos.x, data->pos.y, data->pos.z);
300 guRotateF(sp58, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
301 guMtxCatF(sp58, sp18, sp98);
302
303 switch (state) {
304 case 0:
305 case 1:
306 case 2:
307 case 10:
308 rf = 1.0f;
309 gf = 0.5f;
310 bf = 0.1f;
311 break;
312 case 3:
313 case 30:
314 rf = 1.0f;
315 gf = 0.8f;
316 bf = 0.7f;
317 if (data->unk_00 != 0) {
318 gDPSetRenderMode(gMainGfxPos++, G_RM_ZB_CLD_SURF, G_RM_ZB_CLD_SURF2);
319 }
320 break;
321 case 5:
322 rf = 1.4f;
323 gf = 1.4f;
324 bf = 0.7f;
325 break;
326 default:
327 rf = 1.4f;
328 gf = 0.7f;
329 bf = 0.7f;
330 break;
331 }
332
333 data++;
334 for (i = 0; i < ((EffectInstance*)effect)->numParts - 1; i++, data++) {
335 unk_28 = data->unk_28;
336 if (unk_28 >= 0) {
337 guTranslateF(sp58, data->pos.x, data->pos.y, data->pos.z);
338 sp58[0][0] = sp58[1][1] = sp58[2][2] = data->unk_1C;
339 guMtxCatF(sp58, sp98, sp18);
341 if (temp_s4 >= 36) {
342 temp_s4 = 0;
343 }
344 r = D_E0044DD0[temp_s4++] * rf;
345 g = D_E0044DD0[temp_s4++] * gf;
346 b = D_E0044DD0[temp_s4++] * bf;
347 if (r > 255) {
348 r = 255;
349 }
350 if (g > 255) {
351 g = 255;
352 }
353 if (b > 255) {
354 b = 255;
355 }
356 gDPSetPrimColor(gMainGfxPos++, 0, 0, r, g, b, 255);
358 G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
359 gSPDisplayList(gMainGfxPos++, D_E0044DB0[unk_28 & 7]);
360 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
361 }
362 }
363 gDPPipeSync(gMainGfxPos++);
364}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define general_heap_malloc
#define guRotateF
#define queue_render_task
#define guMtxF2L
#define sin_deg
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define rand_int
#define cos_deg
#define create_effect_instance
struct StarsShimmerFXData * starsShimmer
Definition effects.h:2498
EffectData data
Definition effects.h:2605
#define ASSERT(condition)
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
Gfx D_090011E0_3391A0[]
Gfx D_09001228_3391E8[]
void stars_shimmer_main(s32 type, f32 x, f32 y, f32 z, f32 arg4, f32 arg5, s32 numParts, s32 arg7)
Gfx D_09000F20_338EE0[]
void stars_shimmer_render(EffectInstance *effect)
Gfx D_090011C8_339188[]
Gfx * D_E0044DB0[]
u8 D_E0044DF4[]
u8 D_E0044E04[]
void stars_shimmer_update(EffectInstance *effect)
void stars_shimmer_init(EffectInstance *effect)
Gfx D_09001210_3391D0[]
u8 D_E0044DD0[]
Gfx D_090011F8_3391B8[]
void stars_shimmer_appendGfx(void *effect)
Gfx D_09001258_339218[]
Gfx D_09001270_339230[]
Gfx D_09001240_339200[]
void(* renderUI)(EffectInstance *effectInst)
Definition effects.h:2655
void(* init)(EffectInstance *effectInst)
Definition effects.h:2652
void(* update)(EffectInstance *effectInst)
Definition effects.h:2653
void(* renderWorld)(EffectInstance *effectInst)
Definition effects.h:2654
void * appendGfxArg
void(* appendGfx)(void *)
Camera gCameras[4]
Definition cam_main.c:17
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
s32 gCurrentCameraID
Definition cam_math.c:4
DisplayContext * gDisplayContext
Definition cam_main.c:16