Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
light_rays.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Gfx D_090000B0_36E040[];
5extern Gfx D_09000110_36E0A0[];
6extern Gfx D_09000130_36E0C0[];
7extern Gfx D_090001D8_36E168[];
8
12
16
17s32 D_E006AE10[] = {
18 0, -20, 0, 1, 18,
19 -10, -60, 45, -1, 4,
20 -20, -20, 90, 1, 1,
21 -10, -60, 135, 1, -4,
22 0, -20, 180, -8, 1,
23 -10, -60, 225, -1, -1,
24 -20, -20, 270, 1, -9,
25 -10, -60, 315, 4, 4,
26 0, 10, 22, 4, 1,
27 -10, 20, 67, 1, -1,
28 -20, 10, 112, -1, -1,
29 -10, 20, 157, -8, 1,
30 0, 10, 202, 1, -4,
31 -10, 20, 247, 1, -18,
32 -20, 10, 292, -1, 9,
33 -10, 20, 337, 1, 1
34};
35
39void light_rays_appendGfx(void* effect);
40
41void func_E006A000(LightRaysFXData* part, s32 beamIdx) {
42 s32 temp = beamIdx * 3;
43
44 part->initialRot.x = effect_simple_rand(180, temp);
45 part->initialRot.y = effect_simple_rand(180, temp + 1);
46 part->initialRot.z = effect_simple_rand(180, temp + 2);
47 part->alpha = 0;
48 part->lifetime = 0;
49 part->unk_58 = part->unk_68;
50 part->timeLeft = part->unk_7C;
51 part->unk_8C = part->unk_6C;
52 part->rot.x = part->initialRot.x;
53 part->rot.y = part->initialRot.y;
54 part->rot.z = part->initialRot.z;
55}
56
57void func_E006A0BC(LightRaysFXData* part, s32 beamIdx) {
58 s32 idx = (beamIdx - 1) * 5;
59
60 part->unk_58 = 0;
61 part->timeLeft = beamIdx * 2 + 30;
62 part->rot.x = D_E006AE10[idx++];
63 part->rot.y = D_E006AE10[idx++];
64 part->rot.z = D_E006AE10[idx++];
65 part->alpha = 0;
66 part->lifetime = 0;
67 part->unk_34 = part->unk_38 = 0.0f;
68 part->unk_48 = 0.0f;
69 part->unk_4C = -0.6f;
70 part->unk_3C = 10.0f;
71 part->unk_40 = 0.0f;
72 part->unk_50 = 0.0f;
73 part->unk_54 = 0.6f;
74 part->unk_80 = 0.0f;
75 part->unk_84 = (f32) D_E006AE10[idx++] * 0.0;
76 part->unk_88 = (f32) D_E006AE10[idx++] * 0.1;
77 part->unk_90 = 0;
78}
79
81 s32 type,
82 f32 posX,
83 f32 posY,
84 f32 posZ,
85 f32 scale,
86 EffectInstance** outEffect
87) {
89 EffectBlueprint* bpPtr = &bp;
90 EffectInstance* effect;
91 LightRaysFXData* part;
92 s32 numParts;
93 s32 temp2;
94 s32 temp1;
95 s32 i;
96
97 if (type < 2) {
98 numParts = 9;
99 } else {
100 numParts = 17;
101 }
102
103 bpPtr->init = light_rays_init;
104 bpPtr->update = light_rays_update;
106 bpPtr->unk_00 = 0;
107 bpPtr->renderUI = NULL;
108 bpPtr->effectID = EFFECT_LIGHT_RAYS;
109
110 effect = create_effect_instance(bpPtr);
111 effect->numParts = numParts;
112 part = effect->data.lightRays = general_heap_malloc(numParts * sizeof(*part));
113 ASSERT(effect->data.lightRays != NULL);
114
115 part->type = type;
116 part->timeLeft = 100;
117 part->lifetime = 0;
118 part->pos.x = posX;
119 part->pos.y = posY;
120 part->pos.z = posZ;
121 part->unk_1C = part->unk_20 = scale;
122
123 switch (type) {
124 case 0:
125 case 1:
126 part++;
127 for (i = 1; i < effect->numParts; i++, part++) {
128 temp1 = (i - 1) * 30 / (numParts - 1);
129 temp2 = (i - 1) * 20 / (numParts - 1);
130
131 part->unk_68 = temp1 - 10;
132 part->unk_7C = 50 - temp2;
133 part->unk_6C = 25.0f / part->unk_7C + 2.5;
134
135 func_E006A000(part, i);
136 }
137 break;
138 default:
139 part++;
140 for (i = 1; i < effect->numParts; i++, part++) {
141 func_E006A0BC(part, i);
142 }
143 }
144
145 *outEffect = effect;
146}
147
149}
150
152 part->unk_34 += part->unk_48;
153 if (part->unk_34 > 256.0f) {
154 part->unk_34 -= 256.0f;
155 }
156 if (part->unk_34 < 0.0f) {
157 part->unk_34 += 256.0f;
158 }
159
160 part->unk_3C += part->unk_50;
161 if (part->unk_3C > 256.0f) {
162 part->unk_3C -= 256.0f;
163 }
164 if (part->unk_3C < 0.0f) {
165 part->unk_3C += 256.0f;
166 }
167
168 part->unk_38 += part->unk_4C;
169 if (part->unk_38 > 256.0f) {
170 part->unk_38 -= 256.0f;
171 }
172 if (part->unk_38 < 0.0f) {
173 part->unk_38 += 256.0f;
174 }
175
176 part->unk_40 += part->unk_54;
177 if (part->unk_40 > 256.0f) {
178 part->unk_40 -= 256.0f;
179 }
180 if (part->unk_40 < 0.0f) {
181 part->unk_40 += 256.0f;
182 }
183}
184
186 LightRaysFXData* part = effect->data.lightRays;
187 s32 type = part->type;
188 s32 timeLeft;
189 s32 lifetime;
190 s32 i;
191
192 if (part->timeLeft < 11) {
193 part->timeLeft--;
194 }
195
196 part->lifetime++;
197
198 if (effect->flags & FX_INSTANCE_FLAG_DISMISS) {
199 effect->flags &= ~FX_INSTANCE_FLAG_DISMISS;
200 part->timeLeft = 10;
201 }
202
203 if (part->timeLeft < 0) {
204 remove_effect(effect);
205 return;
206 }
207
208 timeLeft = part->timeLeft;
209 lifetime = part->lifetime;
210
211 switch (type) {
212 case 0:
213 case 1:
214 part++;
215 for (i = 1; i < effect->numParts; i++, part++) {
216 part->timeLeft--;
217 part->lifetime++;
218 if (part->lifetime < 10) {
219 part->alpha = part->lifetime * 12;
220 }
221 if (part->timeLeft < 5) {
222 part->alpha = part->timeLeft * 25;
223 }
224 part->unk_58 += part->unk_8C;
225 if (part->timeLeft <= 0) {
226 func_E006A000(part, lifetime * 10 + 1);
227 }
228 }
229 break;
230 default:
231 part++;
232 for (i = 1; i < effect->numParts; i++, part++) {
233 func_E006A464(part);
234 part->timeLeft--;
235 part->lifetime++;
236 if (part->lifetime < 5) {
237 part->alpha = part->lifetime * 50;
238 }
239 if (part->timeLeft < 5) {
240 part->alpha = part->timeLeft * 50;
241 }
242 if (timeLeft < 10) {
243 part->alpha = (part->alpha * timeLeft) / 10;
244 }
245 if (part->timeLeft <= 0) {
246 func_E006A0BC(part, i);
247 }
248 if (part->unk_90 <= 0 || --part->unk_90 <= 0) {
249 part->rot.x += part->unk_80;
250 part->rot.y += part->unk_84;
251 part->rot.z += part->unk_88;
252 }
253 }
254 }
255}
256
258 RenderTask renderTask;
259 RenderTask* retTask;
260
261 renderTask.appendGfx = light_rays_appendGfx;
262 renderTask.appendGfxArg = effect;
263 renderTask.dist = 10;
265
266 retTask = queue_render_task(&renderTask);
268}
269
271 s32 uls = part->unk_34 * 4.0f;
272 s32 ult = part->unk_38 * 4.0f;
273 s32 uls2 = part->unk_3C * 4.0f;
274 s32 ult2 = part->unk_40 * 4.0f;
275
276 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE, uls, ult, uls + 512, ult + 256);
277 gDPSetTileSize(gMainGfxPos++, 1, uls2, ult2, uls2 + 512, ult2 + 256);
278}
279
280void light_rays_appendGfx(void* effect) {
281 LightRaysFXData* part = ((EffectInstance*)effect)->data.lightRays;
282 s32 type = part->type;
283 Gfx* dlist = D_E006ADF0[type];
284 Gfx* dlist2 = D_E006AE00[type];
285 Matrix4f mtxTransform;
286 Matrix4f mtxTemp;
287 Matrix4f mtxTranslate;
288 s32 i;
289
290 gDPPipeSync(gMainGfxPos++);
291 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
292 gSPDisplayList(gMainGfxPos++, dlist2);
293
294 guTranslateF(mtxTranslate, part->pos.x, part->pos.y, part->pos.z);
295
296 part++;
297 for (i = 1; i < ((EffectInstance*)effect)->numParts; i++, part++) {
298 f32 temp = part->alpha / 255.0f;
299 f32 angleZ;
300 f32 scaleX;
301 f32 scaleY;
302 f32 scaleZ;
303 f32 unk_64;
304
305 if (type >= 2) {
306 func_E006A85C(part);
307 }
308
309 guRotateF(mtxTemp, part->rot.x, 1.0f, 0.0f, 0.0f);
310 guMtxCatF(mtxTemp, mtxTranslate, mtxTransform);
311
312 if (type >= 2) {
313 unk_64 = part->rot.z;
314 if (type == 3) {
315 angleZ = unk_64 + 45.0f;
316 } else {
317 angleZ = unk_64 + 0.0f;
318 }
319
320 guRotateF(mtxTemp, angleZ, 0.0f, 0.0f, 1.0f);
321 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
322 guRotateF(mtxTemp, part->rot.y, 0.0f, 1.0f, 0.0f);
323 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
324 guTranslateF(mtxTemp, part->unk_58, 0.0f, 0.0f);
325 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
326
327 scaleX = scaleZ = (temp + 3.0f) * 0.25;
328 switch (i & 3) {
329 case 0:
330 scaleY = temp * 0.3;
331 break;
332 case 1:
333 scaleY = temp * 0.5;
334 break;
335 case 2:
336 scaleY = temp * 0.9;
337 break;
338 case 3:
339 default:
340 scaleY = temp;
341 break;
342 }
343
344 guScaleF(mtxTemp, scaleX, scaleY, scaleZ);
345 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
346
347 gDPSetPrimColor(gMainGfxPos++, 0, 0, 255, 255, 240, part->alpha);
348 } else {
349 guRotateF(mtxTemp, part->rot.y, 0.0f, 1.0f, 0.0f);
350 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
351 guRotateF(mtxTemp, part->rot.z, 0.0f, 0.0f, 1.0f);
352 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
353 guTranslateF(mtxTemp, part->unk_58, 0.0f, 0.0f);
354 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
355
356 gDPSetPrimColor(gMainGfxPos++, 0, 0, 255, 255, 181, part->alpha);
357 }
358
360
361 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
362 gSPDisplayList(gMainGfxPos++, dlist);
363 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
364 }
365
366 gDPPipeSync(gMainGfxPos++);
367}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define general_heap_malloc
#define guRotateF
#define queue_render_task
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define create_effect_instance
#define guScaleF
struct LightRaysFXData * lightRays
Definition effects.h:2517
Vec3f initialRot
Definition effects.h:843
EffectData data
Definition effects.h:2605
s32 effect_simple_rand(s32, s32)
#define ASSERT(condition)
@ FX_INSTANCE_FLAG_DISMISS
Definition enums.h:3517
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
Gfx D_090000B0_36E040[]
void light_rays_render(EffectInstance *effect)
Definition light_rays.c:257
Gfx D_090001D8_36E168[]
void func_E006A464(LightRaysFXData *part)
Definition light_rays.c:151
void func_E006A85C(LightRaysFXData *part)
Definition light_rays.c:270
s32 D_E006AE10[]
Definition light_rays.c:17
void light_rays_appendGfx(void *effect)
Definition light_rays.c:280
Gfx D_09000130_36E0C0[]
void func_E006A0BC(LightRaysFXData *part, s32 beamIdx)
Definition light_rays.c:57
void light_rays_init(EffectInstance *effect)
Definition light_rays.c:148
Gfx * D_E006ADF0[]
Definition light_rays.c:9
void light_rays_update(EffectInstance *effect)
Definition light_rays.c:185
Gfx D_09000110_36E0A0[]
void func_E006A000(LightRaysFXData *part, s32 beamIdx)
Definition light_rays.c:41
Gfx * D_E006AE00[]
Definition light_rays.c:13
void light_rays_main(s32 type, f32 posX, f32 posY, f32 posZ, f32 scale, EffectInstance **outEffect)
Definition light_rays.c:80
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
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 *)
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16