Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
lightning.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Gfx D_09003280_371FE0[];
5extern Gfx D_090032F8_372058[];
6extern Gfx D_09003378_3720D8[];
7extern Gfx D_090033E0_372140[];
8extern Gfx D_09003580_3722E0[];
9extern Gfx D_09003778_3724D8[];
10extern Gfx D_09003888_3725E8[];
11extern Gfx D_09003948_3726A8[];
12
17
22
23void lightning_init(EffectInstance* effect);
26void lightning_appendGfx(void* effect);
27
32
34 s32 arg0,
35 f32 arg1,
36 f32 arg2,
37 f32 arg3,
38 f32 arg4,
39 f32 arg5
40) {
42 EffectInstance* effect;
43 LightningFXData* data;
44 s32 numParts = 1;
45
49 bp.unk_00 = 0;
50 bp.renderUI = NULL;
51 bp.effectID = EFFECT_LIGHTNING;
52
53 effect = create_effect_instance(&bp);
54 effect->numParts = numParts;
55 data = effect->data.lightning = general_heap_malloc(numParts * sizeof(*data));
56 ASSERT(effect->data.lightning != NULL);
57
58 data->unk_00 = arg0;
59 data->unk_18 = 0;
60 if (arg0 >= 3) {
61 data->unk_14 = 30;
62 } else {
63 data->unk_14 = 100;
64 }
65 data->unk_10 = 255;
66 data->unk_3C = 4;
67 data->unk_40 = 2;
68 data->unk_04 = arg1;
69 data->unk_08 = arg2;
70 data->unk_0C = arg3;
71 data->unk_48 = NULL;
72 data->unk_44 = NULL;
73 data->unk_1C = data->unk_20 = 0.0f;
74 data->unk_2C = 48.0f;
75 data->unk_30 = 32.0f;
76 data->unk_24 = data->unk_28 = 0.0f;
77 data->unk_34 = 8.0f;
78 data->unk_38 = 32.0f;
79
80 if (arg0 == 1 || arg0 == 2) {
81 if (arg0 == 1) {
82 load_effect(EFFECT_GATHER_MAGIC);
83 data->unk_44 = gather_magic_main(0, -118.0f, 184.0f, 79.0f, 1.0f, -1);
84
85 load_effect(EFFECT_BULB_GLOW);
86 bulb_glow_main(0, -120.0f, 189.0f, 77.0f, 1.0f, &data->unk_48);
87 } else {
88 load_effect(EFFECT_SNAKING_STATIC);
89 data->unk_48 = snaking_static_main(0, -120.0f, 189.0f, 72.0f, 1.0f, 0);
90
91 data->unk_48->data.snakingStatic->envCol.r = 255;
92 data->unk_48->data.snakingStatic->envCol.g = 255;
93 data->unk_48->data.snakingStatic->envCol.b = 255;
94 data->unk_48->data.snakingStatic->unk_18 = 255;
95 data->unk_48->data.snakingStatic->unk_1C = 0;
96 data->unk_48->data.snakingStatic->unk_20 = 255;
97 }
98 }
99
100 if (arg0 >= 3) {
101 load_effect(EFFECT_FLASHING_BOX_SHOCKWAVE);
104 } else {
106 }
107 }
108
109 return effect;
110}
111
113}
114
116 LightningFXData* data = effect->data.lightning;
117 s32 unk_00;
118
119 if (effect->flags & FX_INSTANCE_FLAG_DISMISS) {
120 effect->flags &= ~FX_INSTANCE_FLAG_DISMISS;
121 data->unk_14 = 0;
122 }
123
124 unk_00 = data->unk_00;
125
126 if (data->unk_14 < 100) {
127 data->unk_14--;
128 }
129
130 data->unk_18++;
131
132 if (data->unk_14 < 0) {
133 remove_effect(effect);
134
135 if (data->unk_48 != NULL) {
136 remove_effect(data->unk_48);
137 data->unk_48 = NULL;
138 }
139
140 if (data->unk_44 != NULL) {
141 remove_effect(data->unk_44);
142 data->unk_44 = NULL;
143 }
144 } else {
145 s32 unk_14 = data->unk_14;
146 s32 unk_18 = data->unk_18;
147
148 if (data->unk_44 != NULL && unk_18 >= 18) {
149 remove_effect(data->unk_44);
150 data->unk_44 = NULL;
151 }
152
153 if (unk_00 < 3 || unk_18 < 7) {
154 data->unk_1C += data->unk_2C;
155 if (data->unk_1C < 0.0f) {
156 data->unk_1C += 256.0f;
157 } else if (data->unk_1C > 256.0f) {
158 data->unk_1C -= 256.0f;
159 }
160
161 if (unk_18 % data->unk_3C == 0) {
162 data->unk_20 += data->unk_30;
163 if (data->unk_20 < 0.0f) {
164 data->unk_20 += 64.0f;
165 } else if (data->unk_20 > 64.0f) {
166 data->unk_20 -= 64.0f;
167 }
168 }
169
170 if (unk_18 % data->unk_40 == 0) {
171 data->unk_24 += data->unk_34;
172 if (data->unk_24 < 0.0f) {
173 data->unk_24 += 256.0f;
174 } else if (data->unk_24 > 256.0f) {
175 data->unk_24 -= 256.0f;
176 }
177 }
178
179 data->unk_28 += data->unk_38;
180 if (data->unk_28 < 0.0f) {
181 data->unk_28 += 64.0f;
182 }
183 else if (data->unk_28 > 64.0f) {
184 data->unk_28 -= 64.0f;
185 }
186 }
187
188 if (unk_00 >= 3) {
189 if (unk_18 >= 7) {
190 data->unk_10 -= 13;
191 if (data->unk_10 < 0) {
192 data->unk_10 = 0;
193 }
194 }
195 } else if (unk_14 < 10) {
196 data->unk_10 -= 25;
197 if (data->unk_10 < 0) {
198 data->unk_10 = 0;
199 }
200 }
201 }
202}
203
205 RenderTask renderTask;
206 RenderTask* retTask;
207
208 renderTask.appendGfx = lightning_appendGfx;
209 renderTask.appendGfxArg = effect;
210 renderTask.dist = 10;
212
213 retTask = queue_render_task(&renderTask);
215}
216
217void lightning_appendGfx(void* effect) {
218 LightningFXData* data = ((EffectInstance*)effect)->data.lightning;
219 s32 unk_00 = data->unk_00;
220 s32 unk_18 = data->unk_18;
221 Gfx* dlist = D_E006CB60[unk_00];
222 Gfx* dlist2 = D_E006CB78[unk_00];
223 Camera* camera = &gCameras[gCurrentCameraID];
224 Matrix4f sp20;
225 Matrix4f sp60;
226 u16 perspNorm;
227
228 gDPPipeSync(gMainGfxPos++);
229 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
230
231 if (unk_00 != 1 || unk_18 >= 18) {
232 s32 ult2;
233 s32 uls2;
234 s32 uls;
235 s32 ult;
236 f32* unk_28; // TODO required to match
237
238 gSPDisplayList(gMainGfxPos++, dlist2);
239
240 uls = data->unk_1C * 4.0f;
241 ult = data->unk_20 * 4.0f;
242 uls2 = data->unk_24 * 4.0f;
243 unk_28 = &data->unk_28; // TODO dumb pointer temp required to match
244 ult2 = *(unk_28) * 4.0f;
245
246 switch (unk_00) {
247 case 0:
248 case 1:
249 case 2:
250 guPerspectiveF(sp20, &perspNorm, 30.0f, (f32) camera->viewportW / (f32) camera->viewportH, 4.0f, 16384.0f, 1.0f);
252
253 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
254
255 guTranslateF(sp20, data->unk_04, data->unk_08, -500.0f);
257
258 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
259 gDPSetPrimColor(gMainGfxPos++, 0, 0, 255, 47, 198, 255);
260 break;
261 default:
262 guTranslateF(sp20, data->unk_04, data->unk_08, data->unk_0C);
263 guRotateF(sp60, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
264 guMtxCatF(sp60, sp20, sp20);
265 guTranslateF(sp60, 0.0f, 0.0f, 1.0f);
266 guMtxCatF(sp60, sp20, sp20);
268
269 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
270 gDPSetPrimColor(gMainGfxPos++, 0, 0, 255, 255, 0, data->unk_10);
271 break;
272 }
273
274 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE, uls, ult, uls + 1020, ult + 124);
275 gDPSetTileSize(gMainGfxPos++, 1, uls2, ult2, uls2 + 1020, ult2 + 124);
276 gSPDisplayList(gMainGfxPos++, dlist);
277 gDPPipeSync(gMainGfxPos++);
278 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
279
280 if (unk_00 < 3) {
281 gSPMatrix(gMainGfxPos++, &gDisplayContext->camPerspMatrix[gCurrentCameraID], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
282 }
283
284 gDPPipeSync(gMainGfxPos++);
285 }
286}
void bulb_glow_main(s32 arg0, f32 posX, f32 posY, f32 posZ, f32 arg4, EffectInstance **outEffect)
Definition bulb_glow.c:50
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
s8 unk_14
Definition demo_api.c:19
#define general_heap_malloc
#define guRotateF
#define queue_render_task
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define guPerspectiveF
#define load_effect
#define create_effect_instance
struct EffectInstance * unk_44
Definition effects.h:870
struct LightningFXData * lightning
Definition effects.h:2518
@ FX_SHOCK_OVERLAY_LIGHTNING_WORLD
Definition effects.h:1264
@ FX_SHOCK_OVERLAY_LIGHTNING_BATTLE
Definition effects.h:1266
struct SnakingStaticFXData * snakingStatic
Definition effects.h:2551
struct EffectInstance * unk_48
Definition effects.h:871
EffectData data
Definition effects.h:2605
#define ASSERT(condition)
@ FX_INSTANCE_FLAG_DISMISS
Definition enums.h:3517
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ CONTEXT_BATTLE
Definition enums.h:3530
@ RENDER_MODE_SURFACE_XLU_LAYER3
Definition enums.h:3299
EffectInstance * flashing_box_shockwave_main(s32 type, f32 posX, f32 posY, f32 posZ, f32 sizeX, f32 sizeY)
EffectInstance * gather_magic_main(s32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, s32 arg5)
EFFECT_DEF_BULB_GLOW(bulb_glow_main)
void lightning_update(EffectInstance *effect)
Definition lightning.c:115
EFFECT_DEF_FLASHING_BOX_SHOCKWAVE(flashing_box_shockwave_main)
Gfx * D_E006CB60[]
Definition lightning.c:13
EffectInstance * lightning_main(s32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5)
Definition lightning.c:33
void lightning_render(EffectInstance *effect)
Definition lightning.c:204
Gfx D_09003280_371FE0[]
Gfx D_09003378_3720D8[]
Gfx D_09003888_3725E8[]
Gfx D_090032F8_372058[]
EFFECT_DEF_GATHER_MAGIC(gather_magic_main)
void lightning_appendGfx(void *effect)
Definition lightning.c:217
Gfx D_09003948_3726A8[]
Gfx D_09003778_3724D8[]
Gfx D_090033E0_372140[]
void lightning_init(EffectInstance *effect)
Definition lightning.c:112
Gfx D_09003580_3722E0[]
Gfx * D_E006CB78[]
Definition lightning.c:18
EFFECT_DEF_SNAKING_STATIC(snaking_static_main)
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
EffectInstance * snaking_static_main(s32 type, f32 posX, f32 posY, f32 posZ, f32 scale, s32 timeLeft)
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 *)
GameStatus * gGameStatusPtr
Definition main_loop.c:32
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