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

Go to the source code of this file.

Functions

void whirlwind_init (EffectInstance *effect)
 
void whirlwind_update (EffectInstance *effect)
 
void whirlwind_render (EffectInstance *effect)
 
void whirlwind_appendGfx (void *effect)
 
EffectInstancewhirlwind_main (s32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, s32 arg5)
 
void func_E00CE470 (void)
 

Variables

Gfx D_09000400_3D3D30 []
 

Function Documentation

◆ whirlwind_init()

void whirlwind_init ( EffectInstance * effect)

Definition at line 70 of file whirlwind.c.

70 {
71}

Referenced by whirlwind_main().

◆ whirlwind_update()

void whirlwind_update ( EffectInstance * effect)

Definition at line 73 of file whirlwind.c.

73 {
74 s32 temp_a2;
75 s32 temp_v1_3;
76 WhirlwindFXData* part;
77 s32 i;
78 f32 temp;
79
80 part = effect->data.whirlwind;
81 if ((effect->flags & FX_INSTANCE_FLAG_DISMISS)) {
82 effect->flags &= ~FX_INSTANCE_FLAG_DISMISS;
83 part->unk_10 = 16;
84 }
85 if (part->unk_10 < 1000) {
86 part->unk_10--;
87 }
88 part->unk_14++;
89 if (part->unk_10 < 0) {
90 remove_effect(effect);
91 return;
92 }
93 temp = part->unk_34;
94 temp_v1_3 = part->unk_10;
95 temp_a2 = part->unk_14;
96 if (temp_v1_3 < 0x10) {
97 part->primAlpha = temp_v1_3 * 16;
98 }
99
100 if (temp_a2 < 0x10) {
101 part->primAlpha = temp_a2 * 16 + 15;
102 }
103 part->unk_38[0] = part->pos.x;
104 part->unk_58[0] = part->pos.y;
105 part->unk_78[0] = part->pos.z;
106
107 for (i = MAX_WHIRLWIND_SEGMENTS - 1; i > 0; i--) {
108 part->unk_118[i] = (part->unk_38[i - 1] - part->unk_38[i]) * 4.0f;
109 part->unk_38[i] = part->unk_38[i - 1];
110 part->unk_58[i] = part->unk_58[i - 1] + temp * 5.0f;
111 part->unk_78[i] = part->unk_78[i - 1];
112 if (part->unk_118[i] > 90.0f) {
113 part->unk_118[i] = 90.0f;
114 } else if (part->unk_118[i] < -90.0f) {
115 part->unk_118[i] = -90.0f;
116 }
117 }
118
119 part->unk_138 += 10.0f;
120 part->unk_13C += 12.96;
121 part->unk_140 += 17.28;
122 if (part->unk_13C > 64.0f) {
123 part->unk_13C -= 64.0f;
124 }
125 if (part->unk_140 > 64.0f) {
126 part->unk_140 -= 64.0f;
127 }
128 for(i = 0; i < MAX_WHIRLWIND_SEGMENTS; i++) {
129 part->unk_B8[i] += part->unk_D8[i];
130 }
131}
#define remove_effect
struct WhirlwindFXData * whirlwind
Definition effects.h:2567
#define MAX_WHIRLWIND_SEGMENTS
Definition effects.h:1837
EffectData data
Definition effects.h:2605
@ FX_INSTANCE_FLAG_DISMISS
Definition enums.h:3517

Referenced by whirlwind_main().

◆ whirlwind_render()

void whirlwind_render ( EffectInstance * effect)

Definition at line 133 of file whirlwind.c.

133 {
134 RenderTask renderTask;
135 RenderTask* queuedTask;
136
137 renderTask.appendGfx = whirlwind_appendGfx;
138 renderTask.appendGfxArg = effect;
139 renderTask.dist = 10;
141
142 queuedTask = queue_render_task(&renderTask);
144}
#define queue_render_task
void whirlwind_appendGfx(void *effect)
Definition whirlwind.c:149
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
void * appendGfxArg
void(* appendGfx)(void *)

Referenced by whirlwind_main().

◆ whirlwind_appendGfx()

void whirlwind_appendGfx ( void * effect)

Definition at line 149 of file whirlwind.c.

