From 8996496d007a6d3e706d153d9546f73b7943c4b0 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 28 Oct 2022 11:57:00 +0300 Subject: [PATCH] Match and link CBSDie --- asm/MetroidPrime/BodyState/CBSDie.s | 12 ++--- configure.py | 2 +- include/MetroidPrime/BodyState/CBSDie.hpp | 22 ++++++++ .../BodyState/CBodyController.hpp | 9 +++- obj_files.mk | 2 +- src/MetroidPrime/BodyState/CBSDie.cpp | 53 +++++++++++++++++++ 6 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 include/MetroidPrime/BodyState/CBSDie.hpp create mode 100644 src/MetroidPrime/BodyState/CBSDie.cpp diff --git a/asm/MetroidPrime/BodyState/CBSDie.s b/asm/MetroidPrime/BodyState/CBSDie.s index 8359916c..09b4fd9b 100644 --- a/asm/MetroidPrime/BodyState/CBSDie.s +++ b/asm/MetroidPrime/BodyState/CBSDie.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803E13A8 -lbl_803E13A8: +.global __vt__6CBSDie +__vt__6CBSDie: # ROM: 0x3DE3A8 .4byte 0 .4byte 0 @@ -31,8 +31,8 @@ __dt__6CBSDieFv: /* 80135658 001325B8 93 E1 00 0C */ stw r31, 0xc(r1) /* 8013565C 001325BC 7C 7F 1B 79 */ or. r31, r3, r3 /* 80135660 001325C0 41 82 00 30 */ beq lbl_80135690 -/* 80135664 001325C4 3C 60 80 3E */ lis r3, lbl_803E13A8@ha -/* 80135668 001325C8 38 03 13 A8 */ addi r0, r3, lbl_803E13A8@l +/* 80135664 001325C4 3C 60 80 3E */ lis r3, __vt__6CBSDie@ha +/* 80135668 001325C8 38 03 13 A8 */ addi r0, r3, __vt__6CBSDie@l /* 8013566C 001325CC 90 1F 00 00 */ stw r0, 0(r31) /* 80135670 001325D0 41 82 00 10 */ beq lbl_80135680 /* 80135674 001325D4 3C 60 80 3E */ lis r3, __vt__10CBodyState@ha @@ -232,11 +232,11 @@ lbl_801358F0: .global __ct__6CBSDieFv __ct__6CBSDieFv: /* 8013590C 0013286C 3C A0 80 3E */ lis r5, __vt__10CBodyState@ha -/* 80135910 00132870 3C 80 80 3E */ lis r4, lbl_803E13A8@ha +/* 80135910 00132870 3C 80 80 3E */ lis r4, __vt__6CBSDie@ha /* 80135914 00132874 38 05 13 18 */ addi r0, r5, __vt__10CBodyState@l /* 80135918 00132878 C0 02 99 B0 */ lfs f0, lbl_805AB6D0@sda21(r2) /* 8013591C 0013287C 90 03 00 00 */ stw r0, 0(r3) -/* 80135920 00132880 38 84 13 A8 */ addi r4, r4, lbl_803E13A8@l +/* 80135920 00132880 38 84 13 A8 */ addi r4, r4, __vt__6CBSDie@l /* 80135924 00132884 38 00 00 00 */ li r0, 0 /* 80135928 00132888 90 83 00 00 */ stw r4, 0(r3) /* 8013592C 0013288C D0 03 00 04 */ stfs f0, 4(r3) diff --git a/configure.py b/configure.py index 743edc85..e8baded5 100755 --- a/configure.py +++ b/configure.py @@ -185,7 +185,7 @@ LIBS = [ "MetroidPrime/BodyState/CBodyStateCmdMgr", ["MetroidPrime/BodyState/CBodyStateInfo", False], "MetroidPrime/BodyState/CBSAttack", - "MetroidPrime/BodyState/CBSDie", + ["MetroidPrime/BodyState/CBSDie", True], "MetroidPrime/BodyState/CBSFall", "MetroidPrime/BodyState/CBSGetup", "MetroidPrime/BodyState/CBSKnockBack", diff --git a/include/MetroidPrime/BodyState/CBSDie.hpp b/include/MetroidPrime/BodyState/CBSDie.hpp new file mode 100644 index 00000000..dcf5c03e --- /dev/null +++ b/include/MetroidPrime/BodyState/CBSDie.hpp @@ -0,0 +1,22 @@ +#ifndef _CBSDIE +#define _CBSDIE + +#include "MetroidPrime/BodyState/CBodyState.hpp" + +class CBSDie : public CBodyState { +public: + CBSDie(); + ~CBSDie(); + + bool IsDead() const override; + bool IsDying() const override; + void Start(CBodyController& bc, CStateManager& mgr) override; + pas::EAnimationState UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) override; + void Shutdown(CBodyController&) override; + +private: + float x4_remTime; + bool x8_isDead; +}; + +#endif // _CBSDIE diff --git a/include/MetroidPrime/BodyState/CBodyController.hpp b/include/MetroidPrime/BodyState/CBodyController.hpp index bb169bbe..f3eec8dc 100644 --- a/include/MetroidPrime/BodyState/CBodyController.hpp +++ b/include/MetroidPrime/BodyState/CBodyController.hpp @@ -24,9 +24,12 @@ public: void SetDeltaRotation(const CQuaternion& q); void SetCurrentAnimation(const CAnimPlaybackParms& parms, bool loop, bool noTrans); void FaceDirection(const CVector3f& v0, float dt); + void EnableAnimation(bool enable); - bool IsAnimationOver() const { return x300_24_animationOver; } + pas::EFallState GetFallState() const; // { return x2f0_fallState; } pas::ELocomotionType GetLocomotionType() const { return x2ec_locomotionType; } + bool IsAnimationOver() const { return x300_24_animationOver; } + bool ShouldPlayDeathAnims() const { return x300_28_playDeathAnims; } private: CActor& x0_actor; @@ -39,6 +42,10 @@ private: int x2f8_curAnim ; float x2fc_turnSpeed; bool x300_24_animationOver : 1; + bool x300_25_active : 1; + bool x300_26_frozen : 1; + bool x300_27_hasBeenFrozen : 1; + bool x300_28_playDeathAnims : 1; }; #endif // _CBODYCONTROLLER diff --git a/obj_files.mk b/obj_files.mk index bd80e8d1..d21e877c 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -150,7 +150,7 @@ METROIDPRIME :=\ $(BUILD_DIR)/asm/MetroidPrime/BodyState/CBodyStateCmdMgr.o\ $(BUILD_DIR)/asm/MetroidPrime/BodyState/CBodyStateInfo.o\ $(BUILD_DIR)/asm/MetroidPrime/BodyState/CBSAttack.o\ - $(BUILD_DIR)/asm/MetroidPrime/BodyState/CBSDie.o\ + $(BUILD_DIR)/src/MetroidPrime/BodyState/CBSDie.o\ $(BUILD_DIR)/asm/MetroidPrime/BodyState/CBSFall.o\ $(BUILD_DIR)/asm/MetroidPrime/BodyState/CBSGetup.o\ $(BUILD_DIR)/asm/MetroidPrime/BodyState/CBSKnockBack.o\ diff --git a/src/MetroidPrime/BodyState/CBSDie.cpp b/src/MetroidPrime/BodyState/CBSDie.cpp new file mode 100644 index 00000000..79a3bc61 --- /dev/null +++ b/src/MetroidPrime/BodyState/CBSDie.cpp @@ -0,0 +1,53 @@ +#include "MetroidPrime/BodyState/CBSDie.hpp" + +#include "MetroidPrime/CStateManager.hpp" +#include "MetroidPrime/CAnimPlaybackParms.hpp" +#include "MetroidPrime/BodyState/CBodyController.hpp" + +#include "Kyoto/Animation/CPASAnimParmData.hpp" +#include "Kyoto/Animation/CPASDatabase.hpp" + +CBSDie::CBSDie() : x4_remTime(0.0f), x8_isDead(false) {} + +void CBSDie::Start(CBodyController& bc, CStateManager& mgr) override { + const CPASDatabase& db = bc.GetPASDatabase(); + int fallState = bc.GetFallState(); + + bool shouldReset = true; + + if (bc.ShouldPlayDeathAnims()) { + const CPASAnimParmData parms(pas::kAS_Death, CPASAnimParm::FromEnum(fallState)); + const rstl::pair best = db.FindBestAnimation(parms, *mgr.Random(), -1); + if (best.first > 0.f) { + const CAnimPlaybackParms playParms(best.second, -1, 1.f, true); + bc.SetCurrentAnimation(playParms, false, false); + x4_remTime = bc.GetAnimTimeRemaining(); + shouldReset = false; + } + } + + if (shouldReset) { + bc.EnableAnimation(false); + x4_remTime = bc.ShouldPlayDeathAnims() ? 3.f : 4.f; + } + + x8_isDead = false; +} + +pas::EAnimationState CBSDie::UpdateBody(float dt, CBodyController& bc, + CStateManager& mgr) override { + x4_remTime -= dt; + if (x4_remTime <= 0.f) { + bc.EnableAnimation(false); + x8_isDead = true; + } + return pas::kAS_Invalid; +} + +void CBSDie::Shutdown(CBodyController&) override {} + +bool CBSDie::IsDying() const override { return true; } + +bool CBSDie::IsDead() const override { return x8_isDead; } + +CBSDie::~CBSDie() {}