Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
effect_46.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Gfx D_090003A0_38ED30[];
5extern Gfx D_09000420_38EDB0[];
6
7// perhaps additional, unused colors? 36 bytes would give 12 RGB colors
8s32 D_E008CAF0[] = {
9 0xFEACACFE, 0xACD5FEB4, 0x9AD5B4FE,
10 0xB4B4FEB4, 0xDDFEB4FE, 0xFEB4FED5,
11 0xB4FEB4D5, 0xFEB4FEFE, 0xB4FED5AC
12};
13
14u8 ColorsR[] = { 255, 255, 64 };
15u8 ColorsG[] = { 255, 64, 64 };
16u8 ColorsB[] = { 255, 64, 255 };
17
18void effect_46_init(EffectInstance* effect);
21void effect_46_appendGfx(void* effect);
22
23EffectInstance* effect_46_main(s32 type, PlayerStatus* player, f32 scale, s32 duration) {
25 EffectInstance* effect;
26 SpinFXData* part;
27 s32 numParts = 5;
28 s32 colorIdx;
29 s32 i;
30
34 bp.unk_00 = 0;
35 bp.renderUI = NULL;
36 bp.effectID = EFFECT_46;
37
38 effect = create_effect_instance(&bp);
39 effect->numParts = numParts;
40 part = effect->data.spin = general_heap_malloc(numParts * sizeof(*part));
41 ASSERT(effect->data.spin != NULL);
42
43 part->type = type;
44 part->player = player;
45 part->scale = scale * 1.2;
46 part->initialScale = scale * 1.2;
47 part->duration = duration;
48 part->timeLeft = duration;
49 part->alpha = 0;
50 part->lifetime = 0;
51
52 part++;
53 for (i = 1; i < numParts; i++, part++) {
54 switch (type) {
55 case 0:
56 case 2:
57 case 4:
58 case 6:
59 part->pos.x = 0.0f;
60 part->pos.y = i * 7 + 4;
61 part->pos.z = 0.0f;
62 part->rotVel.x = 0.0f;
63 part->rotVel.y = 60.0f;
64 part->rotVel.z = 0.0f;
65 part->rot.x = 0.0f;
66 part->rot.y = i * 120;
67 part->rot.z = 0.0f;
68 part->scale = 1.0f;
69 break;
70 case 1:
71 case 3:
72 case 5:
73 case 7:
74 part->pos.x = 0.0f;
75 part->pos.y = i * 7 + 4;
76 part->pos.z = 0.0f;
77 part->rotVel.x = 0.0f;
78 part->rotVel.y = -60.0f;
79 part->rotVel.z = 0.0f;
80 part->rot.x = 0.0f;
81 part->rot.y = i * 120;
82 part->rot.z = 0.0f;
83 part->scale = 1.0f;
84 part->color.b = 255;
85 part->color.g = 255;
86 part->color.r = 255;
87 break;
88 default:
89 part->pos.x = 0;
90 part->pos.y = player->colliderHeight * 0.5;
91 part->pos.z = 0;
92 part->rotVel.x = effect_rand_int(1) * 8 - 4;
93 part->rotVel.y = 0;
94 part->rotVel.z = effect_rand_int(1) * 8 - 4;
95 part->rot.x = i * 25;
96 part->rot.y = (i - 1) * 360 / (numParts - 1);
97 part->rot.z = 360 - i * 38;
98 part->scale = (f32) (i - 1) / (numParts - 1) * 0.5 + 0.5;
99 break;
100 }
101
102 switch (type) {
103 case 2:
104 case 3:
105 colorIdx = 1;
106 break;
107 case 4:
108 case 5:
109 colorIdx = 2;
110 break;
111 case 6:
112 case 7:
113 colorIdx = (i & 1) + 1;
114 break;
115 default:
116 colorIdx = 0;
117 break;
118 }
119
120 part->color.r = ColorsR[colorIdx];
121 part->color.g = ColorsG[colorIdx];
122 part->color.b = ColorsB[colorIdx];
123 }
124
125 return effect;
126}
127
129}
130
132 SpinFXData* part = effect->data.spin;
133 s32 type;
134 s32 time;
135 s32 i;
136
137 part->timeLeft--;
138 part->lifetime++;
139
140 if (part->timeLeft < 0) {
141 remove_effect(effect);
142 return;
143 }
144
145 type = part->type;
146 time = part->timeLeft;
147
148 if (type == 8) {
149 if (time >= 6) {
150 part->alpha += (255 - part->alpha) * 0.05;
151 }
152 part->scale = (part->initialScale * time) / part->duration;
153 if (time < 10) {
154 part->alpha = time * 25;
155 }
156 } else {
157 if (time >= 6) {
158 part->alpha += (100 - part->alpha) * 0.3;
159 }
160 if (time < 10) {
161 part->alpha *= 0.8;
162 part->scale += (2.0f * part->initialScale - part->scale) * 0.1;
163 }
164 }
165
166 part->pos.x = part->player->pos.x;
167 part->pos.y = part->player->pos.y;
168 part->pos.z = part->player->pos.z;
169
170 part++;
171 for (i = 1; i < effect->numParts; i++, part++) {
172 if (type == 8) {
173 if (i % 2) {
174 part->rotVel.y += (40.0f - part->rotVel.y) * 0.2;
175 } else {
176 part->rotVel.y += (-40.0f - part->rotVel.y) * 0.2;
177 }
178 part->rot.x += part->rotVel.x;
179 part->rot.y += part->rotVel.y;
180 part->rot.z += part->rotVel.z;
181 } else if (time < 10) {
182 part->rot.y += (part->rotVel.y * time) / 10.0f;
183 } else {
184 part->rot.y += part->rotVel.y;
185 }
186 }
187}
188
190 RenderTask renderTask;
191 RenderTask* retTask;
192
193 renderTask.appendGfx = effect_46_appendGfx;
194 renderTask.appendGfxArg = effect;
195 renderTask.dist = 0;
197
198 retTask = queue_render_task(&renderTask);
200}
201
202void effect_46_appendGfx(void* effect) {
203 SpinFXData* part = ((EffectInstance*)effect)->data.spin;
204 s32 type;
205 s32 alpha = part->alpha;
206 f32 curScale = part->scale;
207 f32 initialScale = part->initialScale;
208 Matrix4f mtxTransform;
209 Matrix4f mtxTemp;
210 s32 i;
211
212 type = part->type;
213
214 gDPPipeSync(gMainGfxPos++);
215 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
216 gSPDisplayList(gMainGfxPos++, D_09000420_38EDB0);
217
218 guTranslateF(mtxTransform, part->pos.x, part->pos.y, part->pos.z);
219 guRotateF(mtxTemp, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
220 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
222
223 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
224
225 part++;
226 for (i = 1; i < ((EffectInstance*)effect)->numParts; i++, part++) {
227 guPositionF(mtxTransform, part->rot.x, 0.0f, part->rot.z, curScale * part->scale, part->pos.x, part->pos.y, part->pos.z);
228 guRotateF(mtxTemp, part->rot.y, 0.0f, 1.0f, 0.0f);
229 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
230
231 if (type < 8) {
232 guTranslateF(mtxTemp, 3.0f - (curScale - initialScale) * 3.0f / initialScale, 0.0f, 0.0f);
233 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
234 } else {
235 guTranslateF(mtxTemp, 2.0f, 0.0f, 0.0f);
236 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
237 }
238
239 gDPSetPrimColor(gMainGfxPos++, 0, 0, part->color.r, part->color.g, part->color.b, alpha);
240
242
243 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
244 gSPDisplayList(gMainGfxPos++, D_090003A0_38ED30);
245 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
246 }
247
248 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
249}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
void effect_46_init(EffectInstance *effect)
Definition effect_46.c:128
void effect_46_update(EffectInstance *effect)
Definition effect_46.c:131
Gfx D_090003A0_38ED30[]
EffectInstance * effect_46_main(s32 type, PlayerStatus *player, f32 scale, s32 duration)
Definition effect_46.c:23
Gfx D_09000420_38EDB0[]
void effect_46_appendGfx(void *effect)
Definition effect_46.c:202
void effect_46_render(EffectInstance *effect)
Definition effect_46.c:189
u8 ColorsR[]
Definition effect_46.c:14
u8 ColorsG[]
Definition effect_46.c:15
s32 D_E008CAF0[]
Definition effect_46.c:8
u8 ColorsB[]
Definition effect_46.c:16
#define general_heap_malloc
#define guRotateF
#define queue_render_task
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define guPositionF
#define create_effect_instance
Vec3f pos
Definition effects.h:1202
PlayerStatus * player
Definition effects.h:1201
Color_RGB8 color
Definition effects.h:1211
Vec3f rotVel
Definition effects.h:1210
s32 duration
Definition effects.h:1206
s32 lifetime
Definition effects.h:1208
s32 timeLeft
Definition effects.h:1207
Vec3f rot
Definition effects.h:1209
struct SpinFXData * spin
Definition effects.h:2534
EffectData data
Definition effects.h:2605
f32 initialScale
Definition effects.h:1204
#define ASSERT(condition)
s32 effect_rand_int(s32)
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
#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 *)
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