Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
water_block.c File Reference

Go to the source code of this file.

Data Structures

struct  WaterBlockVtxData
 

Functions

void water_block_init (EffectInstance *effect)
 
void water_block_update (EffectInstance *effect)
 
void water_block_render (EffectInstance *effect)
 
void water_block_appendGfx (void *effect)
 
EffectInstancewater_block_main (s32 type, f32 x, f32 y, f32 z, f32 arg4, s32 duration)
 
 EFFECT_DEF_WATER_SPLASH (water_splash_main)
 
void func_E00B4574 (void)
 

Variables

WaterBlockVtxData D_E00B4CF0 []
 
Gfx D_09000300_3B6EF0 []
 
Gfx D_090003B0_3B6FA0 []
 
Gfx D_090004A0_3B7090 []
 
Gfx D_090004D8_3B70C8 []
 
Gfx D_09000538_3B7128 []
 

Data Structure Documentation

◆ WaterBlockVtxData

struct WaterBlockVtxData
Data Fields
Vec3b pos
s16 normX
s16 normY
Color_RGB8 color

Function Documentation

◆ water_block_init()

void water_block_init ( EffectInstance * effect)

Definition at line 111 of file water_block.c.

111 {
112}

Referenced by water_block_main().

◆ water_block_update()

void water_block_update ( EffectInstance * effect)

Definition at line 116 of file water_block.c.

116 {
117 WaterBlockFXData *data;
118 f32 temp_f20;
119 s32 type;
120 s32 time;
121 s32 timeLeft;
122 s32 i;
123
124 data = effect->data.waterBlock;
125 type = data->type;
126 if (effect->flags & FX_INSTANCE_FLAG_DISMISS) {
127 if (type == FX_WATER_BLOCK_DESTROY) {
128 effect->flags = effect->flags & ~FX_INSTANCE_FLAG_DISMISS;
129 data->timeLeft = 4;
130 } else {
131 effect->flags = effect->flags & ~FX_INSTANCE_FLAG_DISMISS;
132 data->timeLeft = 16;
133 }
134 }
135
136 if (data->timeLeft < 1000) {
137 data->timeLeft--;
138 }
139
140 data->lifetime++;
141 if (data->lifetime > 90 * 60 * 60) {
142 data->lifetime = 256;
143 }
144
145 timeLeft = data->timeLeft;
146 if (timeLeft < 0) {
147 if (type == FX_WATER_BLOCK_DESTROY) {
148 load_effect(EFFECT_WATER_SPLASH);
149 water_splash_main(0, data->pos.x, data->pos.y + 24.0f, data->pos.z, 2.0f, 30);
150 water_splash_main(1, data->pos.x, data->pos.y + 24.0f, data->pos.z, 2.0f, 30);
151 }
152 remove_effect(effect);
153 return;
154 }
155
156 time = data->lifetime;
157 if (type == FX_WATER_BLOCK_CREATE) {
158 if (timeLeft < 16) {
159 data->color.a = timeLeft * 16;
160 data->alpha = timeLeft * 16;
161 }
162 if (time < 16) {
163 data->color.a = (time * 16) + 15;
164 data->alpha = (time * 16) + 15;
165 }
166 } else if (time < 4) {
167 data->color.a = (time * 64) + 63;
168 data->alpha = (time * 64) + 63;
169 }
170
171 data->color.g = sin_deg((time * 6) + time) * 32.0f + 127.0f;
172 temp_f20 = (f32)time * 0.01;
173 data->unk_30 = (sin_deg(temp_f20 * 6.0f) * 32.0f * sin_deg(temp_f20)) + 256.0f + (cos_deg(2.0f * temp_f20) * 32.0f) + (cos_deg(temp_f20) * 32.0f);
174 data->unk_34 += 0.2;
175 if (data->unk_34 >= 128.0f) {
176 data->unk_34 = 0.0f;
177 }
178
179 for (i = 0; i < NUM_WATER_BLOCK_COMPONENTS; i++) {
180 data->unk_88[i]++;
181 if (data->unk_88[i] >= 0) {
182 if (data->unk_88[i] == 0) {
183 data->unk_38[i] = 0.0f;
184 data->unk_48[i] = 240.0f;
185 data->unk_58[i] = (rand_int(10) - 5) * 0.2;
186 data->unk_68[i] = rand_int(10) + 2;
187 data->unk_78[i] = rand_int(10) + 1;
188 }
189 data->unk_48[i] += data->unk_68[i];
190 data->unk_38[i] += data->unk_58[i];
191 data->unk_58[i] *= 0.97;
192 data->unk_68[i] += (10.0f - data->unk_68[i]) * 0.1;
193 if (data->unk_48[i] > 480.0f) {
194 data->unk_88[i] = ~rand_int(10);
195 }
196 }
197 }
198}
#define sin_deg
#define remove_effect
#define rand_int
#define load_effect
#define cos_deg
struct WaterBlockFXData * waterBlock
Definition effects.h:2554
@ FX_WATER_BLOCK_DESTROY
Definition effects.h:1540
@ FX_WATER_BLOCK_CREATE
Definition effects.h:1539
#define NUM_WATER_BLOCK_COMPONENTS
Definition effects.h:1543
EffectData data
Definition effects.h:2605
@ FX_INSTANCE_FLAG_DISMISS
Definition enums.h:3517
EffectInstance * water_splash_main(s32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, s32 arg5)

