Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
bulb_glow.c
Go to the documentation of this file.
1#include "common.h"
2#include "nu/nusys.h"
3#include "effects_internal.h"
4
5typedef struct UnkBulbGlow {
6 /* 0x00 */ s32 unk_00;
7 /* 0x04 */ s32 unk_04;
8 /* 0x08 */ f32 unk_08;
9 /* 0x0C */ f32 unk_0C;
10 /* 0x10 */ s32 unk_10;
11 /* 0x14 */ s32 unk_14;
12} UnkBulbGlow; // size = 0x18
13
14extern Gfx D_09001400_37C1D0[];
15extern Gfx D_090014B8_37C288[];
16extern Gfx D_09001570_37C340[];
17extern Gfx D_09001618_37C3E8[];
18extern Gfx D_090016C0_37C490[];
19
23
25 { 0x00000080, 0x00000080, 0.5f, 0.5f, 0x00000040, 0x00000004 },
26 { 0x00000040, 0x00000040, 2.0f, 2.0f, 0x00000020, 0x00000010 },
27 { 0x00000040, 0x00000040, 1.0f, 1.0f, 0x00000040, 0x00000008 },
28 { 0x00000040, 0x00000040, 2.0f, 2.0f, 0x00000010, 0x00000010 },
29 { 0x00000040, 0x00000040, 1.0f, 1.0f, 0x00000020, 0x00000010 },
30 { 0x00000040, 0x00000040, 1.0f, 1.0f, 0x00000040, 0x00000008 },
31};
32
33s32 D_E00789A8 = 0;
34
36 { 255, 255, 255 },
37 { 255, 255, 128 },
38 { 255, 128, 255 },
39 { 128, 255, 255 },
40 { 255, 128, 128 },
41 { 128, 255, 128 },
42 { 128, 128, 255 },
43};
44
45void bulb_glow_init(EffectInstance* effect);
48void bulb_glow_appendGfx(void* effect);
49
50void bulb_glow_main(s32 arg0, f32 posX, f32 posY, f32 posZ, f32 arg4, EffectInstance** outEffect) {
52 EffectInstance* effect;
53 BulbGlowFXData* data;
54 s32 numParts = 1;
55
59 bp.unk_00 = 0;
60 bp.renderUI = NULL;
61 bp.effectID = EFFECT_BULB_GLOW;
62
63 effect = create_effect_instance(&bp);
64 effect->numParts = numParts;
65 data = effect->data.bulbGlow = general_heap_malloc(numParts * sizeof(*data));
66 ASSERT(effect->data.bulbGlow != NULL);
67
68 data->type = arg0 & 255;
69 if (arg0 < 256) {
70 data->timeLeft = 100;
71 } else {
72 data->timeLeft = 80;
73 }
74 data->lifetime = 0;
75 data->brightness = 127;
76 data->pos.x = posX;
77 data->pos.y = posY;
78 data->pos.z = posZ;
80
81 D_E00789A8++;
82 if (D_E00789A8 >= 16) {
83 D_E00789A8 = 0;
84 }
85
86 data->unk_20 = rand_int(7);
87 *outEffect = effect;
88}
89
91}
92
94 BulbGlowFXData* data = effect->data.bulbGlow;
95 s32 time;
96
97 if (effect->flags & FX_INSTANCE_FLAG_DISMISS) {
98 effect->flags &= ~FX_INSTANCE_FLAG_DISMISS;
99 data->timeLeft = 10;
100 }
101
102 data->lifetime++;
103
104 if (data->timeLeft < 100) {
105 data->timeLeft--;
106 }
107 if (data->timeLeft < 0) {
108 remove_effect(effect);
109 return;
110 }
111
112 time = data->lifetime;
113 if (data->type == 0) {
114 if (time < 11) {
115 data->brightness = (time * 6) + 4;
116 } else {
117 data->brightness = 64;
118 }
119
120 if (time & 1) {
121 data->brightness *= 0.6;
122 }
123
124 if (time >= 15) {
125 data->type = 4;
126 data->brightness = 127;
127 }
128 }
129}
130
132 BulbGlowFXData* data = effect->data.bulbGlow;
133 RenderTask renderTask;
134 RenderTask* renderTaskPtr = &renderTask;
135 RenderTask* retTask;
136
137 renderTask.appendGfxArg = effect;
138 renderTask.appendGfx = bulb_glow_appendGfx;
139 if (data->type == 5) {
140 renderTask.dist = 0;
141 renderTaskPtr->renderMode = RENDER_MODE_SURFACE_OPA;
142 } else {
143 renderTask.dist = -100;
144 renderTaskPtr->renderMode = RENDER_MODE_CLOUD_NO_ZCMP;
145 }
146
147 retTask = queue_render_task(renderTaskPtr);
149}
150
151void func_E0078274(void) {
152}
153
154#define TMEM_ADDR(x) (x / sizeof(u64))
155
156void bulb_glow_appendGfx(void* effect) {
157 BulbGlowFXData* data = ((EffectInstance*)effect)->data.bulbGlow;
158 f32 centerX;
159 f32 centerY;
160 s32 xMin;
161 s32 numRects;
162 s32 yMin;
163 s32 type;
164 s32 rectHeight;
165 s32 glowExtent;
166 s32 colorScale;
167 s32 brightness;
168 s32 yMax;
169 s32 xStart;
170 s32 xMax;
171 s32 isPointVisible;
172 s32 yStart;
173 UnkBulbGlow* temp_s1;
174 Color_RGB8* color;
175 s32 i;
176 s32 j;
177 u8 r, g, b;
178
179 brightness = data->brightness;
180 type = data->type;
181 if (brightness > 127) {
182 brightness = 127;
183 }
184
185 gDPPipeSync(gMainGfxPos++);
186 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
187
188 temp_s1 = &D_E0078918[type];
189 glowExtent = temp_s1->unk_10;
190 rectHeight = temp_s1->unk_14;
191
192 isPointVisible = is_point_visible(data->pos.x, data->pos.y, data->pos.z, data->depthQueryID, &centerX, &centerY);
193
194 if (type == 5) {
195 isPointVisible = TRUE;
196 }
197
198 if (!isPointVisible || centerX < 0.0f || centerY < 0.0f || centerX >= SCREEN_WIDTH || centerY >= SCREEN_HEIGHT) {
199 return;
200 }
201
202 gSPDisplayList(gMainGfxPos++, D_E0078900[type]);
203 color = &D_E00789AC[data->unk_20];
204 colorScale = brightness * 2;
205 r = color->r * colorScale / 255;
206 g = color->g * colorScale / 255;
207 b = color->b * colorScale / 255;
208
209 gDPSetPrimColor(gMainGfxPos++, 0, 0, r, g, b, 127);
210
211 xMin = centerX - glowExtent;
212 xMax = xMin + glowExtent * 2;
213 yMin = centerY - glowExtent;
214 yMax = yMin + glowExtent * 2;
215
216 xStart = 0;
217 if (xMin < 0) {
218 xStart = -xMin;
219 }
220 yStart = 0;
221 if (yMin < 0) {
222 yStart = -yMin;
223 }
224 if (xMax > SCREEN_WIDTH) {
225 xMax = SCREEN_WIDTH - 1;
226 }
227 if (yMax > SCREEN_HEIGHT) {
228 yMax = SCREEN_HEIGHT - 1;
229 }
230
231 numRects = (yMax - yMin) / rectHeight;
232
233 for (i = yStart / rectHeight; i < numRects; i++) {
234 s32 y = yMin + i * rectHeight;
235 if (y + rectHeight >= SCREEN_HEIGHT) {
236 break;
237 }
238
239 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE,
240 (s32) (xMin * temp_s1->unk_08) * 4,
241 (s32) (temp_s1->unk_04 * 20 - i * temp_s1->unk_14 * temp_s1->unk_0C) * 4,
242 (s32) (xMin * temp_s1->unk_08 + temp_s1->unk_00) * 4,
243 (s32) (temp_s1->unk_04 * 21 - i * temp_s1->unk_14 * temp_s1->unk_0C) * 4);
244
245 for (j = 0; j < 1; j++) {
246 gDPLoadMultiTile(gMainGfxPos++,
248 TMEM_ADDR(TMEM_SIZE/2), G_TX_RENDERTILE + 1, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, 0,
249 xMin + xStart, 0, xMax - 1, rectHeight - 1,
250 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 9, 8, G_TX_NOLOD, G_TX_NOLOD);
251 gSPTextureRectangle(gMainGfxPos++,
252 (xMin + xStart) * 4, y * 4,
253 xMax * 4, (y + rectHeight) * 4,
254 G_TX_RENDERTILE,
255 ((xMin + xStart) & 0x1FF) << 5, 0,
256 1 << 10, 1 << 10);
257 gDPPipeSync(gMainGfxPos++);
258 }
259 }
260}
Gfx D_09001400_37C1D0[]
UnkBulbGlow D_E0078918[]
Definition bulb_glow.c:24
void bulb_glow_main(s32 arg0, f32 posX, f32 posY, f32 posZ, f32 arg4, EffectInstance **outEffect)
Definition bulb_glow.c:50
Gfx D_09001570_37C340[]
void bulb_glow_update(EffectInstance *effect)
Definition bulb_glow.c:93
Gfx D_090014B8_37C288[]
Gfx D_09001618_37C3E8[]
Gfx D_090016C0_37C490[]
Color_RGB8 D_E00789AC[]
Definition bulb_glow.c:35
Gfx * D_E0078900[]
Definition bulb_glow.c:20
void bulb_glow_init(EffectInstance *effect)
Definition bulb_glow.c:90
s32 D_E00789A8
Definition bulb_glow.c:33
#define TMEM_ADDR(x)
Definition bulb_glow.c:154
void bulb_glow_render(EffectInstance *effect)
Definition bulb_glow.c:131
void bulb_glow_appendGfx(void *effect)
Definition bulb_glow.c:156
void func_E0078274(void)
Definition bulb_glow.c:151
u16 * nuGfxCfb_ptr
Definition cam_main.c:14
#define general_heap_malloc
#define is_point_visible
#define queue_render_task
#define remove_effect
#define rand_int
#define create_effect_instance
struct BulbGlowFXData * bulbGlow
Definition effects.h:2524
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_SURFACE_OPA
Definition enums.h:3264
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
#define SCREEN_WIDTH
Definition macros.h:105
#define TMEM_SIZE
Definition macros.h:121
#define SCREEN_HEIGHT
Definition macros.h:106
#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