Skip to content
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
17 changes: 16 additions & 1 deletion include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,22 @@ enum PLACE { FIRST_PLACE, SECOND_PLACE, THIRD_PLACE, FOURTH_PLACE };
* @brief Max representable time, 100 minutes measured in centiseconds
*/
#define MAX_TIME 0x927C0
#define DEGREES_CONVERSION_FACTOR 182

/* The codebase uses 16-bit representations of angles (either u16 or s16 depending on context).
Thus, values of [0, 2**16 - 1] (for u16) or [-2**15, 2**15 - 1] (for s16) represent evenly
spaced angles around a circle. (e.g. (u16) 0x8000 is 2**15, which represents half a circle, or 180 degrees)

However, it is clear that the developers were thinking in terms of degrees and often worked
with values that corresponded to a specific number of degrees. The DEGREES macro converts
from the specified number of degrees to the 16-bit representation. This allows readers to
think in degrees while leaving the compiled machine code unaffected.

Note that 2**16 / 360 is not an integer. It has a value of ~182.04, but is rounded to 182
by the DEGREES function. There is some inconsistency with how the codebase handles this.
e.g. 70 degrees might be represented as DEGREES(70) or 70 * DEGREES(1), which are slightly
different values due to this rounding. As a practical matter, this rounding is less than
0.1 degrees in all cases */
#define DEGREES(degree) ((u16) (degree * 65536.0f / 360.0f))

// player->unk_046

