From 4adf87f622b2ef1b646034556cea93826a2ad4d6 Mon Sep 17 00:00:00 2001 From: Arceveti <73617174+Arceveti@users.noreply.github.com> Date: Tue, 28 Sep 2021 17:33:18 -0700 Subject: [PATCH] Some cleanup/fixes --- src/engine/graph_node.c | 2 +- src/engine/level_script.c | 4 +- src/engine/math_util.c | 49 ++++++++++++------------ src/engine/math_util.h | 3 +- src/game/behaviors/intro_peach.inc.c | 3 +- src/game/behaviors/snowman.inc.c | 14 ++----- src/game/behaviors/spawn_star.inc.c | 7 +--- src/game/camera.c | 50 ++++++++++-------------- src/game/insn_disasm.c | 12 +++--- src/game/mario.c | 2 +- src/game/mario_actions_airborne.c | 7 +--- src/game/mario_actions_automatic.c | 7 +--- src/game/mario_actions_moving.c | 2 +- src/game/mario_actions_stationary.c | 9 ++--- src/game/mario_actions_submerged.c | 2 +- src/game/mario_misc.c | 4 +- src/game/platform_displacement.c | 2 +- src/game/puppycam2.c | 57 ++++++++++------------------ src/game/puppyprint.c | 55 ++++++++++++--------------- 19 files changed, 120 insertions(+), 171 deletions(-) diff --git a/src/engine/graph_node.c b/src/engine/graph_node.c index 1b0790ad..a2b2f5d1 100644 --- a/src/engine/graph_node.c +++ b/src/engine/graph_node.c @@ -887,7 +887,7 @@ void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f posit position[1] = (f32) values[retrieve_animation_index(frame, &attribute)]; position[2] = (f32) values[retrieve_animation_index(frame, &attribute)]; } else { - vec3f_set(position, 0, 0, 0); + vec3_zero(position); } } diff --git a/src/engine/level_script.c b/src/engine/level_script.c index c22544fa..360a704f 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -460,8 +460,8 @@ static void level_cmd_23(void) { } static void level_cmd_init_mario(void) { - vec3s_set(gMarioSpawnInfo->startPos, 0, 0, 0); - vec3s_set(gMarioSpawnInfo->startAngle, 0, 0, 0); + vec3_zero(gMarioSpawnInfo->startPos); + vec3_zero(gMarioSpawnInfo->startAngle); gMarioSpawnInfo->activeAreaIndex = -1; gMarioSpawnInfo->areaIndex = 0; diff --git a/src/engine/math_util.c b/src/engine/math_util.c index 76b8d1a6..d83439c7 100644 --- a/src/engine/math_util.c +++ b/src/engine/math_util.c @@ -598,7 +598,7 @@ void mtxf_rotate_xy(Mtx *mtx, s32 angle) { */ void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, register Mat4 camMtx) { register s32 i; - register f32 *temp = (f32 *)dest; + register f32 *temp1 = (f32 *)dest; register f32 *temp2 = (f32 *)camMtx; f32 y[3]; register f32 *x = y; @@ -608,12 +608,12 @@ void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, register Mat4 camMtx) { *x = (temp3[12] - temp2[12]); temp2++; temp3++; - x = ((u32)x)+4; + x = (f32 *)(((u32)x) + 4); } temp2 -=3;; for (i = 0; i < 3; i++) { - *temp = x[-3] * temp2[0] + x[-2] * temp2[1] + x[-1] * temp2[2]; - temp++; + *temp1 = x[-3] * temp2[0] + x[-2] * temp2[1] + x[-1] * temp2[2]; + temp1++; temp2 += 4; } } @@ -756,6 +756,25 @@ void vec3s_set_dist_and_angle(Vec3s from, Vec3s to, s16 dist, Angle32 pitch, Ang to[2] = (from[2] + (dcos * coss(yaw ))); } +/** + * Similar to approach_s32, but converts to s16 and allows for overflow between 32767 and -32768 + */ +s32 approach_angle(s32 current, s32 target, s32 inc) { + s32 dist = (s16)(target - current); + if (dist < 0) { + dist += inc; + if (dist > 0) dist = 0; + } else if (dist > 0) { + dist -= inc; + if (dist < 0) dist = 0; + } + return (target - dist); +} +Bool32 approach_angle_bool(s16 *current, s32 target, s32 inc) { + *current = approach_angle(*current, target, inc); + return (*current != target); +} + s32 approach_s16(s32 current, s32 target, s32 inc, s32 dec) { s16 dist = (target - current); if (dist >= 0) { // target >= current @@ -765,10 +784,9 @@ s32 approach_s16(s32 current, s32 target, s32 inc, s32 dec) { } return current; } - Bool32 approach_s16_bool(s16 *current, s32 target, s32 inc, s32 dec) { *current = approach_s16(*current, target, inc, dec); - return !(*current == target); + return (*current != target); } /** @@ -784,10 +802,9 @@ s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec) { } return current; } - Bool32 approach_s32_bool(s32 *current, s32 target, s32 inc, s32 dec) { *current = approach_s32(*current, target, inc, dec); - return !(*current == target); + return (*current != target); } /** @@ -803,7 +820,6 @@ f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec) { } return current; } - Bool32 approach_f32_bool(f32 *current, f32 target, f32 inc, f32 dec) { *current = approach_f32(*current, target, inc, dec); return !(*current == target); @@ -826,21 +842,6 @@ s32 approach_f32_signed(f32 *current, f32 target, f32 inc) { return reachedTarget; } -/** - * Similar to approach_s32, but converts to s16 and allows for overflow between 32767 and -32768 - */ -s32 approach_angle(s32 current, s32 target, s32 inc) { - s32 dist = (s16)(target - current); - if (dist < 0) { - dist += inc; - if (dist > 0) dist = 0; - } else if (dist > 0) { - dist -= inc; - if (dist < 0) dist = 0; - } - return (target - dist); -} - /** * Approaches an f32 value by taking the difference between the target and current value * and adding a fraction of that to the current value. diff --git a/src/engine/math_util.h b/src/engine/math_util.h index 0b08c90c..c09b957a 100644 --- a/src/engine/math_util.h +++ b/src/engine/math_util.h @@ -486,9 +486,11 @@ void vec3f_get_dist_and_angle( Vec3f from, Vec3f to, f32 *dist, void vec3s_set_dist_and_angle( Vec3s from, Vec3s to, s16 dist, Angle32 pitch, Angle32 yaw); void vec3f_set_dist_and_angle( Vec3f from, Vec3f to, f32 dist, Angle32 pitch, Angle32 yaw); +s32 approach_angle(s32 current, s32 target, s32 inc); s32 approach_s16(s32 current, s32 target, s32 inc, s32 dec); s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec); f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec); +Bool32 approach_angle_bool(s16 *current, s32 target, s32 inc); Bool32 approach_s16_bool(s16 *current, s32 target, s32 inc, s32 dec); Bool32 approach_s32_bool(s32 *current, s32 target, s32 inc, s32 dec); Bool32 approach_f32_bool(f32 *current, f32 target, f32 inc, f32 dec); @@ -499,7 +501,6 @@ Bool32 approach_f32_bool(f32 *current, f32 target, f32 inc, f32 dec); #define approach_s32_symmetric_bool(current, target, inc) approach_s32_bool((current), (target), (inc), (inc)) #define approach_f32_symmetric_bool(current, target, inc) approach_f32_bool((current), (target), (inc), (inc)) s32 approach_f32_signed(f32 *current, f32 target, f32 inc); -s32 approach_angle(s32 current, s32 target, s32 inc); s32 approach_f32_asymptotic_bool(f32 *current, f32 target, f32 multiplier); f32 approach_f32_asymptotic(f32 current, f32 target, f32 multiplier); s32 approach_s16_asymptotic_bool(s16 *current, s16 target, s16 divisor); diff --git a/src/game/behaviors/intro_peach.inc.c b/src/game/behaviors/intro_peach.inc.c index ab3706b0..906dbc39 100644 --- a/src/game/behaviors/intro_peach.inc.c +++ b/src/game/behaviors/intro_peach.inc.c @@ -7,13 +7,12 @@ void intro_peach_set_pos_and_opacity(struct Object *obj, f32 targetOpacity, f32 increment) { Vec3f newPos; s16 focusPitch, focusYaw; - f32 newOpacity; vec3f_get_angle(gLakituState.pos, gLakituState.focus, &focusPitch, &focusYaw); vec3f_set_dist_and_angle(gLakituState.pos, newPos, obj->oIntroPeachDistToCamera, obj->oIntroPeachPitchFromFocus + focusPitch, obj->oIntroPeachYawFromFocus + focusYaw); vec3f_copy(&obj->oPosVec, newPos); - newOpacity = obj->oOpacity; + f32 newOpacity = obj->oOpacity; camera_approach_f32_symmetric_bool(&newOpacity, targetOpacity, increment); obj->oOpacity = newOpacity; } diff --git a/src/game/behaviors/snowman.inc.c b/src/game/behaviors/snowman.inc.c index 9560bdf0..61d12ced 100644 --- a/src/game/behaviors/snowman.inc.c +++ b/src/game/behaviors/snowman.inc.c @@ -153,11 +153,8 @@ void bhv_snowmans_bottom_loop(void) { } void bhv_snowmans_head_init(void) { - u8 starFlags; - s8 behParams; - - starFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); - behParams = (o->oBehParams >> 24) & 0xFF; + u8 starFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); + s8 behParams = (o->oBehParams >> 24) & 0xFF; cur_obj_scale(0.7f); @@ -166,11 +163,8 @@ void bhv_snowmans_head_init(void) { o->oBuoyancy = 2.0f; if ((starFlags & (1 << behParams)) && gCurrActNum != behParams + 1) { - spawn_object_abs_with_rot(o, 0, MODEL_CCM_SNOWMAN_BASE, bhvBigSnowmanWhole, -4230, -1344, 1813, - 0, 0, 0); - o->oPosX = -4230.0f; - o->oPosY = -994.0f; - o->oPosZ = 1813.0f; + spawn_object_abs_with_rot(o, 0, MODEL_CCM_SNOWMAN_BASE, bhvBigSnowmanWhole, -4230, -1344, 1813, 0, 0, 0); + vec3_set(&o->oPosVec, -4230.0f, -994.0f, 1813.0f); o->oAction = 1; } } diff --git a/src/game/behaviors/spawn_star.inc.c b/src/game/behaviors/spawn_star.inc.c index cd546b85..c088ea43 100644 --- a/src/game/behaviors/spawn_star.inc.c +++ b/src/game/behaviors/spawn_star.inc.c @@ -117,12 +117,9 @@ void bhv_star_spawn_loop(void) { } struct Object *spawn_star(struct Object *starObj, f32 x, f32 y, f32 z) { - starObj = spawn_object_abs_with_rot(o, 0, MODEL_STAR, bhvStarSpawnCoordinates, o->oPosX, o->oPosY, - o->oPosZ, 0, 0, 0); + starObj = spawn_object_abs_with_rot(o, 0, MODEL_STAR, bhvStarSpawnCoordinates, o->oPosX, o->oPosY, o->oPosZ, 0, 0, 0); starObj->oBehParams = o->oBehParams; - starObj->oHomeX = x; - starObj->oHomeY = y; - starObj->oHomeZ = z; + vec3_set(&starObj->oHomeVec, x, y, z); starObj->oFaceAnglePitch = 0; starObj->oFaceAngleRoll = 0; return starObj; diff --git a/src/game/camera.c b/src/game/camera.c index 9768997b..d63beb0e 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -1618,7 +1618,7 @@ void mode_fixed_camera(struct Camera *c) { c->nextYaw = update_fixed_camera(c, c->focus, c->pos); c->yaw = c->nextYaw; pan_ahead_of_player(c); - vec3f_set(sCastleEntranceOffset, 0.f, 0.f, 0.f); + vec3_zero(sCastleEntranceOffset); } /** @@ -2756,7 +2756,7 @@ void update_lakitu(struct Camera *c) { if (c->cutscene) { vec3f_add(gLakituState.focus, sPlayer2FocusOffset); - vec3f_set(sPlayer2FocusOffset, 0, 0, 0); + vec3_zero(sPlayer2FocusOffset); } vec3f_get_dist_and_angle(gLakituState.pos, gLakituState.focus, &gLakituState.focusDistance, @@ -3072,8 +3072,8 @@ void init_camera(struct Camera *c) { gLakituState.keyDanceRoll = 0; gLakituState.unused = 0; sStatusFlags &= ~CAM_FLAG_SMOOTH_MOVEMENT; - vec3f_set(sCastleEntranceOffset, 0.f, 0.f, 0.f); - vec3f_set(sPlayer2FocusOffset, 0.f, 0.f, 0.f); + vec3_zero(sCastleEntranceOffset); + vec3_zero(sPlayer2FocusOffset); find_mario_floor_and_ceil(&sMarioGeometry); sMarioGeometry.prevFloorHeight = sMarioGeometry.currFloorHeight; sMarioGeometry.prevCeilHeight = sMarioGeometry.currCeilHeight; @@ -3494,7 +3494,7 @@ void shake_camera_handheld(Vec3f pos, Vec3f focus) { s16 pitch, yaw; if (sHandheldShakeMag == 0) { - vec3f_set(shakeOffset, 0.f, 0.f, 0.f); + vec3_zero(shakeOffset); } else { for (i = 0; i < 4; i++) { shakeSpline[i][0] = sHandheldShakeSpline[i].point[0]; @@ -4437,9 +4437,9 @@ void clear_cutscene_vars(UNUSED struct Camera *c) { for (i = 0; i < 10; i++) { sCutsceneVars[i].unused1 = 0; - vec3f_set(sCutsceneVars[i].point, 0.f, 0.f, 0.f); - vec3f_set(sCutsceneVars[i].unusedPoint, 0.f, 0.f, 0.f); - vec3s_set(sCutsceneVars[i].angle, 0, 0, 0); + vec3_zero(sCutsceneVars[i].point); + vec3_zero(sCutsceneVars[i].unusedPoint); + vec3_zero(sCutsceneVars[i].angle); sCutsceneVars[i].unused2 = 0; } } @@ -5885,11 +5885,8 @@ s16 camera_course_processing(struct Camera *c) { case AREA_BBH: // if camera is fixed at bbh_room_13_balcony_camera (but as floats) - if (vec3f_compare(sFixedModeBasePosition, 210.f, 420.f, 3109.f) == 1) - { - if (sMarioCamState->pos[1] < 1800.f) { - transition_to_camera_mode(c, CAMERA_MODE_CLOSE, 30); - } + if (sFixedModeBasePosition[0] == 210.f && sFixedModeBasePosition[1] == 420.f && sFixedModeBasePosition[2] == 3109.f && sMarioCamState->pos[1] < 1800.f) { + transition_to_camera_mode(c, CAMERA_MODE_CLOSE, 30); } break; @@ -6756,7 +6753,7 @@ void cutscene_grand_star_front_of_mario(struct Camera *c) { */ void cutscene_grand_star_mario_jump(UNUSED struct Camera *c) { vec3s_set(sCutsceneVars[0].angle, 0, sMarioCamState->faceAngle[1], 0); - vec3f_set(sCutsceneVars[2].point, 0.f, 0.f, 0.f); + vec3_zero(sCutsceneVars[2].point); } /** @@ -7362,20 +7359,12 @@ void cutscene_bowser_arena_start(struct Camera *c) { * Create the dialog box depending on which bowser fight Mario is in. */ void bowser_fight_intro_dialog(UNUSED struct Camera *c) { - s16 dialog; - switch (gCurrLevelNum) { - case LEVEL_BOWSER_1: - dialog = DIALOG_067; - break; - case LEVEL_BOWSER_2: - dialog = DIALOG_092; - break; - default: // LEVEL_BOWSER_3 - dialog = DIALOG_093; + case LEVEL_BOWSER_1: create_dialog_box(DIALOG_067); break; + case LEVEL_BOWSER_2: create_dialog_box(DIALOG_092); break; + case LEVEL_BOWSER_3: create_dialog_box(DIALOG_093); break; + default: break; } - - create_dialog_box(dialog); } /** @@ -7383,7 +7372,6 @@ void bowser_fight_intro_dialog(UNUSED struct Camera *c) { */ void cutscene_bowser_arena_dialog(struct Camera *c) { cutscene_event(bowser_fight_intro_dialog, c, 0, 0); - if (get_dialog_id() == DIALOG_NONE) { gCutsceneTimer = CUTSCENE_LOOP; } @@ -7449,7 +7437,7 @@ void cutscene_star_spawn_update_boss_fight(struct Camera *c) { update_boss_fight_camera(c, focus, pos); approach_vec3f_asymptotic(c->focus, focus, 0.2f, 0.2f, 0.2f); - approach_vec3f_asymptotic(c->pos, pos, 0.2f, 0.2f, 0.2f); + approach_vec3f_asymptotic(c->pos, pos, 0.2f, 0.2f, 0.2f); } /** @@ -7496,7 +7484,7 @@ void cutscene_star_spawn_end(struct Camera *c) { void cutscene_exit_waterfall_warp(struct Camera *c) { //! hardcoded position - vec3f_set(c->pos, -3899.f, 39.f, -5671.f); + vec3_set(c->pos, -3899.f, 39.f, -5671.f); } /** @@ -7504,7 +7492,7 @@ void cutscene_exit_waterfall_warp(struct Camera *c) { */ void cutscene_exit_to_castle_grounds_focus_mario(struct Camera *c) { vec3f_copy(c->focus, sMarioCamState->pos); - c->focus[1] = c->pos[1] + (sMarioCamState->pos[1] + 125.f - c->pos[1]) * 0.5f; + c->focus[1] = c->pos[1] + ((sMarioCamState->pos[1] + 125.f - c->pos[1]) * 0.5f); approach_vec3f_asymptotic(c->focus, sMarioCamState->pos, 0.05f, 0.4f, 0.05f); } @@ -7701,7 +7689,7 @@ void cutscene_prepare_cannon_start(struct Camera *c) { sCutsceneVars[2].point[0] = 30.f; // Store the cannon door's position in sCutsceneVars[3]'s point vec3f_copy(sCutsceneVars[3].point, &gCutsceneFocus->oPosVec); - vec3s_set(sCutsceneVars[5].angle, 0, 0, 0); + vec3_zero(sCutsceneVars[5].angle); } /** diff --git a/src/game/insn_disasm.c b/src/game/insn_disasm.c index 337a60a0..c2dfb31a 100644 --- a/src/game/insn_disasm.c +++ b/src/game/insn_disasm.c @@ -21,15 +21,15 @@ extern far char *parse_map(u32); static char insn_as_string[100]; typedef struct __attribute__((packed)) { - u8 rd : 5; + u8 rd : 5; u8 shift_amt : 5; - u8 function : 6; + u8 function : 6; } RTypeData; typedef struct __attribute__((packed)) { u8 opcode : 6; - u8 rs : 5; - u8 rt : 5; + u8 rs : 5; + u8 rt : 5; union { RTypeData rdata; u16 immediate; @@ -44,7 +44,7 @@ typedef union { typedef struct __attribute__((packed)) { u32 type; u32 arbitraryParam; - u8 opcode : 6; + u8 opcode : 6; u8 function : 6; u8 name[10]; } InsnTemplate; @@ -67,7 +67,7 @@ InsnTemplate insn_db[] = { {I_TYPE, PARAM_NONE, 0b100101, 0, "LHU"}, {I_TYPE, PARAM_NONE, 0b101011, 0, "SW"}, {I_TYPE, PARAM_NONE, 0b100011, 0, "LW"}, - {I_TYPE, PARAM_LUI, 0b001111, 0, "LUI"}, + {I_TYPE, PARAM_LUI, 0b001111, 0, "LUI"}, // branches {I_TYPE, PARAM_SWAP_RS_IMM, 0b000100, 0, "BEQ"}, diff --git a/src/game/mario.c b/src/game/mario.c index 1dd100c3..11be2998 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -1100,7 +1100,7 @@ s32 check_common_hold_action_exits(struct MarioState *m) { s32 transition_submerged_to_walking(struct MarioState *m) { set_camera_mode(m->area->camera, m->area->camera->defMode, 1); - vec3s_set(m->angleVel, 0, 0, 0); + vec3_zero(m->angleVel); if (m->heldObj == NULL) { return set_mario_action(m, ACT_WALKING, 0); diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index 23192561..9f79162e 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -1862,10 +1862,7 @@ s32 act_riding_hoot(struct MarioState *m) { #endif return set_mario_action(m, ACT_FREEFALL, 0); } - - m->pos[0] = m->usedObj->oPosX; - m->pos[1] = m->usedObj->oPosY - 92.5f; - m->pos[2] = m->usedObj->oPosZ; + vec3_copy_y_off(m->pos, &m->usedObj->oPosVec, -92.5f); m->faceAngle[1] = 0x4000 - m->usedObj->oMoveAngleYaw; @@ -1877,7 +1874,7 @@ s32 act_riding_hoot(struct MarioState *m) { } } - vec3f_set(m->vel, 0.0f, 0.0f, 0.0f); + vec3_zero(m->vel); vec3f_set(m->marioObj->header.gfx.pos, m->pos[0], m->pos[1], m->pos[2]); vec3s_set(m->marioObj->header.gfx.angle, 0, 0x4000 - m->faceAngle[1], 0); return FALSE; diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index 5cbd080a..961a12c9 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -697,11 +697,8 @@ s32 act_in_cannon(struct MarioState *m) { m->statusForCamera->cameraEvent = CAM_EVENT_CANNON; m->statusForCamera->usedObj = m->usedObj; - vec3f_set(m->vel, 0.0f, 0.0f, 0.0f); - - m->pos[0] = m->usedObj->oPosX; - m->pos[1] = m->usedObj->oPosY + 350.0f; - m->pos[2] = m->usedObj->oPosZ; + vec3_zero(m->vel); + vec3_copy_y_off(m->pos, &m->usedObj->oPosVec, 350.0f); m->forwardVel = 0.0f; diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index ab153e9b..600f51a4 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -497,7 +497,7 @@ void update_walking_speed(struct MarioState *m) { } #elif GROUND_TURN_MODE == 3 // Instant turn. m->faceAngle[1] = m->intendedYaw; -#elif GROUND_TURN_MODE == 4 +#elif GROUND_TURN_MODE == 4 // Experimental. m->faceAngle[1] = approach_s16_asymptotic(m->faceAngle[1], m->intendedYaw, m->forwardVel / 8.0f); // should be max speed for the current action instead of m->forwardVel #endif apply_slope_accel(m); diff --git a/src/game/mario_actions_stationary.c b/src/game/mario_actions_stationary.c index 4aa2d109..bae1ebc4 100644 --- a/src/game/mario_actions_stationary.c +++ b/src/game/mario_actions_stationary.c @@ -774,9 +774,6 @@ s32 act_stop_crawling(struct MarioState *m) { } s32 act_shockwave_bounce(struct MarioState *m) { - s16 bounceTimer; - f32 bounceAmt; - if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_SHOCKWAVE) { #if ENABLE_RUMBLE queue_rumble_data(70, 40); @@ -797,10 +794,10 @@ s32 act_shockwave_bounce(struct MarioState *m) { return set_mario_action(m, ACT_IDLE, 0); } - bounceTimer = (m->actionTimer % 16) << 12; - bounceAmt = (f32)(((f32)(6 - m->actionTimer / 8) * 8.0f) + 4.0f); + s16 bounceTimer = (m->actionTimer % 16) << 12; + f32 bounceAmt = (f32)(((f32)(6 - m->actionTimer / 8) * 8.0f) + 4.0f); mario_set_forward_vel(m, 0); - vec3f_set(m->vel, 0.0f, 0.0f, 0.0f); + vec3_zero(m->vel); if (sins(bounceTimer) >= 0.0f) { m->pos[1] = sins(bounceTimer) * bounceAmt + m->floorHeight; } else { diff --git a/src/game/mario_actions_submerged.c b/src/game/mario_actions_submerged.c index d0a15374..85bfadc1 100644 --- a/src/game/mario_actions_submerged.c +++ b/src/game/mario_actions_submerged.c @@ -492,7 +492,7 @@ static s32 check_water_jump(struct MarioState *m) { if (m->input & INPUT_A_PRESSED) { if (probe >= m->waterLevel - 80 && m->faceAngle[0] >= 0 && m->controller->stickY < -60.0f) { - vec3s_set(m->angleVel, 0, 0, 0); + vec3_zero(m->angleVel); m->vel[1] = 62.0f; diff --git a/src/game/mario_misc.c b/src/game/mario_misc.c index 7d081003..0409bc8d 100644 --- a/src/game/mario_misc.c +++ b/src/game/mario_misc.c @@ -427,8 +427,8 @@ Gfx *geo_mario_head_rotation(s32 callContext, struct GraphNode *node, UNUSED Mat rotNode->rotation[1] = bodyState->headAngle[2]; rotNode->rotation[2] = bodyState->headAngle[0]; } else { - vec3s_set(bodyState->headAngle, 0, 0, 0); - vec3s_set(rotNode->rotation, 0, 0, 0); + vec3_zero(bodyState->headAngle); + vec3_zero(rotNode->rotation); } } return NULL; diff --git a/src/game/platform_displacement.c b/src/game/platform_displacement.c index bbb4b5fa..4169f8c0 100644 --- a/src/game/platform_displacement.c +++ b/src/game/platform_displacement.c @@ -150,7 +150,7 @@ void apply_platform_displacement(struct PlatformDisplacementInfo *displaceInfo, // Make sure inertia isn't set on the first frame otherwise the previous value isn't cleared if ((platform != displaceInfo->prevPlatform) || (gGlobalTimer != displaceInfo->prevTimer + 1)) { - vec3f_set(sMarioAmountDisplaced, 0.f, 0.f, 0.f); + vec3_zero(sMarioAmountDisplaced); } } diff --git a/src/game/puppycam2.c b/src/game/puppycam2.c index 10168fb9..6bf921b3 100644 --- a/src/game/puppycam2.c +++ b/src/game/puppycam2.c @@ -637,10 +637,8 @@ static void puppycam_input_hold_preset3(void) { gPuppyCam.pitchAcceleration = approach_f32_asymptotic(gPuppyCam.pitchAcceleration, 0, DECELERATION); } } else { - if (gPlayer1Controller->buttonPressed & L_TRIG) { - if (gPuppyCam.yawTarget % 0x2000) { - gPuppyCam.yawTarget += 0x2000 - gPuppyCam.yawTarget % 0x2000; - } + if ((gPlayer1Controller->buttonPressed & L_TRIG) && (gPuppyCam.yawTarget % 0x2000)) { + gPuppyCam.yawTarget += 0x2000 - gPuppyCam.yawTarget % 0x2000; } if (gPuppyCam.mode3Flags & PUPPYCAM_MODE3_ZOOMED_MED) gPuppyCam.pitchTarget = approach_s32(gPuppyCam.pitchTarget, 0x3800, 0x200, 0x200); @@ -702,8 +700,8 @@ static void puppycam_input_hold_preset3(void) { // Handles C Button inputs for modes that have held inputs, rather than presses. static void puppycam_input_hold(void) { - f32 ivX = ((gPuppyCam.options.invertX*2)-1)*(gPuppyCam.options.sensitivityX/100.f); - f32 ivY = ((gPuppyCam.options.invertY*2)-1)*(gPuppyCam.options.sensitivityY/100.f); + f32 ivX = ((gPuppyCam.options.invertX * 2) - 1) * (gPuppyCam.options.sensitivityX / 100.f); + f32 ivY = ((gPuppyCam.options.invertY * 2) - 1) * (gPuppyCam.options.sensitivityY / 100.f); s8 stickMag[2] = {100, 100}; if (gPuppyCam.intendedFlags & PUPPYCAM_BEHAVIOUR_FREE) { @@ -830,13 +828,12 @@ void puppycam_debug_view(void) { } static void puppycam_view_panning(void) { - f32 panFloor, panMulti; s32 expectedPanX, expectedPanZ; s32 height = gPuppyCam.targetObj->oPosY; s32 panEx = (gPuppyCam.zoomTarget >= 1000) * 160; //Removes the basic panning when idling if the zoom level is at the closest. f32 slideSpeed = 1; - panMulti = CLAMP(gPuppyCam.zoom / (f32)gPuppyCam.zoomPoints[2], 0.f, 1.f); + f32 panMulti = CLAMP(gPuppyCam.zoom / (f32)gPuppyCam.zoomPoints[2], 0.f, 1.f); if (gPuppyCam.options.inputType == 2) { panMulti /= 2; } @@ -850,7 +847,7 @@ static void puppycam_view_panning(void) { gPuppyCam.pan[0] = approach_f32_asymptotic(gPuppyCam.pan[0], expectedPanX, 0.02f*slideSpeed); gPuppyCam.pan[2] = approach_f32_asymptotic(gPuppyCam.pan[2], expectedPanZ, 0.02f*slideSpeed); if (gMarioState->vel[1] == 0.0f) { - panFloor = CLAMP(find_floor_height((s16)(gPuppyCam.targetObj->oPosX+expectedPanX), (s16)(gPuppyCam.targetObj->oPosY + 200), + f32 panFloor = CLAMP(find_floor_height((s16)(gPuppyCam.targetObj->oPosX+expectedPanX), (s16)(gPuppyCam.targetObj->oPosY + 200), (s16)(gPuppyCam.targetObj->oPosZ+expectedPanZ)), gPuppyCam.targetObj->oPosY - 50,gPuppyCam.targetObj->oPosY + 50); // If the floor is lower than 150 units below Mario, then ignore the Y value and tilt the camera instead. if (panFloor <= gPuppyCam.targetObj->oPosY - 150) { @@ -922,26 +919,23 @@ const struct sPuppyAngles puppyAnglesNull = { static s32 puppycam_check_volume_bounds(struct sPuppyVolume *volume, s32 index) { s32 rel[3]; s32 pos[2]; - f32 distCheck; if (sPuppyVolumeStack[index]->room != gMarioCurrentRoom && sPuppyVolumeStack[index]->room != -1) { return FALSE; } if (sPuppyVolumeStack[index]->shape == PUPPYVOLUME_SHAPE_BOX) { // Fetch the relative position. to the triggeree. - rel[0] = sPuppyVolumeStack[index]->pos[0] - gPuppyCam.targetObj->oPosX; - rel[1] = sPuppyVolumeStack[index]->pos[1] - gPuppyCam.targetObj->oPosY; - rel[2] = sPuppyVolumeStack[index]->pos[2] - gPuppyCam.targetObj->oPosZ; + vec3_diff(rel, sPuppyVolumeStack[index]->pos, &gPuppyCam.targetObj->oPosVec); // Use the dark, forbidden arts of trig to rotate the volume. pos[0] = rel[2] * sins(sPuppyVolumeStack[index]->rot) + rel[0] * coss(sPuppyVolumeStack[index]->rot); pos[1] = rel[2] * coss(sPuppyVolumeStack[index]->rot) - rel[0] * sins(sPuppyVolumeStack[index]->rot); - #ifdef VISUAL_DEBUG +#ifdef VISUAL_DEBUG Vec3f debugPos[2]; vec3f_set(debugPos[0], sPuppyVolumeStack[index]->pos[0], sPuppyVolumeStack[index]->pos[1], sPuppyVolumeStack[index]->pos[2]); vec3f_set(debugPos[1], sPuppyVolumeStack[index]->radius[0], sPuppyVolumeStack[index]->radius[1], sPuppyVolumeStack[index]->radius[2]); debug_box_color(0x0000FF00); debug_box_rot(debugPos[0], debugPos[1], sPuppyVolumeStack[index]->rot, DEBUG_SHAPE_BOX | DEBUG_UCODE_DEFAULT); - #endif +#endif // Now compare values. if (-sPuppyVolumeStack[index]->radius[0] < pos[0] && pos[0] < sPuppyVolumeStack[index]->radius[0] && -sPuppyVolumeStack[index]->radius[1] < rel[1] && rel[1] < sPuppyVolumeStack[index]->radius[1] && @@ -951,11 +945,8 @@ static s32 puppycam_check_volume_bounds(struct sPuppyVolume *volume, s32 index) } } else if (sPuppyVolumeStack[index]->shape == PUPPYVOLUME_SHAPE_CYLINDER) { // s16 dir; - f32 dist; - rel[0] = sPuppyVolumeStack[index]->pos[0] - gPuppyCam.targetObj->oPosX; - rel[1] = sPuppyVolumeStack[index]->pos[1] - gPuppyCam.targetObj->oPosY; - rel[2] = sPuppyVolumeStack[index]->pos[2] - gPuppyCam.targetObj->oPosZ; - dist = sqrtf(sqr(rel[0]) + sqr(rel[2])); + vec3_diff(rel, sPuppyVolumeStack[index]->pos, &gPuppyCam.targetObj->oPosVec); + f32 dist = sqrtf(sqr(rel[0]) + sqr(rel[2])); #ifdef VISUAL_DEBUG Vec3f debugPos[2]; vec3f_set(debugPos[0], sPuppyVolumeStack[index]->pos[0], sPuppyVolumeStack[index]->pos[1], sPuppyVolumeStack[index]->pos[2]); @@ -963,7 +954,7 @@ static s32 puppycam_check_volume_bounds(struct sPuppyVolume *volume, s32 index) debug_box_color(0x0000FF00); debug_box_rot(debugPos[0], debugPos[1], sPuppyVolumeStack[index]->rot, DEBUG_SHAPE_CYLINDER | DEBUG_UCODE_DEFAULT); #endif - distCheck = (dist < sPuppyVolumeStack[index]->radius[0]); + f32 distCheck = (dist < sPuppyVolumeStack[index]->radius[0]); if (-sPuppyVolumeStack[index]->radius[1] < rel[1] && rel[1] < sPuppyVolumeStack[index]->radius[1] && distCheck) { *volume = *sPuppyVolumeStack[index]; @@ -1151,8 +1142,8 @@ static void puppycam_projection(void) { targetPos3[0] = (s16)approach_f32_asymptotic(targetPos[0], targetPos2[0], 0.5f); targetPos3[1] = (s16)approach_f32_asymptotic(targetPos[1], targetPos2[1], 0.5f); targetPos3[2] = (s16)approach_f32_asymptotic(targetPos[2], targetPos2[2], 0.5f); - gPuppyCam.targetDist[0] = approach_f32_asymptotic(gPuppyCam.targetDist[0],(ABS(LENCOS(sqrtf(((targetPos[0]-targetPos2[0])*(targetPos[0]-targetPos2[0]))+((targetPos[2]-targetPos2[2])*(targetPos[2]-targetPos2[2]))), - (s16)ABS(((gPuppyCam.yaw + 0x8000) % 0xFFFF - 0x8000) - (atan2s(targetPos[2]-targetPos2[2], targetPos[0]-targetPos2[0])) % 0xFFFF - 0x8000)+0x4000))), 0.2f); + gPuppyCam.targetDist[0] = approach_f32_asymptotic(gPuppyCam.targetDist[0],(ABS(LENCOS(sqrtf(((targetPos[0] - targetPos2[0]) * (targetPos[0] - targetPos2[0])) + ((targetPos[2] - targetPos2[2]) * (targetPos[2] - targetPos2[2]))), + (s16)ABS(((gPuppyCam.yaw + 0x8000) % 0xFFFF - 0x8000) - (atan2s(targetPos[2] - targetPos2[2], targetPos[0] - targetPos2[0])) % 0xFFFF - 0x8000) + 0x4000))), 0.2f); } else { gPuppyCam.targetDist[0] = approach_f32_asymptotic(gPuppyCam.targetDist[0], 0, 0.2f); } @@ -1229,7 +1220,7 @@ static void puppycam_script(void) { } } -//Handles collision detection using ray casting. +// Handles collision detection using ray casting. static void puppycam_collision(void) { struct WallCollisionData wall0, wall1; struct Surface *surf[2]; @@ -1243,17 +1234,13 @@ static void puppycam_collision(void) { return; } // The ray, starting from the top - target[0][0] = gPuppyCam.targetObj->oPosX; - target[0][1] = gPuppyCam.targetObj->oPosY + (gPuppyCam.povHeight) - CLAMP(gPuppyCam.targetObj->oPosY - gPuppyCam.targetFloorHeight, 0, 300); - target[0][2] = gPuppyCam.targetObj->oPosZ; + vec3_copy_y_off(target[0], &gPuppyCam.targetObj->oPosVec, (gPuppyCam.povHeight) - CLAMP(gPuppyCam.targetObj->oPosY - gPuppyCam.targetFloorHeight, 0, 300)); // The ray, starting from the bottom - target[1][0] = gPuppyCam.targetObj->oPosX; - target[1][1] = gPuppyCam.targetObj->oPosY + (gPuppyCam.povHeight * 0.4f); - target[1][2] = gPuppyCam.targetObj->oPosZ; + vec3_copy_y_off(target[1], &gPuppyCam.targetObj->oPosVec, (gPuppyCam.povHeight * 0.4f)); - camdir[0][0] = LENSIN(LENSIN(gPuppyCam.zoomTarget,pitchTotal),gPuppyCam.yaw) + gPuppyCam.shake[0]; - camdir[0][1] = LENCOS(gPuppyCam.zoomTarget,pitchTotal) + gPuppyCam.shake[1]; - camdir[0][2] = LENCOS(LENSIN(gPuppyCam.zoomTarget,pitchTotal),gPuppyCam.yaw) + gPuppyCam.shake[2]; + camdir[0][0] = LENSIN(LENSIN(gPuppyCam.zoomTarget, pitchTotal), gPuppyCam.yaw) + gPuppyCam.shake[0]; + camdir[0][1] = LENCOS(gPuppyCam.zoomTarget, pitchTotal) + gPuppyCam.shake[1]; + camdir[0][2] = LENCOS(LENSIN(gPuppyCam.zoomTarget, pitchTotal), gPuppyCam.yaw) + gPuppyCam.shake[2]; vec3_copy(camdir[1], camdir[0]); @@ -1274,9 +1261,7 @@ static void puppycam_collision(void) { if (dist[0] >= dist[1]) { vec3_copy(gPuppyCam.pos, hitpos[0]); } else { - gPuppyCam.pos[0] = hitpos[1][0]; - gPuppyCam.pos[1] = hitpos[1][1] + (gPuppyCam.povHeight * 0.6f); - gPuppyCam.pos[2] = hitpos[1][2]; + vec3_copy_y_off(gPuppyCam.pos, hitpos[1], (gPuppyCam.povHeight * 0.6f)); } } } diff --git a/src/game/puppyprint.c b/src/game/puppyprint.c index da42b513..1cc02994 100644 --- a/src/game/puppyprint.c +++ b/src/game/puppyprint.c @@ -656,7 +656,7 @@ void get_char_from_byte(u8 letter, s32 *textX, s32 *textY, s32 *spaceX, s32 *off case '?': *textX = 60; *textY = 0; *spaceX = textLen[15]; break; // Question mark case '"': *textX = 40; *textY = 12; *spaceX = textLen[42]; break; // Speech mark - case'\'': *textX = 44; *textY = 12; *spaceX = textLen[43]; break; // Apostrophe. + case'\'': *textX = 44; *textY = 12; *spaceX = textLen[43]; break; // Apostrophe case ':': *textX = 48; *textY = 12; *spaceX = textLen[44]; break; // Colon case ';': *textX = 52; *textY = 12; *spaceX = textLen[45]; break; // Semicolon case '.': *textX = 56; *textY = 12; *spaceX = textLen[46]; break; // Full stop @@ -698,7 +698,7 @@ s32 text_iterate_command(const char *str, s32 i, s32 runCMD) { a = ((str[i + 11] - '0') * 10); a += str[i + 12] - '0'; // Multiply each value afterwards by 2.575f to make 255. - print_set_envcolour(r * 2.575f, g * 2.575f, b * 2.575f, a * 2.575f); + print_set_envcolour((r * 2.575f), (g * 2.575f), (b * 2.575f), (a * 2.575f)); } else if (strncmp(str+i, "", 6) == 0) { // Same as above, except it fades between two colours. The third set of numbers is the speed it fades. s32 r, g, b, a, r2, g2, b2, a2, spd, r3, g3, b3, a3, r4, g4, b4, a4; r = ((str[i + 6] - '0') * 10); @@ -906,17 +906,15 @@ void render_multi_image(Texture *image, s32 x, s32 y, s32 width, s32 height, UNU // Find how best to seperate the horizontal. Keep going until it finds a whole value. while (TRUE) { - f32 val = (f32)width/(f32)num; + f32 val = (f32)width / (f32)num; - if ((s32)val == val && (s32) val >= 1) - { + if ((s32)val == val && (s32) val >= 1) { imW = num; break; } num /= 2; - if (num == 1) - { - print_text(32,32,"IMAGE WIDTH FAILURE"); + if (num == 1) { + print_text(32, 32, "IMAGE WIDTH FAILURE"); return; } } @@ -926,42 +924,39 @@ void render_multi_image(Texture *image, s32 x, s32 y, s32 width, s32 height, UNU num = 2; // Find the width mask while (TRUE) { - if ((s32) num == imW) + if ((s32) num == imW) { break; - + } num *= 2; maskW++; if (maskW == 9) { - print_text(32,32,"WIDTH MASK FAILURE"); + print_text(32, 32, "WIDTH MASK FAILURE"); return; } } num = 2; - //Find the height mask + // Find the height mask while (TRUE) { - if ((s32) num == imH) + if ((s32) num == imH) { break; - - num*=2; + } + num *= 2; maskH++; - if (maskH == 9) - { - print_text(32,32,"HEIGHT MASK FAILURE"); + if (maskH == 9) { + print_text(32, 32, "HEIGHT MASK FAILURE"); return; } } num = height; - //Find the height remainder + // Find the height remainder peakH = height - (height % imH); - cycles = (width*peakH)/(imW*imH); + cycles = (width * peakH) / (imW * imH); - //Pass 1 - for (i = 0; i < cycles; i++) - { + // Pass 1 + for (i = 0; i < cycles; i++) { posW = 0; posH = (i*imH); - while (posH >= peakH) - { + while (posH >= peakH) { posW += imW; posH -= peakH; } @@ -969,14 +964,12 @@ void render_multi_image(Texture *image, s32 x, s32 y, s32 width, s32 height, UNU gDPLoadTextureTile(gDisplayListHead++, image, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, posW, posH, posW+imW-1, posH+imH-1, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, maskW, maskH, 0, 0); gSPScisTextureRectangle(gDisplayListHead++, (x + posW) << 2, (y + posH) << 2, (x + posW+imW-mOne) << 2,(y + posH + imH-mOne) << 2, G_TX_RENDERTILE, 0, 0, modeSC << 10, 1 << 10); } - //If there's a remainder on the vertical side, then it will cycle through that too. - if (height-peakH != 0) - { + // If there's a remainder on the vertical side, then it will cycle through that too. + if (height-peakH != 0) { posW = 0; posH = peakH; - for (i = 0; i < (width/imW); i++) - { - posW = i*imW; + for (i = 0; i < (width / imW); i++) { + posW = i * imW; gDPLoadSync(gDisplayListHead++); gDPLoadTextureTile(gDisplayListHead++, image, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, posW, posH, posW+imW-1, height-1, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, maskW, maskH, 0, 0); gSPScisTextureRectangle(gDisplayListHead++, (x + posW) << 2, (y + posH) << 2, (x + posW+imW-mOne) << 2,(y + posH + imH-mOne) << 2, G_TX_RENDERTILE, 0, 0, modeSC << 10, 1 << 10);