Referenced by water_block_main().

◆ water_block_render()

void water_block_render ( EffectInstance * effect)

Definition at line 200 of file water_block.c.

200 {
201 RenderTask renderTask;
202 RenderTask* retTask;
203
204 renderTask.appendGfx = water_block_appendGfx;
205 renderTask.appendGfxArg = effect;
206 renderTask.dist = 20;
208
209 retTask = queue_render_task(&renderTask);
211}
#define queue_render_task
void water_block_appendGfx(void *effect)
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
void * appendGfxArg
void(* appendGfx)(void *)

Referenced by water_block_main().

◆ water_block_appendGfx()

void water_block_appendGfx ( void * effect)

Definition at line 216 of file water_block.c.

216 {
217 Matrix4f sp20;
218 Matrix4f sp60;
219 WaterBlockFXData* data = ((EffectInstance*)effect)->data.waterBlock;
220 s32 alpha = data->color.a;
221 Vtx* vtxBase;
222 EffectInstance* effectTemp = effect;
223 WaterBlockVtxData* vtxData;
224 Vtx* curVtx;
225 s32 timePhase;
226 s32 i;
227
228 gDPPipeSync(gMainGfxPos++);
229 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(effectTemp->graphics->data));
230 guTranslateF(sp20, data->pos.x, data->pos.y, data->pos.z);
232
233 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
234
235 gSPBranchList(gMainGfxPos, &gMainGfxPos[81]);
236 vtxBase = (Vtx*)++gMainGfxPos;
238
239 timePhase = gGameStatusPtr->frameCounter * 4;
240
241 for (vtxData = D_E00B4CF0, i = 0, curVtx = vtxBase; i < ARRAY_COUNT(D_E00B4CF0); i++, vtxData++, curVtx++) {
242 f32 x = vtxData->pos.x * 10;
243 f32 y = vtxData->pos.y * 10;
244 f32 z = vtxData->pos.z * 10;
245
246 if (y != 0.0f) {
247 f32 dx = sin_deg(timePhase + effect_simple_rand(1000, (x + (y * 10.0f) + (z * 100.0f)))) * 20.0f;
248 f32 dy = sin_deg(timePhase + effect_simple_rand(1000, ((x * 10.0f) + (y * 100.0f) + z))) * 20.0f;
249 f32 dz = sin_deg(timePhase + effect_simple_rand(1000, ((x * 100.0f) + y + (z * 10.0f)))) * 20.0f;
250 x += dx;
251 y += dy;
252 z += dz;
253 }
254
255 curVtx->v.ob[0] = x;
256 curVtx->v.ob[1] = y;
257 curVtx->v.ob[2] = z;
258
259 curVtx->v.tc[0] = vtxData->normX;
260 curVtx->v.tc[1] = vtxData->normY;
261
262 curVtx->v.cn[0] = vtxData->color.r;
263 curVtx->v.cn[1] = vtxData->color.g;
264 curVtx->v.cn[2] = vtxData->color.b;
265 curVtx->v.cn[3] = 80;
266 }
267
268 guScaleF(sp20, 0.1f, 0.1f, 0.1f);
270
271 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
272 gDPSetEnvColor(gMainGfxPos++, 0, 0, 255, data->alpha);
273 gDPSetPrimColor(gMainGfxPos++, 0, 0, 255, 255, 255, alpha);
274 gSPDisplayList(gMainGfxPos++, D_090003B0_3B6FA0);
275
276 for (i = 0; i < NUM_WATER_BLOCK_COMPONENTS; i++) {
277 if (data->unk_88[i] >= 0) {
278 guPositionF(sp20, 0.0f, 0.0f, 0.0f, data->unk_78[i], data->unk_38[i], data->unk_48[i], 0.0f);
280 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
281 gSPDisplayList(gMainGfxPos++, D_090004A0_3B7090);
282 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
283 }
284 }
285
286 gSPDisplayList(gMainGfxPos++, D_09000300_3B6EF0);
287 gDPSetPrimColor(gMainGfxPos++, 0, 0, data->color.r, data->color.g, data->color.b, alpha * 0.3);
288 gSPClearGeometryMode(gMainGfxPos++, G_CULL_BOTH);
289 gSPSetGeometryMode(gMainGfxPos++, G_CULL_BACK);
290
291 gSPVertex(gMainGfxPos++, vtxBase, 30, 0);
292
293 gSPDisplayList(gMainGfxPos++, D_090004D8_3B70C8);
294
295 gSPVertex(gMainGfxPos++, &vtxBase[28], 12, 0);
296
297 gSPDisplayList(gMainGfxPos++, D_09000538_3B7128)
298 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
299 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
300}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define guMtxF2L
#define guTranslateF
#define guPositionF
#define guScaleF
Gfx D_09000538_3B7128[]
Gfx D_090004D8_3B70C8[]
Gfx D_09000300_3B6EF0[]
WaterBlockVtxData D_E00B4CF0[]
Definition water_block.c:11
Gfx D_090003B0_3B6FA0[]
Gfx D_090004A0_3B7090[]
struct EffectGraphics * graphics
Definition effects.h:2606
s32 effect_simple_rand(s32, s32)
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16

