Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
sun.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Gfx D_09000898_40C438[];
5extern Gfx D_09000980_40C520[];
6extern Gfx D_09000998_40C538[];
7extern Gfx D_090009B0_40C550[];
8extern Gfx D_090009C8_40C568[];
9extern Gfx D_090009E0_40C580[];
10
15
17
18void sun_init(EffectInstance* effect);
19void sun_update(EffectInstance* effect);
20void sun_render(EffectInstance* effect);
21void sun_appendGfx(void* effect);
22
23EffectInstance* sun_main(s32 shineFromRight, f32 offsetX, f32 offsetY, f32 offsetZ, f32 arg4, s32 duration) {
25 EffectInstance* effect;
26 SunFXData* data;
27 s32 numParts = 1;
28 s32 i;
29
30 bp.init = sun_init;
31 bp.update = sun_update;
33 bp.unk_00 = 0;
34 bp.renderUI = NULL;
35 bp.effectID = EFFECT_SUN;
36
37 effect = create_effect_instance(&bp);
38 effect->numParts = numParts;
39
40 data = effect->data.sun = general_heap_malloc(sizeof(*data));
41 ASSERT(data != NULL);
42
43 data->shineFromRight = shineFromRight;
44 data->lifeTime = 0;
45 if (duration <= 0) {
46 data->timeLeft = 1000;
47 } else {
48 data->timeLeft = duration;
49 }
50 data->pos.x = offsetX;
51 data->pos.y = offsetY;
52 data->pos.z = offsetZ;
53 data->unk_34 = arg4;
54 data->primColor.r = 255;
55 data->primColor.g = 255;
56 data->primColor.b = 255;
57 data->envColor.r = 255;
58 data->envColor.g = 255;
59 data->envColor.b = 255;
60 data->envColor.a = 255;
61
62 for (i = 0; i < ARRAY_COUNT(data->texScrollAmt); i++) {
63 data->texScrollAmt[i] = 0.0f;
64 }
65 data->targetAlpha = 255;
66 data->alpha = 0;
67
68 return effect;
69}
70
71void sun_init(EffectInstance* effect) {
72}
73
75 SunFXData* data = effect->data.sun;
76 s32 time;
77 s32 i;
78
79 if (effect->flags & FX_INSTANCE_FLAG_DISMISS) {
80 effect->flags &= ~FX_INSTANCE_FLAG_DISMISS;
81 data->timeLeft = 16;
82 }
83 if (data->timeLeft < 1000) {
84 data->timeLeft--;
85 }
86
87 data->lifeTime++;
88 if (data->lifeTime > 90*60*60) {
89 data->lifeTime = 256;
90 }
91 if (data->timeLeft < 0) {
92 remove_effect(effect);
93 return;
94 }
95
96 time = data->lifeTime;
97 if (data->timeLeft < 16) {
98 data->alpha -= 16;
99 if (data->alpha < 0) {
100 data->alpha = 0;
101 }
102 }
103 if (data->targetAlpha < 0) {
104 data->targetAlpha = 0;
105 } else if (data->targetAlpha > 255) {
106 data->targetAlpha = 255;
107 }
108
109 if (data->alpha > data->targetAlpha) {
110 data->alpha -= 8;
111 if (data->alpha < data->targetAlpha) {
112 data->alpha = data->targetAlpha;
113 }
114 } else if (data->alpha < data->targetAlpha) {
115 data->alpha += 8;
116 if (data->targetAlpha < data->alpha) {
117 data->alpha = data->targetAlpha;
118 }
119 }
120
121 for (i = 0; i < ARRAY_COUNT(data->texScrollAmt); i++) {
122 data->texScrollAmt[i] -= 4.0
123 * ((sin_deg((time * 2 + (20 * i))) * 0.01) + 0.05)
124 * sin_deg(((f32) time * 0.25) + (SQ(i) * 20));
125
126 if (data->texScrollAmt[i] < 0.0f) {
127 data->texScrollAmt[i] += 256.0f;
128 }
129 if (data->texScrollAmt[i] > 256.0f) {
130 data->texScrollAmt[i] -= 256.0f;
131 }
132 }
133}
134
136 RenderTask renderTask;
137 RenderTask* retTask;
138
139 renderTask.appendGfx = sun_appendGfx;
140 renderTask.appendGfxArg = effect;
141 renderTask.dist = 10;
143
144 retTask = queue_render_task(&renderTask);
146}
147
148void sun_appendGfx(void* argEffect) {
149 EffectInstance* effect = (EffectInstance*) argEffect;
150 SunFXData* data;
151 Matrix4f mtx;
152 Matrix4f mtxUnused;
153 s32 alpha;
154 s32 offsetS;
155 s32 fromRight;
156 s32 i;
157
158 data = effect->data.sun;
159 alpha = data->alpha;
160 fromRight = data->shineFromRight;
161
162 if (alpha != 0) {
163 gDPPipeSync(gMainGfxPos++);
164 gSPSegment(gMainGfxPos++, 0x9, VIRTUAL_TO_PHYSICAL(effect->graphics->data));
165
166 if (!fromRight) {
167 guOrthoF(mtx, -1600.0f, 1600.0f, -1200.0f, 1200.0f, -100.0f, 100.0f, 1.0f);
168 } else {
169 guOrthoF(mtx, 1600.0f, -1600.0f, -1200.0f, 1200.0f, -100.0f, 100.0f, 1.0f);
170 }
171
174 G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
175 guTranslateF(mtx, 0.0f, 0.0f, 0.0f);
178 G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
179
180 gDPSetPrimColor(gMainGfxPos++, 0, 0, data->primColor.r, data->primColor.g, data->primColor.b, alpha >> 1);
181 gDPSetEnvColor(gMainGfxPos++, data->envColor.r, data->envColor.g, data->envColor.b, data->envColor.a);
182 gSPDisplayList(gMainGfxPos++, D_E0120794[0]);
183
184 for (i = 0; i < ARRAY_COUNT(data->texScrollAmt); i++) {
185 offsetS = data->texScrollAmt[i] * 4.0f;
186 gDPSetTileSize(gMainGfxPos++, 1, offsetS + (44 * i), 0, offsetS + (44 * i) + 252, 124);
187 gSPDisplayList(gMainGfxPos++, D_E0120780[i]);
188 }
189 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
191 G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
192 gDPPipeSync(gMainGfxPos++);
193 }
194}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define general_heap_malloc
#define guOrthoF
#define queue_render_task
#define guMtxF2L
#define sin_deg
#define guTranslateF
#define remove_effect
#define create_effect_instance
Color_RGB8 primColor
Definition effects.h:2373
s32 alpha
Definition effects.h:2378
Vec3f pos
Definition effects.h:2370
f32 unk_34
Definition effects.h:2377
struct SunFXData * sun
Definition effects.h:2594
s32 lifeTime
Definition effects.h:2372
f32 texScrollAmt[5]
Definition effects.h:2376
Color_RGBA8 envColor
Definition effects.h:2374
struct EffectGraphics * graphics
Definition effects.h:2606
s32 shineFromRight
Definition effects.h:2369
s32 targetAlpha
Definition effects.h:2379
EffectData data
Definition effects.h:2605
s32 timeLeft
Definition effects.h:2371
#define ASSERT(condition)
@ FX_INSTANCE_FLAG_DISMISS
Definition enums.h:3517
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define SQ(x)
Definition macros.h:166
#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 *)
void sun_update(EffectInstance *effect)
Definition sun.c:74
Gfx D_09000898_40C438[]
void sun_render(EffectInstance *effect)
Definition sun.c:135
Gfx D_090009C8_40C568[]
Gfx * D_E0120780[]
Definition sun.c:11
Gfx D_090009E0_40C580[]
Gfx D_09000980_40C520[]
EffectInstance * sun_main(s32 shineFromRight, f32 offsetX, f32 offsetY, f32 offsetZ, f32 arg4, s32 duration)
Definition sun.c:23
void sun_init(EffectInstance *effect)
Definition sun.c:71
Gfx * D_E0120794[]
Definition sun.c:16
Gfx D_09000998_40C538[]
Gfx D_090009B0_40C550[]
void sun_appendGfx(void *effect)
Definition sun.c:148
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