Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
butterflies.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Vtx D_09002D40_3ADD70[][6]; // TODO confirm this type is correct
5extern Gfx D_09003880_3AE8B0[];
6extern Gfx D_090038F8_3AE928[];
7extern Gfx D_09003968_3AE998[];
8extern Gfx D_090039D8_3AEA08[];
9extern Gfx D_09003A48_3AEA78[];
10extern Gfx D_09003AB8_3AEAE8[];
11extern Gfx D_09003B28_3AEB58[];
12extern Gfx D_09003B98_3AEBC8[];
13extern Gfx D_09003C08_3AEC38[];
14extern Gfx D_09003C78_3AECA8[];
15extern Gfx D_09003CE8_3AED18[];
16extern Gfx D_09003D58_3AED88[];
17extern Gfx D_09003DC8_3AEDF8[];
18
22
23s8 D_E00AA6EC[] = {
24 -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 0, 0, 0, 0, 0, 0, 0, 0
25};
26
30void butterflies_appendGfx(void* effect);
31
32EffectInstance* butterflies_main(s32 arg0, f32 arg1, f32 arg2, f32 arg3) {
34 EffectInstance* effect;
36 s32 numParts = 1;
37 s32 i;
38
39 bp.unk_00 = 0;
43 bp.renderUI = NULL;
44 bp.effectID = EFFECT_BUTTERFLIES;
45
46 effect = create_effect_instance(&bp);
47 effect->numParts = numParts;
48 part = effect->data.butterflies = general_heap_malloc(numParts * sizeof(*part));
49 ASSERT(effect->data.butterflies != NULL);
50
51 part->unk_04 = 1000;
52 part->unk_00 = arg0;
53 part->unk_24 = 255;
54 part->unk_0C = arg1;
55 part->unk_18 = arg1;
56 part->unk_10 = arg2;
57 part->unk_1C = arg2;
58 part->unk_14 = arg3;
59 part->unk_20 = arg3;
60 part->unk_08 = 0;
61 part->unk_2C = 0;
62 part->unk_30 = 0;
63 part->unk_34 = 50.0f;
64 part->unk_38 = 30.0f;
65 return effect;
66}
67
69}
70
72 ButterfliesFXData* temp_s0;
73 f32 temp_f20;
74 f32 temp_f20_2;
75 f32 temp_f22;
76 f32 temp_f24;
77 f32 temp_f4;
78 f32 temp_f6;
79 f32 temp_f8;
80 f32 var_f12;
81 f32 var_f20;
82 f32 var_f22;
83 f32 var_f24;
84
85 temp_s0 = effect->data.butterflies;
86 if (effect->flags & FX_INSTANCE_FLAG_DISMISS) {
87 effect->flags &= ~FX_INSTANCE_FLAG_DISMISS;
88 temp_s0->unk_04 = 900;
89 }
90
91 if (temp_s0->unk_04 < 1000) {
92 temp_s0->unk_04--;
93 }
94 temp_s0->unk_08 += 1;
95 if (temp_s0->unk_04 < 0) {
96 remove_effect(effect);
97 return;
98 }
99 if (temp_s0->unk_04 < 0x10) {
100 temp_s0->unk_24 = temp_s0->unk_04 * 0x10;
101 }
102
103 temp_s0->unk_30--;
104 if (temp_s0->unk_30 <= 0) {
105 s32 t;
106
107 temp_f20 = rand_int(359);
108 temp_f24 = temp_s0->unk_18 + (temp_s0->unk_34 * sin_deg(temp_f20));
109 temp_f22 = temp_s0->unk_1C + rand_int(temp_s0->unk_38);
110 temp_f20_2 = temp_s0->unk_20 + (temp_s0->unk_34 * cos_deg(temp_f20));
111 t = rand_int(100) + 10;
112 temp_f4 = temp_s0->unk_0C;
113 temp_f6 = temp_s0->unk_10;
114 temp_f8 = temp_s0->unk_14;
115 var_f24 = temp_f24 - temp_f4;
116 var_f22 = temp_f22 - temp_f6;
117 var_f20 = temp_f20_2 - temp_f8;
118 temp_s0->unk_30 = t;
119 if (var_f24 == 0.0f && var_f22 == 0.0f && var_f20 == 0.0f) {
120 var_f24 = temp_s0->unk_18 - temp_f4;
121 var_f22 = temp_s0->unk_1C - temp_f6;
122 var_f20 = temp_s0->unk_20 - temp_f8;
123 if (var_f24 == 0.0f && var_f22 == 0.0f && var_f20 == 0.0f) {
124 var_f24 = 1.0f;
125 var_f20 = 0.0f;
126 var_f22 = 0.0f;
127 }
128 }
129 var_f12 = SQ(var_f24) + SQ(var_f22) + SQ(var_f20);
130 if (var_f12 != 0.0f) {
131 var_f12 = 1.0f / sqrtf(var_f12);
132 }
133 var_f24 *= var_f12;
134 var_f22 *= var_f12;
135 var_f20 *= var_f12;
136 temp_s0->unk_3C = var_f24;
137 temp_s0->unk_40 = var_f22;
138 temp_s0->unk_44 = var_f20;
139 temp_s0->unk_28 = atan2(0.0f, 0.0f, -temp_s0->unk_3C, temp_s0->unk_44);
140 }
141 temp_s0->unk_2C += 3;
142 if (temp_s0->unk_2C >= 30) {
143 temp_s0->unk_2C -= 30;
144 }
145 temp_s0->unk_0C += temp_s0->unk_3C;
146 temp_s0->unk_10 += temp_s0->unk_40;
147 temp_s0->unk_14 += temp_s0->unk_44;
148}
149
151 RenderTask renderTask;
152 RenderTask* retTask;
153
154 renderTask.appendGfx = butterflies_appendGfx;
155 renderTask.appendGfxArg = effect;
156 renderTask.dist = 0;
158
159 retTask = queue_render_task(&renderTask);
161}
162
163
164void butterflies_appendGfx(void* effect) {
165 EffectInstance* effectTemp = effect;
166 ButterfliesFXData* data = effectTemp->data.butterflies;
167 Matrix4f sp18;
168 Matrix4f sp58;
169
170 s32 primColor = data->unk_24;
171 s32 type = data->unk_00;
172
173 gDPPipeSync(gMainGfxPos++);
174 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(effectTemp->graphics->data));
175
176 guTranslateF(sp18, data->unk_0C, data->unk_10 + D_E00AA6EC[data->unk_2C] * 0.3f, data->unk_14);
177 guRotateF(sp58, data->unk_28, 0.0f, 1.0f, 0.0f);
178 guMtxCatF(sp58, sp18, sp18);
179 guScaleF(sp58, 0.02f, 0.02f, 0.02f);
180 guMtxCatF(sp58, sp18, sp18);
182
183 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
184 gDPSetPrimColor(gMainGfxPos++, 0, 0, primColor, primColor, primColor, 255);
185 gSPDisplayList(gMainGfxPos++, D_09003880_3AE8B0);
186 gSPDisplayList(gMainGfxPos++, D_E00AA6C0[type]);
187 gSPVertex(gMainGfxPos++, &D_09002D40_3ADD70[data->unk_2C], 6, 0);
188 gSPDisplayList(gMainGfxPos++, D_09003DC8_3AEDF8);
189 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
190 gDPPipeSync(gMainGfxPos++);
191}
Gfx D_09003D58_3AED88[]
Gfx D_090039D8_3AEA08[]
Gfx D_09003B98_3AEBC8[]
Gfx D_09003C78_3AECA8[]
Gfx D_09003880_3AE8B0[]
Gfx D_09003AB8_3AEAE8[]
Gfx D_090038F8_3AE928[]
Gfx D_09003B28_3AEB58[]
Gfx D_09003CE8_3AED18[]
Gfx D_09003A48_3AEA78[]
void butterflies_render(EffectInstance *effect)
Gfx D_09003C08_3AEC38[]
s8 D_E00AA6EC[]
Definition butterflies.c:23
Gfx D_09003968_3AE998[]
void butterflies_appendGfx(void *effect)
Gfx D_09003DC8_3AEDF8[]
Vtx D_09002D40_3ADD70[][6]
Gfx * D_E00AA6C0[11]
Definition butterflies.c:19
void butterflies_update(EffectInstance *effect)
Definition butterflies.c:71
void butterflies_init(EffectInstance *effect)
Definition butterflies.c:68
EffectInstance * butterflies_main(s32 arg0, f32 arg1, f32 arg2, f32 arg3)
Definition butterflies.c:32
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define general_heap_malloc
#define guRotateF
#define queue_render_task
#define sqrtf
#define guMtxF2L
#define sin_deg
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define rand_int
#define cos_deg
#define atan2
#define create_effect_instance
#define guScaleF
struct ButterfliesFXData * butterflies
Definition effects.h:2549
struct EffectGraphics * graphics
Definition effects.h:2606
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
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
#define SQ(x)
Definition macros.h:166
#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