Fix animation comparisons after character anim commit

This commit is contained in:
David Joslin 2023-10-27 23:45:48 -07:00
parent b28fd30b43
commit 048f4f1fd4
4 changed files with 17 additions and 10 deletions

View File

@ -1566,8 +1566,9 @@ void play_character_sound_if_no_flag(struct MarioState* m, enum CharacterSound c
f32 get_character_anim_offset(struct MarioState* m) { f32 get_character_anim_offset(struct MarioState* m) {
if (m == NULL || m->marioObj == NULL) { return 0; } if (m == NULL || m->marioObj == NULL) { return 0; }
struct Object* marioObj = m->marioObj; struct Object* marioObj = m->marioObj;
if (!marioObj) { return 0; }
struct Character* c = get_character(m); struct Character* c = get_character(m);
if (!c->animOffsetEnabled) { return 0; } if (!c || !c->animOffsetEnabled) { return 0; }
s32 animID = marioObj->header.gfx.animInfo.animID; s32 animID = marioObj->header.gfx.animInfo.animID;
if (animID < 0 || animID >= ANIM_TYPE_MAX) { return 0; } if (animID < 0 || animID >= ANIM_TYPE_MAX) { return 0; }
@ -1590,8 +1591,9 @@ f32 get_character_anim_offset(struct MarioState* m) {
void update_character_anim_offset(struct MarioState* m) { void update_character_anim_offset(struct MarioState* m) {
if (m == NULL || m->marioObj == NULL) { return; } if (m == NULL || m->marioObj == NULL) { return; }
struct Object* marioObj = m->marioObj; struct Object* marioObj = m->marioObj;
if (!marioObj) { return; }
struct Character* c = get_character(m); struct Character* c = get_character(m);
if (!c->animOffsetEnabled) { return; } if (!c || !c->animOffsetEnabled) { return; }
f32 targetOffset = get_character_anim_offset(m); f32 targetOffset = get_character_anim_offset(m);
@ -1611,6 +1613,6 @@ s32 get_character_anim(struct MarioState* m, enum CharacterAnimID characterAnim)
if (m == NULL || m->marioObj == NULL) { return 0; } if (m == NULL || m->marioObj == NULL) { return 0; }
struct Character* character = ((m == NULL || m->character == NULL) ? &gCharacters[CT_MARIO] : m->character); struct Character* character = ((m == NULL || m->character == NULL) ? &gCharacters[CT_MARIO] : m->character);
if (characterAnim < 0 || characterAnim >= CHAR_ANIM_MAX) { return 0; } if (!character || characterAnim < 0 || characterAnim >= CHAR_ANIM_MAX) { return 0; }
return character->anims[characterAnim]; return character->anims[characterAnim];
} }

View File

@ -120,9 +120,12 @@ s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) {
* Sets the character specific animation without any acceleration, running at its default rate. * Sets the character specific animation without any acceleration, running at its default rate.
*/ */
s16 set_character_animation(struct MarioState *m, s32 targetAnimID) { s16 set_character_animation(struct MarioState *m, s32 targetAnimID) {
if (!m) { return 0; }
struct Object *o = m->marioObj; struct Object *o = m->marioObj;
if (!o || !m->animation) { return 0; }
struct Animation *targetAnim = m->animation->targetAnim; struct Animation *targetAnim = m->animation->targetAnim;
s32 charAnimID = get_character_anim(m, targetAnimID); s32 charAnimID = get_character_anim(m, targetAnimID);
if (!targetAnim) { return 0; }
if (load_patchable_table(m->animation, charAnimID)) { if (load_patchable_table(m->animation, charAnimID)) {
targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values); targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values);
@ -193,8 +196,11 @@ s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel)
* slowed down via acceleration. * slowed down via acceleration.
*/ */
s16 set_character_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel) { s16 set_character_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel) {
if (!m) { return 0; }
struct Object *o = m->marioObj; struct Object *o = m->marioObj;
if (!o || !m->animation) { return 0; }
struct Animation *targetAnim = m->animation->targetAnim; struct Animation *targetAnim = m->animation->targetAnim;
if (!targetAnim) { return 0; }
s32 charAnimID = get_character_anim(m, targetAnimID); s32 charAnimID = get_character_anim(m, targetAnimID);
if (load_patchable_table(m->animation, charAnimID)) { if (load_patchable_table(m->animation, charAnimID)) {

View File

@ -77,14 +77,14 @@ void play_step_sound(struct MarioState *m, s16 frame1, s16 frame2) {
if (!m) { return; } if (!m) { return; }
if (is_anim_past_frame(m, frame1) || is_anim_past_frame(m, frame2)) { if (is_anim_past_frame(m, frame1) || is_anim_past_frame(m, frame2)) {
if (m->flags & MARIO_METAL_CAP) { if (m->flags & MARIO_METAL_CAP) {
if (m->marioObj->header.gfx.animInfo.animID == CHAR_ANIM_TIPTOE) { if (m->marioObj->header.gfx.animInfo.animID == get_character_anim(m, CHAR_ANIM_TIPTOE)) {
play_sound_and_spawn_particles(m, SOUND_ACTION_METAL_STEP_TIPTOE, 0); play_sound_and_spawn_particles(m, SOUND_ACTION_METAL_STEP_TIPTOE, 0);
} else { } else {
play_sound_and_spawn_particles(m, SOUND_ACTION_METAL_STEP, 0); play_sound_and_spawn_particles(m, SOUND_ACTION_METAL_STEP, 0);
} }
} else if (m->quicksandDepth > 50.0f) { } else if (m->quicksandDepth > 50.0f) {
play_sound(SOUND_ACTION_QUICKSAND_STEP, m->marioObj->header.gfx.cameraToObject); play_sound(SOUND_ACTION_QUICKSAND_STEP, m->marioObj->header.gfx.cameraToObject);
} else if (m->marioObj->header.gfx.animInfo.animID == CHAR_ANIM_TIPTOE) { } else if (m->marioObj->header.gfx.animInfo.animID == get_character_anim(m, CHAR_ANIM_TIPTOE)) {
play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_STEP_TIPTOE, 0); play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_STEP_TIPTOE, 0);
} else { } else {
play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_STEP, 0); play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_STEP, 0);
@ -755,9 +755,9 @@ void tilt_body_walking(struct MarioState *m, s16 startYaw) {
if (!m) { return; } if (!m) { return; }
struct MarioBodyState *val0C = m->marioBodyState; struct MarioBodyState *val0C = m->marioBodyState;
UNUSED struct Object *marioObj = m->marioObj; UNUSED struct Object *marioObj = m->marioObj;
//s16 animID = m->marioObj->header.gfx.animInfo.animID; s16 animID = m->marioObj->header.gfx.animInfo.animID;
if (m->action == ACT_WALKING) {//animID == CHAR_ANIM_WALKING || animID == CHAR_ANIM_RUNNING) { if (animID == get_character_anim(m, CHAR_ANIM_WALKING) || animID == get_character_anim(m, CHAR_ANIM_RUNNING)) {
s16 dYaw = m->faceAngle[1] - startYaw; s16 dYaw = m->faceAngle[1] - startYaw;
//! (Speed Crash) These casts can cause a crash if (dYaw * forwardVel / 12) or //! (Speed Crash) These casts can cause a crash if (dYaw * forwardVel / 12) or
//! (forwardVel * 170) exceed or equal 2^31. //! (forwardVel * 170) exceed or equal 2^31.

View File

@ -430,8 +430,7 @@ Gfx* geo_mario_tilt_torso(s32 callContext, struct GraphNode* node, Mat4* mtx) {
if (callContext == GEO_CONTEXT_RENDER) { if (callContext == GEO_CONTEXT_RENDER) {
struct GraphNodeRotation* rotNode = (struct GraphNodeRotation*) node->next; struct GraphNodeRotation* rotNode = (struct GraphNodeRotation*) node->next;
if (action != ACT_BUTT_SLIDE && action != ACT_HOLD_BUTT_SLIDE && action != ACT_WALKING if (action != ACT_BUTT_SLIDE && action != ACT_HOLD_BUTT_SLIDE && action != ACT_WALKING && action != ACT_RIDING_SHELL_GROUND) {
&& action != ACT_RIDING_SHELL_GROUND) {
vec3s_copy(bodyState->torsoAngle, gVec3sZero); vec3s_copy(bodyState->torsoAngle, gVec3sZero);
} }
rotNode->rotation[0] = bodyState->torsoAngle[1] * character->torsoRotMult; rotNode->rotation[0] = bodyState->torsoAngle[1] * character->torsoRotMult;