Skip to content

Commit

Permalink
Merge pull request n64decomp#69 from Reonu/merge_nightly_fixes
Browse files Browse the repository at this point in the history
Fixes for merging nightly
  • Loading branch information
thecozies authored Oct 5, 2021
2 parents 77bf073 + da285a1 commit febc16c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 53 deletions.
6 changes: 3 additions & 3 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
// 1 is similar to vanilla, but prevents Mario from moving in the wrong direction, and allows finer control with the analog stick.
// 2 is similar to mode 1, but a bit further from vanilla, and allows instant turnaround if Mario is moving slower than a certain threshold.
// 3 is instant turning to the intended direction regardless of speed and angle.
// 4 is an expeimental asymptotic turn.
// 4 is an experimental asymptotic turn.
#define GROUND_TURN_MODE 0
// Improved hanging:
// - Doesn't require holding down the A button
Expand Down Expand Up @@ -105,7 +105,7 @@
#define HANGING_FIX
// The last frame that will be considered a firsty when wallkicking
#define FIRSTY_LAST_FRAME 1
// The maximum angle the player can wall kick, in degrees. 0..90
// The maximum angle the player can wall kick, in degrees. 0..90. To allow 45 degree wall kicks, you must supply `46` to allow 45 and under.
#define WALL_KICK_DEGREES 45
// Disable BLJs and crush SimpleFlips's dreams
//#define DISABLE_BLJ
Expand All @@ -131,7 +131,7 @@
// Allow for retries on collecting the remaining blue coins from a blue coin switch
#define BLUE_COIN_SWITCH_RETRY
// Fixes shell cancel
#define SHELL_CANCEL_FIX
//#define SHELL_CANCEL_FIX
// The number of chain balls the Chain Chomp has. Vanilla is 5.
#define CHAIN_CHOMP_NUM_SEGMENTS 5
// The number of parts Pokey has, including the head. Vanilla is 5, max is 30.
Expand Down
18 changes: 11 additions & 7 deletions src/engine/math_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ Vec3i gVec3iZero = { 0, 0, 0 };
Vec3s gVec3sOne = { 1, 1, 1 };

/// From Wiseguy
static inline s32 roundf(f32 in) {
static inline s32 asm_roundf(f32 in) {
f32 tmp;
s32 out;
__asm__("round.w.s %0,%1" : "=f" (tmp) : "f" (in));
__asm__("mfc1 %0,%1" : "=r" (out) : "f" (tmp));
return out;
}

// static inline float absf(float in) {
// f32 out;
// __asm__("abs.s %0,%1" : "=f" (out) : "f" (in));
// return out;
// }
f32 roundf(f32 x) {
return asm_roundf(x);
}

static inline float asm_absf(float in) {
f32 out;
__asm__("abs.s %0,%1" : "=f" (out) : "f" (in));
return out;
}

f32 absf(f32 x) {
return ABSF(x);
return asm_absf(x);
}

/// Returns the lowest of three values.
Expand Down
1 change: 1 addition & 0 deletions src/engine/math_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ extern f32 gSineTable[];
} \
}

