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