Some small optimizations

This commit is contained in:
Arceveti
2021-09-23 18:56:14 -07:00
parent ecd56464cd
commit 304ee502c8
23 changed files with 191 additions and 341 deletions

View File

@@ -2370,7 +2370,7 @@ const BehaviorScript bhvLllTiltingInvertedPyramid[] = {
const BehaviorScript bhvKoopaShell[] = {
BEGIN(OBJ_LIST_LEVEL),
OR_LONG(oFlags, (OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE | OBJ_FLAG_SILHOUETTE)), //! Silhouette doesn't show up in-game
OR_LONG(oFlags, (OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE | OBJ_FLAG_SILHOUETTE)), //! Silhouette doesn't show up in-game, due to the combine mode
SET_OBJ_PHYSICS(/*Wall hitbox radius*/ 30, /*Gravity*/ -400, /*Bounciness*/ -50, /*Drag strength*/ 1000, /*Friction*/ 1000, /*Buoyancy*/ 200, /*Unused*/ 0, 0),
BEGIN_LOOP(),
CALL_NATIVE(bhv_koopa_shell_loop),

File diff suppressed because it is too large Load Diff

View File

@@ -23,6 +23,7 @@ extern f32 gSineTable[];
#define sins(x) gSineTable[(u16) (x) >> 4]
#define coss(x) gCosineTable[(u16) (x) >> 4]
#define atans(x) gArctanTable[(s32)((((x) * 1024) + 0.5f))] // is this correct? used for atan2_lookup
#define DEG_PER_RAD 57.29577950560105
#define RAD_PER_DEG (1.0 / DEG_PER_RAD)
@@ -349,7 +350,6 @@ void vec3s_set(Vec3s dest, s16 x, s16 y, s16 z);
void vec3s_add(Vec3s dest, Vec3s a);
void vec3s_sum(Vec3s dest, Vec3s a, Vec3s b);
void vec3s_sub(Vec3s dest, Vec3s a);
void vec3s_to_vec3f(Vec3f dest, Vec3s a);
void vec3f_to_vec3s(Vec3s dest, Vec3f a);
void find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c);
void vec3f_cross(Vec3f dest, Vec3f a, Vec3f b);

View File

@@ -25,7 +25,7 @@ void bhv_donut_platform_spawner_update(void) {
dx = gMarioObject->oPosX - sDonutPlatformPositions[i][0];
dy = gMarioObject->oPosY - sDonutPlatformPositions[i][1];
dz = gMarioObject->oPosZ - sDonutPlatformPositions[i][2];
marioSqDist = dx * dx + dy * dy + dz * dz;
marioSqDist = sqr(dx) + sqr(dy) + sqr(dz);
// dist > 1000 and dist < 2000
if (marioSqDist > 1000000.0f && marioSqDist < 4000000.0f) {

View File

@@ -17,8 +17,6 @@ void bhv_lll_drawbridge_spawner_loop(void) {
}
void bhv_lll_drawbridge_loop(void) {
s32 globalTimer = gGlobalTimer;
switch (o->oAction) {
case LLL_DRAWBRIDGE_ACT_LOWER:
o->oFaceAngleRoll += 0x100;
@@ -32,9 +30,7 @@ void bhv_lll_drawbridge_loop(void) {
if ((s16) o->oFaceAngleRoll < -0x1FFD) {
o->oFaceAngleRoll = 0xDFFF;
//! Because the global timer increments when the game is paused, pausing and unpausing
// the game at regular intervals can leave the drawbridge raised indefinitely.
if (o->oTimer >= 51 && (globalTimer % 8) == 0) {
if (o->oTimer >= 51 && (o->oTimer % 8) == 0) {
o->oAction = LLL_DRAWBRIDGE_ACT_LOWER;
cur_obj_play_sound_2(SOUND_GENERAL_BOAT_TILT1);
}
@@ -43,9 +39,7 @@ void bhv_lll_drawbridge_loop(void) {
if ((s16) o->oFaceAngleRoll >= 0) {
o->oFaceAngleRoll = 0;
//! Because the global timer increments when the game is paused, pausing and unpausing
// the game at regular intervals can leave the drawbridge lowered indefinitely.
if (o->oTimer >= 51 && (globalTimer % 8) == 0) {
if (o->oTimer >= 51 && (o->oTimer % 8) == 0) {
o->oAction = LLL_DRAWBRIDGE_ACT_RAISE;
cur_obj_play_sound_2(SOUND_GENERAL_BOAT_TILT2);
}

View File

@@ -9,9 +9,7 @@ void bhv_squishable_platform_loop(void) {
}
void bhv_bitfs_sinking_platform_loop(void) {
o->oPosY -=
sins(o->oBitfsPlatformTimer)
* 0.58; //! f32 double conversion error accumulates on Wii VC causing the platform to rise up
o->oPosY -= sins(o->oBitfsPlatformTimer) * 0.58f;
o->oBitfsPlatformTimer += 0x100;
}

View File

@@ -3,7 +3,7 @@
s32 arc_to_goal_pos(Vec3f a0, Vec3f a1, f32 yVel, f32 gravity) {
f32 dx = a0[0] - a1[0];
f32 dz = a0[2] - a1[2];
f32 planarDist = sqrtf(dx * dx + dz * dz);
f32 planarDist = sqrtf(sqr(dx) + sqr(dz));
s32 time;
o->oMoveAngleYaw = atan2s(dz, dx);
o->oVelY = yVel;

View File

@@ -104,7 +104,7 @@ static void klepto_change_target(void) {
dx = gMarioObject->oPosX - sKleptoTargetPositions[i][0];
dz = gMarioObject->oPosZ - sKleptoTargetPositions[i][2];
targetDist = sqrtf(dx * dx + dz * dz);
targetDist = sqrtf(sqr(dx) + sqr(dz));
if (targetDist < minTargetDist) {
minTargetDist = targetDist;
newTarget = i;

View File

@@ -44,7 +44,7 @@ static void mad_piano_act_attack(void) {
} else {
f32 dx = o->oPosX - o->oHomeX;
f32 dz = o->oPosZ - o->oHomeZ;
f32 distToHome = sqrtf(dx * dx + dz * dz);
f32 distToHome = sqrtf(sqr(dx) + sqr(dz));
if (distToHome > 400.0f) {
distToHome = 400.0f / distToHome;

View File

@@ -372,12 +372,10 @@ void bhv_monty_mole_update(void) {
f32 dy = o->oPosY - sMontyMoleLastKilledPosY;
f32 dz = o->oPosZ - sMontyMoleLastKilledPosZ;
f32 distToLastKill = sqrtf(dx * dx + dy * dy + dz * dz);
//! The two farthest holes on the bottom level of TTM are more than
// 1500 units away from each other, so the counter resets if you
// attack moles in these holes consecutively.
if (distToLastKill < 1500.0f) {
if ((sqr(dx) + sqr(dy) + sqr(dz)) < sqr(1500.0f)) {
if (sMontyMoleKillStreak == 7) {
play_puzzle_jingle();
spawn_object(o, MODEL_1UP, bhv1upWalking);
@@ -387,8 +385,9 @@ void bhv_monty_mole_update(void) {
}
}
//! No overflow check
sMontyMoleKillStreak += 1;
if (sMontyMoleKillStreak < (1 << 15)) {
sMontyMoleKillStreak++;
}
sMontyMoleLastKilledPosX = o->oPosX;
sMontyMoleLastKilledPosY = o->oPosY;

View File

@@ -41,7 +41,7 @@ void set_home_to_mario(void) {
o->oPosY = o->oHomeY;
dx = o->oHomeX - o->oPosX;
dz = o->oHomeZ - o->oPosZ;
o->oForwardVel = sqrtf(dx * dx + dz * dz) / 23.0f;
o->oForwardVel = sqrtf(sqr(dx) + sqr(dz)) / 23.0f;
}
void set_y_home_to_pos(void) {

View File

@@ -92,7 +92,7 @@ void bhv_tilting_inverted_pyramid_loop(void) {
dx = gMarioObject->oPosX - o->oPosX;
dy = 500.0f;
dz = gMarioObject->oPosZ - o->oPosZ;
d = sqrtf(dx * dx + dy * dy + dz * dz);
d = sqrtf(sqr(dx) + sqr(dy) + sqr(dz));
//! Always true since dy = 500, making d >= 500.
if (d != 0.0f) {

View File

@@ -192,7 +192,7 @@ void wiggler_init_segments(void) {
bodyPart->yaw = prevBodyPart->yaw + dyaw;
// As the head tilts, propagate the tilt backward
dxz = sqrtf(dx * dx + dz * dz);
dxz = sqrtf(sqr(dx) + sqr(dz));
dpitch = atan2s(dxz, dy) - prevBodyPart->pitch;
clamp_s16(&dpitch, -0x2000, 0x2000);
bodyPart->pitch = prevBodyPart->pitch + dpitch;

View File

@@ -1287,8 +1287,8 @@ s32 update_parallel_tracking_camera(struct Camera *c, Vec3f focus, Vec3f pos) {
vec3f_copy(focOffset, marioOffset);
// OK
focOffset[0] = -focOffset[0] * 0.f;
focOffset[1] = focOffset[1] * 0.f;
focOffset[0] = 0.f;
focOffset[1] = 0.f;
// Repeat above calcs with camOffset
camOffset[0] = pos[0] - parMidPoint[0];
@@ -1319,11 +1319,6 @@ s32 update_parallel_tracking_camera(struct Camera *c, Vec3f focus, Vec3f pos) {
marioOffset[1] = marioOffset[1] * zoom;
marioOffset[2] = camOffset[2];
//! Does nothing because focOffset[0] is always 0
focOffset[0] *= 0.3f;
//! Does nothing because focOffset[1] is always 0
focOffset[1] *= 0.3f;
pathAngle[0] = pathPitch;
pathAngle[1] = pathYaw; //! No effect
@@ -2128,12 +2123,8 @@ s16 update_default_camera(struct Camera *c) {
unusedFreeRoamWallYaw = avoidYaw;
sAvoidYawVel = yaw;
sStatusFlags |= CAM_FLAG_COLLIDED_WITH_WALL;
//! Does nothing
vec3f_get_dist_and_angle(sMarioCamState->pos, cPos, &xzDist, &tempPitch, &tempYaw);
// Rotate to avoid the wall
approach_s16_asymptotic_bool(&yaw, avoidYaw, 10);
//! Does nothing
vec3f_set_dist_and_angle(sMarioCamState->pos, cPos, xzDist, tempPitch, tempYaw);
sAvoidYawVel = (sAvoidYawVel - yaw) / 0x100;
} else {
if (gMarioStates[0].forwardVel == 0.f) {
@@ -2386,8 +2377,6 @@ s32 update_spiral_stairs_camera(struct Camera *c, Vec3f focus, Vec3f pos) {
}
focYaw += sSpiralStairsYawOffset;
posYaw = focYaw;
//! @bug unnecessary
camera_approach_s16_symmetric_bool(&posYaw, focYaw, 0x1000);
vec3f_set_dist_and_angle(sFixedModeBasePosition, cPos, 300.f, 0, posYaw);
@@ -4442,7 +4431,7 @@ s16 calculate_pitch(Vec3f from, Vec3f to) {
f32 dx = to[0] - from[0];
f32 dy = to[1] - from[1];
f32 dz = to[2] - from[2];
s16 pitch = atan2s(sqrtf(dx * dx + dz * dz), dy);
s16 pitch = atan2s(sqrtf(sqr(dx) + sqr(dz)), dy);
return pitch;
}
@@ -4464,7 +4453,7 @@ void calculate_angles(Vec3f from, Vec3f to, s16 *pitch, s16 *yaw) {
f32 dy = to[1] - from[1];
f32 dz = to[2] - from[2];
*pitch = atan2s(sqrtf(dx * dx + dz * dz), dy);
*pitch = atan2s(sqrtf(sqr(dx) + sqr(dz)), dy);
*yaw = atan2s(dz, dx);
}
@@ -4475,7 +4464,7 @@ f32 calc_abs_dist(Vec3f a, Vec3f b) {
f32 distX = b[0] - a[0];
f32 distY = b[1] - a[1];
f32 distZ = b[2] - a[2];
f32 distAbs = sqrtf(distX * distX + distY * distY + distZ * distZ);
f32 distAbs = sqrtf(sqr(distX) + sqr(distY) + sqr(distZ));
return distAbs;
}
@@ -4486,7 +4475,7 @@ f32 calc_abs_dist(Vec3f a, Vec3f b) {
f32 calc_hor_dist(Vec3f a, Vec3f b) {
f32 distX = b[0] - a[0];
f32 distZ = b[2] - a[2];
f32 distHor = sqrtf(distX * distX + distZ * distZ);
f32 distHor = sqrtf(sqr(distX) + sqr(distZ));
return distHor;
}
@@ -7028,20 +7017,6 @@ void retrieve_info_star(struct Camera *c) {
vec3f_copy(c->focus, sCameraStoreCutscene.focus);
}
static UNUSED void unused_vec3s_to_vec3f(Vec3f dst, Vec3s src) {
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
static UNUSED void unused_vec3f_to_vec3s(Vec3s dst, Vec3f src) {
// note: unlike vec3f_to_vec3s(), this function doesn't round the numbers and instead simply
// truncates them
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
/**
* Rotate the camera's focus around the camera's position by incYaw and incPitch
*/
@@ -7942,11 +7917,8 @@ void cutscene_bowser_arena_set_pos(struct Camera *c) {
* The y offset starts at 120, then decreases to 0 before reaching ~240 on the last frame.
*/
void cutscene_bowser_arena_focus_sine(UNUSED struct Camera *c) {
//! unused initialization
f32 yOff = 150.0f;
// cvar4 was zeroed when the cutscene started.
yOff = sins(sCutsceneVars[4].angle[1]) * 120.0f + 120.0f;
f32 yOff = sins(sCutsceneVars[4].angle[1]) * 120.0f + 120.0f;
sCutsceneVars[4].angle[1] -= 0x200;
approach_f32_asymptotic_bool(&sCutsceneVars[0].point[1], yOff, 0.5f);
}

View File

@@ -151,8 +151,8 @@ void orbit_from_positions(Vec3s from, Vec3s to, s16 *radius, s16 *pitch, s16 *ya
f32 dy = to[1] - from[1];
f32 dz = to[2] - from[2];
*radius = (s16) sqrtf(dx * dx + dy * dy + dz * dz);
*pitch = atan2s(sqrtf(dx * dx + dz * dz), dy);
*radius = (s16) sqrtf(sqr(dx) + sqr(dy) + sqr(dz));
*pitch = atan2s(sqrtf(sqr(dx) + sqr(dz)), dy);
*yaw = atan2s(dz, dx);
}

View File

@@ -718,7 +718,7 @@ void set_steep_jump_action(struct MarioState *m) {
f32 y = sins(faceAngleTemp) * m->forwardVel;
f32 x = coss(faceAngleTemp) * m->forwardVel * 0.75f;
m->forwardVel = sqrtf(y * y + x * x);
m->forwardVel = sqrtf(sqr(y) + sqr(x));
m->faceAngle[1] = atan2s(x, y) + angleTemp;
}
@@ -1834,10 +1834,10 @@ void init_mario(void) {
gMarioState->area = gCurrentArea;
gMarioState->marioObj = gMarioObject;
gMarioState->marioObj->header.gfx.animInfo.animID = -1;
vec3s_copy(gMarioState->faceAngle, gMarioSpawnInfo->startAngle);
vec3s_set(gMarioState->angleVel, 0, 0, 0);
vec3s_to_vec3f(gMarioState->pos, gMarioSpawnInfo->startPos);
vec3f_set(gMarioState->vel, 0, 0, 0);
vec3_copy(gMarioState->faceAngle, gMarioSpawnInfo->startAngle);
vec3_zero(gMarioState->angleVel);
vec3_copy(gMarioState->pos, gMarioSpawnInfo->startPos);
vec3_zero(gMarioState->vel);
gMarioState->floorHeight = find_floor(gMarioState->pos[0], gMarioState->pos[1], gMarioState->pos[2], &gMarioState->floor);
if (gMarioState->pos[1] < gMarioState->floorHeight) {

View File

@@ -254,7 +254,7 @@ void handle_save_menu(struct MarioState *m) {
if (gSaveOptSelectIndex == MENU_OPT_SAVE_AND_QUIT) {
//! crashes
fade_into_special_warp(WARP_SPECIAL_MARIO_HEAD_REGULAR, 0);// reset game
fade_into_special_warp(WARP_SPECIAL_MARIO_HEAD_REGULAR, 0); // reset game
}
}

View File

@@ -694,7 +694,7 @@ void push_or_sidle_wall(struct MarioState *m, Vec3f startPos) {
s16 dWallAngle;
f32 dx = m->pos[0] - startPos[0];
f32 dz = m->pos[2] - startPos[2];
f32 movedDistance = sqrtf(dx * dx + dz * dz);
f32 movedDistance = sqrtf(sqr(dx) + sqr(dz));
//! (Speed Crash) If a wall is after moving 16384 distance, this crashes.
s32 animSpeed = (s32)(movedDistance * 2.0f * 0x10000);

View File

@@ -139,8 +139,8 @@ static void apply_water_current(struct MarioState *m, Vec3f step) {
f32 dy = whirlpool->pos[1] - m->pos[1];
f32 dz = whirlpool->pos[2] - m->pos[2];
f32 lateralDist = sqrtf(dx * dx + dz * dz);
f32 distance = sqrtf(lateralDist * lateralDist + dy * dy);
f32 lateralDist = sqrtf(sqr(dx) + sqr(dz));
f32 distance = sqrtf(lateralDist * lateralDist + sqr(dy));
s16 pitchToWhirlpool = atan2s(lateralDist, dy);
s16 yawToWhirlpool = atan2s(dz, dx);
@@ -1049,7 +1049,7 @@ static s32 act_caught_in_whirlpool(struct MarioState *m) {
f32 dx = m->pos[0] - whirlpool->oPosX;
f32 dz = m->pos[2] - whirlpool->oPosZ;
f32 distance = sqrtf(dx * dx + dz * dz);
f32 distance = sqrtf(sqr(dx) + sqr(dz));
if ((marioObj->oMarioWhirlpoolPosY += m->vel[1]) < 0.0f) {
marioObj->oMarioWhirlpoolPosY = 0.0f;

View File

@@ -191,7 +191,7 @@ static void platform_on_track_update_pos_or_spawn_ball(s32 ballIndex, f32 x, f32
dy = nextWaypoint->pos[1] - y;
dz = nextWaypoint->pos[2] - z;
distToNextWaypoint = sqrtf(dx * dx + dy * dy + dz * dz);
distToNextWaypoint = sqrtf(sqr(dx) + sqr(dy) + sqr(dz));
// Move directly to the next waypoint, even if it's farther away
// than amountToMove
@@ -856,7 +856,7 @@ static void treat_far_home_as_mario(f32 threshold) {
f32 dx = o->oHomeX - o->oPosX;
f32 dy = o->oHomeY - o->oPosY;
f32 dz = o->oHomeZ - o->oPosZ;
f32 distance = sqrtf(dx * dx + dy * dy + dz * dz);
f32 distance = sqrtf(sqr(dx) + sqr(dy) + sqr(dz));
if (distance > threshold) {
o->oAngleToMario = atan2s(dz, dx);
@@ -865,7 +865,7 @@ static void treat_far_home_as_mario(f32 threshold) {
dx = o->oHomeX - gMarioObject->oPosX;
dy = o->oHomeY - gMarioObject->oPosY;
dz = o->oHomeZ - gMarioObject->oPosZ;
distance = sqrtf(dx * dx + dy * dy + dz * dz);
distance = sqrtf(sqr(dx) + sqr(dy) + sqr(dz));
if (distance > threshold) {
o->oDistanceToMario = 20000.0f;

Some files were not shown because too many files have changed in this diff Show More