Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
lightning_bolt.c File Reference

Go to the source code of this file.

Data Structures

struct  LightningPreset
 

Functions

void lightning_bolt_init (EffectInstance *effect)
 
void lightning_bolt_update (EffectInstance *effect)
 
void lightning_bolt_render (EffectInstance *effect)
 
void lightning_bolt_appendGfx (void *effect)
 
EffectInstancelightning_bolt_main (s32 type, f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ, f32 scale, s32 duration)
 
f32 lightning_bolt_get_rand_symmetric (f32 interval)
 
void func_E00BC36C (void)
 

Variables

LightningPreset D_E00BCC30 []
 
LightningPreset D_E00BCD38 []
 
LightningPresetD_E00BCE40 [] = { D_E00BCC30, D_E00BCD38 }
 
Gfx D_09001000_3BBEA0 []
 

Data Structure Documentation

◆ LightningPreset

struct LightningPreset
Data Fields
u8 offset[12]
u8 width[12]

Function Documentation

◆ lightning_bolt_init()

void lightning_bolt_init ( EffectInstance * effect)

Definition at line 112 of file lightning_bolt.c.

112 {
113}

Referenced by lightning_bolt_main().

◆ lightning_bolt_update()

void lightning_bolt_update ( EffectInstance * effect)

Definition at line 119 of file lightning_bolt.c.

119 {
120 LightningBoltFXData* data = effect->data.lightningBolt;
121 s32 type = data->type;
122
123 if (effect->flags & FX_INSTANCE_FLAG_DISMISS) {
124 effect->flags &= ~FX_INSTANCE_FLAG_DISMISS;
125 data->timeLeft = 16;
126 }
127
128 if (data->timeLeft < 1000) {
129 data->timeLeft--;
130 }
131
132 data->lifetime++;
133
134 if (data->timeLeft < 0) {
135 remove_effect(effect);
136 return;
137 }
138
139 if (type == 2) {
140 if (data->lifetime >= 40) {
141 data->outerColor.a *= 0.5;
142 }
143 } else {
144 if (data->lifetime >= 11) {
145 data->outerColor.a *= 0.5;
146 }
147 }
148}
#define remove_effect
struct LightningBoltFXData * lightningBolt
Definition effects.h:2558
EffectData data
Definition effects.h:2605
@ FX_INSTANCE_FLAG_DISMISS
Definition enums.h:3517

Referenced by lightning_bolt_main().

◆ lightning_bolt_render()

void lightning_bolt_render ( EffectInstance * effect)

Definition at line 150 of file lightning_bolt.c.

150 {
151 LightningBoltFXData* data = effect->data.lightningBolt;
152 RenderTask renderTask;
153 RenderTask* retTask;
154 RenderTask* renderTaskPointer = &renderTask;
155
157 renderTask.appendGfxArg = effect;
159 renderTask.dist = data->tipPos.z + 1000.0f;
160 } else {
161 renderTask.dist = 10;
162 }
163
164 renderTaskPointer->renderMode = RENDER_MODE_CLOUD_NO_ZCMP;
165 retTask = queue_render_task(renderTaskPointer);
167}
#define queue_render_task
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ CONTEXT_BATTLE
Definition enums.h:3530
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
void lightning_bolt_appendGfx(void *effect)
void * appendGfxArg
void(* appendGfx)(void *)
GameStatus * gGameStatusPtr
Definition main_loop.c:32

Referenced by lightning_bolt_main().

◆ lightning_bolt_appendGfx()

void lightning_bolt_appendGfx ( void * effect)

Definition at line 172 of file lightning_bolt.c.

