Optimize out a bunch of sqrtf

This commit is contained in:
Arceveti
2021-09-28 22:43:29 -07:00
parent 28e8d99707
commit 8e398008d8
60 changed files with 332 additions and 535 deletions

View File

@@ -10,14 +10,11 @@
#include "game/level_update.h"
#include "game/object_list_processor.h"
#include "game/camera.h"
#include "engine/math_util.h"
#include "seq_ids.h"
#include "dialog_ids.h"
#if defined(VERSION_EU) || defined(VERSION_SH)
#define EU_FLOAT(x) x##f
#else
#define EU_FLOAT(x) x
#endif
// N.B. sound banks are different from the audio banks referred to in other
// files. We should really fix our naming to be less ambiguous...
@@ -845,7 +842,7 @@ static void process_sound_request(u32 bits, f32 *pos) {
// Allocate from free list
soundIndex = sSoundBankFreeListFront[bank];
dist = sqrtf(pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]) * one;
dist = sqrtf(sqr(pos[0]) + sqr(pos[1]) + sqr(pos[2])) * one;
sSoundBanks[bank][soundIndex].x = &pos[0];
sSoundBanks[bank][soundIndex].y = &pos[1];
sSoundBanks[bank][soundIndex].z = &pos[2];

View File

@@ -9,10 +9,6 @@
#include "game/area.h"
#include "geo_layout.h"
// unused Mtx(s)
s16 identityMtx[4][4] = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } };
s16 zeroMtx[4][4] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
/**
* Initialize a geo node with a given type. Sets all links such that there
* are no siblings, parent or children for this node.

View File

@@ -12,6 +12,10 @@
#include "config.h"
// unused Mtx(s)
s16 identityMtx[4][4] = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } };
s16 zeroMtx[4][4] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
Vec3f gVec3fX = { 1.0f, 0.0f, 0.0f };
Vec3f gVec3fY = { 0.0f, 1.0f, 0.0f };
Vec3f gVec3fZ = { 0.0f, 0.0f, 1.0f };
@@ -40,11 +44,7 @@ static inline s32 roundf(f32 in) {
// }
f32 absf(f32 x) {
if (x >= 0) {
return x;
} else {
return -x;
}
return ABSF(x);
}
/// Returns the lowest of three values.
@@ -543,7 +543,7 @@ void mtxf_mul_vec3s(Mat4 mtx, Vec3s b) {
register s32 i;
register s16 *c = b;
for (i = 0; i < 3; i++) {
c[0] = x * temp2[0] + y * temp2[4] + z * temp2[8] + temp2[12];
c[0] = (x * temp2[0]) + (y * temp2[4]) + (z * temp2[8]) + temp2[12];
c++;
temp2++;
}
@@ -566,13 +566,13 @@ void mtxf_mul_vec3s(Mat4 mtx, Vec3s b) {
void mtxf_to_mtx_scale(Mtx *dest, Mat4 src) {
Mat4 temp;
register s32 i, j;
for( i = 0; i < 4; i++ ) {
for( j = 0; j < 3; j++ ) {
temp[i][j] = src[i][j] / gWorldScale;
for(i = 0; i < 4; i++) {
for(j = 0; j < 3; j++) {
temp[i][j] = (src[i][j] / gWorldScale);
}
temp[i][3] = src[i][3];
}
guMtxF2L( temp, dest );
guMtxF2L(temp, dest);
}
void mtxf_to_mtx_constant(register s16 *dest, register f32 *src) {
@@ -580,7 +580,7 @@ void mtxf_to_mtx_constant(register s16 *dest, register f32 *src) {
s32 i;
for (i = 0; i < 16; i++) {
asFixedPoint = (src[i] * (1 << 16));
dest[i] = (asFixedPoint >> 16);
dest[i ] = (asFixedPoint >> 16);
dest[i + 16] = (asFixedPoint & 0xFFFF);
}
}
@@ -660,7 +660,7 @@ void vec3f_get_lateral_dist(Vec3f from, Vec3f to, f32 *lateralDist) {
*lateralDist = sqrtf(sqr(dx) + sqr(dz));
}
/// Finds the squared horizontal distance between two vectors.
/// Finds the squared horizontal distance between two vectors. Avoids a sqrtf call.
void vec3f_get_lateral_dist_squared(Vec3f from, Vec3f to, f32 *lateralDist) {
register f32 dx = (to[0] - from[0]);
register f32 dz = (to[2] - from[2]);
@@ -674,7 +674,7 @@ void vec3f_get_dist(Vec3f from, Vec3f to, f32 *dist) {
*dist = vec3_mag(d);
}
/// Finds the squared distance between two vectors.
/// Finds the squared distance between two vectors. Avoids a sqrtf call.
void vec3f_get_dist_squared(Vec3f from, Vec3f to, f32 *dist) {
register Vec3f d;
vec3_diff(d, to, from);

View File

@@ -481,20 +481,21 @@ void mtxf_to_mtx_scale(Mtx *dest, Mat4 src);
void mtxf_rotate_xy(Mtx *mtx, s32 angle);
void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx);
void vec2f_get_lateral_dist( Vec2f from, Vec2f to, f32 *lateralDist );
void vec3f_get_lateral_dist( Vec3f from, Vec3f to, f32 *lateralDist );
void vec3f_get_dist( Vec3f from, Vec3f to, f32 *dist );
void vec3f_get_dist_squared( Vec3f from, Vec3f to, f32 *dist );
void vec3f_get_dist_and_yaw( Vec3f from, Vec3f to, f32 *dist, Angle *yaw);
void vec3f_get_pitch( Vec3f from, Vec3f to, Angle *pitch );
void vec3f_get_yaw( Vec3f from, Vec3f to, Angle *yaw);
void vec3f_get_angle( Vec3f from, Vec3f to, Angle *pitch, Angle *yaw);
void vec3f_get_lateral_dist_and_pitch( Vec3f from, Vec3f to, f32 *lateralDist, Angle *pitch );
void vec3f_get_lateral_dist_and_yaw( Vec3f from, Vec3f to, f32 *lateralDist, Angle *yaw);
void vec3f_get_lateral_dist_and_angle( Vec3f from, Vec3f to, f32 *lateralDist, Angle *pitch, Angle *yaw);
void vec3f_get_dist_and_lateral_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, f32 *lateralDist, Angle *pitch, Angle *yaw);
void vec3s_get_dist_and_angle( Vec3s from, Vec3s to, s16 *dist, Angle *pitch, Angle *yaw);
void vec3f_get_dist_and_angle( Vec3f from, Vec3f to, f32 *dist, Angle *pitch, Angle *yaw);
void vec2f_get_lateral_dist( Vec2f from, Vec2f to, f32 *lateralDist );
void vec3f_get_lateral_dist( Vec3f from, Vec3f to, f32 *lateralDist );
void vec3f_get_lateral_dist_squared( Vec3f from, Vec3f to, f32 *lateralDist );
void vec3f_get_dist( Vec3f from, Vec3f to, f32 *dist );
void vec3f_get_dist_squared( Vec3f from, Vec3f to, f32 *dist );
void vec3f_get_dist_and_yaw( Vec3f from, Vec3f to, f32 *dist, Angle *yaw);
void vec3f_get_pitch( Vec3f from, Vec3f to, Angle *pitch );
void vec3f_get_yaw( Vec3f from, Vec3f to, Angle *yaw);
void vec3f_get_angle( Vec3f from, Vec3f to, Angle *pitch, Angle *yaw);
void vec3f_get_lateral_dist_and_pitch( Vec3f from, Vec3f to, f32 *lateralDist, Angle *pitch );
void vec3f_get_lateral_dist_and_yaw( Vec3f from, Vec3f to, f32 *lateralDist, Angle *yaw);
void vec3f_get_lateral_dist_and_angle( Vec3f from, Vec3f to, f32 *lateralDist, Angle *pitch, Angle *yaw);
void vec3f_get_dist_and_lateral_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, f32 *lateralDist, Angle *pitch, Angle *yaw);
void vec3s_get_dist_and_angle( Vec3s from, Vec3s to, s16 *dist, Angle *pitch, Angle *yaw);
void vec3f_get_dist_and_angle( Vec3f from, Vec3f to, f32 *dist, Angle *pitch, Angle *yaw);
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);

View File

@@ -717,9 +717,9 @@ static void get_optimal_coll_dist(struct Object *obj) {
*/
void load_object_collision_model(void) {
TerrainData vertexData[600];
#if PUPPYPRINT_DEBUG
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
#endif
TerrainData *collisionData = gCurrentObject->collisionData;
f32 marioDist = gCurrentObject->oDistanceToMario;

View File

@@ -569,7 +569,7 @@ Gfx *geo_snufit_move_mask(s32 callContext, struct GraphNode *node, UNUSED Mat4 *
Gfx *geo_snufit_scale_body(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
// Bowser key cutscene
Gfx *geo_scale_bowser_key(s32 run, struct GraphNode *node, UNUSED f32 mtx[4][4]);
Gfx *geo_scale_bowser_key(s32 run, struct GraphNode *node, UNUSED Mat4 mtx);
// Water splash
extern struct WaterDropletParams gShallowWaterSplashDropletParams;

View File

@@ -270,7 +270,7 @@ static void fixed_circling_amp_idle_loop(void) {
f32 xToMario = gMarioObject->header.gfx.pos[0] - o->oPosX;
f32 yToMario = gMarioObject->header.gfx.pos[1] + 120.0f - o->oPosY;
f32 zToMario = gMarioObject->header.gfx.pos[2] - o->oPosZ;
s16 vAngleToMario = atan2s(sqrtf(xToMario * xToMario + zToMario * zToMario), -yToMario);
s16 vAngleToMario = atan2s(sqrtf(sqr(xToMario) + sqr(zToMario)), -yToMario);
obj_turn_toward_object(o, gMarioObject, 19, 0x1000);
o->oFaceAnglePitch = approach_s16_symmetric(o->oFaceAnglePitch, vAngleToMario, 0x1000);

View File

@@ -12,7 +12,7 @@
static void handle_merry_go_round_music(void) {
// If the music should play, play it and check whether it still should.
// Otherwise, don't play it and check whether it should.
if (o->oMerryGoRoundMusicShouldPlay == FALSE) {
if (!o->oMerryGoRoundMusicShouldPlay) {
if (gMarioCurrentRoom == BBH_NEAR_MERRY_GO_ROUND_ROOM) {
// Play the merry-go-round and BBH music at the same time
play_secondary_music(SEQ_EVENT_MERRY_GO_ROUND, 45, 20, 200);

View File

@@ -44,7 +44,7 @@ void bhv_beta_chest_bottom_loop(void) {
void bhv_beta_chest_lid_loop(void) {
switch (o->oAction) {
case BETA_CHEST_ACT_IDLE_CLOSED:
if (dist_between_objects(o->parentObj, gMarioObject) < 300.0f) {
if (dist_between_objects_squared(o->parentObj, gMarioObject) < sqr(300.0f)) {
o->oAction++; // Set to BETA_CHEST_ACT_OPENING
}

View File

@@ -14,9 +14,9 @@ static struct ObjectHitbox sBooGivingStarHitbox = {
// Relative positions
static s16 sCourtyardBooTripletPositions[][3] = {
{0, 50, 0},
{210, 110, 210},
{-210, 70, -210}
{ 0, 50, 0},
{ 210, 110, 210},
{-210, 70, -210}
};
static void boo_stop(void) {
@@ -31,20 +31,14 @@ void bhv_boo_init(void) {
static s32 boo_should_be_stopped(void) {
if (cur_obj_has_behavior(bhvMerryGoRoundBigBoo) || cur_obj_has_behavior(bhvMerryGoRoundBoo)) {
if (!gMarioOnMerryGoRound) {
return TRUE;
} else {
return FALSE;
}
return (!gMarioOnMerryGoRound);
} else {
if (o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM) {
return TRUE;
}
if (o->oRoom == 10) {
if (gTimeStopState & TIME_STOP_MARIO_OPENED_DOOR) {
return TRUE;
}
if ((o->oRoom == 10) && (gTimeStopState & TIME_STOP_MARIO_OPENED_DOOR)) {
return TRUE;
}
}
@@ -52,20 +46,10 @@ static s32 boo_should_be_stopped(void) {
}
static s32 boo_should_be_active(void) {
f32 activationRadius;
if (cur_obj_has_behavior(bhvBalconyBigBoo)) {
activationRadius = 5000.0f;
} else {
activationRadius = 1500.0f;
}
f32 activationRadius = (cur_obj_has_behavior(bhvBalconyBigBoo) ? 5000.0f : 1500.0f);
if (cur_obj_has_behavior(bhvMerryGoRoundBigBoo) || cur_obj_has_behavior(bhvMerryGoRoundBoo)) {
if (gMarioOnMerryGoRound == TRUE) {
return TRUE;
} else {
return FALSE;
}
return (gMarioOnMerryGoRound);
} else if (o->oRoom == -1) {
if (o->oDistanceToMario < activationRadius) {
return TRUE;
@@ -299,11 +283,7 @@ static s32 boo_update_during_death(void) {
}
static s32 obj_has_attack_type(u32 attackType) {
if ((o->oInteractStatus & INT_STATUS_ATTACK_MASK) == attackType) {
return TRUE;
} else {
return FALSE;
}
return ((o->oInteractStatus & INT_STATUS_ATTACK_MASK) == attackType);
}
static s32 boo_get_attack_status(void) {
@@ -338,7 +318,7 @@ static void boo_chase_mario(f32 minDY, s16 yawIncrement, f32 mul) {
if (boo_vanish_or_appear()) {
o->oInteractType = 0x8000;
if (cur_obj_lateral_dist_from_mario_to_home() > 1500.0f) {
if (!cur_obj_lateral_dist_from_mario_to_home_is_in_range(1500.0f)) {
targetYaw = cur_obj_angle_to_home();
} else {
targetYaw = o->oAngleToMario;

View File

@@ -187,11 +187,7 @@ s32 bowser_set_anim_look_up_and_walk(void) {
if (cur_obj_check_anim_frame(21)) {
o->oForwardVel = 3.0f;
}
if (cur_obj_check_if_near_animation_end()) {
return TRUE;
} else {
return FALSE;
}
return (cur_obj_check_if_near_animation_end());
}
/**
@@ -201,11 +197,7 @@ s32 bowser_set_anim_look_up_and_walk(void) {
s32 bowser_set_anim_slow_gait(void) {
o->oForwardVel = 3.0f;
cur_obj_init_animation_with_sound(BOWSER_ANIM_SLOW_GAIT);
if (cur_obj_check_if_near_animation_end()) {
return TRUE;
} else {
return FALSE;
}
return (cur_obj_check_if_near_animation_end());
}
/**
@@ -217,11 +209,7 @@ s32 bowser_set_anim_look_down_stop_walk(void) {
if (cur_obj_check_anim_frame(20)) {
o->oForwardVel = 0.0f;
}
if (cur_obj_check_if_near_animation_end()) {
return TRUE;
} else {
return FALSE;
}
return (cur_obj_check_if_near_animation_end());
}
@@ -315,7 +303,7 @@ void bowser_bitdw_actions(void) {
// Generate random float
f32 rand = random_float();
// Set attacks when Bowser Reacts
if (o->oBowserIsReacting == FALSE) {
if (!o->oBowserIsReacting) {
if (o->oBowserStatus & BOWSER_STATUS_ANGLE_MARIO) {
if (o->oDistanceToMario < 1500.0f) {
o->oAction = BOWSER_ACT_BREATH_FIRE; // nearby
@@ -358,7 +346,7 @@ void bowser_bitfs_actions(void) {
// Generate random float
f32 rand = random_float();
// Set attacks when Bowser Reacts
if (o->oBowserIsReacting == FALSE) {
if (!o->oBowserIsReacting) {
if (o->oBowserStatus & BOWSER_STATUS_ANGLE_MARIO) {
if (o->oDistanceToMario < 1300.0f) { // nearby
if (rand < 0.5f) { // 50% chance
@@ -425,7 +413,7 @@ void bowser_bits_actions(void) {
case FALSE:
// oBowserBitsJustJump never changes value,
// so its always FALSE, maybe a debug define
if (o->oBowserBitsJustJump == FALSE) {
if (!o->oBowserBitsJustJump) {
bowser_bits_action_list();
} else {
bowser_set_act_big_jump();
@@ -669,11 +657,7 @@ void bowser_act_hit_mine(void) {
*/
s32 bowser_set_anim_jump(void) {
cur_obj_init_animation_with_sound(BOWSER_ANIM_JUMP_START);
if (cur_obj_check_anim_frame(11)) {
return TRUE;
} else {
return FALSE;
}
return (cur_obj_check_anim_frame(11));
}
/**
@@ -859,11 +843,7 @@ s32 bowser_turn_on_timer(s32 time, s16 yaw) {
}
o->oForwardVel = 0.0f;
o->oMoveAngleYaw += yaw;
if (o->oTimer >= time) {
return TRUE;
} else {
return FALSE;
}
return (o->oTimer >= time);
}
/**
@@ -1069,7 +1049,7 @@ void bowser_act_jump_onto_stage(void) {
o->oDragStrength = 10.0f;
o->oSubAction++;
// Spawn shockwave (BITS only) if is not on a platform
if (onDynamicFloor == FALSE) {
if (!onDynamicFloor) {
bowser_spawn_shockwave();
// If is on a dynamic floor in BITS, then jump
// because of the falling platform
@@ -1644,7 +1624,7 @@ void bhv_bowser_loop(void) {
s16 angleToCentre; // AngleToCentre from Bowser's perspective
// Set distance/angle values
o->oBowserDistToCentre = sqrtf(o->oPosX * o->oPosX + o->oPosZ * o->oPosZ);
o->oBowserDistToCentre = sqrtf(sqr(o->oPosX) + sqr(o->oPosZ));
o->oBowserAngleToCentre = atan2s(0.0f - o->oPosZ, 0.0f - o->oPosX);
angleToMario = abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario);
angleToCentre = abs_angle_diff(o->oMoveAngleYaw, o->oBowserAngleToCentre);

View File

@@ -214,12 +214,8 @@ void bhv_flame_bouncing_loop(void) {
if (bowser_flame_should_despawn(300)) {
obj_mark_for_deletion(o);
}
if (bowser != NULL) {
if (bowser->oHeldState == HELD_FREE) {
if (lateral_dist_between_objects(o, bowser) < 300.0f) {
obj_mark_for_deletion(o);
}
}
if ((bowser != NULL) && (bowser->oHeldState == HELD_FREE) && (lateral_dist_between_objects_squared(o, bowser) < sqr(300.0f))) {
obj_mark_for_deletion(o);
}
}

View File

@@ -1,8 +1,8 @@
// bowser_key_cutscene.inc.c
Gfx *geo_scale_bowser_key(s32 run, struct GraphNode *node, UNUSED Mat4 mtx) {
Gfx *geo_scale_bowser_key(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtx) {
struct Object *nodeObj;
if (run == TRUE) {
if (callContext == GEO_CONTEXT_RENDER) {
nodeObj = (struct Object *) gCurGraphNodeObject;
((struct GraphNodeScale *) node->next)->scale = nodeObj->oBowserKeyScale;
}

View File

@@ -67,7 +67,7 @@ void bub_act_1(void) {
if (dy > 300.0f)
o->oPosY = o->oPosY - 1.0f;
}
if (800.0f < cur_obj_lateral_dist_from_mario_to_home())
if (!cur_obj_lateral_dist_from_mario_to_home_is_in_range(800.0f))
o->oAngleToMario = cur_obj_angle_to_home();
cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x100);
if (o->oDistanceToMario < 200.0f)
@@ -101,7 +101,7 @@ void bub_act_2(void) {
if (dy > 300.0f)
o->oPosY -= 1.0f;
}
if (cur_obj_lateral_dist_from_mario_to_home() > 800.0f)
if (!cur_obj_lateral_dist_from_mario_to_home_is_in_range(800.0f))
o->oAngleToMario = cur_obj_angle_to_home();
cur_obj_rotate_yaw_toward(o->oAngleToMario + 0x8000, 0x400);
if (o->oTimer > 200 && o->oDistanceToMario > 600.0f)

View File

@@ -73,7 +73,7 @@ void butterfly_act_return_home(void) {
f32 homeDistY = o->oHomeY - o->oPosY;
f32 homeDistZ = o->oHomeZ - o->oPosZ;
s16 hAngleToHome = atan2s(homeDistZ, homeDistX);
s16 vAngleToHome = atan2s(sqrtf(homeDistX * homeDistX + homeDistZ * homeDistZ), -homeDistY);
s16 vAngleToHome = atan2s(sqrtf(sqr(homeDistX) + sqr(homeDistZ)), -homeDistY);
o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, hAngleToHome, 0x800);
o->oMoveAnglePitch = approach_s16_symmetric(o->oMoveAnglePitch, vAngleToHome, 0x50);
@@ -84,9 +84,7 @@ void butterfly_act_return_home(void) {
cur_obj_init_animation(1);
o->oAction = BUTTERFLY_ACT_RESTING;
o->oPosX = o->oHomeX;
o->oPosY = o->oHomeY;
o->oPosZ = o->oHomeZ;
vec3_copy(&o->oPosVec, &o->oHomeVec);
}
}

View File

@@ -88,10 +88,8 @@ static void chain_chomp_act_uninitialized(void) {
static void chain_chomp_update_chain_segments(void) {
struct ChainSegment *prevSegment;
struct ChainSegment *segment;
f32 offsetX;
f32 offsetY;
f32 offsetZ;
f32 offset;
Vec3f offset;
f32 mag;
f32 segmentVelY;
f32 maxTotalOffset;
s32 i;
@@ -115,40 +113,41 @@ static void chain_chomp_update_chain_segments(void) {
segment->posY = 0.0f;
}
// Cap distance to previous chain part (so that the tail follows the
// chomp)
// Cap distance to previous chain part (so that the tail follows the chomp)
offsetX = segment->posX - prevSegment->posX;
offsetY = segment->posY - prevSegment->posY;
offsetZ = segment->posZ - prevSegment->posZ;
offset = sqrtf(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ);
offset[0] = segment->posX - prevSegment->posX;
offset[1] = segment->posY - prevSegment->posY;
offset[2] = segment->posZ - prevSegment->posZ;
mag = (sqr(offset[0]) + sqr(offset[1]) + sqr(offset[2]));
if (offset > o->oChainChompMaxDistBetweenChainParts) {
offset = o->oChainChompMaxDistBetweenChainParts / offset;
offsetX *= offset;
offsetY *= offset;
offsetZ *= offset;
if (mag > sqr(o->oChainChompMaxDistBetweenChainParts)) {
mag = sqrtf(mag);
mag = o->oChainChompMaxDistBetweenChainParts / mag;
offset[0] *= mag;
offset[1] *= mag;
offset[2] *= mag;
}
// Cap distance to pivot (so that it stretches when the chomp moves far
// from the wooden post)
offsetX += prevSegment->posX;
offsetY += prevSegment->posY;
offsetZ += prevSegment->posZ;
offset = sqrtf(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ);
offset[0] += prevSegment->posX;
offset[1] += prevSegment->posY;
offset[2] += prevSegment->posZ;
mag = (sqr(offset[0]) + sqr(offset[1]) + sqr(offset[2]));
maxTotalOffset = o->oChainChompMaxDistFromPivotPerChainPart * (5 - i);
if (offset > maxTotalOffset) {
offset = maxTotalOffset / offset;
offsetX *= offset;
offsetY *= offset;
offsetZ *= offset;
if (mag > sqr(maxTotalOffset)) {
mag = sqrtf(mag);
mag = maxTotalOffset / mag;
offset[0] *= mag;
offset[1] *= mag;
offset[2] *= mag;
}
segment->posX = offsetX;
segment->posY = offsetY;
segment->posZ = offsetZ;
segment->posX = offset[0];
segment->posY = offset[1];
segment->posZ = offset[2];
}
}
@@ -397,9 +396,9 @@ static void chain_chomp_act_move(void) {
o->oChainChompSegments[0].posZ = o->oPosZ - o->parentObj->oPosZ;
o->oChainChompDistToPivot =
sqrtf(o->oChainChompSegments[0].posX * o->oChainChompSegments[0].posX
+ o->oChainChompSegments[0].posY * o->oChainChompSegments[0].posY
+ o->oChainChompSegments[0].posZ * o->oChainChompSegments[0].posZ);
sqrtf(sqr(o->oChainChompSegments[0].posX)
+ sqr(o->oChainChompSegments[0].posY)
+ sqr(o->oChainChompSegments[0].posZ));
// If the chain is fully stretched
maxDistToPivot = o->oChainChompMaxDistFromPivotPerChainPart * 5;

View File

@@ -38,8 +38,8 @@ void bhv_chuckya_anchor_mario_loop(void) {
s32 unknown_chuckya_function(s32 updateAngle, f32 latDist, f32 dist, s32 time) {
s32 ret = 0;
if (o->oChuckyaUnused != 4) {
if (latDist < cur_obj_lateral_dist_from_mario_to_home()) {
if (cur_obj_lateral_dist_to_home() < 200.0f) {
if (!cur_obj_lateral_dist_from_mario_to_home_is_in_range(latDist)) {
if (cur_obj_lateral_dist_to_home_is_in_range(200.0f)) {
ret = 0;
} else {
ret = 1;
@@ -86,7 +86,7 @@ void chuckya_act_0(void) {
switch (initialSubAction = o->oSubAction) {
case 0:
o->oForwardVel = 0;
if (cur_obj_lateral_dist_from_mario_to_home() < 2000.0f) {
if (cur_obj_lateral_dist_from_mario_to_home_is_in_range(2000.0f)) {
cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x400);
if (o->oChuckyaSubActionTimer > 40
|| abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) < 0x1000)
@@ -98,7 +98,7 @@ void chuckya_act_0(void) {
approach_forward_vel(&o->oForwardVel, 30.0f, 4.0f);
if (abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) > 0x4000)
o->oSubAction = 2;
if (cur_obj_lateral_dist_from_mario_to_home() > 2000.0f)
if (!cur_obj_lateral_dist_from_mario_to_home_is_in_range(2000.0f))
o->oSubAction = 3;
break;
case 2:
@@ -107,14 +107,14 @@ void chuckya_act_0(void) {
o->oSubAction = 0;
break;
case 3:
if (cur_obj_lateral_dist_to_home() < 500.0f)
if (cur_obj_lateral_dist_to_home_is_in_range(500.0f))
o->oForwardVel = 0;
else {
approach_forward_vel(&o->oForwardVel, 10.0f, 4.0f);
o->oAngleToMario = cur_obj_angle_to_home();
cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x800);
}
if (cur_obj_lateral_dist_from_mario_to_home() < 1900.0f)
if (cur_obj_lateral_dist_from_mario_to_home_is_in_range(1900.0f))
o->oSubAction = 0;
break;
}

View File

@@ -18,8 +18,9 @@ void bhv_end_birds_2_loop(void) {
vec3f_set_dist_and_angle(gCamera->pos, pos, 14000.f, pitch, yaw);
obj_rotate_towards_point(gCurrentObject, pos, 0, 0, 8, 8);
if ((gCurrentObject->oEndBirdCutsceneVars9PointX == 0.f) && (gCurrentObject->oTimer == 0))
if ((gCurrentObject->oEndBirdCutsceneVars9PointX == 0.f) && (gCurrentObject->oTimer == 0)) {
cur_obj_play_sound_2(SOUND_GENERAL_BIRDS_FLY_AWAY);
}
break;
}

View File

@@ -12,12 +12,8 @@ struct ObjectHitbox sEyerokHitbox = {
s8 sEyerokAnimStatesList[] = { 0, 1, 3, 2, 1, 0 };
static s32 eyerok_check_mario_relative_z(s32 arg0) {
if (gMarioObject->oPosZ - o->oHomeZ < arg0) {
return TRUE;
} else {
return FALSE;
}
static s32 eyerok_check_mario_relative_z(s32 z) {
return (gMarioObject->oPosZ - o->oHomeZ < z);
}
static void eyerok_spawn_hand(s16 side, s32 model, const BehaviorScript *behavior) {

View File

@@ -29,7 +29,7 @@ void haunted_chair_act_0(void) {
if (o->parentObj != o) {
if (o->oHauntedChairFallTargetAngle == 0) {
if (lateral_dist_between_objects(o, o->parentObj) < 250.0f) {
if (lateral_dist_between_objects_squared(o, o->parentObj) < sqr(250.0f)) {
dAngleToPiano = obj_angle_to_object(o, o->parentObj) - o->oFaceAngleYaw + 0x2000;
if (dAngleToPiano & 0x4000) {
o->oHauntedChairFallFromPianoAngle = &o->oFaceAngleRoll;

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