Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
main_loop.c
Go to the documentation of this file.
1#include "common.h"
2#include "nu/nusys.h"
3#include "ld_addrs.h"
4#include "hud_element.h"
5#include "sprite.h"
6#include "overlay.h"
7#include "game_modes.h"
8#include "dx/profiling.h"
9#include "dx/debug_menu.h"
10
15
17
20
22 .curButtons = { 0 },
23 .pressedButtons = { 0 },
24 .heldButtons = { 0 },
25 .prevButtons = { 0 },
26 .stickX = { 0 },
27 .stickY = { 0 },
28 .unk_48 = { 0 },
29 .unk_50 = { 0 },
30};
31
35s32 D_800741A4 = 0;
36
38 1.000000, 0.000000, 0.000000, 0.000000,
39 0.000000, 1.000000, 0.000000, 0.000000,
40 0.000000, 0.000000, 1.000000, 0.000000,
41 0.000000, 0.000000, 0.000000, 1.000000
42);
43
44s32 D_800741E8[2] = {0, 0}; // padding?
46u16 D_800741F2 = 0;
49s32 D_800741FC = 0;
50
51void gfx_init_state(void);
52void gfx_draw_background(void);
53
54void step_game_loop(void) {
56
57 PlayerData* playerData = &gPlayerData;
58 const int MAX_GAME_TIME = 1000*60*60*60 - 1; // 1000 hours minus one frame at 60 fps
59
60#if !VERSION_JP
63#endif
64
66
67 playerData->frameCounter += 2;
68 if (playerData->frameCounter > MAX_GAME_TIME) {
69 playerData->frameCounter = MAX_GAME_TIME;
70 }
71
72#if VERSION_JP
75#endif
76
78
79 if (gGameStepDelayCount != 0) {
81 if (gGameStepDelayCount == 0) {
83 } else {
84 return;
85 }
86 }
87
109
111 switch (SoftResetState) {
112 case 0:
115
116 if (SoftResetOverlayAlpha == 255) {
117 SoftResetState = 1;
118 SoftResetDelay = 3;
119 } else {
121 if (SoftResetOverlayAlpha > 255) {
123 }
124 }
125 break;
126 case 1:
129 if (SoftResetDelay == 0) {
132 gOverrideFlags &= ~GLOBAL_OVERRIDES_SOFT_RESET;
133 }
134 break;
135 }
136 } else {
138 SoftResetState = 0;
139 }
140
143 } else {
144 gOverrideFlags &= ~GLOBAL_OVERRIDES_PREV_DISABLE_BATTLES;
145 }
146
149 } else {
150 gOverrideFlags &= ~GLOBAL_OVERRIDES_PREV_200;
151 }
152
155 } else {
156 gOverrideFlags &= ~GLOBAL_OVERRIDES_PREV_400;
157 }
158
161 } else {
162 gOverrideFlags &= ~GLOBAL_OVERRIDES_PREV_800;
163 }
164
165 // Unused rand_int used to advance the global random seed each visual frame
166 rand_int(1);
167}
168
172
175
176 gDPFullSync(gMainGfxPos++);
177 gSPEndDisplayList(gMainGfxPos++);
178
179 // TODO these << 3 >> 3 shouldn't be necessary. There's almost definitely something we're missing here...
180 ASSERT((s32)((u32)((gMainGfxPos - gDisplayContext->backgroundGfx) << 3) >> 3) < ARRAY_COUNT(
182
183 nuGfxTaskStart(&gDisplayContext->backgroundGfx[0], (u32)(gMainGfxPos - gDisplayContext->backgroundGfx) * 8,
184 NU_GFX_UCODE_F3DEX2, NU_SC_NOSWAPBUFFER);
185}
186
187void gfx_draw_frame(void) {
188 profiler_gfx_started();
189
190 gMatrixListPos = 0;
192
195 return;
196 }
197
198 gSPMatrix(gMainGfxPos++, &MasterIdentityMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
199
201
203
205 render_frame(FALSE);
206 }
207
210
217
220 }
221
223
225 render_frame(TRUE);
226 }
227
230 ) {
232 }
233
237
240 ) {
242 }
243
245
248 }
249
252 }
253
255
257 switch (SoftResetState) {
258 case 0:
259 case 1:
261 break;
262 }
263 }
264
266
267 profiler_gfx_completed();
269
270 #if DX_DEBUG_MENU
271 dx_debug_console_main();
272 #endif
273
275
276 gDPFullSync(gMainGfxPos++);
277 gSPEndDisplayList(gMainGfxPos++);
278
279 nuGfxTaskStart(gDisplayContext->mainGfx, (u32)(gMainGfxPos - gDisplayContext->mainGfx) * 8, NU_GFX_UCODE_F3DEX2,
280 NU_SC_TASK_LODABLE | NU_SC_SWAPBUFFER);
283}
284
286 s32 i;
287
288 DMA_COPY_SEGMENT(engine4);
289 DMA_COPY_SEGMENT(engine1);
290 DMA_COPY_SEGMENT(evt);
291 DMA_COPY_SEGMENT(entity);
292 DMA_COPY_SEGMENT(engine2);
293 DMA_COPY_SEGMENT(font_width);
294
295 gOverrideFlags = 0;
326 clear_npcs();
329 clear_entity_data(FALSE);
341 poll_rumble();
342
343 for (i = 0; i < ARRAY_COUNT(gGameStatusPtr->unk_50); i++) {
344 gGameStatusPtr->unk_50[i] = 3;
345 gGameStatusPtr->unk_48[i] = 12;
346 }
347
350}
351
389
391 return gTimeFreezeMode;
392}
393
394#if VERSION_IQUE
395static const f32 rodata_padding[] = {0.0f, 0.0f};
396#endif
u16 * nuGfxCfb_ptr
Definition cam_main.c:14
Vec2b altViewportOffset
Gfx mainGfx[0x2080]
Gfx backgroundGfx[0x200]
#define rand_int
#define ASSERT(condition)
@ OVERLAY_SCREEN_MARIO
Definition enums.h:2395
@ DEBUG_SCRIPTS_NONE
Definition enums.h:4275
@ INTRO_PART_NONE
Definition enums.h:3556
@ TIME_FREEZE_FULL
Definition enums.h:3466
@ TIME_FREEZE_POPUP_MENU
Definition enums.h:3467
@ TIME_FREEZE_PARTIAL
Definition enums.h:3465
@ TIME_FREEZE_NONE
Definition enums.h:3464
@ TIME_FREEZE_EXIT
Definition enums.h:3468
@ PLAYER_SPRITES_MARIO_WORLD
Definition enums.h:6346
@ GLOBAL_OVERRIDES_MESSAGES_OVER_FRONTUI
Definition enums.h:4323
@ GLOBAL_OVERRIDES_SOFT_RESET
Definition enums.h:4324
@ GLOBAL_OVERRIDES_800
Definition enums.h:4330
@ GLOBAL_OVERRIDES_200
Definition enums.h:4328
@ GLOBAL_OVERRIDES_PREV_400
Definition enums.h:4333
@ GLOBAL_OVERRIDES_MESSAGES_OVER_CURTAINS
Definition enums.h:4338
@ GLOBAL_OVERRIDES_400
Definition enums.h:4329
@ GLOBAL_OVERRIDES_PREV_200
Definition enums.h:4332
@ GLOBAL_OVERRIDES_DISABLE_BATTLES
Definition enums.h:4327
@ GLOBAL_OVERRIDES_DISABLE_RENDER_WORLD
Definition enums.h:4321
@ GLOBAL_OVERRIDES_WINDOWS_OVER_CURTAINS
Definition enums.h:4335
@ GLOBAL_OVERRIDES_PREV_800
Definition enums.h:4334
@ GLOBAL_OVERRIDES_DISABLE_DRAW_FRAME
Definition enums.h:4322
@ GLOBAL_OVERRIDES_PREV_DISABLE_BATTLES
Definition enums.h:4331
@ EVT_GROUP_FLAG_MENUS
Definition evt.h:135
@ EVT_GROUP_FLAG_INTERACT
Definition evt.h:134
void clear_script_list(void)
void clear_item_entity_data(void)
void create_cameras(void)
Definition cam_main.c:255
void render_workers_frontUI(void)
Definition worker.c:150
void clear_animator_list(void)
Definition animator.c:222
void update_ambient_sounds(void)
Definition ambience.c:32
void render_screen_overlay_backUI(void)
void clear_saved_variables(void)
Definition vars_access.c:5
void clear_screen_overlays(void)
void initialize_curtains(void)
Definition curtains.c:212
void clear_render_tasks(void)
Definition model.c:4536
void func_802C3EE4(void)
void clear_model_data(void)
Definition model.c:2364
void render_messages(void)
Definition msg.c:568
void clear_trigger_data(void)
Definition trigger.c:13
void mdl_reset_transform_flags(void)
Definition model.c:3756
void clear_character_set(void)
Definition msg.c:192
void clear_sprite_shading_data(void)
void clear_entity_data(b32)
Definition entity.c:787
s32 disable_player_input(void)
Definition 77480.c:990
void render_workers_backUI(void)
Definition worker.c:163
s32 resume_all_group(s32 groupFlags)
void update_curtains(void)
Definition curtains.c:220
void func_80028838(void)
Definition input.c:23
void clear_printers(void)
Definition msg.c:196
void update_scripts(void)
void clear_player_status(void)
Definition 77480.c:807
void clear_effect_data(void)
Definition effects.c:37
void update_triggers(void)
Definition trigger.c:89
HeapNode * general_heap_create(void)
Definition heap.c:6
void update_entities(void)
Definition entity.c:82
void player_render_interact_prompts(void)
Definition 77480.c:1028
void update_input(void)
Definition input.c:31
void clear_worker_list(void)
Definition worker.c:10
void reset_ambient_sounds(void)
Definition ambience.c:28
void update_max_rumble_duration(void)
Definition rumble.c:34
void bgm_update_music_settings(void)
void render_curtains(void)
Definition curtains.c:223
void clear_windows(void)
Definition windows.c:135
void clear_player_data(void)
Definition inventory.c:49
void update_windows(void)
Definition windows.c:143
void crash_screen_set_draw_info(u16 *frameBufPtr, s16 width, s16 height)
void render_frame(s32 flag)
Definition cam_main.c:91
void render_window_root(void)
Definition windows.c:347
void render_screen_overlay_frontUI(void)
void bgm_reset_sequence_players(void)
void update_workers(void)
Definition worker.c:125
void clear_entity_models(void)
void func_80138198(void)
void reset_background_settings(void)
Definition background.c:33
void poll_rumble(void)
Definition rumble.c:10
void render_effects_UI(void)
Definition effects.c:136
void suspend_all_group(s32 groupFlags)
void update_messages(void)
Definition msg.c:247
void fio_init_flash(void)
Definition fio.c:232
void render_game_mode_backUI(void)
Definition game_modes.c:172
void clear_game_mode(void)
Definition game_modes.c:150
void set_game_mode(s32 modeID)
Definition game_modes.c:127
void step_game_mode(void)
Definition game_modes.c:163
void render_game_mode_frontUI(void)
Definition game_modes.c:180
@ GAME_MODE_STARTUP
Definition game_modes.h:7
void render_hud_elements_frontUI(void)
void update_hud_elements(void)
void render_hud_elements_backUI(void)
void hud_element_clear_cache(void)
s16 SoftResetOverlayAlpha
Definition main_loop.c:33
s32 gOverrideFlags
Definition main_loop.c:11
void gfx_task_background(void)
Definition main_loop.c:169
s32 D_800741A4
Definition main_loop.c:35
void step_game_loop(void)
Definition main_loop.c:54
s32 D_800741E8[2]
Definition main_loop.c:44
BSS s16 SoftResetDelay
Definition main_loop.c:14
GameStatus gGameStatus
Definition main_loop.c:21
u16 ** nuGfxCfb
Definition main_loop.c:13
DisplayContext DisplayContexts[2]
Definition main_loop.c:16
GameStatus * gGameStatusPtr
Definition main_loop.c:32
void gfx_draw_background(void)
Logic for the drawing the scene background.
s16 SoftResetState
Definition main_loop.c:34
void gfx_init_state(void)
void set_time_freeze_mode(s32 mode)
Time freeze modes: 0: none 1: NPCs move, can't be interacted with 2: NPCs don't move,...
Definition main_loop.c:358
void load_engine_data(void)
Definition main_loop.c:285
u16 gMatrixListPos
Definition main_loop.c:45
void gfx_draw_frame(void)
Definition main_loop.c:187
s32 gPauseBackgroundFade
Definition main_loop.c:48
s32 D_800741FC
Definition main_loop.c:49
s8 gGameStepDelayCount
Definition main_loop.c:19
u16 D_800741F2
Definition main_loop.c:46
s8 gGameStepDelayAmount
Definition main_loop.c:18
s32 gCurrentDisplayContextIndex
Definition main_loop.c:47
s32 get_time_freeze_mode(void)
Definition main_loop.c:390
s32 gTimeFreezeMode
Definition main_loop.c:12
Mtx MasterIdentityMtx
Definition main_loop.c:37
void clear_npcs(void)
Definition npc.c:60
void init_encounter_status(void)
Definition npc.c:2191
void _render_transition_stencil(u8, f32, ScreenOverlay *)
#define GFX_PROFILER_SWITCH(complete, begin)
Definition profiling.h:212
#define profiler_frame_setup()
Definition profiling.h:159
#define profiler_update(which, delta)
Definition profiling.h:157
@ PROFILER_TIME_SUB_GFX_HUD_ELEMENTS
Definition profiling.h:67
@ PROFILER_TIME_CONTROLLERS
Definition profiling.h:54
@ PROFILER_TIME_SUB_GFX_BACK_UI
Definition profiling.h:67
@ PROFILER_TIME_ENTITIES
Definition profiling.h:61
@ PROFILER_TIME_MESSAGES
Definition profiling.h:58
@ PROFILER_TIME_SUB_GFX_FRONT_UI
Definition profiling.h:67
@ PROFILER_TIME_HUD_ELEMENTS
Definition profiling.h:59
@ PROFILER_TIME_TRIGGERS
Definition profiling.h:56
@ PROFILER_TIME_STEP_GAME_MODE
Definition profiling.h:60
@ PROFILER_TIME_WORKERS
Definition profiling.h:55
@ PROFILER_TIME_EVT
Definition profiling.h:57
@ PROFILER_TIME_SUB_GFX_UPDATE
Definition profiling.h:67
#define profiler_print_times()
Definition profiling.h:158
#define GFX_PROFILER_COMPLETE(which)
Definition profiling.h:217
void sfx_update_env_sound_params(void)
Definition sfx.c:334
void sfx_stop_env_sounds(void)
Definition sfx.c:361
void sfx_clear_sounds(void)
Definition sfx.c:304
#define DMA_COPY_SEGMENT(segment)
Definition macros.h:525
#define RDP_MATRIX( Ax, Bx, Cx, Dx, Ay, By, Cy, Dy, Az, Bz, Cz, Dz, Aw, Bw, Cw, Dw)
Definition macros.h:233
#define SCREEN_WIDTH
Definition macros.h:105
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define SCREEN_HEIGHT
Definition macros.h:106
void spr_render_init(void)
Definition sprite.c:814
void spr_init_sprites(s32 playerSpriteSet)
Definition sprite.c:764
Gfx * gMainGfxPos
Definition cam_main.c:15
PlayerData gPlayerData
Definition 77480.c:40
DisplayContext * gDisplayContext
Definition cam_main.c:16