Referenced by water_block_render().

◆ water_block_main()

EffectInstance * water_block_main ( s32 type,
f32 x,
f32 y,
f32 z,
f32 arg4,
s32 duration )

Definition at line 65 of file water_block.c.

65 {
67 EffectBlueprint* bpPtr = &bp;
68 EffectInstance* effect;
69 WaterBlockFXData* data;
70 s32 i;
71 s32 var_a1;
72 s32 numParts = 1;
73
74 bpPtr->init = water_block_init;
75 bpPtr->update = &water_block_update;
77 bpPtr->unk_00 = 0;
78 bpPtr->renderUI = NULL;
79 bpPtr->effectID = EFFECT_WATER_BLOCK;
80
81 effect = create_effect_instance(bpPtr);
82 effect->numParts = numParts;
83 data = effect->data.waterBlock = general_heap_malloc(sizeof(*data));
84 ASSERT(data != NULL);
85
86 data->type = type;
87 data->lifetime = 0;
88 if (duration <= 0) {
89 data->timeLeft = 1000;
90 } else {
91 data->timeLeft = duration;
92 }
93
94 data->color.a = 0;
95 data->pos.x = x;
96 data->pos.y = y;
97 data->pos.z = z;
98 data->unk_2C = arg4;
99 data->color.r = 47;
100 data->color.g = 127;
101 data->color.b = 255;
102 data->unk_30 = 0.0f;
103 data->unk_34 = 0.0f;
104
105 for (i = NUM_WATER_BLOCK_COMPONENTS - 1, var_a1 = -13; i >= 0; var_a1 += 4, i--) {
106 data->unk_88[i] = var_a1;
107 }
108 return effect;
109}
#define general_heap_malloc
#define create_effect_instance
void water_block_update(EffectInstance *effect)
void water_block_init(EffectInstance *effect)
void water_block_render(EffectInstance *effect)
#define ASSERT(condition)
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

◆ EFFECT_DEF_WATER_SPLASH()

EFFECT_DEF_WATER_SPLASH ( water_splash_main )

◆ func_E00B4574()

void func_E00B4574 ( void )

Definition at line 213 of file water_block.c.

213 {
214}

Variable Documentation

◆ D_E00B4CF0

WaterBlockVtxData D_E00B4CF0[]

