From 4ead8b11e8065995ca319ed849f899e6774c1c4d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 30 Jun 2020 20:59:19 +1000 Subject: [PATCH] Decompile modelSetAnimSpeedAuto --- src/game/chr/chraction.c | 8 ++--- src/include/lib/lib_1a500.h | 2 +- src/lib/lib_1a500.c | 66 ++++++++++--------------------------- 3 files changed, 23 insertions(+), 53 deletions(-) diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index 140669c89..ff34f9786 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -20337,7 +20337,7 @@ glabel chrTickAttackWalk /* f044300: 00000000 */ nop /* f044304: 45000005 */ bc1f .L0f04431c /* f044308: 00000000 */ nop -/* f04430c: 0c0077c1 */ jal func0001df04 +/* f04430c: 0c0077c1 */ jal modelSetAnimSpeedAuto /* f044310: 3c064180 */ lui $a2,0x4180 /* f044314: 1000000d */ b .L0f04434c /* f044318: 00000000 */ nop @@ -20352,7 +20352,7 @@ glabel chrTickAttackWalk /* f044338: 3c064180 */ lui $a2,0x4180 /* f04433c: 46062202 */ mul.s $f8,$f4,$f6 /* f044340: 44054000 */ mfc1 $a1,$f8 -/* f044344: 0c0077c1 */ jal func0001df04 +/* f044344: 0c0077c1 */ jal modelSetAnimSpeedAuto /* f044348: 00000000 */ nop .L0f04434c: /* f04434c: 0fc0e56b */ jal chrRecordLastSeeTargetTime @@ -20775,7 +20775,7 @@ void chrTickRunPos(struct chrdata *chr) if (modelGetNumAnimFrames(model) * 0.5f < fVar6) { zero = 0; - func0001df04(model, modelGetNumAnimFrames(model) - zero, 16); + modelSetAnimSpeedAuto(model, modelGetNumAnimFrames(model) - zero, 16); } else { zero = 0; fVar7 = modelGetNumAnimFrames(model) * 0.5f; @@ -20785,7 +20785,7 @@ void chrTickRunPos(struct chrdata *chr) fVar6 += modelGetNumAnimFrames(model); } - func0001df04(model, fVar6, 16); + modelSetAnimSpeedAuto(model, fVar6, 16); } chrStop(chr); diff --git a/src/include/lib/lib_1a500.h b/src/include/lib/lib_1a500.h index 5b0c14e23..e82b1f466 100644 --- a/src/include/lib/lib_1a500.h +++ b/src/include/lib/lib_1a500.h @@ -68,7 +68,7 @@ void modelSetAnimLooping(struct model *model, f32 loopframe, f32 loopmerge); void modelSetAnimEndFrame(struct model *model, f32 endframe); u32 func0001de98(void); void modelSetAnimSpeed(struct model *model, f32 speed, f32 startframe); -void func0001df04(struct model *model, f32 arg1, f32 arg2); +void modelSetAnimSpeedAuto(struct model *model, f32 arg1, f32 startframe); void modelSetAnimPlaySpeed(struct model *model, f32 speed, f32 frame); void modelSetAnim70(struct model *model, void *callback); u32 func0001e018(void); diff --git a/src/lib/lib_1a500.c b/src/lib/lib_1a500.c index cc0940fe6..c4de686ac 100644 --- a/src/lib/lib_1a500.c +++ b/src/lib/lib_1a500.c @@ -4261,54 +4261,24 @@ void modelSetAnimSpeed(struct model *model, f32 speed, f32 startframe) } } -GLOBAL_ASM( -glabel func0001df04 -/* 1df04: 27bdffe0 */ addiu $sp,$sp,-32 -/* 1df08: afbf0014 */ sw $ra,0x14($sp) -/* 1df0c: 8c830020 */ lw $v1,0x20($a0) -/* 1df10: 44856000 */ mtc1 $a1,$f12 -/* 1df14: 44867000 */ mtc1 $a2,$f14 -/* 1df18: 10600020 */ beqz $v1,.L0001df9c -/* 1df1c: 00803825 */ or $a3,$a0,$zero -/* 1df20: c462000c */ lwc1 $f2,0xc($v1) -/* 1df24: 460c103e */ c.le.s $f2,$f12 -/* 1df28: 00000000 */ nop -/* 1df2c: 45020004 */ bc1fl .L0001df40 -/* 1df30: 84640000 */ lh $a0,0x0($v1) -/* 1df34: 10000010 */ b .L0001df78 -/* 1df38: 46026001 */ sub.s $f0,$f12,$f2 -/* 1df3c: 84640000 */ lh $a0,0x0($v1) -.L0001df40: -/* 1df40: e7ae0028 */ swc1 $f14,0x28($sp) -/* 1df44: e7ac0024 */ swc1 $f12,0x24($sp) -/* 1df48: afa70020 */ sw $a3,0x20($sp) -/* 1df4c: 0c008dda */ jal animGetNumFrames -/* 1df50: afa3001c */ sw $v1,0x1c($sp) -/* 1df54: 44822000 */ mtc1 $v0,$f4 -/* 1df58: 8fa3001c */ lw $v1,0x1c($sp) -/* 1df5c: c7ac0024 */ lwc1 $f12,0x24($sp) -/* 1df60: 468021a0 */ cvt.s.w $f6,$f4 -/* 1df64: c468000c */ lwc1 $f8,0xc($v1) -/* 1df68: 8fa70020 */ lw $a3,0x20($sp) -/* 1df6c: c7ae0028 */ lwc1 $f14,0x28($sp) -/* 1df70: 46083281 */ sub.s $f10,$f6,$f8 -/* 1df74: 460c5000 */ add.s $f0,$f10,$f12 -.L0001df78: -/* 1df78: 46000480 */ add.s $f18,$f0,$f0 -/* 1df7c: c470001c */ lwc1 $f16,0x1c($v1) -/* 1df80: 44067000 */ mfc1 $a2,$f14 -/* 1df84: 00e02025 */ or $a0,$a3,$zero -/* 1df88: 460e9103 */ div.s $f4,$f18,$f14 -/* 1df8c: 46048080 */ add.s $f2,$f16,$f4 -/* 1df90: 44051000 */ mfc1 $a1,$f2 -/* 1df94: 0c0077ac */ jal modelSetAnimSpeed -/* 1df98: 00000000 */ nop -.L0001df9c: -/* 1df9c: 8fbf0014 */ lw $ra,0x14($sp) -/* 1dfa0: 27bd0020 */ addiu $sp,$sp,0x20 -/* 1dfa4: 03e00008 */ jr $ra -/* 1dfa8: 00000000 */ nop -); +void modelSetAnimSpeedAuto(struct model *model, f32 arg1, f32 startframe) +{ + struct anim *anim = model->anim; + f32 tmp; + f32 speed; + + if (anim) { + if (anim->frame <= arg1) { + tmp = arg1 - anim->frame; + } else { + tmp = animGetNumFrames(anim->animnum) - anim->frame + arg1; + } + + speed = anim->speed + (tmp + tmp) / startframe; + + modelSetAnimSpeed(model, speed, startframe); + } +} void modelSetAnimPlaySpeed(struct model *model, f32 speed, f32 startframe) {