f32 roundf(f32 x);
f32 absf(f32 x);
s32 min_3i(s32 a0, s32 a1, s32 a2);
f32 min_3f(f32 a0, f32 a1, f32 a2);
Expand Down
4 changes: 2 additions & 2 deletions src/game/behaviors/pokey.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static void pokey_act_uninitialized(void) {
s32 i;
s16 partModel;

if (o->oDistanceToMario < 4000.0f) {
if (o->oDistanceToMario < o->oDrawingDistance) {
partModel = MODEL_POKEY_HEAD;

for (i = 0; i < POKEY_NUM_SEGMENTS; i++) {
Expand Down Expand Up @@ -177,7 +177,7 @@ static void pokey_act_wander(void) {

if (o->oPokeyNumAliveBodyParts == POKEY_PART_BP_HEAD) {
obj_mark_for_deletion(o);
} else if (o->oDistanceToMario > 4500.0f) {
} else if (o->oDistanceToMario > (o->oDrawingDistance + 500.0f)) {
o->oAction = POKEY_ACT_UNLOAD_PARTS;
o->oForwardVel = 0.0f;
} else {
Expand Down
37 changes: 11 additions & 26 deletions src/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,13 +896,7 @@ void radial_camera_move(struct Camera *c) {

// How much the camera's yaw changed
s16 yawOffset = calculate_yaw(sMarioCamState->pos, c->pos) - atan2s(areaDistZ, areaDistX);

if (yawOffset > maxAreaYaw) {
yawOffset = maxAreaYaw;
}
if (yawOffset < minAreaYaw) {
yawOffset = minAreaYaw;
}
yawOffset = CLAMP(yawOffset, minAreaYaw, maxAreaYaw);

// Check if Mario stepped on a surface that rotates the camera. For example, when Mario enters the
// gate in BoB, the camera turns right to face up the hill path
Expand Down Expand Up @@ -3874,23 +3868,16 @@ s32 clamp_positions_and_find_yaw(Vec3f pos, Vec3f origin, f32 xMax, f32 xMin, f3
/**
* The yaw passed here is the yaw of the direction FROM Mario TO Lakitu.
*
* wallYaw always has 90 degrees added to it before this is called -- it's parallel to the wall.
*
* @return the new yaw from Mario to rotate towards.
*
* @warning this is jank. It actually returns the yaw that will rotate further INTO the wall. So, the
* developers just add 180 degrees to the result.
*/
s32 calc_avoid_yaw(s16 yawFromMario, s16 wallYaw) {
s16 yawDiff = wallYaw - yawFromMario + DEGREES(90);

if (yawDiff < 0) {
if (yawFromMario < (s16)(wallYaw + DEGREES(180))) {
// Deflect to the right
yawFromMario = wallYaw;
yawFromMario = wallYaw + DEGREES(90);
} else {
// Note: this favors the left side if the wall is exactly perpendicular to the camera.
// Deflect to the left
yawFromMario = wallYaw + DEGREES(180);
yawFromMario = wallYaw - DEGREES(90);
}
return yawFromMario;
}
Expand Down Expand Up @@ -6118,7 +6105,7 @@ void resolve_geometry_collisions(Vec3f pos) {
s32 rotate_camera_around_walls(UNUSED struct Camera *c, Vec3f cPos, s16 *avoidYaw, s16 yawRange) {
struct WallCollisionData colData;
struct Surface *wall;
s16 wallYaw, horWallNorm;
s16 wallYaw;
// The yaw of the vector from Mario to the camera.
s16 yawFromMario;
s32 status = 0;
Expand Down Expand Up @@ -6156,10 +6143,9 @@ s32 rotate_camera_around_walls(UNUSED struct Camera *c, Vec3f cPos, s16 *avoidYa
status = 1;
wall = colData.walls[colData.numWalls - 1];
// wallYaw is parallel to the wall, not perpendicular
wallYaw = atan2s(wall->normal.z, wall->normal.x) + DEGREES(90);
// Calculate the avoid direction. The function returns the opposite direction so add 180
// degrees.
*avoidYaw = calc_avoid_yaw(yawFromMario, wallYaw) + DEGREES(180);
wallYaw = SURFACE_YAW(wall);
// Calculate the avoid direction. The function returns the opposite direction so add 180 degrees.
*avoidYaw = calc_avoid_yaw(yawFromMario, wallYaw);
}
}

Expand All @@ -6172,17 +6158,16 @@ s32 rotate_camera_around_walls(UNUSED struct Camera *c, Vec3f cPos, s16 *avoidYa

if (find_wall_collisions(&colData) != 0) {
wall = colData.walls[colData.numWalls - 1];
horWallNorm = atan2s(wall->normal.z, wall->normal.x);
wallYaw = horWallNorm + DEGREES(90);
wallYaw = SURFACE_YAW(wall);
// If Mario would be blocked by the surface, then avoid it
if ((is_range_behind_surface(sMarioCamState->pos, cPos, wall, yawRange, SURFACE_WALL_MISC) == 0)
&& (is_behind_surface(sMarioCamState->pos, wall))
// Also check if the wall is tall enough to cover Mario
&& (!is_surf_within_bounding_box(wall, -1.f, 150.f, -1.f))) {
// Calculate the avoid direction. The function returns the opposite direction so add 180
// degrees.
*avoidYaw = calc_avoid_yaw(yawFromMario, wallYaw) + DEGREES(180);
camera_approach_s16_symmetric_bool(avoidYaw, horWallNorm, yawRange);
*avoidYaw = calc_avoid_yaw(yawFromMario, wallYaw);
camera_approach_s16_symmetric_bool(avoidYaw, wallYaw, yawRange);
status = 3;
step = 8;
}
Expand Down
9 changes: 0 additions & 9 deletions src/game/mario_step.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,6 @@ s32 perform_air_step(struct MarioState *m, u32 stepArg) {
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);

/*if (stepResult == AIR_STEP_HIT_WALL && m->wall != NULL) {
wallDYaw = abs_angle_diff(atan2s(m->wall->normal.z, m->wall->normal.x), m->faceAngle[1]);
if ((stepArg & AIR_STEP_CHECK_BONK) && (wallDYaw > DEGREES(180 - WALL_KICK_DEGREES))) {
if (m->forwardVel > 16.0f) {
mario_bonk_reflection(m, (stepArg & AIR_STEP_BONK_NEGATE_SPEED), m->wall);
}
}
}*/

return stepResult;
}

Expand Down
12 changes: 6 additions & 6 deletions src/game/object_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ void obj_set_held_state(struct Object *obj, const BehaviorScript *heldBehavior)
}

f32 lateral_dist_between_objects(struct Object *obj1, struct Object *obj2) {
f32 lateralDist;
vec3f_get_lateral_dist(&obj1->oPosVec, &obj2->oPosVec, &lateralDist);
return lateralDist;
register f32 dx = (obj2->oPosX - obj1->oPosX);
register f32 dz = (obj2->oPosZ - obj1->oPosZ);
return sqrtf(sqr(dx) + sqr(dz));
}

f32 dist_between_objects(struct Object *obj1, struct Object *obj2) {
f32 dist;
vec3f_get_dist(&obj1->oPosVec, &obj2->oPosVec, &dist);
return dist;
register Vec3f d;
vec3_diff(d, &obj2->oPosVec, &obj1->oPosVec);
return vec3_mag(d);
}

void cur_obj_forward_vel_approach_upward(f32 target, f32 increment) {
Expand Down

0 comments on commit febc16c

Please sign in to comment.