From 67ee6b395b16002a2c960b8e6fa1124ee001d67c Mon Sep 17 00:00:00 2001 From: Arceveti <73617174+Arceveti@users.noreply.github.com> Date: Wed, 29 Sep 2021 00:09:11 -0700 Subject: [PATCH] callContext arg name in geo functions --- src/game/behavior_actions.c | 7 ++- src/game/behavior_actions.h | 14 +++--- src/game/behaviors/king_bobomb.inc.c | 8 ++-- src/game/behaviors/tuxie.inc.c | 30 ++++++------- src/game/behaviors/ukiki.inc.c | 15 ++----- src/goddard/gd_math.c | 67 ++++------------------------ src/menu/intro_geo.c | 47 +++++++++---------- src/menu/intro_geo.h | 12 ++--- 8 files changed, 65 insertions(+), 135 deletions(-) diff --git a/src/game/behavior_actions.c b/src/game/behavior_actions.c index ef80ee68..62942ccc 100644 --- a/src/game/behavior_actions.c +++ b/src/game/behavior_actions.c @@ -156,12 +156,11 @@ void spawn_mist_particles_variable(s32 count, s32 offsetY, f32 size) { #include "behaviors/breakable_box.inc.c" // not sure what this is doing here. not in a behavior file. -Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx) { +Gfx *geo_move_mario_part_from_parent(s32 callContext, UNUSED struct GraphNode *node, Mat4 mtx) { Mat4 mtx2; - struct Object *obj; - if (run == TRUE) { - obj = (struct Object *) gCurGraphNodeObject; + if (callContext == GEO_CONTEXT_RENDER) { + struct Object *obj = (struct Object *) gCurGraphNodeObject; if (obj == gMarioObject && obj->prevObj != NULL) { create_transformation_from_matrices(mtx2, mtx, *gCurGraphNodeCamera->matrixPtr); obj_update_pos_from_parent_transformation(mtx2, obj->prevObj); diff --git a/src/game/behavior_actions.h b/src/game/behavior_actions.h index bab17674..71f353ee 100644 --- a/src/game/behavior_actions.h +++ b/src/game/behavior_actions.h @@ -551,25 +551,25 @@ void bhv_dust_smoke_loop(void); void bhv_yoshi_loop(void); void bhv_volcano_trap_loop(void); -Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx); +Gfx *geo_move_mario_part_from_parent(s32 callContext, UNUSED struct GraphNode *node, Mat4 mtx); // Bowser -Gfx *geo_bits_bowser_coloring(s32 run, struct GraphNode *node, UNUSED s32 a2); -Gfx *geo_update_body_rot_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx); -Gfx *geo_switch_bowser_eyes(s32 run, struct GraphNode *node, UNUSED Mat4 *mtx); +Gfx *geo_bits_bowser_coloring(s32 callContext, struct GraphNode *node, UNUSED s32 context); +Gfx *geo_update_body_rot_from_parent(s32 callContext, UNUSED struct GraphNode *node, Mat4 mtx); +Gfx *geo_switch_bowser_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx); // Tuxie -Gfx *geo_switch_tuxie_mother_eyes(s32 run, struct GraphNode *node, UNUSED Mat4 *mtx); +Gfx *geo_switch_tuxie_mother_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx); // Cap switch -Gfx *geo_update_held_mario_pos(s32 run, UNUSED struct GraphNode *node, Mat4 mtx); +Gfx *geo_update_held_mario_pos(s32 callContext, UNUSED struct GraphNode *node, Mat4 mtx); // Snufit Gfx *geo_snufit_move_mask(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 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 Mat4 mtx); +Gfx *geo_scale_bowser_key(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtx); // Water splash extern struct WaterDropletParams gShallowWaterSplashDropletParams; diff --git a/src/game/behaviors/king_bobomb.inc.c b/src/game/behaviors/king_bobomb.inc.c index b408d20f..ed0d012f 100644 --- a/src/game/behaviors/king_bobomb.inc.c +++ b/src/game/behaviors/king_bobomb.inc.c @@ -1,12 +1,10 @@ // king_bobomb.c.inc // Copy of geo_update_projectile_pos_from_parent -Gfx *geo_update_held_mario_pos(s32 run, UNUSED struct GraphNode *node, Mat4 mtx) { +Gfx *geo_update_held_mario_pos(s32 callContext, UNUSED struct GraphNode *node, Mat4 mtx) { Mat4 mtx2; - struct Object *obj; - - if (run == TRUE) { - obj = (struct Object *) gCurGraphNodeObject; + if (callContext == GEO_CONTEXT_RENDER) { + struct Object *obj = (struct Object *) gCurGraphNodeObject; if (obj->prevObj != NULL) { create_transformation_from_matrices(mtx2, mtx, *gCurGraphNodeCamera->matrixPtr); obj_update_pos_from_parent_transformation(mtx2, obj->prevObj); diff --git a/src/game/behaviors/tuxie.inc.c b/src/game/behaviors/tuxie.inc.c index 6c2655d9..c61ecdba 100644 --- a/src/game/behaviors/tuxie.inc.c +++ b/src/game/behaviors/tuxie.inc.c @@ -277,34 +277,30 @@ void bhv_small_penguin_loop(void) { /** Geo switch logic for Tuxie's mother's eyes. Cases 0-4. Interestingly, case * 4 is unused, and is the eye state seen in Shoshinkai 1995 footage. */ -Gfx *geo_switch_tuxie_mother_eyes(s32 run, struct GraphNode *node, UNUSED Mat4 *mtx) { - struct Object *obj; - struct GraphNodeSwitchCase *switchCase; - s32 timer; - - if (run == TRUE) { - obj = (struct Object *) gCurGraphNodeObject; - switchCase = (struct GraphNodeSwitchCase *) node; +Gfx *geo_switch_tuxie_mother_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx) { + if (callContext == GEO_CONTEXT_RENDER) { + struct Object *obj = (struct Object *) gCurGraphNodeObject; + struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node; switchCase->selectedCase = 0; // timer logic for blinking. uses cases 0-2. - timer = gGlobalTimer % 50; - if (timer < 43) + s32 timer = gGlobalTimer % 50; + if (timer < 43) { switchCase->selectedCase = 0; - else if (timer < 45) + } else if (timer < 45) { switchCase->selectedCase = 1; - else if (timer < 47) + } else if (timer < 47) { switchCase->selectedCase = 2; - else + } else { switchCase->selectedCase = 1; - + } /** make Tuxie's Mother have angry eyes if Mario takes the correct baby * after giving it back. The easiest way to check this is to see if she's * moving, since she only does when she's chasing Mario. */ - if (segmented_to_virtual(bhvTuxiesMother) == obj->behavior) - if (obj->oForwardVel > 5.0f) - switchCase->selectedCase = 3; + if ((segmented_to_virtual(bhvTuxiesMother) == obj->behavior) && (obj->oForwardVel > 5.0f)) { + switchCase->selectedCase = 3; + } } return NULL; } diff --git a/src/game/behaviors/ukiki.inc.c b/src/game/behaviors/ukiki.inc.c index bd58174c..32ed6a0d 100644 --- a/src/game/behaviors/ukiki.inc.c +++ b/src/game/behaviors/ukiki.inc.c @@ -27,25 +27,18 @@ void handle_cap_ukiki_reset(void) { * the cap ukiki. */ s32 is_cap_ukiki_and_mario_has_normal_cap_on_head(void) { - if (o->oBehParams2ndByte == UKIKI_CAP) { - if (does_mario_have_normal_cap_on_head(gMarioState)) { - return TRUE; - } - } - - return FALSE; + return ((o->oBehParams2ndByte == UKIKI_CAP) && does_mario_have_normal_cap_on_head(gMarioState)); } /** * Unused copy of geo_update_projectile_pos_from_parent. Perhaps a copy paste mistake. */ -Gfx *geo_update_projectile_pos_from_parent_copy(s32 run,UNUSED struct GraphNode *node, Mat4 mtx) { +Gfx *geo_update_projectile_pos_from_parent_copy(s32 callContext, UNUSED struct GraphNode *node, Mat4 mtx) { Mat4 mtx2; - struct Object* obj; - if (run == TRUE) { + if (callContext == GEO_CONTEXT_RENDER) { // TODO: change global type to Object pointer - obj = (struct Object *) gCurGraphNodeObject; + struct Object *obj = (struct Object *) gCurGraphNodeObject; if (obj->prevObj != NULL) { create_transformation_from_matrices(mtx2, mtx, *gCurGraphNodeCamera->matrixPtr); diff --git a/src/goddard/gd_math.c b/src/goddard/gd_math.c index c030e584..bdf4dd67 100644 --- a/src/goddard/gd_math.c +++ b/src/goddard/gd_math.c @@ -136,7 +136,6 @@ void gd_rot_mat_about_vec(Mat4f *mtx, struct GdVec3f *vec) { * translation column of a mat4f matrix. */ void gd_add_vec3f_to_mat4f_offset(Mat4f *mtx, struct GdVec3f *vec) { - UNUSED Mat4f temp; f32 z, y, x; x = vec->x; @@ -230,7 +229,6 @@ f32 gd_clamp_f32(f32 a, f32 b) { } else if (a < -b) { a = -b; } - return a; } @@ -375,8 +373,7 @@ f32 gd_dot_vec3f(struct GdVec3f *a, struct GdVec3f *b) { * Inverts each element of src into dst. */ void UNUSED gd_invert_elements_mat4f(Mat4f *src, Mat4f *dst) { - s32 i; - s32 j; + s32 i, j; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { @@ -397,8 +394,7 @@ void gd_inverse_mat4f(Mat4f *src, Mat4f *dst) { gd_adjunct_mat4f(src, dst); determinant = gd_mat4f_det(dst); - if (ABS(determinant) < 1e-5) //? 1e-5f - { + if (ABS(determinant) < 1e-5) { //? 1e-5f fatal_print("Non-singular matrix, no inverse!\n"); } @@ -530,9 +526,7 @@ f32 gd_3x3_det(f32 r0c0, f32 r0c1, f32 r0c2, * returns the determinant. */ f32 gd_2x2_det(f32 a, f32 b, f32 c, f32 d) { - f32 det = a * d - b * c; - - return det; + return (a * d) - (b * c); } /** @@ -554,46 +548,6 @@ void UNUSED gd_create_neg_vec_zero_first_mat_row(Mat4f *mtx, struct GdVec3f *vec } } -/** - * This function quite literally does nothing. - * Seems to have been meant to create a vector from a quaternion? - */ -void UNUSED gd_broken_quat_to_vec3f(f32 quat[4], struct GdVec3f *vec, f32 zHalf, s32 i, s32 run) { - s32 j; - s32 k; - UNUSED f32 jVal; - UNUSED f32 kVal; - UNUSED struct GdVec3f uVec; - struct GdVec3f tVec; - - tVec.x = vec->x; - tVec.y = vec->y; - tVec.z = vec->z; - - if (run < 0) { - goto end; - } - - if ((j = i + 1) >= 4) { - j = 1; - } - - if ((k = j + 1) >= 4) { - k = 1; - } - - jVal = quat[j]; - kVal = quat[k]; - uVec.x = quat[0]; - uVec.y = quat[i]; - uVec.z = zHalf + zHalf; - -end: - vec->x = tVec.x; - vec->y = tVec.y; - vec->z = tVec.z; -} - /** * This function is a pitch rotation of a quaternion, with the sign allowing both regular * and inverse multiplication. @@ -896,8 +850,7 @@ void gd_print_bounding_box(UNUSED const char *prefix, UNUSED const struct GdBoun * does have a "Matrix:" prefix, so it was definitely used at one point. */ void gd_print_mtx(UNUSED const char *prefix, const Mat4f *mtx) { - s32 i; - s32 j; + s32 i, j; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { @@ -927,13 +880,9 @@ void UNUSED gd_print_quat(const char *prefix, const f32 f[4]) { void UNUSED gd_rot_mat_offset(Mat4f *dst, f32 x, f32 y, f32 z, s32 copy) { f32 adj = 100.0f; Mat4f rot; - f32 c; - f32 s; - f32 opp; - f32 mag; struct GdVec3f vec; - opp = gd_sqrt_f(SQ(x) + SQ(y) + SQ(z)); + f32 opp = gd_sqrt_f(SQ(x) + SQ(y) + SQ(z)); if (opp == 0.0f) { if (copy) { @@ -942,9 +891,9 @@ void UNUSED gd_rot_mat_offset(Mat4f *dst, f32 x, f32 y, f32 z, s32 copy) { return; } - mag = gd_sqrt_f(SQ(adj) + SQ(opp)); - c = adj / mag; - s = opp / mag; + f32 mag = gd_sqrt_f(SQ(adj) + SQ(opp)); + f32 c = adj / mag; + f32 s = opp / mag; vec.x = -y / opp; vec.y = -x / opp; diff --git a/src/menu/intro_geo.c b/src/menu/intro_geo.c index 4bc27261..7a56f995 100644 --- a/src/menu/intro_geo.c +++ b/src/menu/intro_geo.c @@ -37,19 +37,18 @@ static s32 sTmCopyrightAlpha; /** * Geo callback to render the "Super Mario 64" logo on the title screen */ -Gfx *geo_intro_super_mario_64_logo(s32 state, struct GraphNode *node, UNUSED void *context) { +Gfx *geo_intro_super_mario_64_logo(s32 callContext, struct GraphNode *node, UNUSED void *context) { struct GraphNode *graphNode = node; Gfx *dl = NULL; Gfx *dlIter = NULL; - Mtx *scaleMat; - f32 *scaleTable1 = segmented_to_virtual(intro_seg7_table_scale_1); - f32 *scaleTable2 = segmented_to_virtual(intro_seg7_table_scale_2); - if (state != 1) { + if (callContext != GEO_CONTEXT_RENDER) { sIntroFrameCounter = 0; - } else if (state == 1) { + } else if (callContext == GEO_CONTEXT_RENDER) { + f32 *scaleTable1 = segmented_to_virtual(intro_seg7_table_scale_1); + f32 *scaleTable2 = segmented_to_virtual(intro_seg7_table_scale_2); SET_GRAPH_NODE_LAYER(graphNode->flags, LAYER_OPAQUE); - scaleMat = alloc_display_list(sizeof(*scaleMat)); + Mtx *scaleMat = alloc_display_list(sizeof(*scaleMat)); dl = alloc_display_list(4 * sizeof(*dl)); dlIter = dl; Vec3f scale; @@ -83,14 +82,14 @@ Gfx *geo_intro_super_mario_64_logo(s32 state, struct GraphNode *node, UNUSED voi /** * Geo callback to render TM and Copyright on the title screen */ -Gfx *geo_intro_tm_copyright(s32 state, struct GraphNode *node, UNUSED void *context) { +Gfx *geo_intro_tm_copyright(s32 callContext, struct GraphNode *node, UNUSED void *context) { struct GraphNode *graphNode = node; Gfx *dl = NULL; Gfx *dlIter = NULL; - if (state != 1) { // reset + if (callContext != GEO_CONTEXT_RENDER) { // reset sTmCopyrightAlpha = 0; - } else if (state == 1) { // draw + } else if (callContext == GEO_CONTEXT_RENDER) { // draw dl = alloc_display_list(5 * sizeof(*dl)); dlIter = dl; gSPDisplayList(dlIter++, dl_proj_mtx_fullscreen); @@ -179,7 +178,7 @@ static s8 *introBackgroundTables[] = { introBackgroundIndexTable }; /** * Geo callback to render the intro background tiles */ -Gfx *geo_intro_regular_backdrop(s32 state, struct GraphNode *node, UNUSED void *context) { +Gfx *geo_intro_regular_backdrop(s32 callContext, struct GraphNode *node, UNUSED void *context) { struct GraphNodeMore *graphNode = (struct GraphNodeMore *) node; s32 index = graphNode->bgTableID & 0xff; // TODO: word at offset 0x18 of struct GraphNode (always ends up being 0) s8 *backgroundTable = introBackgroundTables[index]; @@ -187,7 +186,7 @@ Gfx *geo_intro_regular_backdrop(s32 state, struct GraphNode *node, UNUSED void * Gfx *dlIter = NULL; s32 i; - if (state == 1) { // draw + if (callContext == GEO_CONTEXT_RENDER) { // draw dl = alloc_display_list(16 * sizeof(*dl)); dlIter = dl; SET_GRAPH_NODE_LAYER(graphNode->node.flags, LAYER_OPAQUE); @@ -212,14 +211,13 @@ static s8 gameOverBackgroundTable[] = { /** * Geo callback to render the Game Over background tiles */ -Gfx *geo_intro_gameover_backdrop(s32 state, struct GraphNode *node, UNUSED void *context) { +Gfx *geo_intro_gameover_backdrop(s32 callContext, struct GraphNode *node, UNUSED void *context) { struct GraphNode *graphNode = node; Gfx *dl = NULL; Gfx *dlIter = NULL; - s32 j; - s32 i; + s32 i, j; - if (state != 1) { // reset + if (callContext != GEO_CONTEXT_RENDER) { // reset sGameOverFrameCounter = 0; sGameOverTableIndex = -2; for (i = 0; i < ARRAY_COUNT(gameOverBackgroundTable); ++i) @@ -376,17 +374,16 @@ u16 *intro_sample_frame_buffer(s32 imageW, s32 imageH, s32 sampleW, s32 sampleH) return image; } -Gfx *geo_intro_face_easter_egg(s32 state, struct GraphNode *node, UNUSED void *context) { +Gfx *geo_intro_face_easter_egg(s32 callContext, struct GraphNode *node, UNUSED void *context) { struct GraphNodeGenerated *genNode = (struct GraphNodeGenerated *)node; Gfx *dl = NULL; s32 i; - if (state != 1) { + if (callContext != GEO_CONTEXT_RENDER) { for (i = 0; i < 48; i++) { sFaceVisible[i] = 0; } - - } else if (state == 1) { + } else if (callContext == GEO_CONTEXT_RENDER) { if (sFaceCounter == 0) { if (gPlayer1Controller->buttonPressed & Z_TRIG) { play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource); @@ -399,7 +396,6 @@ Gfx *geo_intro_face_easter_egg(s32 state, struct GraphNode *node, UNUSED void *c sFaceCounter = 0; } } - // Draw while the first or last face is visible. if (sFaceVisible[0] == 1 || sFaceVisible[17] == 1) { u16 *image = intro_sample_frame_buffer(40, 40, 2, 2); @@ -415,18 +411,17 @@ Gfx *geo_intro_face_easter_egg(s32 state, struct GraphNode *node, UNUSED void *c #endif #if ENABLE_RUMBLE -Gfx *geo_intro_rumble_pak_graphic(s32 state, struct GraphNode *node, UNUSED void *context) { +Gfx *geo_intro_rumble_pak_graphic(s32 callContext, struct GraphNode *node, UNUSED void *context) { struct GraphNodeGenerated *genNode = (struct GraphNodeGenerated *)node; Gfx *dlIter; Gfx *dl = NULL; - s32 introContext; s8 backgroundTileSix = 0; - if (state != 1) { + if (callContext != GEO_CONTEXT_RENDER) { dl = NULL; - } else if (state == 1) { + } else if (callContext == GEO_CONTEXT_RENDER) { SET_GRAPH_NODE_LAYER(genNode->fnNode.node.flags, LAYER_OPAQUE); - introContext = genNode->parameter & 0xFF; + s32 introContext = (genNode->parameter & 0xFF); if (introContext == 0) { backgroundTileSix = introBackgroundIndexTable[6]; } else if (introContext == 1) { diff --git a/src/menu/intro_geo.h b/src/menu/intro_geo.h index 3f882621..fb9f1349 100644 --- a/src/menu/intro_geo.h +++ b/src/menu/intro_geo.h @@ -7,16 +7,16 @@ #include "types.h" #include "engine/graph_node.h" -Gfx *geo_intro_super_mario_64_logo(s32 state, struct GraphNode *node, UNUSED void *context); -Gfx *geo_intro_tm_copyright(s32 state, struct GraphNode *node, UNUSED void *context); -Gfx *geo_intro_regular_backdrop(s32 state, struct GraphNode *node, UNUSED void *context); -Gfx *geo_intro_gameover_backdrop(s32 state, struct GraphNode *node, UNUSED void *context); +Gfx *geo_intro_super_mario_64_logo(s32 callContext, struct GraphNode *node, UNUSED void *context); +Gfx *geo_intro_tm_copyright(s32 callContext, struct GraphNode *node, UNUSED void *context); +Gfx *geo_intro_regular_backdrop(s32 callContext, struct GraphNode *node, UNUSED void *context); +Gfx *geo_intro_gameover_backdrop(s32 callContext, struct GraphNode *node, UNUSED void *context); #ifdef GODDARD_EASTER_EGG -Gfx *geo_intro_face_easter_egg(s32 state, struct GraphNode *node, UNUSED void *context); +Gfx *geo_intro_face_easter_egg(s32 callContext, struct GraphNode *node, UNUSED void *context); #endif #if ENABLE_RUMBLE -Gfx *geo_intro_rumble_pak_graphic(s32 state, struct GraphNode *node, UNUSED void *context); +Gfx *geo_intro_rumble_pak_graphic(s32 callContext, struct GraphNode *node, UNUSED void *context); #endif #endif // INTRO_GEO_H