172 {
173 Vtx_t* vtxBuffer;
174 f32 widthScale;
175 f32 cosAngle;
176 f32 edgeDeltaY;
177 f32 temp;
178 f32 sinAngle;
179 f32 edgeDeltaX;
180 f32 avgDeltaY;
181 f32 avgDeltaX;
182 f32 deltaPos;
183 f32 theta;
184 f32 nextAngle;
185 f32 edgeAngle;
186 f32 prevAngle;
187 s16 texOffsetX;
188 s32 temp_a0;
189 s32 alpha;
190 s32 type;
191 s32 lifetime;
192 s32 quadCount;
193 LightningPreset* preset;
194 Vtx_t* vtx;
195 f32 edgeDeltaZ;
196 f32 deltaX, deltaY, deltaZ;
197 LightningBoltFXData* data = ((EffectInstance*)effect)->data.lightningBolt;
198 Matrix4f sp10;
199 Matrix4f unused;
200 s32 i;
201 f32 edgeLength;
202
203 lifetime = data->lifetime;
204 alpha = data->outerColor.a;
205 type = data->type;
206 widthScale = data->widthScale;
207
208 gDPPipeSync(gMainGfxPos++);
209 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
210
211 guScaleF(sp10, 0.1f, 0.1f, 0.1f);
213
214 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
215 gDPSetPrimColor(gMainGfxPos++, 0, 0, data->outerColor.r, data->outerColor.g, data->outerColor.b, alpha);
216 gDPSetEnvColor(gMainGfxPos++, data->innerColor.r, data->innerColor.g, data->innerColor.b, 128);
217 gSPDisplayList(gMainGfxPos++, D_09001000_3BBEA0);
218
219 temp_a0 = lifetime - 1;
220 if (type != 2) {
221 if (temp_a0 <= 10) {
222 preset = &D_E00BCE40[type][temp_a0];
223 } else {
224 preset = &D_E00BCE40[type][10];
225 }
226 } else if (temp_a0 < 8) {
227 preset = &D_E00BCE40[0][temp_a0];
228 } else if (temp_a0 < 0x24) {
229 preset = &D_E00BCE40[0][temp_a0 % 6 + 2];
230 } else {
231 preset = &D_E00BCE40[0][10];
232 }
233
234 for (i = 0; i < ARRAY_COUNT(data->boltVertexPosX); i++) {
235 avgDeltaX = (data->endPos.x - data->startPos.x) * (1 / 11.0f);
236 avgDeltaY = (data->endPos.y - data->startPos.y) * (1 / 11.0f);
237 theta = (data->unk_110 + (i - lifetime) * 10) % 120 - 60;
238 deltaPos = preset->offset[i];
239
240 sinAngle = sin_deg(theta) * deltaPos * 0.04;
241 cosAngle = cos_deg(theta) * deltaPos * 0.04;
242
243 deltaX = avgDeltaX * cosAngle - avgDeltaY * sinAngle;
244 deltaY = avgDeltaX * sinAngle + avgDeltaY * cosAngle;
245 deltaZ = 0.0f;
246
247 data->boltVertexPosX[i] = data->startPos.x + (data->endPos.x - data->startPos.x) * i * (1 / 11.0f) + deltaX;
248 data->boltVertexPosY[i] = data->startPos.y + (data->endPos.y - data->startPos.y) * i * (1 / 11.0f) + deltaY;
249 data->boltVertexPosZ[i] = data->startPos.z + (data->endPos.z - data->startPos.z) * i * (1 / 11.0f) + deltaZ;
250 data->edgeLength[i] = (f32) preset->width[i] * 0.1;
251 }
252
253 vtxBuffer = (Vtx_t*) (gMainGfxPos + 1);
254 vtx = (Vtx_t*) (gMainGfxPos + 1);
255 gSPBranchList(gMainGfxPos, gMainGfxPos + 0x31);
256 gMainGfxPos += 0x31;
257
258 for (i = 0; i < ARRAY_COUNT(data->boltVertexPosX); i++) {
259 if (i == 0) {
260 edgeLength = 8.0f;
261 edgeAngle = -atan2(data->boltVertexPosY[1], -data->boltVertexPosX[1], data->boltVertexPosY[0], -data->boltVertexPosX[0]);
262 } else {
263 edgeLength = 8.0f;
264 if (i == ARRAY_COUNT(data->boltVertexPosX) - 1) {
265 edgeAngle = -90.0f;
266 } else {
267 nextAngle = -atan2(data->boltVertexPosY[i + 1], -data->boltVertexPosX[i + 1], data->boltVertexPosY[i], -data->boltVertexPosX[i]);
268 prevAngle = -atan2(data->boltVertexPosY[i], -data->boltVertexPosX[i], data->boltVertexPosY[i - 1], -data->boltVertexPosX[i - 1]);
269 if (prevAngle - nextAngle > 180.0f) {
270 nextAngle += 360.0f;
271 } else if (prevAngle - nextAngle < -180.0f) {
272 prevAngle += 360.0f;
273 }
274 temp = nextAngle + prevAngle; // required to match
275 edgeAngle = temp;
276 edgeAngle *= 0.5;
277
278 if (prevAngle + nextAngle < 0.0f) { // required to match
279 nextAngle += 360.0f;
280 }
281 }
282 }
283
284 edgeLength *= (widthScale * data->edgeLength[i]);
285 texOffsetX = (128 - i * 12) * 32;
286 edgeDeltaX = edgeLength * sin_deg(edgeAngle);
287 edgeDeltaY = edgeLength * cos_deg(edgeAngle);
288 edgeDeltaZ = 0.0f;
289
290 vtx->ob[0] = (data->boltVertexPosX[i] + edgeDeltaX) * 10.0f;
291 vtx->ob[1] = (data->boltVertexPosY[i] + edgeDeltaY) * 10.0f;
292 vtx->ob[2] = (data->boltVertexPosZ[i] + edgeDeltaZ) * 10.0f;
293 vtx->tc[0] = texOffsetX;
294 vtx->tc[1] = 0;
295 vtx->cn[0] = i * 50;
296 vtx->cn[1] = i * 120;
297 vtx->cn[2] = i * 30;
298 vtx++;
299
300 vtx->ob[0] = (data->boltVertexPosX[i] - edgeDeltaX) * 10.0f;
301 vtx->ob[1] = (data->boltVertexPosY[i] - edgeDeltaY) * 10.0f;
302 vtx->ob[2] = (data->boltVertexPosZ[i] + edgeDeltaZ) * 10.0f;
303 vtx->tc[0] = texOffsetX;
304 vtx->tc[1] = 0x400;
305 vtx->cn[0] = i * 50;
306 vtx->cn[1] = i * 120;
307 vtx->cn[2] = i * 30;
308 vtx++;
309 }
310
311 quadCount = i;
312
313 gSPVertex(gMainGfxPos++, vtxBuffer, i * 2, 0);
314 gSPClearGeometryMode(gMainGfxPos++, G_SHADING_SMOOTH);
315
316 for (i = 0; i < quadCount - 1; i++) {
317 gSP2Triangles(gMainGfxPos++, i * 2 + 1, i * 2 + 0, i * 2 + 2, 0,
318 i * 2 + 1, i * 2 + 2, i * 2 + 3, 0);
319 }
320
321 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
322}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define guMtxF2L
#define sin_deg
#define cos_deg
#define atan2
#define guScaleF
f32 boltVertexPosZ[12]
Definition effects.h:1623
f32 boltVertexPosY[12]
Definition effects.h:1622
f32 boltVertexPosX[12]
Definition effects.h:1621
LightningPreset * D_E00BCE40[]
Gfx D_09001000_3BBEA0[]
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16

