Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
flower_trail.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Gfx D_09000E20_32DCE0[];
5extern Gfx D_09000E38_32DCF8[];
6
10void flower_trail_appendGfx(void* effect);
11
13 Matrix4f transformMtx;
14 Matrix4f tempMtx;
15
16 guRotateF(transformMtx, effect->rot.x, 1.0f, 0.0f, 0.0f);
17 guRotateF(tempMtx, effect->rot.z, 0.0f, 0.0f, 1.0f);
18 guMtxCatF(tempMtx, transformMtx, transformMtx);
19 guRotateF(tempMtx, effect->rot.y, 0.0f, 1.0f, 0.0f);
20 guMtxCatF(transformMtx, tempMtx, transformMtx);
21 guScaleF(tempMtx, effect->scale.x, effect->scale.y, effect->scale.z);
22 guMtxCatF(tempMtx, transformMtx, transformMtx);
23 guTranslateF(tempMtx, effect->pos.x, effect->pos.y, effect->pos.z);
24 guMtxCatF(transformMtx, tempMtx, transformMtx);
25 guMtxF2L(transformMtx, &effect->transformMtx);
26}
27
29 if (!effect->triggeredByNpc && effect->visibilityAmt != 0.0f && gPlayerStatus.actionState == ACTION_STATE_IDLE) {
30 effect->timeLeft++;
31 return;
32 }
33
34 effect->primAlpha -= 12;
35 effect->integrator[2] += effect->integrator[3];
36 effect->integrator[1] += effect->integrator[2];
37 effect->integrator[0] += effect->integrator[1];
38 effect->rot.z += effect->integrator[0] * effect->velScaleA;
39 effect->pos.x -= effect->integrator[0] * effect->velScaleB * effect->vel.x;
40 effect->pos.z -= effect->integrator[0] * effect->velScaleB * effect->vel.z;
41
42 if (effect->integrator[0] < 0.0f) {
43 effect->visibilityAmt = 0.0f;
44 }
45}
46
47void flower_trail_main(s32 triggeredByNpc, f32 posX, f32 posY, f32 posZ, f32 angle, f32 direction) {
49 EffectInstance* effect;
50 FlowerFXData* part;
51 s32 numParts = 1;
52 f32 partAngle;
53 f32 angleOffset;
54 s32 i;
55
59 bp.unk_00 = 0;
60 bp.renderUI = NULL;
61 bp.effectID = EFFECT_FLOWER_TRAIL;
62
63 effect = create_effect_instance(&bp);
64 effect->numParts = numParts;
65
66 part = effect->data.flowerTrail = general_heap_malloc(numParts * sizeof(*part));
67 ASSERT(effect->data.flowerTrail != NULL);
68
69 mem_clear(part, numParts * sizeof(*part));
70
71 for (i = 0; i < numParts; i++, part++) {
72 part->alive = TRUE;
73 part->triggeredByNpc = triggeredByNpc;
74 part->unk_7C = 0.0f;
75
76 part->pos.x = posX;
77 part->pos.y = posY;
78 part->pos.z = posZ;
79
80 part->scale.x = 1.0f;
81 part->scale.y = 1.0f;
82 part->scale.z = 1.0f;
83
84 part->primAlpha = 255;
85
86 part->visibilityAmt = 1.0f;
87 part->velScaleB = 5.4f;
88 if (direction != 0.0f) {
89 part->velScaleA = -10.0f;
90 } else {
91 part->velScaleA = 10.0f;
92 }
93
94 part->integrator[0] = 0.5f;
95 part->integrator[1] = -0.07f;
96 part->integrator[2] = 0.003f;
97 part->integrator[3] = 0;
98
99 part->timeLeft = 15;
100 part->rot.y = angle;
101 part->rot.x = 0.0f;
102 part->rot.z = 0.0f;
103 part->useAltColor = (rand_int(100) >> 4) & 1;
104
105 if (direction != 0.0f) {
106 angleOffset = -90.0f;
107 partAngle = clamp_angle(angle + angleOffset);
108 } else {
109 angleOffset = 90.0f;
110 partAngle = clamp_angle(angle + angleOffset);
111 }
112
113 part->vel.x = sin_deg(partAngle);
114 part->vel.z = cos_deg(partAngle);
115 }
116}
117
120
122 FlowerFXData* part = effect->data.flowerTrail;
123 s32 anyAlive = FALSE;
124 s32 i;
125
126 for (i = 0; i < effect->numParts; i++, part++) {
127 if (part->alive) {
128 part->timeLeft--;
129 if (part->timeLeft <= 0) {
130 part->alive = FALSE;
131 } else {
132 anyAlive = TRUE;
135 }
136 }
137 }
138
139 if (!anyAlive) {
140 remove_effect(effect);
141 }
142}
143
145 RenderTask renderTask;
146 RenderTask* queuedTaskPtr;
147
149 renderTask.appendGfxArg = effect;
150 renderTask.dist = 0;
152
153 queuedTaskPtr = queue_render_task(&renderTask);
155}
156
158 remove_effect(effect);
159}
160
161void flower_trail_appendGfx(void* argEffect) {
162 EffectInstance* effect = argEffect;
163 FlowerFXData* part = effect->data.flowerTrail;
164 Gfx* dlist;
165 s32 i;
166
167 gDPPipeSync(gMainGfxPos++);
168 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(effect->graphics->data));
169
170 for (i = 0; i < effect->numParts; i++, part++) {
171 if (part->alive) {
172 if (part->useAltColor) {
173 dlist = D_09000E20_32DCE0;
174 } else {
175 dlist = D_09000E38_32DCF8;
176 }
177
179
180 gDPPipeSync(gMainGfxPos++);
181 gDPSetPrimColor(gMainGfxPos++, 0, 0, 112, 96, 24, part->primAlpha);
183 G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
184 gSPDisplayList(gMainGfxPos++, dlist);
185 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
186 }
187 }
188 gDPPipeSync(gMainGfxPos++);
189}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define general_heap_malloc
#define guRotateF
#define queue_render_task
#define guMtxF2L
#define sin_deg
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define rand_int
#define clamp_angle
#define cos_deg
#define create_effect_instance
#define mem_clear
#define guScaleF
s8 useAltColor
Definition effects.h:67
f32 integrator[4]
Definition effects.h:77
Vec3f rot
Definition effects.h:71
f32 velScaleA
Definition effects.h:73
struct FlowerFXData * flowerTrail
Definition effects.h:2473
u16 triggeredByNpc
Definition effects.h:64
struct EffectGraphics * graphics
Definition effects.h:2606
Mtx transformMtx
Definition effects.h:72
s16 timeLeft
Definition effects.h:65
f32 visibilityAmt
Definition effects.h:75
Vec3f scale
Definition effects.h:70
Vec3f pos
Definition effects.h:69
f32 velScaleB
Definition effects.h:74
EffectData data
Definition effects.h:2605
VecXZf vel
Definition effects.h:78
#define ASSERT(condition)
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ RENDER_MODE_PASS_THROUGH
Definition enums.h:3306
@ ACTION_STATE_IDLE
Definition enums.h:2426
Gfx D_09000E20_32DCE0[]
void flower_trail_render(EffectInstance *effect)
void flower_trail_update(EffectInstance *effect)
Gfx D_09000E38_32DCF8[]
void flower_trail_update_part(FlowerFXData *effect)
void flower_trail_appendGfx(void *effect)
void flower_trail_init(EffectInstance *effect)
void flower_trail_dispose(EffectInstance *effect)
void flower_trail_update_part_transform(FlowerFXData *effect)
void flower_trail_main(s32 triggeredByNpc, f32 posX, f32 posY, f32 posZ, f32 angle, f32 direction)
#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
PlayerStatus gPlayerStatus
Definition 77480.c:39
DisplayContext * gDisplayContext
Definition cam_main.c:16