Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a macro for the common approach angle idiom #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/engine/math_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ extern f32 gCosineTable[];

#define sqr(x) ((x) * (x))

#define approach_angle(current, target, rate) \
((target) - approach_s32((s16)((target) - (current)), 0, (rate), (rate)))

void *vec3f_copy(Vec3f dest, Vec3f src);
void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z);
void *vec3f_add(Vec3f dest, Vec3f a);
Expand Down
5 changes: 2 additions & 3 deletions src/game/mario_actions_automatic.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ s32 act_climbing_pole(struct MarioState *m) {

marioObj->oMarioPolePos += m->controller->stickY / 8.0f;
marioObj->oMarioPoleYawVel = 0;
m->faceAngle[1] = cameraAngle - approach_s32((s16)(cameraAngle - m->faceAngle[1]), 0, 0x400, 0x400);
m->faceAngle[1] = approach_angle(m->faceAngle[1], cameraAngle, 0x400);

if (set_pole_position(m, 0.0f) == POLE_NONE) {
sp24 = m->controller->stickY / 4.0f * 0x10000;
Expand Down Expand Up @@ -350,8 +350,7 @@ s32 update_hang_moving(struct MarioState *m) {
m->forwardVel = maxSpeed;
}

m->faceAngle[1] =
m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x800);

m->slideYaw = m->faceAngle[1];
m->slideVelX = m->forwardVel * sins(m->faceAngle[1]);
Expand Down
3 changes: 1 addition & 2 deletions src/game/mario_actions_cutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ s32 act_reading_npc_dialog(struct MarioState *m) {
if (m->actionState < 8) {
// turn to NPC
angleToNPC = mario_obj_angle_to_object(m, m->usedObj);
m->faceAngle[1] =
angleToNPC - approach_s32((angleToNPC - m->faceAngle[1]) << 16 >> 16, 0, 2048, 2048);
m->faceAngle[1] = approach_angle(m->faceAngle[1], angleToNPC, 0x800);
// turn head to npc
m->actionTimer += headTurnAmount;
// set animation
Expand Down
9 changes: 3 additions & 6 deletions src/game/mario_actions_moving.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ void update_shell_speed(struct MarioState *m) {
m->forwardVel = 64.0f;
}

m->faceAngle[1] =
m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x800);

apply_slope_accel(m);
}
Expand Down Expand Up @@ -459,8 +458,7 @@ void update_walking_speed(struct MarioState *m) {
m->forwardVel = 48.0f;
}

m->faceAngle[1] =
m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x800);
apply_slope_accel(m);
}

Expand Down Expand Up @@ -1322,8 +1320,7 @@ s32 act_burning_ground(struct MarioState *m) {
m->forwardVel = approach_f32(m->forwardVel, 32.0f, 4.0f, 1.0f);

if (m->input & INPUT_NONZERO_ANALOG) {
m->faceAngle[1] =
m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x600, 0x600);
m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x600);
}

apply_slope_accel(m);
Expand Down
3 changes: 1 addition & 2 deletions src/game/mario_actions_submerged.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,7 @@ static void update_metal_water_walking_speed(struct MarioState *m) {
m->forwardVel = 32.0f;
}

m->faceAngle[1] =
m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800);
m->faceAngle[1] = approach_angle(m->faceAngle[1], m->intendedYaw, 0x800);

m->slideVelX = m->forwardVel * sins(m->faceAngle[1]);
m->slideVelZ = m->forwardVel * coss(m->faceAngle[1]);
Expand Down