Referenced by lightning_bolt_render().

◆ lightning_bolt_main()

EffectInstance * lightning_bolt_main ( s32 type,
f32 startX,
f32 startY,
f32 startZ,
f32 endX,
f32 endY,
f32 endZ,
f32 scale,
s32 duration )

Definition at line 46 of file lightning_bolt.c.

56{
58 EffectInstance* effect;
60 s32 numParts = 1;
61 f32 temp;
62
66 bp.unk_00 = 0;
67 bp.renderUI = NULL;
68 bp.effectID = EFFECT_LIGHTNING_BOLT;
69
70 effect = create_effect_instance(&bp);
71 effect->numParts = numParts;
72 data = effect->data.lightningBolt = general_heap_malloc(numParts * sizeof(*data));
73 ASSERT(effect->data.lightningBolt != NULL);
74
75 data->type = type;
76 data->lifetime = 0;
77 if (duration <= 0) {
78 data->timeLeft = 1000;
79 } else {
80 data->timeLeft = duration;
81 }
82 data->outerColor.a = 255;
83 data->startPos.x = startX;
84 data->startPos.y = startY;
85 data->startPos.z = startZ;
86 data->endPos.x = endX;
87 data->endPos.y = endY;
88 data->endPos.z = endZ;
89 data->tipPos.x = startX;
90 data->tipPos.y = startY;
91 data->tipPos.z = startZ;
92 data->widthScale = scale;
93
94 temp = SQ(startX - endX) + SQ(startY - endY) + SQ(startZ - endZ);
95
96 if (temp != 0.0f) {
97 data->unk_114 = sqrtf(temp) * 0.005;
98 data->outerColor.r = 255;
99 data->outerColor.g = 220;
100 data->outerColor.b = 20;
101 data->innerColor.r = 255;
102 data->innerColor.g = 255;
103 data->innerColor.b = 255;
104 data->unk_110 = rand_int(359);
105
106 return effect;
107 } else {
108 return NULL;
109 }
110}
#define general_heap_malloc
#define sqrtf
#define rand_int
#define create_effect_instance
#define ASSERT(condition)
void lightning_bolt_update(EffectInstance *effect)
void lightning_bolt_render(EffectInstance *effect)
void lightning_bolt_init(EffectInstance *effect)
#define SQ(x)
Definition macros.h:166
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

