Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
flame.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3#include "nu/nusys.h"
4
5typedef struct FlamePreset {
7 /* 0x03 */ s8 keyCenter;
8 /* 0x04 */ Color_RGB8 envColor;
9 /* 0x07 */ s8 primIntensity;
10 /* 0x08 */ u8 sizeScale;
11 /* 0x0C */ Gfx* dlist;
12} FlamePreset; // size = 0x10
13
14extern Gfx D_09000800_3543B0[];
15extern Gfx D_090008F8_3544A8[]; //TODO rename EffectGfx_Flame_DrawQuad
16extern Gfx D_09000918_3544C8[];
17extern Gfx D_090009E0_354590[];
18
21 .colorScale = { 255, 109, 255 },
22 .keyCenter = 92,
23 .envColor = { 102, 191, 255 },
24 .primIntensity = 75,
25 .sizeScale = 50,
26 .dlist = D_09000800_3543B0,
27 },
28 [FX_FLAME_RED] {
29 .colorScale = { 255, 255, 255 },
30 .keyCenter = 0,
31 .envColor = { 255, 32, 0 },
32 .primIntensity = 75,
33 .sizeScale = 100,
34 .dlist = D_09000800_3543B0,
35 },
37 .colorScale = { 255, 0, 255 },
38 .keyCenter = 92,
39 .envColor = { 107, 168, 255 },
40 .primIntensity = 75,
41 .sizeScale = 10,
42 .dlist = D_09000800_3543B0,
43 },
45 .colorScale = { 255, 255, 255 },
46 .keyCenter = 244,
47 .envColor = { 247, 175, 175 },
48 .primIntensity = 22,
49 .sizeScale = 30,
50 .dlist = D_09000800_3543B0,
51 },
52};
53
55
56void flame_init(EffectInstance* effect);
57void flame_update(EffectInstance* effect);
58void flame_render(EffectInstance* effect);
59void flame_appendGfx(void* effect);
60
62 s32 type,
63 f32 arg1,
64 f32 arg2,
65 f32 arg3,
66 f32 arg4,
67 EffectInstance** outEffect
68) {
70 EffectBlueprint* bpPtr = &bp;
71 EffectInstance* effect;
72 FlameFXData* data;
73 s32 numParts = 1;
74
75 if (type > FX_FLAME_PINK) {
76 type = FX_FLAME_PINK;
77 }
78
79 bpPtr->init = flame_init;
80 bpPtr->update = flame_update;
82 bpPtr->unk_00 = 0;
83 bpPtr->renderUI = NULL;
84 bpPtr->effectID = EFFECT_FLAME;
85
86 effect = create_effect_instance(bpPtr);
87 effect->numParts = numParts;
88 data = effect->data.flame = general_heap_malloc(numParts * sizeof(*data));
89 ASSERT(effect->data.flame != NULL);
90
91 data->type = type;
92 data->unk_18 = 0;
93 data->pos.x = arg1;
94 data->pos.y = arg2;
95 data->pos.z = arg3;
96 data->baseScale = arg4 * FlamePresets[type].sizeScale * 0.01;
97 data->unk_1C = 0;
98 data->unk_24 = 0;
99 data->unk_20 = 0;
100 data->scaleW = 1.0f;
101 data->scaleH = 1.0f;
102 data->unk_28 = 1.0f;
103
104 if (outEffect != NULL) {
105 *outEffect = effect;
106 }
107}
108
110}
111
113 FlameFXData* part = effect->data.flame;
114 s32 i;
115
116 for (i = 0; i < effect->numParts; i++, part++) {
117 part->unk_1C += part->unk_20;
118 if (part->unk_1C > 64.0f) {
119 part->unk_1C -= 64.0f;
120 }
121 if (part->unk_1C < 0.0f) {
122 part->unk_1C += 64.0f;
123 }
124
125 part->unk_24 += part->unk_28;
126 if (part->unk_24 > 128.0f) {
127 part->unk_24 -= 128.0f;
128 }
129 if (part->unk_24 < 0.0f) {
130 part->unk_24 += 128.0f;
131 }
132 }
133}
134
136 FlameFXData* data = effect->data.flame;
137 RenderTask renderTask;
138 RenderTask* renderTaskPtr = &renderTask;
139 RenderTask* retTask;
140 s32 outDist;
141 f32 outX;
142 f32 outY;
143 f32 outZ;
144 f32 outW;
145
146 transform_point(gCameras[gCurrentCameraID].mtxPerspective, data->pos.x, data->pos.y, data->pos.z, 1.0f,
147 &outX, &outY, &outZ, &outW);
148
149 outDist = outZ + 5000;
150 if (outDist < 0) {
151 outDist = 0;
152 } else if (outDist > 10000) {
153 outDist = 10000;
154 }
155
156 if (outW < 0.01 && -0.01 < outW) {
157 outDist = 0;
158 }
159
160 renderTaskPtr->appendGfx = flame_appendGfx;
161 renderTaskPtr->dist = -outDist;
162 renderTaskPtr->appendGfxArg = effect;
164
165 queue_render_task(renderTaskPtr);
166}
167
168void flame_appendGfx(void* effect) {
169 FlameFXData* data = ((EffectInstance*)effect)->data.flame;
170 Camera* camera = &gCameras[gCurrentCameraID];
171 s32 type = data->type;
172 s32 uls = data->unk_1C * 4.0f;
173 s32 ult = data->unk_24 * 4.0f;
174 FlamePreset* preset;
175 Matrix4f sp18;
176 Matrix4f sp58;
177 Matrix4f sp98;
178
179 gDPPipeSync(gMainGfxPos++);
180 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
181
184 gSPDisplayList(gMainGfxPos++, D_09000918_3544C8);
185 gDPSetTileSize(gMainGfxPos++, 1, uls, ult, uls + 128, ult + 256);
186 gSPDisplayList(gMainGfxPos++, D_090009E0_354590);
187 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, VIRTUAL_TO_PHYSICAL(nuGfxCfb_ptr));
188 gDPSetScissorFrac(gMainGfxPos++, G_SC_NON_INTERLACE,
189 camera->viewportStartX * 4.0f,
190 camera->viewportStartY * 4.0f,
191 (camera->viewportStartX + camera->viewportW) * 4.0f,
192 (camera->viewportStartY + camera->viewportH) * 4.0f);
193 }
194
195 preset = &FlamePresets[type];
196
197 gSPDisplayList(gMainGfxPos++, preset->dlist);
198 gDPSetKeyR(gMainGfxPos++, preset->keyCenter, preset->colorScale.r, 0);
199 gDPSetKeyGB(gMainGfxPos++, preset->keyCenter, preset->colorScale.g, 0, preset->keyCenter, preset->colorScale.b, 0);
200 gDPSetPrimColor(gMainGfxPos++, 0, 0, preset->primIntensity, preset->primIntensity, preset->primIntensity, 0);
201 gDPSetEnvColor(gMainGfxPos++, preset->envColor.r, preset->envColor.g, preset->envColor.b, 0);
202
203 guTranslateF(sp18, data->pos.x, data->pos.y, data->pos.z);
204 guRotateF(sp58, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
205 guMtxCatF(sp58, sp18, sp98);
206 guScaleF(sp58, data->baseScale * data->scaleW, data->baseScale * data->scaleH, data->baseScale);
207 guMtxCatF(sp58, sp98, sp98);
209
211 G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
212 gSPDisplayList(gMainGfxPos++, D_090008F8_3544A8);
213 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
214 gDPPipeSync(gMainGfxPos++);
215}
u16 * nuGfxCfb_ptr
Definition cam_main.c:14
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define general_heap_malloc
#define transform_point
#define guRotateF
#define queue_render_task
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define create_effect_instance
#define guScaleF
Vec3f pos
Definition effects.h:488
f32 baseScale
Definition effects.h:489
@ FX_FLAME_RED
Definition effects.h:481
@ FX_FLAME_SMALL_BLUE
Definition effects.h:482
@ FX_FLAME_BLUE
Definition effects.h:480
@ FX_FLAME_PINK
Definition effects.h:483
EffectData data
Definition effects.h:2605
struct FlameFXData * flame
Definition effects.h:2496
#define ASSERT(condition)
@ RENDER_MODE_SURFACE_XLU_LAYER1
Definition enums.h:3282
Gfx D_09000800_3543B0[]
Definition flame.c:13
Gfx D_09000918_3544C8[]
s32 LastFlameRenderFrame
Definition flame.c:54
void flame_render(EffectInstance *effect)
Definition flame.c:135
Gfx * dlist
Definition flame.c:11
void flame_update(EffectInstance *effect)
Definition flame.c:112
Color_RGB8 colorScale
Definition flame.c:6
Gfx D_090008F8_3544A8[]
void flame_appendGfx(void *effect)
Definition flame.c:168
FlamePreset FlamePresets[]
Definition flame.c:19
void flame_main(s32 type, f32 arg1, f32 arg2, f32 arg3, f32 arg4, EffectInstance **outEffect)
Definition flame.c:61
u8 sizeScale
Definition flame.c:10
Color_RGB8 envColor
Definition flame.c:8
s8 primIntensity
Definition flame.c:9
Gfx D_090009E0_354590[]
Definition flame.c:37
s8 keyCenter
Definition flame.c:7
void flame_init(EffectInstance *effect)
Definition flame.c:109
#define SCREEN_WIDTH
Definition macros.h:105
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
s16 viewportStartX
s16 viewportStartY
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 *)
GameStatus * gGameStatusPtr
Definition main_loop.c:32
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