Expand Down
6 changes: 3 additions & 3 deletions src/actors/banana/update.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ void update_actor_banana(struct BananaActor* banana) {
banana->velocity[1] = -5.0f;
}
banana->pos[1] += banana->velocity[1];
banana->rot[0] += 0x16C;
banana->rot[1] -= 0x5B0;
banana->rot[2] += 0x38E;
banana->rot[0] += DEGREES(2);
banana->rot[1] -= DEGREES(8);
banana->rot[2] += DEGREES(5);
banana->unk_04 -= 1;
if (banana->unk_04 == 0) {
destroy_actor((struct Actor*) banana);
Expand Down
13 changes: 7 additions & 6 deletions src/actors/blue_and_red_shells/update.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void update_actor_red_blue_shell(struct ShellActor* shell) {
destroy_destructable_actor((struct Actor*) shell);
}

shell->rotVelocity += 0x71C;
shell->rotVelocity += DEGREES(10);
switch (shell->state) {
case HELD_SHELL:
player = &gPlayers[shell->playerId];
Expand Down Expand Up @@ -277,16 +277,17 @@ void update_actor_red_blue_shell(struct ShellActor* shell) {
controller->buttonDepressed &= ~Z_TRIG;
shell->state = RELEASED_SHELL;
if (player->unk_0C0 > 0) {
shell->rotAngle = 0x78E3;
shell->rotAngle = DEGREES(170);
} else {
shell->rotAngle = -0x78E4;
// The minus 1 is almost certainly just due to rounding the other way
shell->rotAngle = -DEGREES(170) - 1;
}
}
break;
case RELEASED_SHELL:
player = &gPlayers[shell->playerId];
if (shell->rotAngle > 0) {
shell->rotAngle -= 0x71C;
shell->rotAngle -= DEGREES(10);
if (shell->rotAngle < 0) {
shell->state = MOVING_SHELL;
func_800C9060(shell->playerId, SOUND_ARG_LOAD(0x19, 0x00, 0x80, 0x04));
Expand All @@ -300,7 +301,7 @@ void update_actor_red_blue_shell(struct ShellActor* shell) {
}
}
} else {
shell->rotAngle += 0x71C;
shell->rotAngle += DEGREES(10);
if (shell->rotAngle > 0) {
shell->state = MOVING_SHELL;
func_800C9060(shell->playerId, SOUND_ARG_LOAD(0x19, 0x00, 0x80, 0x04));
Expand Down Expand Up @@ -454,7 +455,7 @@ void update_actor_red_blue_shell(struct ShellActor* shell) {
if (shell->velocity[1] < -5.0f) {
shell->velocity[1] = -5.0f;
}
shell->rotAngle += 0x5B0;
shell->rotAngle += DEGREES(8);
shell->someTimer -= 1;
shell->pos[1] += shell->velocity[1];
if (shell->someTimer == 0) {
Expand Down
9 changes: 5 additions & 4 deletions src/actors/fake_item_box/render.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ void render_actor_fake_item_box(Camera* camera, struct FakeItemBox* fakeItemBox)

gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING);
gDPSetCombineMode(gDisplayListHead++, G_CC_MODULATEIA, G_CC_MODULATEIA);
if ((fakeItemBox->rot[1] < 0xAA1) && (fakeItemBox->rot[1] > 0)) {
// unclear why it is 14.95 degrees instead of 15. Perhaps just a typo when entering the value as a s16.
if ((fakeItemBox->rot[1] < DEGREES(14.95f)) && (fakeItemBox->rot[1] > 0)) {
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
} else if ((fakeItemBox->rot[1] >= 0x6AA5) && (fakeItemBox->rot[1] < 0x754E)) {
} else if ((fakeItemBox->rot[1] > (150 * DEGREES(1))) && (fakeItemBox->rot[1] < (165 * DEGREES(1)))) {
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
} else if ((fakeItemBox->rot[1] >= 0x38E1) && (fakeItemBox->rot[1] < 0x438A)) {
} else if ((fakeItemBox->rot[1] > (80 * DEGREES(1))) && (fakeItemBox->rot[1] < (95 * DEGREES(1)))) {
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
} else if ((fakeItemBox->rot[1] >= 0xC711) && (fakeItemBox->rot[1] < 0xD1BA)) {
} else if ((fakeItemBox->rot[1] > (280 * DEGREES(1))) && (fakeItemBox->rot[1] < (295 * DEGREES(1)))) {
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
} else {
gDPSetBlendMask(gDisplayListHead++, 0xFF);
Expand Down
18 changes: 9 additions & 9 deletions src/actors/fake_item_box/update.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ void update_actor_fake_item_box(struct FakeItemBox* fake_item_box) {
switch (fake_item_box->state) {
case 0:
fake_item_box->boundingBoxSize = fake_item_box->sizeScaling * 5.5f;
fake_item_box->rot[0] -= 0xB6;
fake_item_box->rot[1] += 0x16C;
fake_item_box->rot[2] -= 0xB6;
fake_item_box->rot[0] -= DEGREES(1);
fake_item_box->rot[1] += DEGREES(2);
fake_item_box->rot[2] -= DEGREES(1);

temp_f14 = temp_v0_4->pos[0] - fake_item_box->pos[0];
temp_f16 = temp_v0_4->pos[1] - fake_item_box->pos[1];
Expand Down Expand Up @@ -71,19 +71,19 @@ void update_actor_fake_item_box(struct FakeItemBox* fake_item_box) {
fake_item_box->someTimer--;
}
}
fake_item_box->rot[0] -= 0xB6;
fake_item_box->rot[1] += 0x16C;
fake_item_box->rot[2] -= 0xB6;
fake_item_box->rot[0] -= DEGREES(1);
fake_item_box->rot[1] += DEGREES(2);
fake_item_box->rot[2] -= DEGREES(1);
break;

case 2:
if ((fake_item_box->someTimer >= 0x14) || (fake_item_box->someTimer < 0)) {
destroy_actor((struct Actor*) fake_item_box);
} else {
fake_item_box->someTimer++;
fake_item_box->rot[0] += 0x444;
fake_item_box->rot[1] -= 0x2D8;
fake_item_box->rot[2] += 0x16C;
fake_item_box->rot[0] += DEGREES(6);
fake_item_box->rot[1] -= DEGREES(4);
fake_item_box->rot[2] += DEGREES(2);
}
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/actors/falling_rock/update.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void update_actor_falling_rocks(struct FallingRock* rock) {
if (rock->pos[1] < D_8015F8E4) {
func_8029CF0C(d_course_choco_mountain_falling_rock_spawns, rock);
}
rock->rot[0] += (s16) ((rock->velocity[2] * 5461.0f) / 20.0f);
rock->rot[0] += (s16) ((rock->velocity[2] * 5461.0f) / 20.0f); // DEGREES(30) is 5460
rock->rot[2] += (s16) ((rock->velocity[0] * 5461.0f) / 20.0f);
rock->velocity[1] -= 0.1;
if (rock->velocity[1] < (-2.0f)) {
Expand Down
13 changes: 7 additions & 6 deletions src/actors/green_shell/update.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void update_actor_green_shell(struct ShellActor* shell) {
(y < gCourseMinY)) {
destroy_destructable_actor((struct Actor*) shell);
}
shell->rotVelocity += 0x71C;
shell->rotVelocity += DEGREES(10);
switch (shell->state) {
case HELD_SHELL:
player = &gPlayers[shell->playerId];
Expand Down Expand Up @@ -79,9 +79,10 @@ void update_actor_green_shell(struct ShellActor* shell) {
} else {
shell->state = 1;
if (player->unk_0C0 > 0) {
shell->rotAngle = 0x78E3;
shell->rotAngle = DEGREES(170);
} else {
shell->rotAngle = -0x78E4;
// The minus 1 is almost certainly just due to rounding the other way
shell->rotAngle = -DEGREES(170) - 1;
}
}
}
Expand All @@ -90,7 +91,7 @@ void update_actor_green_shell(struct ShellActor* shell) {
case RELEASED_SHELL:
player = &gPlayers[shell->playerId];
if (shell->rotAngle > 0) {
shell->rotAngle -= 0xE38;
shell->rotAngle -= DEGREES(20);
if (shell->rotAngle < 0) {
shell->state = 2;
shell->someTimer = 0x001E;
Expand All @@ -100,7 +101,7 @@ void update_actor_green_shell(struct ShellActor* shell) {
add_green_shell_in_unexpired_actor_list((struct Actor*) shell - gActorList);
}
} else {
shell->rotAngle += 0xE38;
shell->rotAngle += DEGREES(20);
if (shell->rotAngle > 0) {
shell->state = 2;
shell->someTimer = 0x001E;
Expand Down Expand Up @@ -186,7 +187,7 @@ void update_actor_green_shell(struct ShellActor* shell) {
if (shell->velocity[1] < -5.0f) {
shell->velocity[1] = -5.0f;
}
shell->rotAngle += 0x5B0;
shell->rotAngle += DEGREES(8);
shell->someTimer -= 1;
shell->pos[1] += shell->velocity[1];
if (shell->someTimer == 0) {
Expand Down
9 changes: 5 additions & 4 deletions src/actors/item_box/render.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ void render_actor_item_box(Camera* camera, struct ItemBox* item_box) {

gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING);
gDPSetCombineMode(gDisplayListHead++, G_CC_MODULATEIA, G_CC_MODULATEIA);
if ((item_box->rot[1] < 0xAA1) && (item_box->rot[1] > 0)) {
// unclear why it is 14.95 degrees instead of 15. Perhaps just a typo when entering the value as a s16.
if ((item_box->rot[1] < DEGREES(14.95f)) && (item_box->rot[1] > 0)) {
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
} else if ((item_box->rot[1] >= 0x6AA5) && (item_box->rot[1] < 0x754E)) {
} else if ((item_box->rot[1] > (150 * DEGREES(1))) && (item_box->rot[1] < (165 * DEGREES(1)))) {
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
} else if ((item_box->rot[1] >= 0x38E1) && (item_box->rot[1] < 0x438A)) {
} else if ((item_box->rot[1] > (80 * DEGREES(1))) && (item_box->rot[1] < (95 * DEGREES(1)))) {
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
} else if ((item_box->rot[1] >= 0xC711) && (item_box->rot[1] < 0xD1BA)) {
} else if ((item_box->rot[1] > (280 * DEGREES(1))) && (item_box->rot[1] < (295 * DEGREES(1)))) {
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
} else {
gDPSetBlendMask(gDisplayListHead++, 0xFF);
Expand Down
24 changes: 12 additions & 12 deletions src/actors/item_box/update.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
void update_actor_item_box_hot_air_balloon(struct ItemBox* itemBox) {
switch (itemBox->state) {
case 5:
itemBox->rot[0] += 0xB6;
itemBox->rot[1] -= 0x16C;
itemBox->rot[2] += 0xB6;
itemBox->rot[0] += DEGREES(1);
itemBox->rot[1] -= DEGREES(2);
itemBox->rot[2] += DEGREES(1);
break;
case 3:
if (itemBox->someTimer == 0x14) {
itemBox->state = 5;
itemBox->flags = -0x4000;
} else {
itemBox->someTimer++;
itemBox->rot[0] += 0x444;
itemBox->rot[1] -= 0x2D8;
itemBox->rot[2] += 0x16C;
itemBox->rot[0] += DEGREES(6);
itemBox->rot[1] -= DEGREES(4);
itemBox->rot[2] += DEGREES(2);
}
break;
}
Expand All @@ -48,9 +48,9 @@ void update_actor_item_box(struct ItemBox* itemBox) {
}
break;
case 2:
itemBox->rot[0] += 0xB6;
itemBox->rot[1] -= 0x16C;
itemBox->rot[2] += 0xB6;
itemBox->rot[0] += DEGREES(1);
itemBox->rot[1] -= DEGREES(2);
itemBox->rot[2] += DEGREES(1);
break;
case 3:
if (itemBox->someTimer == 20) {
Expand All @@ -59,9 +59,9 @@ void update_actor_item_box(struct ItemBox* itemBox) {
itemBox->flags = 0xC000;
} else {
itemBox->someTimer++;
itemBox->rot[0] += 0x444;
itemBox->rot[1] -= 0x2D8;
itemBox->rot[2] += 0x16C;
itemBox->rot[0] += DEGREES(6);
itemBox->rot[1] -= DEGREES(4);
itemBox->rot[2] += DEGREES(2);
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/actors/mario_sign/update.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ void update_actor_mario_sign(struct Actor* arg0) {
arg0->pos[1] += 4.0f;
if (arg0->pos[1] > 800.0f) {
arg0->flags |= 0x800;
arg0->rot[1] += 1820;
arg0->rot[1] += DEGREES(10);
}
} else {
arg0->rot[1] += 182;
arg0->rot[1] += DEGREES(1);
}
}
}
2 changes: 1 addition & 1 deletion src/actors/paddle_boat/update.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
* @param boat
*/
void update_actor_paddle_boat(struct PaddleWheelBoat* boat) {
boat->wheelRot += 0x38E;
boat->wheelRot += DEGREES(5);
}
Loading