149 {
150 Matrix4f sp20;
151 Matrix4f sp60;
152 s32 spA0;
153 s32 primAlpha;
154 Gfx* triangleDisplayList;
155 Vtx* vertexBuffer;
156 s32 spB0;
157 s32 spB4;
158 f32 spB8;
159 Gfx* whirlwindMainDisplayList;
160 Gfx* savedPos;
161 f32 temp_f20_2;
162 f32 temp_f20_3;
163 f32 var_f4;
164 f32 f22;
165 s32 i;
166 EffectInstance* eff = (EffectInstance*)effect;
167 WhirlwindFXData* data = eff->data.whirlwind;
168
169 spA0 = data->unk_10;
170 primAlpha = data->primAlpha >> 1;
171 spB8 = data->unk_34;
172 spB0 = data->unk_13C * 4.0f;
173 spB4 = data->unk_140 * 4.0f;
174 gDPPipeSync(gMainGfxPos++);
175 gSPSegment(gMainGfxPos++, 0x09, OS_K0_TO_PHYSICAL(eff->graphics->data));
176
177 guTranslateF(sp20, 0.0f, 0.0f, 0.0f);
179
180 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
181 gSPDisplayList(gMainGfxPos++, D_09000400_3D3D30);
182
183 // Reserve 0x208 bytes (65 commands) for a vertex buffer (2x16 Vtx + space for the current command)
184 gSPBranchList(gMainGfxPos, &gMainGfxPos[65]);
185 vertexBuffer = (Vtx*)(gMainGfxPos + 1);
186
187 // set the current position we're writing gfx commands to past the vertex buffer
189
190 // fill the vertex buffer; 2 sets of 16 verticies
191 for (i = 0; i <= (360 / 24); i++) {
192 Vtx* vtx = &vertexBuffer[i];
193 vtx->v.ob[0] = cos_deg(i * (360 / 15)) * 100.0f;
194 vtx->v.ob[1] = 0;
195 vtx->v.ob[2] = sin_deg(i * (360 / 15)) * 100.0f;
196 vtx->v.tc[0] = i * 128;
197 vtx->v.tc[1] = 0;
198
199 vtx = &vertexBuffer[i + (360 / 24 + 1)];
200 vtx->v.ob[0] = cos_deg(i * (360 / 15)) * 100.0f;
201 vtx->v.ob[1] = 0;
202 vtx->v.ob[2] = sin_deg(i * (360 / 15)) * 100.0f;
203 vtx->v.tc[0] = i * 512;
204 vtx->v.tc[1] = 1024;
205 }
206
207 // Reserve 0x88 bytes (17 commands, including this one) for a separate dynamically generated display list
208 gSPBranchList(gMainGfxPos, &gMainGfxPos[17]);
209
210 // Get a reference to the dynamically generated display list
211 triangleDisplayList = ++gMainGfxPos;
212
213 // Generate display list
214 for (i = 0; i < 15; i++) {
215 gSP2Triangles(gMainGfxPos++, i + 0x10, i + 1, i, 0, i + 0x10, i + 0x11, i + 1, 0);
216 }
217
218 // This marks the end of our dynamically generated display list, return control back to the main display list
219 gSPEndDisplayList(gMainGfxPos++);
220
221 guScaleF(sp20, 0.1f, 0.1f, 0.1f);
223 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
224
225 // Save position to later insert a branch around the commands that follow this
226 savedPos = gMainGfxPos++;
227
228 // Save position of main display list
229 whirlwindMainDisplayList = gMainGfxPos;
230
231 // Generate main display list
232 for(i = 0; i < (MAX_WHIRLWIND_SEGMENTS - 1); i++) {
233 guPositionF(sp20, 0.0f, 0.0f, data->unk_118[i], 1.0f, data->unk_38[i] * 10.0f, data->unk_58[i] * 10.0f, data->unk_78[i] * 10.0f);
234 guRotateF(sp60, data->unk_138 + i * i, -0.03f, 1.0f, 0.1f);
235 guMtxCatF(sp60, sp20, sp20);
236 var_f4 = data->unk_98[i] * spB8;
237 if (spA0 < 0x10) {
238 var_f4 += (127 - primAlpha) * 0.02f;
239 }
240 guScaleF(sp60, var_f4, spB8, var_f4);
241 guMtxCatF(sp60, sp20, sp20);
242 temp_f20_2 = data->unk_F8[i] * 10.0f;
243 f22 = data->unk_B8[i];
244 guTranslateF(sp60, temp_f20_2 * sin_deg(f22), 0.0f, temp_f20_2 * cos_deg(f22));
245 guMtxCatF(sp60, sp20, sp20);
247 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
248 gSPVertex(gMainGfxPos++, vertexBuffer, 16, 0);
249 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
250
251 guPositionF(sp20, 0.0f, 0.0f, data->unk_118[i + 1], 1.0f, data->unk_38[i + 1] * 10.0f, data->unk_58[i + 1] * 10.0f, data->unk_78[i + 1] * 10.0f);
252 guRotateF(sp60, data->unk_138 + i * i, 0.03f, 1.0f, 0.0f);
253 guMtxCatF(sp60, sp20, sp20);
254 guScaleF(sp60, data->unk_98[i + 1] * spB8, spB8, data->unk_98[i + 1] * spB8);
255 guMtxCatF(sp60, sp20, sp20);
256 temp_f20_3 = data->unk_F8[i] * 10.0f;
257 guTranslateF(sp60, temp_f20_3 * sin_deg(data->unk_B8[i]), 0.0f, temp_f20_3 * cos_deg(data->unk_B8[i]));
258 guMtxCatF(sp60, sp20, sp20);
260 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
261 gSPVertex(gMainGfxPos++, &vertexBuffer[16], 16, 16);
262 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
263
264 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE, spB0 + i * 16, 0, (spB0 + i * 16 + 63) << 2, 31 << 2);
265 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE + 1, spB4 + i * 8, 0, (spB4 + i * 8 + 63) << 2, 31 << 2);
266
267 // Call the display list to create triangles from the verticies
268 gSPDisplayList(gMainGfxPos++, triangleDisplayList);
269 }
270
271 gSPEndDisplayList(gMainGfxPos++);
272
273 // Now that the length of our display list is known, insert a branch at the previously saved location
274 gSPBranchList(savedPos, gMainGfxPos);
275 gSPClearGeometryMode(gMainGfxPos++, G_CULL_BOTH);
276 gDPSetPrimColor(gMainGfxPos++, 0, 0, data->primR, data->primG, data->primB, primAlpha);
277 gDPSetEnvColor(gMainGfxPos++, data->envR, data->envG, data->envB, 32);
278
279 // Call the main display list
280 gSPDisplayList(gMainGfxPos++, whirlwindMainDisplayList);
281 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
282 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
283}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define guRotateF
#define guMtxF2L
#define sin_deg
#define guTranslateF
#define guMtxCatF
#define guPositionF
#define cos_deg
#define guScaleF
Gfx D_09000400_3D3D30[]
struct EffectGraphics * graphics
Definition effects.h:2606
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16

