Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
effects.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects.h"
3#include "ld_addrs.h"
4
5typedef s8 TlbEntry[0x1000];
7
8#define EFFECT_GLOBALS_TLB_IDX 0x10
9
12
14extern Addr gEffectGlobals;
15
16#define FX_ENTRY(name, gfx_name) { \
17 .entryPoint = name##_main, \
18 .dmaStart = effect_##name##_ROM_START, \
19 .dmaEnd = effect_##name##_ROM_END, \
20 .dmaDest = effect_##name##_VRAM, \
21 .graphicsDmaStart = gfx_name##_ROM_START, \
22 .graphicsDmaEnd = gfx_name##_ROM_END, \
23}
24
25#include "effects/effect_table.c"
26
27s32 D_8007FEB8[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 5, 3, 4, 13, 60, 0, 512, 0, 0, 3, 0 };
28
32
34 s32* data = effect->data.any;
35
36 ((f32*)data)[1] = x;
37 ((f32*)data)[2] = y;
38 ((f32*)data)[3] = z;
39}
40
42 s32 i;
43
44 for (i = 0; i < ARRAY_COUNT(gEffectSharedData); i++) {
46 }
47
48 for (i = 0; i < ARRAY_COUNT(gEffectInstances); i++) {
50 }
51
55}
56
57void func_80059D48(void) {
58}
59
60void update_effects(void) {
63 s32 i;
64
65 // reset free delay for each EffectSharedData touched in previous update
67 if (sharedData->flags & FX_SHARED_DATA_LOADED) {
68 if (!(sharedData->flags & FX_SHARED_DATA_CAN_FREE)) {
70 sharedData->freeDelay = 3;
71 }
72 }
73 }
74
75 // update each EffectInstances
76 for (i = 0; i < ARRAY_COUNT(gEffectInstances); i++) {
78
81
84 effectInstance->shared->update(effectInstance);
86 }
87 } else {
89 effectInstance->shared->update(effectInstance);
91 }
92 }
93 }
94 }
95
96 // free any EffectSharedData which haven't been used recently
98 if (sharedData->flags & FX_SHARED_DATA_LOADED) {
100 if (sharedData->freeDelay != 0) {
101 sharedData->freeDelay--;
102 } else {
103 if (sharedData->graphics != NULL) {
104 general_heap_free(sharedData->graphics);
105 sharedData->graphics = NULL;
106 }
107 sharedData->flags = 0;
108 osUnmapTLB(i);
109 }
110 }
111 }
112 }
113 }
114}
115
117 s32 i;
118
119 for (i = 0; i < ARRAY_COUNT(gEffectInstances); i++) {
121
122 if (effectInstance != NULL) {
128 }
129 } else {
130 if (!(effectInstance->flags & FX_INSTANCE_FLAG_BATTLE)) {
131 effectInstance->shared->renderScene(effectInstance);
132 }
133 }
134 }
135 }
136 }
137 }
138}
139
141 s32 cond = TRUE;
142 s32 i;
143
144 for (i = 0; i < ARRAY_COUNT(gEffectInstances); i++) {
146
147 if (effectInstance != NULL) {
150 void (*renderUI)(EffectInstance* effect);
151
153 continue;
154 }
155
157 continue;
158 }
159
160 renderUI = effectInstance->shared->renderUI;
161 if (renderUI != stub_effect_delegate) {
162 if (cond) {
164
169 G_SHADING_SMOOTH | G_CLIPPING | 0x40F9FA);
172 camera->viewportStartX,
173 camera->viewportStartY,
174 camera->viewportStartX + camera->viewportW,
175 camera->viewportStartY + camera->viewportH);
177
178 cond = FALSE;
179 if (!(camera->flags & CAMERA_FLAG_ORTHO)) {
180 gSPPerspNormalize(gMainGfxPos++, camera->perspNorm);
183 }
184 }
185
186 renderUI(effectInstance);
187 }
188 }
189 }
190 }
191 }
192}
193
197 s32 i;
198
199 // Search for an unused instance
200 for (i = 0; i < ARRAY_COUNT(gEffectInstances); i++) {
201 if (gEffectInstances[i] == NULL) {
202 break;
203 }
204 }
205
207
208 // Allocate space for the new instance
211
213 newEffectInst->effectID = effectBp->effectID;
215
216 // Look for a loaded effect of the proper index
217 for (i = 0; i < ARRAY_COUNT(gEffectSharedData); i++) {
218 if ((sharedData->flags & FX_SHARED_DATA_LOADED) && (sharedData->effectIndex == effectBp->effectID)) {
219 break;
220 }
221 sharedData++;
222 }
223
225
226 // If this is the first new instance of the effect, initialize the function pointers
227 if (sharedData->instanceCounter == 0) {
228 sharedData->update = effectBp->update;
229 if (sharedData->update == NULL) {
230 sharedData->renderScene = stub_effect_delegate;
231 }
232
233 sharedData->renderScene = effectBp->renderScene;
234 if (sharedData->renderScene == NULL) {
235 sharedData->renderScene = stub_effect_delegate;
236 }
237
238 sharedData->renderUI = effectBp->renderUI;
239 if (sharedData->renderUI == NULL) {
241 }
242 }
243
244 sharedData->instanceCounter++;
245 newEffectInst->shared = sharedData;
246
247 if (effectBp->init != NULL) {
248 effectBp->init(newEffectInst);
249 }
250
253 }
254 return newEffectInst;
255}
256
258 s32 i;
259
260 for (i = 0; i < ARRAY_COUNT(gEffectInstances); i++) {
262 break;
263 }
264 }
265
267
268 if (effectInstance->data.any == NULL) {
271 } else {
275 }
276}
277
279 s32 i;
280
281 for (i = 0; i < ARRAY_COUNT(gEffectInstances); i++) {
282 EffectInstance* effect = gEffectInstances[i];
283
284 if (effect != NULL && effect->flags & FX_INSTANCE_FLAG_BATTLE) {
285 if (effect->data.any != NULL) {
286 general_heap_free(effect->data.any);
287 }
288 general_heap_free(effect);
290 }
291 }
292}
293
294s32 load_effect(s32 effectIndex) {
297 s32 i;
298
299 // Look for a loaded effect matching the desired index
300 for (i = 0, sharedData = &gEffectSharedData[0]; i < ARRAY_COUNT(gEffectSharedData); i++) {
301 if (sharedData->flags & FX_SHARED_DATA_LOADED && sharedData->effectIndex == effectIndex) {
302 break;
303 }
304 sharedData++;
305 }
306
307 // If an effect was found within the table, initialize it and return
309 sharedData->effectIndex = effectIndex;
310 sharedData->instanceCounter = 0;
312 return 1;
313 }
314
315 // If a loaded effect wasn't found, look for the first empty space
316 for (i = 0, sharedData = &gEffectSharedData[0]; i < ARRAY_COUNT(gEffectSharedData); i++) {
317 if (!(sharedData->flags & FX_SHARED_DATA_LOADED)) {
318 break;
319 }
320 sharedData++;
321 }
322
323 // If no empty space was found, panic
325
326 // Map space for the effect
327 osMapTLB(i, OS_PM_4K, effectEntry->dmaDest, (s32)(gEffectDataBuffer[i]) & 0xFFFFFF, -1, -1);
328
329 // Copy the effect into the newly mapped space
330 dma_copy(effectEntry->dmaStart, effectEntry->dmaEnd, effectEntry->dmaDest);
331
332 // If there's graphics data for the effect, allocate space and copy into the new space
333 if (effectEntry->graphicsDmaStart != NULL) {
334 void* graphics = general_heap_malloc(effectEntry->graphicsDmaEnd - effectEntry->graphicsDmaStart);
335 sharedData->graphics = graphics;
336 ASSERT(graphics != NULL);
337 dma_copy(effectEntry->graphicsDmaStart, effectEntry->graphicsDmaEnd, sharedData->graphics);
338 }
339
340 // Initialize the newly loaded effect data
341 sharedData->effectIndex = effectIndex;
342 sharedData->instanceCounter = 0;
344 return 1;
345}
BSS s32 PopupMenu_SelectedIndex
#define general_heap_malloc
#define remove_effect
#define load_effect
#define create_effect_instance
EffectInstance * gEffectInstances[96]
Definition effects.c:11
s32 D_8007FEB8[]
Definition effects.c:27
Addr gEffectGlobals
void update_effects(void)
Definition effects.c:60
void func_80059D48(void)
Definition effects.c:57
void remove_all_effects(void)
Definition effects.c:278
void set_effect_pos_offset(EffectInstance *effect, f32 x, f32 y, f32 z)
Definition effects.c:33
void stub_effect_delegate(EffectInstance *effect)
Used for unbound function points in effect structs.
Definition effects.c:30
void clear_effect_data(void)
Definition effects.c:41
TlbEntry TlbMappablePage[15]
Definition effects.c:6
void render_effects_scene(void)
Definition effects.c:116
TlbMappablePage gEffectDataBuffer
BSS EffectSharedData gEffectSharedData[15]
Definition effects.c:10
#define EFFECT_GLOBALS_TLB_IDX
Definition effects.c:8
void render_effects_UI(void)
Definition effects.c:140
s8 TlbEntry[0x1000]
Definition effects.c:5
EffectInstanceDataPtr data
Definition effects.h:2605
struct EffectSharedData * shared
Definition effects.h:2606
#define ASSERT(condition)
@ FX_INSTANCE_FLAG_BATTLE
Definition enums.h:3515
@ FX_INSTANCE_FLAG_ENABLED
Definition enums.h:3514
@ FX_INSTANCE_FLAG_HAS_UPDATED
Definition enums.h:3516
@ CAMERA_FLAG_ORTHO
Definition enums.h:4723
@ FX_SHARED_DATA_LOADED
Definition enums.h:3521
@ FX_SHARED_DATA_CAN_FREE
Definition enums.h:3522
@ CONTEXT_WORLD
Definition enums.h:3528
@ GLOBAL_OVERRIDES_800
Definition enums.h:4329
@ GLOBAL_OVERRIDES_400
Definition enums.h:4328
u32 dma_copy(Addr romStart, Addr romEnd, void *vramDest)
Definition 43F0.c:443
s32 general_heap_free(void *data)
Definition heap.c:18
#define DMA_COPY_SEGMENT(segment)
Definition macros.h:529
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
void(* renderScene)(EffectInstance *effectInst)
Definition effects.h:2664
void(* renderUI)(EffectInstance *effectInst)
Definition effects.h:2665
u8 Addr[]
Linker symbol address, as in ld_addrs.h.
Definition types.h:16
s32 gOverrideFlags
Definition main_loop.c:11
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Camera gCameras[4]
Definition cam_main.c:17
Gfx * gMainGfxPos
Definition cam_main.c:15
s32 gCurrentCameraID
Definition cam_math.c:4
DisplayContext * gDisplayContext
Definition cam_main.c:16