Definition at line 11 of file water_block.c.

11 {
12 {{ 25, 4, -25 }, 1025, 72, { 176, 176, 176 }},
13 {{ 22, 0, -22 }, 963, 0, { 176, 176, 176 }},
14 {{-22, 0, -22 }, 61, 0, { 176, 176, 176 }},
15 {{-25, 4, -25 }, 1, 72, { 176, 176, 176 }},
16 {{ 25, 46, -25 }, 1025, 951, { 176, 176, 176 }},
17 {{-25, 46, -25 }, 1, 951, { 176, 176, 176 }},
18 {{ 22, 50, -22 }, 890, 997, { 174, 208, 216 }},
19 {{-22, 50, -22 }, 133, 997, { 174, 208, 216 }},
20 {{-22, 50, 22 }, 133, 997, { 174, 208, 216 }},
21 {{ 22, 50, 22 }, 890, 997, { 174, 208, 216 }},
22 {{-22, 0, -22 }, 133, 25, { 148, 165, 176 }},
23 {{ 22, 0, -22 }, 890, 25, { 148, 165, 176 }},
24 {{ 22, 0, 22 }, 890, 25, { 148, 165, 176 }},
25 {{-22, 0, 22 }, 133, 25, { 148, 165, 176 }},
26 {{-22, 50, 22 }, 963, 1021, { 120, 110, 136 }},
27 {{-22, 50, -22 }, 61, 1021, { 120, 110, 136 }},
28 {{-25, 46, -25 }, 0, 951, { 120, 110, 136 }},
29 {{-25, 46, 25 }, 1024, 951, { 120, 110, 136 }},
30 {{-25, 4, -25 }, 0, 72, { 120, 110, 136 }},
31 {{-25, 4, 25 }, 1024, 72, { 120, 110, 136 }},
32 {{-22, 0, -22 }, 61, 0, { 120, 110, 136 }},
33 {{-22, 0, 22 }, 963, 0, { 120, 110, 136 }},
34 {{-22, 50, -22 }, 61, 1021, { 176, 176, 176 }},
35 {{ 22, 50, -22 }, 963, 1021, { 176, 176, 176 }},
36 {{ 22, 0, 22 }, 963, 0, { 120, 110, 136 }},
37 {{ 22, 0, -22 }, 61, 0, { 120, 110, 136 }},
38 {{ 25, 4, -25 }, 0, 72, { 120, 110, 136 }},
39 {{ 25, 4, 25 }, 1024, 72, { 120, 110, 136 }},
40 {{ 25, 46, -25 }, 0, 951, { 120, 110, 136 }},
41 {{ 25, 46, 25 }, 1024, 951, { 120, 110, 136 }},
42 {{ 22, 50, -22 }, 61, 1021, { 120, 110, 136 }},
43 {{-22, 0, 22 }, 61, 0, { 240, 240, 240 }},
44 {{ 25, 4, 25 }, 1025, 72, { 240, 240, 240 }},
45 {{ 25, 46, 25 }, 1025, 951, { 240, 240, 240 }},
46 {{ 22, 50, 22 }, 963, 1021, { 120, 110, 136 }},
47 {{ 22, 0, 22 }, 963, 0, { 240, 240, 240 }},
48 {{-25, 4, 25 }, 1, 72, { 240, 240, 240 }},
49 {{-25, 46, 25 }, 1, 951, { 240, 240, 240 }},
50 {{ 22, 50, 22 }, 963, 1021, { 240, 240, 240 }},
51 {{-22, 50, 22 }, 61, 1021, { 240, 240, 240 }},
52};

Referenced by water_block_appendGfx().

◆ D_09000300_3B6EF0

Gfx D_09000300_3B6EF0[]
extern

Referenced by water_block_appendGfx().

◆ D_090003B0_3B6FA0

Gfx D_090003B0_3B6FA0[]
extern

Referenced by water_block_appendGfx().

◆ D_090004A0_3B7090

Gfx D_090004A0_3B7090[]
extern

Referenced by water_block_appendGfx().

◆ D_090004D8_3B70C8

Gfx D_090004D8_3B70C8[]
extern

Referenced by water_block_appendGfx().

◆ D_09000538_3B7128

Gfx D_09000538_3B7128[]
extern

Referenced by water_block_appendGfx().