Referenced by whirlwind_render().

◆ whirlwind_main()

EffectInstance * whirlwind_main ( s32 arg0,
f32 arg1,
f32 arg2,
f32 arg3,
f32 arg4,
s32 arg5 )

Definition at line 11 of file whirlwind.c.

11 {
13 EffectBlueprint* bpPtr = &bp;
14 EffectInstance *effect;
15 WhirlwindFXData* part;
16 s32 numParts;
17 s32 i;
18
22 bp.unk_00 = 0;
23 bp.renderUI = NULL;
24 bp.effectID = EFFECT_WHIRLWIND;
25
26 numParts = 1;
27 effect = create_effect_instance(bpPtr);
28 effect->numParts = numParts;
29 part = effect->data.whirlwind = general_heap_malloc(effect->numParts * sizeof(*part));
30 ASSERT(part != NULL);
31
32 part->unk_00 = arg0;
33 part->unk_14 = 0;
34 if (arg5 <= 0) {
35 part->unk_10 = 1000;
36 } else {
37 part->unk_10 = arg5;
38 }
39 part->primAlpha = 0;
40 part->pos.x = arg1;
41 part->pos.y = arg2;
42 part->pos.z = arg3;
43 part->unk_34 = arg4;
44
45 part->primR = 255;
46 part->primG = 255;
47 part->primB = 255;
48
49 part->envR = 255;
50 part->envG = 255;
51 part->envB = 235;
52
53 for(i = 0; i < MAX_WHIRLWIND_SEGMENTS; i++) {
54 part->unk_38[i] = arg1;
55 part->unk_58[i] = arg2;
56 part->unk_78[i] = arg3;
57 part->unk_98[i] = i * 0.2 + 1.0;
58 part->unk_B8[i] = rand_int(360);
59 part->unk_D8[i] = rand_int(100) * 0.1 + 2.0;
60 part->unk_F8[i] = rand_int(30) * 0.1;
61 part->unk_118[i] = 0;
62 }
63 part->unk_138 = 0;
64 part->unk_13C = 0;
65 part->unk_140 = 0;
66
67 return effect;
68}
#define general_heap_malloc
#define rand_int
#define create_effect_instance
void whirlwind_render(EffectInstance *effect)
Definition whirlwind.c:133
void whirlwind_update(EffectInstance *effect)
Definition whirlwind.c:73
void whirlwind_init(EffectInstance *effect)
Definition whirlwind.c:70
#define ASSERT(condition)
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

◆ func_E00CE470()

void func_E00CE470 ( void )

Definition at line 146 of file whirlwind.c.

146 {
147}

Variable Documentation

◆ D_09000400_3D3D30

Gfx D_09000400_3D3D30[]
extern

Referenced by whirlwind_appendGfx().