◆ lightning_bolt_get_rand_symmetric()

f32 lightning_bolt_get_rand_symmetric ( f32 interval)

Definition at line 115 of file lightning_bolt.c.

115 {
116 return (f32)rand_int(interval) - interval * 0.5;
117}

◆ func_E00BC36C()

void func_E00BC36C ( void )

Definition at line 169 of file lightning_bolt.c.

169 {
170}

Variable Documentation

◆ D_E00BCC30

LightningPreset D_E00BCC30[]
Initial value:
= {
{{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, {10, 9, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0}},
{{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, {8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0}},
{{35, 5, 25, 5, 0, 25, 35, 5, 15, 0, 0, 0}, {10, 13, 15, 12, 11, 13, 10, 12, 5, 1, 0, 0}},
{{45, 15, 35, 15, 0, 35, 45, 55, 25, 5, 2, 0}, {13, 10, 12, 10, 13, 10, 13, 10, 12, 9, 5, 1}},
{{15, 15, 15, 15, 15, 15, 0, 15, 15, 5, 2, 0}, {14, 10, 15, 10, 13, 30, 32, 30, 24, 50, 40, 60}},
{{1, 5, 15, 15, 35, 45, 40, 35, 25, 5, 2, 0}, {4, 6, 10, 5, 8, 14, 6, 10, 14, 35, 50, 50}},
{{1, 15, 25, 15, 25, 35, 45, 40, 35, 15, 5, 0}, {2, 2, 23, 12, 8, 15, 15, 5, 6, 18, 38, 60}},
{{30, 25, 15, 5, 15, 15, 25, 30, 35, 25, 5, 0}, {3, 3, 3, 11, 3, 12, 4, 5, 2, 12, 42, 50}},
{{33, 33, 20, 12, 25, 17, 15, 20, 22, 20, 5, 0}, {3, 3, 3, 2, 10, 2, 2, 12, 2, 2, 2, 20}},
{{30, 30, 25, 25, 35, 20, 15, 10, 15, 15, 5, 0}, {2, 2, 2, 2, 2, 2, 6, 2, 2, 2, 6, 5}},
{{27, 27, 22, 22, 32, 17, 12, 7, 12, 12, 2, 0}, {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0}},
}

Definition at line 9 of file lightning_bolt.c.

9 {
10 {{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, {10, 9, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0}},
11 {{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, {8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0}},
12 {{35, 5, 25, 5, 0, 25, 35, 5, 15, 0, 0, 0}, {10, 13, 15, 12, 11, 13, 10, 12, 5, 1, 0, 0}},
13 {{45, 15, 35, 15, 0, 35, 45, 55, 25, 5, 2, 0}, {13, 10, 12, 10, 13, 10, 13, 10, 12, 9, 5, 1}},
14 {{15, 15, 15, 15, 15, 15, 0, 15, 15, 5, 2, 0}, {14, 10, 15, 10, 13, 30, 32, 30, 24, 50, 40, 60}},
15 {{1, 5, 15, 15, 35, 45, 40, 35, 25, 5, 2, 0}, {4, 6, 10, 5, 8, 14, 6, 10, 14, 35, 50, 50}},
16 {{1, 15, 25, 15, 25, 35, 45, 40, 35, 15, 5, 0}, {2, 2, 23, 12, 8, 15, 15, 5, 6, 18, 38, 60}},
17 {{30, 25, 15, 5, 15, 15, 25, 30, 35, 25, 5, 0}, {3, 3, 3, 11, 3, 12, 4, 5, 2, 12, 42, 50}},
18 {{33, 33, 20, 12, 25, 17, 15, 20, 22, 20, 5, 0}, {3, 3, 3, 2, 10, 2, 2, 12, 2, 2, 2, 20}},
19 {{30, 30, 25, 25, 35, 20, 15, 10, 15, 15, 5, 0}, {2, 2, 2, 2, 2, 2, 6, 2, 2, 2, 6, 5}},
20 {{27, 27, 22, 22, 32, 17, 12, 7, 12, 12, 2, 0}, {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0}},
21};

◆ D_E00BCD38

LightningPreset D_E00BCD38[]
Initial value:
= {
{{25, 25, 25, 5, 25, 5, 25, 25, 5, 25, 25, 25}, {4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0}},
{{15, 15, 15, 25, 15, 15, 5, 25, 25, 15, 25, 25}, {4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0}},
{{25, 25, 25, 5, 15, 25, 5, 5, 15, 5, 5, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 0, 0}},
{{25, 25, 25, 5, 25, 5, 25, 25, 5, 15, 5, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
{{15, 15, 15, 45, 35, 45, 35, 35, 25, 35, 15, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
{{45, 55, 35, 25, 55, 15, 45, 25, 45, 35, 15, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
{{85, 25, 15, 75, 25, 65, 35, 45, 75, 85, 15, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
{{85, 15, 35, 55, 65, 45, 25, 75, 35, 45, 35, 40}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
{{85, 15, 35, 55, 65, 45, 25, 75, 35, 45, 35, 40}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
{{85, 15, 35, 55, 65, 45, 25, 75, 35, 45, 35, 40}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
{{30, 30, 25, 25, 35, 20, 15, 10, 15, 15, 5, 0}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 0}},
}

Definition at line 23 of file lightning_bolt.c.

23 {
24 {{25, 25, 25, 5, 25, 5, 25, 25, 5, 25, 25, 25}, {4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0}},
25 {{15, 15, 15, 25, 15, 15, 5, 25, 25, 15, 25, 25}, {4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0}},
26 {{25, 25, 25, 5, 15, 25, 5, 5, 15, 5, 5, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 0, 0}},
27 {{25, 25, 25, 5, 25, 5, 25, 25, 5, 15, 5, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
28 {{15, 15, 15, 45, 35, 45, 35, 35, 25, 35, 15, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
29 {{45, 55, 35, 25, 55, 15, 45, 25, 45, 35, 15, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
30 {{85, 25, 15, 75, 25, 65, 35, 45, 75, 85, 15, 0}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
31 {{85, 15, 35, 55, 65, 45, 25, 75, 35, 45, 35, 40}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
32 {{85, 15, 35, 55, 65, 45, 25, 75, 35, 45, 35, 40}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
33 {{85, 15, 35, 55, 65, 45, 25, 75, 35, 45, 35, 40}, {4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 6, 5}},
34 {{30, 30, 25, 25, 35, 20, 15, 10, 15, 15, 5, 0}, {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 0}},
35};

◆ D_E00BCE40

LightningPreset* D_E00BCE40[] = { D_E00BCC30, D_E00BCD38 }

Definition at line 37 of file lightning_bolt.c.

LightningPreset D_E00BCC30[]
LightningPreset D_E00BCD38[]

Referenced by lightning_bolt_appendGfx().

◆ D_09001000_3BBEA0

Gfx D_09001000_3BBEA0[]
extern