From 9b4b9d9c032a79a38f2d3ac4a923baba1c77f09d Mon Sep 17 00:00:00 2001 From: Arceveti <73617174+Arceveti@users.noreply.github.com> Date: Wed, 29 Sep 2021 12:35:46 -0700 Subject: [PATCH] Add ENABLE_DEBUG_FREE_MOVE + improve debug free move controls --- include/config.h | 2 ++ src/game/camera.c | 19 ++++++---- src/game/mario.c | 7 +++- src/game/mario_actions_airborne.c | 4 +-- src/game/mario_actions_cutscene.c | 59 ++++++++++++++----------------- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/include/config.h b/include/config.h index 88106dc8..99adb2e6 100644 --- a/include/config.h +++ b/include/config.h @@ -192,6 +192,8 @@ //#define TEST_LEVEL LEVEL_BOB // Enable debug level select //#define DEBUG_LEVEL_SELECT +// Enable debug free move (DPad up to enter, A to exit) +//#define ENABLE_DEBUG_FREE_MOVE // Custom debug mode. Press DPAD left to show the debug UI. Press DPAD right to enter the noclip mode. //#define CUSTOM_DEBUG // Include Puppyprint, a display library for text and large images. Also includes a custom, enhanced performance profiler. diff --git a/src/game/camera.c b/src/game/camera.c index 0c91c8e7..5021c5d4 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -2681,6 +2681,9 @@ void set_camera_mode(struct Camera *c, s16 mode, s16 frames) { sLakituDist = 0; sLakituPitch = 0; sAreaYawChange = 0; +// #ifdef CAMERA_FIX +// if ((sMarioCamState->action & ACT_GROUP_MASK) != ACT_GROUP_SUBMERGED) mode = CAMERA_MODE_8_DIRECTIONS; +// #endif sModeInfo.newMode = (mode != -1) ? mode : sModeInfo.lastMode; sModeInfo.lastMode = c->mode; @@ -4932,8 +4935,11 @@ void set_fixed_cam_axis_sa_lobby(UNUSED s16 preset) { * Only block area mode changes if Mario is in a cannon, * or if the camera is in Mario mode and Mario is not swimming or in water with the metal cap */ -void check_blocking_area_processing(const u8 *mode) { - if (sMarioCamState->action & ACT_FLAG_METAL_WATER || +void check_blocking_area_processing(UNUSED const u8 *mode) { +#ifdef CAMERA_FIX + sStatusFlags |= CAM_FLAG_BLOCK_AREA_PROCESSING; +#else + if ((sMarioCamState->action & ACT_FLAG_METAL_WATER) || (sMarioCamState->action == ACT_DEBUG_FREE_MOVE) || *mode == CAMERA_MODE_BEHIND_MARIO || *mode == CAMERA_MODE_WATER_SURFACE) { sStatusFlags |= CAM_FLAG_BLOCK_AREA_PROCESSING; } @@ -4947,6 +4953,7 @@ void check_blocking_area_processing(const u8 *mode) { *mode == CAMERA_MODE_INSIDE_CANNON) { sStatusFlags |= CAM_FLAG_BLOCK_AREA_PROCESSING; } +#endif } void cam_rr_exit_building_side(struct Camera *c) { @@ -5809,7 +5816,6 @@ struct CutsceneSplinePoint sEndingLookAtSkyFocus[] = { */ s16 camera_course_processing(struct Camera *c) { s16 level = gCurrLevelNum; - s16 mode; s8 area = gCurrentArea->index; // Bounds iterator u32 b; @@ -5866,7 +5872,7 @@ s16 camera_course_processing(struct Camera *c) { b++; } } - +#if !defined(CAMERA_FIX) && !defined(DISABLE_LEVEL_SPECIFIC_CHECKS) // Area-specific camera processing if (!(sStatusFlags & CAM_FLAG_BLOCK_AREA_PROCESSING)) { switch (gCurrLevelArea) { @@ -5968,14 +5974,13 @@ s16 camera_course_processing(struct Camera *c) { break; } } - +#endif sStatusFlags &= ~CAM_FLAG_BLOCK_AREA_PROCESSING; if (oldMode == CAMERA_MODE_C_UP) { sModeInfo.lastMode = c->mode; c->mode = oldMode; } - mode = c->mode; - return mode; + return c->mode; } /** diff --git a/src/game/mario.c b/src/game/mario.c index 3c4727ee..7ea43b67 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -1709,6 +1709,12 @@ s32 execute_mario_action(struct MarioState *m) { vec3f_get_dist_and_lateral_dist_and_angle(m->prevPos, m->pos, &m->moveSpeed, &m->lateralSpeed, &m->movePitch, &m->moveYaw); vec3_copy(m->prevPos, m->pos); if (m->action) { +#ifdef ENABLE_DEBUG_FREE_MOVE + if (gPlayer1Controller->buttonDown & U_JPAD) { + set_camera_mode(m->area->camera, CAMERA_MODE_8_DIRECTIONS, 1); + set_mario_action(m, ACT_DEBUG_FREE_MOVE, 0); + } +#endif m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; mario_reset_bodystate(m); update_mario_inputs(m); @@ -1722,7 +1728,6 @@ s32 execute_mario_action(struct MarioState *m) { if (m->floor == NULL) { return ACTIVE_PARTICLE_NONE; } - // The function can loop through many action shifts in one frame, // which can lead to unexpected sub-frame behavior. Could potentially hang // if a loop of actions were found, but there has not been a situation found. diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index 897b4480..aa574dbd 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -373,11 +373,9 @@ void update_flying(struct MarioState *m) { } u32 common_air_action_step(struct MarioState *m, u32 landAction, s32 animation, u32 stepArg) { - u32 stepResult; - update_air_without_turn(m); - stepResult = perform_air_step(m, stepArg); + u32 stepResult = perform_air_step(m, stepArg); switch (stepResult) { case AIR_STEP_NONE: set_mario_animation(m, animation); diff --git a/src/game/mario_actions_cutscene.c b/src/game/mario_actions_cutscene.c index 31e2c793..027a198d 100644 --- a/src/game/mario_actions_cutscene.c +++ b/src/game/mario_actions_cutscene.c @@ -524,56 +524,49 @@ s32 act_reading_sign(struct MarioState *m) { s32 act_debug_free_move(struct MarioState *m) { struct WallCollisionData wallData; - struct Surface *surf; - f32 floorHeight; + struct Surface *floor, *ceil; Vec3f pos; - f32 speed; - u32 action; - - // integer immediates, generates convert instructions for some reason - speed = gPlayer1Controller->buttonDown & B_BUTTON ? 4 : 1; - if (gPlayer1Controller->buttonDown & L_TRIG) { - speed = 0.01f; - } - + f32 speed = ((gPlayer1Controller->buttonDown & B_BUTTON) ? 4.0f : 1.0f); + if (gPlayer1Controller->buttonDown & L_TRIG) speed = 0.01f; + if (m->area->camera->mode != CAMERA_MODE_8_DIRECTIONS) set_camera_mode(m->area->camera, CAMERA_MODE_8_DIRECTIONS, 1); set_mario_animation(m, MARIO_ANIM_A_POSE); vec3f_copy(pos, m->pos); - if (gPlayer1Controller->buttonDown & U_JPAD) { pos[1] += 16.0f * speed; + } else if (gPlayer1Controller->buttonPressed == A_BUTTON) { + m->vel[1] = 0.0f; + set_camera_mode(m->area->camera, m->area->camera->defMode, 1); + m->input &= ~INPUT_A_PRESSED; + if (m->pos[1] <= (m->waterLevel - 100)) { + return set_mario_action(m, ACT_WATER_IDLE, 0); + } else if (m->pos[1] <= m->floorHeight) { + return set_mario_action(m, ACT_IDLE, 0); + } else { + gPlayer1Controller->buttonDown &= ~U_JPAD; + return set_mario_action(m, ACT_FREEFALL, 0); + } } if (gPlayer1Controller->buttonDown & D_JPAD) { pos[1] -= 16.0f * speed; } - if (m->intendedMag > 0) { - pos[0] += 32.0f * speed * sins(m->intendedYaw); - pos[2] += 32.0f * speed * coss(m->intendedYaw); + pos[0] += (2.0f * speed * sins(m->intendedYaw) * m->intendedMag); + pos[2] += (2.0f * speed * coss(m->intendedYaw) * m->intendedMag); } - resolve_and_return_wall_collisions(pos, 60.0f, 50.0f, &wallData); - - floorHeight = find_floor(pos[0], pos[1], pos[2], &surf); - if (surf != NULL) { - if (pos[1] < floorHeight) { - pos[1] = floorHeight; - } - vec3f_copy(m->pos, pos); + set_mario_wall(m, ((wallData.numWalls > 0) ? wallData.walls[0] : NULL)); + f32 floorHeight = find_floor(pos[0], pos[1], pos[2], &floor); + f32 ceilHeight = find_ceil( pos[0], pos[1], pos[2], &ceil); + if (floor == NULL) return FALSE; + if ((ceilHeight - floorHeight) >= 160.0f) { + if ((floor != NULL) && ( pos[1] < floorHeight)) pos[1] = floorHeight; + if (( ceil != NULL) && ((pos[1] + 160.0f) > ceilHeight)) pos[1] = (ceilHeight - 160.0f); + vec3_copy(m->pos, pos); } - m->faceAngle[1] = m->intendedYaw; vec3f_copy(m->marioObj->header.gfx.pos, m->pos); vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0); - if (gPlayer1Controller->buttonPressed == A_BUTTON) { - if (m->pos[1] <= m->waterLevel - 100) { - action = ACT_WATER_IDLE; - } else { - action = ACT_IDLE; - } - set_mario_action(m, action, 0); - } - return FALSE; }