Made cur_obj_call_action_function safer

This commit is contained in:
MysterD 2023-04-11 14:40:24 -07:00
parent aba6483e5e
commit 3825026faa
29 changed files with 40 additions and 38 deletions

View file

@ -170,5 +170,5 @@ static void (*sBetaBooKeyActions[])(void) = { beta_boo_key_inside_boo_loop, beta
* Update function for bhvBetaBooKey.
*/
void bhv_beta_boo_key_loop(void) {
cur_obj_call_action_function(sBetaBooKeyActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sBetaBooKeyActions);
}

View file

@ -555,7 +555,7 @@ void bhv_boo_loop(void) {
//PARTIAL_UPDATE
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sBooActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sBooActions);
cur_obj_move_standard(78);
boo_approach_target_opacity_and_update_scale();
@ -793,7 +793,7 @@ void bhv_big_boo_loop(void) {
o->oGraphYOffset = o->oBooBaseScale * 60.0f;
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sBooGivingStarActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sBooGivingStarActions);
cur_obj_move_standard(78);
boo_approach_target_opacity_and_update_scale();
@ -870,7 +870,7 @@ void bhv_boo_with_cage_loop(void) {
//PARTIAL_UPDATE
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sBooWithCageActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sBooWithCageActions);
cur_obj_move_standard(78);
boo_approach_target_opacity_and_update_scale();

View file

@ -59,7 +59,7 @@ void bhv_bowser_tail_anchor_init(void) {
}
void bhv_bowser_tail_anchor_loop(void) {
cur_obj_call_action_function(sBowserTailAnchorActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sBowserTailAnchorActions);
o->oParentRelativePosX = 90.0f;
if (o->parentObj->oAction == 4)
o->parentObj->oIntangibleTimer = -1;
@ -1204,7 +1204,7 @@ void bowser_free_update(void) {
o->oBowserUnk10E = 0;
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sBowserActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sBowserActions);
cur_obj_move_standard(-78);
if (bowser_check_fallen_off_stage())
o->oAction = 2; // bowser go home?
@ -1657,7 +1657,7 @@ void bhv_falling_bowser_platform_loop(void) {
}
}
cur_obj_call_action_function(sFallingBowserPlatformActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sFallingBowserPlatformActions);
}
void bowser_flame_despawn(void) {

View file

@ -275,7 +275,7 @@ void (*sBowserPuzzlePieceActions[])(void) = {
void bhv_lll_bowser_puzzle_piece_loop(void) {
bhv_lll_bowser_puzzle_piece_update();
cur_obj_call_action_function(sBowserPuzzlePieceActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sBowserPuzzlePieceActions);
o->oPosX = o->oBowserPuzzlePieceOffsetX + o->oHomeX;
o->oPosY = o->oBowserPuzzlePieceOffsetY + o->oHomeY;

View file

@ -28,7 +28,7 @@ void (*sBirdChirpChirpActions[])(void) = { bub_spawner_act_0, bub_spawner_act_1,
bub_spawner_act_2, bub_spawner_act_3 };
void bhv_bub_spawner_loop(void) {
cur_obj_call_action_function(sBirdChirpChirpActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sBirdChirpChirpActions);
}
void bub_move_vertically(s32 a0) {
@ -136,7 +136,7 @@ void bhv_bub_loop(void) {
}
o->oWallHitboxRadius = 30.0f;
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sCheepCheepActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sCheepCheepActions);
cur_obj_move_using_fvel_and_gravity();
if (o->parentObj->oAction == 2)
obj_mark_for_deletion(o);

View file

@ -86,7 +86,7 @@ void (*sBulletBillActions[])(void) = { bullet_bill_act_0, bullet_bill_act_1, bul
bullet_bill_act_3, bullet_bill_act_4 };
void bhv_bullet_bill_loop(void) {
cur_obj_call_action_function(sBulletBillActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sBulletBillActions);
if (cur_obj_check_interacted())
o->oAction = 4;
}

View file

@ -237,7 +237,7 @@ void bhv_cannon_base_loop(void) {
cur_obj_push_mario_away_from_cylinder(220, 300);
}
cur_obj_call_action_function(sOpenedCannonActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sOpenedCannonActions);
if (o->oCannonUnkF8)
o->oCannonUnkF8++;
o->oInteractStatus = 0;

View file

@ -65,5 +65,5 @@ void bhv_cap_switch_loop(void) {
sync_object_init_field(o, &capSwitchForcePress);
}
cur_obj_call_action_function(sCapSwitchActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sCapSwitchActions);
}

View file

@ -193,7 +193,7 @@ void (*sChuckyaActions[])(void) = { chuckya_act_0, chuckya_act_1, chuckya_act_2,
void chuckya_move(void) {
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sChuckyaActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sChuckyaActions);
cur_obj_move_standard(-30);
if (o->oInteractStatus & INT_STATUS_GRABBED_MARIO) {
o->oAction = 1;

View file

@ -255,7 +255,7 @@ void coin_inside_boo_act_0(void) {
void (*sCoinInsideBooActions[])(void) = { coin_inside_boo_act_0, coin_inside_boo_act_1 };
void bhv_coin_inside_boo_loop(void) {
cur_obj_call_action_function(sCoinInsideBooActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sCoinInsideBooActions);
}
void bhv_coin_sparkles_loop(void) {

View file

@ -154,7 +154,7 @@ struct SpawnParticlesInfo D_8032F3FC = { 0, 5, MODEL_WHITE_PARTICLE_DL, 0,
2.0f, 2.0f };
void bhv_elevator_loop(void) {
cur_obj_call_action_function(sElevatorActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sElevatorActions);
// allow bubbled players to pass through
if (gMarioStates[0].action == ACT_BUBBLED) {

View file

@ -214,5 +214,5 @@ void bhv_exclamation_box_init(void) {
void bhv_exclamation_box_loop(void) {
cur_obj_scale(2.0f);
cur_obj_call_action_function(sExclamationBoxActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sExclamationBoxActions);
}

View file

@ -73,7 +73,7 @@ static void (*sFishSpawnerActions[])(void) = {
};
void bhv_fish_spawner_loop(void) {
cur_obj_call_action_function(sFishSpawnerActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sFishSpawnerActions);
}
/**
@ -276,7 +276,7 @@ void bhv_fish_loop(void)
}
// Call fish action methods and apply physics engine.
cur_obj_call_action_function(sFishActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sFishActions);
cur_obj_move_using_fvel_and_gravity();
// If the parent object has action set to two, then delete the fish object.

View file

@ -99,7 +99,7 @@ void (*sHeaveHoActions[])(void) = { heave_ho_act_0, heave_ho_act_1, heave_ho_act
void heave_ho_move(void) {
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sHeaveHoActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sHeaveHoActions);
cur_obj_move_standard(-78);
if (o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER)
o->oGraphYOffset = -15.0f;

View file

@ -41,7 +41,7 @@ void jumping_box_free_update(void) {
obj_set_hitbox(o, &sJumpingBoxHitbox);
cur_obj_update_floor_and_walls();
cur_obj_move_standard(78);
cur_obj_call_action_function(sJumpingBoxActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sJumpingBoxActions);
}
void bhv_jumping_box_loop(void) {

View file

@ -365,7 +365,7 @@ void king_bobomb_move(void) {
cur_obj_move_standard(-78);
else
cur_obj_move_using_fvel_and_gravity();
cur_obj_call_action_function(sKingBobombActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sKingBobombActions);
exec_anim_sound_state(sKingBobombSoundStates);
s32 distanceToPlayer = dist_between_objects(o, gMarioStates[0].marioObj);
if (distanceToPlayer < 5000.0f * draw_distance_scalar())

View file

@ -60,7 +60,7 @@ void bhv_lll_rotating_block_fire_bars_loop(void) {
sync_object_init(o, 4000.0f);
sync_object_init_field(o, &o->oAngleVelYaw);
}
cur_obj_call_action_function(sRotatingCwFireBarsActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sRotatingCwFireBarsActions);
if (o->oBehParams2ndByte == 0)
load_object_collision_model();
}

View file

@ -33,7 +33,7 @@ void mr_i_piranha_particle_act_1(void) {
void (*sMrIParticleActions[])(void) = { mr_i_piranha_particle_act_0, mr_i_piranha_particle_act_1 };
void bhv_mr_i_particle_loop(void) {
cur_obj_call_action_function(sMrIParticleActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sMrIParticleActions);
}
void spawn_mr_i_particle(void) {
@ -283,7 +283,7 @@ void bhv_mr_i_loop(void) {
s32 distanceToPlayer = player ? dist_between_objects(o, player) : 10000;
obj_set_hitbox(o, &sMrIHitbox);
cur_obj_call_action_function(sMrIActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sMrIActions);
if (o->oAction != 3) {
if (distanceToPlayer > 3000.0f || o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM) {
o->oAction = 0;

View file

@ -369,7 +369,7 @@ void bhv_piranha_plant_loop(void) {
cur_obj_set_hitbox_radius_and_height(150.0f, 100.0f);
cur_obj_set_hurtbox_radius_and_height(150.0f, 100.0f);
cur_obj_call_action_function(TablePiranhaPlantActions);
CUR_OBJ_CALL_ACTION_FUNCTION(TablePiranhaPlantActions);
// In WF, hide all Piranha Plants once high enough up.
if (gCurrLevelNum == LEVEL_WF) {
struct Object* player = gMarioStates[0].marioObj;

View file

@ -63,5 +63,5 @@ void bhv_grindel_thwomp_loop(void) {
sync_object_init_field(o, &o->oTimer);
sync_object_init_field(o, &o->oVelY);
}
cur_obj_call_action_function(sGrindelThwompActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sGrindelThwompActions);
}

View file

@ -85,6 +85,6 @@ void bhv_tox_box_loop(void) {
sync_object_init_field(o, &o->oToxBoxMovementStep);
}
}
cur_obj_call_action_function(sToxBoxActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sToxBoxActions);
load_object_collision_model();
}

View file

@ -164,5 +164,5 @@ void bhv_tumbling_bridge_loop(void) {
}
}
cur_obj_call_action_function(sTumblingBridgeActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sTumblingBridgeActions);
}

View file

@ -160,7 +160,7 @@ void bhv_tuxies_mother_loop(void) {
}
o->activeFlags |= ACTIVE_FLAG_UNK10;
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sTuxiesMotherActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sTuxiesMotherActions);
cur_obj_move_standard(-78);
play_penguin_walking_sound(PENGUIN_WALK_BIG);
o->oInteractStatus = 0;
@ -289,7 +289,7 @@ void small_penguin_free_actions(void) {
cur_obj_become_tangible();
cur_obj_enable_rendering();
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sSmallPenguinActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sSmallPenguinActions);
cur_obj_move_standard(-78);
play_penguin_walking_sound(PENGUIN_WALK_BABY);
}

View file

@ -149,7 +149,7 @@ void bhv_tweester_loop(void) {
}
obj_set_hitbox(o, &sTweesterHitbox);
cur_obj_call_action_function(sTweesterActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sTweesterActions);
o->oInteractStatus = 0;
}

View file

@ -504,7 +504,7 @@ void ukiki_free_loop(void) {
s32 steepSlopeAngleDegrees;
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sUkikiActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sUkikiActions);
if (o->oAction == UKIKI_ACT_GO_TO_CAGE || o->oAction == UKIKI_ACT_RETURN_HOME) {
steepSlopeAngleDegrees = -88;

View file

@ -103,5 +103,5 @@ void (*sUkikiCageActions[])(void) = {
* Main behavior loop for the cage. Only calls the relevant action.
*/
void bhv_ukiki_cage_loop(void) {
cur_obj_call_action_function(sUkikiCageActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sUkikiCageActions);
}

View file

@ -284,7 +284,7 @@ void bhv_whomp_loop(void) {
}
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sWhompActions);
CUR_OBJ_CALL_ACTION_FUNCTION(sWhompActions);
cur_obj_move_standard(-20);
if (o->oAction != 9) {
// o->oBehParams2ndByte here seems to be a flag

View file

@ -2663,9 +2663,9 @@ s32 cur_obj_move_up_and_down(s32 a0) {
return FALSE;
}
void cur_obj_call_action_function(void (*actionFunctions[])(void)) {
void cur_obj_call_action_function(void (*actionFunctions[])(void), uint32_t actionFunctionsLength) {
if (!actionFunctions) { return; }
if ((uint32_t)o->oAction >= actionFunctionsLength) { return; }
void (*actionFunction)(void) = actionFunctions[o->oAction];
if (!actionFunction) { return; }
actionFunction();

View file

@ -256,6 +256,8 @@ struct GraphNode_802A45E4 {
/*0x22*/ s16 unk22;
};
#define CUR_OBJ_CALL_ACTION_FUNCTION(_action_func) cur_obj_call_action_function(_action_func, (sizeof(_action_func) / sizeof(&_action_func[0])))
void obj_set_hitbox(struct Object *obj, struct ObjectHitbox *hitbox);
s32 signum_positive(s32 x);
f32 absf(f32 x);
@ -273,7 +275,7 @@ void cur_obj_scale_over_time(s32 a0, s32 a1, f32 sp10, f32 sp14);
void cur_obj_set_pos_to_home_with_debug(void);
s32 cur_obj_is_mario_on_platform(void);
s32 cur_obj_move_up_and_down(s32 a0);
void cur_obj_call_action_function(void (*actionFunctions[])(void));
void cur_obj_call_action_function(void (*actionFunctions[])(void), uint32_t actionFunctionsLength);
void spawn_base_star_with_no_lvl_exit(void);
s32 bit_shift_left(s32 a0);
s32 cur_obj_mario_far_away(void);