From b7c315e2f4a92b1d29e88e1b982fa48a230b54ae Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 21 Oct 2022 19:23:06 +0300 Subject: [PATCH] Match and link CScriptCameraHintTrigger Former-commit-id: 4b457fed708903ee0bf51dcc6ef2611f937f40be --- asm/MetroidPrime/ScriptLoader.s | 2 +- .../ScriptObjects/CScriptCameraHintTrigger.s | 22 +++---- configure.py | 2 +- .../CScriptCameraHintTrigger.hpp | 28 ++++++++ obj_files.mk | 2 +- .../CScriptCameraHintTrigger.cpp | 64 +++++++++++++++++++ 6 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 include/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.hpp create mode 100644 src/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.cpp diff --git a/asm/MetroidPrime/ScriptLoader.s b/asm/MetroidPrime/ScriptLoader.s index 7f23766b..25bf4bec 100644 --- a/asm/MetroidPrime/ScriptLoader.s +++ b/asm/MetroidPrime/ScriptLoader.s @@ -22514,7 +22514,7 @@ lbl_800D99B8: /* 800D9A08 000D6968 38 81 00 1C */ addi r4, r1, 0x1c /* 800D9A0C 000D696C 38 C1 00 D0 */ addi r6, r1, 0xd0 /* 800D9A10 000D6970 39 01 00 60 */ addi r8, r1, 0x60 -/* 800D9A14 000D6974 48 17 1C D5 */ bl "__ct__24CScriptCameraHintTriggerF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC12CTransform4fbb" +/* 800D9A14 000D6974 48 17 1C D5 */ bl "__ct__24CScriptCameraHintTriggerF9TUniqueIdbRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC12CTransform4fbb" /* 800D9A18 000D6978 7C 7A 1B 78 */ mr r26, r3 lbl_800D9A1C: /* 800D9A1C 000D697C 38 61 00 D0 */ addi r3, r1, 0xd0 diff --git a/asm/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.s b/asm/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.s index f2c4925f..4febac24 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.s @@ -3,15 +3,15 @@ .section .data .balign 8 -.global lbl_803E8C40 -lbl_803E8C40: +.global __vt__24CScriptCameraHintTrigger +__vt__24CScriptCameraHintTrigger: # ROM: 0x3E5C40 .4byte 0 .4byte 0 .4byte __dt__24CScriptCameraHintTriggerFv .4byte Accept__24CScriptCameraHintTriggerFR8IVisitor .4byte PreThink__7CEntityFfR13CStateManager - .4byte AcceptScriptMsg__24CScriptCameraHintTriggerF20EScriptObjectMessage9TUniqueIdR13CStateManager + .4byte Think__24CScriptCameraHintTriggerFfR13CStateManager .4byte AcceptScriptMsg__6CActorF20EScriptObjectMessage9TUniqueIdR13CStateManager .4byte SetActive__6CActorFUc .4byte PreRender__6CActorFR13CStateManagerRC14CFrustumPlanes @@ -56,9 +56,9 @@ __dt__24CScriptCameraHintTriggerFv: /* 8024B3B0 00248310 93 C1 00 08 */ stw r30, 8(r1) /* 8024B3B4 00248314 7C 7E 1B 79 */ or. r30, r3, r3 /* 8024B3B8 00248318 41 82 00 28 */ beq lbl_8024B3E0 -/* 8024B3BC 0024831C 3C A0 80 3F */ lis r5, lbl_803E8C40@ha +/* 8024B3BC 0024831C 3C A0 80 3F */ lis r5, __vt__24CScriptCameraHintTrigger@ha /* 8024B3C0 00248320 38 80 00 00 */ li r4, 0 -/* 8024B3C4 00248324 38 05 8C 40 */ addi r0, r5, lbl_803E8C40@l +/* 8024B3C4 00248324 38 05 8C 40 */ addi r0, r5, __vt__24CScriptCameraHintTrigger@l /* 8024B3C8 00248328 90 1E 00 00 */ stw r0, 0(r30) /* 8024B3CC 0024832C 4B E0 A3 25 */ bl __dt__6CActorFv /* 8024B3D0 00248330 7F E0 07 35 */ extsh. r0, r31 @@ -74,8 +74,8 @@ lbl_8024B3E0: /* 8024B3F4 00248354 38 21 00 10 */ addi r1, r1, 0x10 /* 8024B3F8 00248358 4E 80 00 20 */ blr -.global AcceptScriptMsg__24CScriptCameraHintTriggerF20EScriptObjectMessage9TUniqueIdR13CStateManager -AcceptScriptMsg__24CScriptCameraHintTriggerF20EScriptObjectMessage9TUniqueIdR13CStateManager: +.global Think__24CScriptCameraHintTriggerFfR13CStateManager +Think__24CScriptCameraHintTriggerFfR13CStateManager: /* 8024B3FC 0024835C 94 21 FF E0 */ stwu r1, -0x20(r1) /* 8024B400 00248360 7C 08 02 A6 */ mflr r0 /* 8024B404 00248364 90 01 00 24 */ stw r0, 0x24(r1) @@ -281,8 +281,8 @@ Accept__24CScriptCameraHintTriggerFR8IVisitor: /* 8024B6E0 00248640 38 21 00 10 */ addi r1, r1, 0x10 /* 8024B6E4 00248644 4E 80 00 20 */ blr -.global "__ct__24CScriptCameraHintTriggerF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC12CTransform4fbb" -"__ct__24CScriptCameraHintTriggerF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC12CTransform4fbb": +.global "__ct__24CScriptCameraHintTriggerF9TUniqueIdbRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC12CTransform4fbb" +"__ct__24CScriptCameraHintTriggerF9TUniqueIdbRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfoRC9CVector3fRC12CTransform4fbb": /* 8024B6E8 00248648 94 21 FF 00 */ stwu r1, -0x100(r1) /* 8024B6EC 0024864C 7C 08 02 A6 */ mflr r0 /* 8024B6F0 00248650 90 01 01 04 */ stw r0, 0x104(r1) @@ -336,9 +336,9 @@ Accept__24CScriptCameraHintTriggerFR8IVisitor: /* 8024B7B0 00248710 38 61 00 88 */ addi r3, r1, 0x88 /* 8024B7B4 00248714 38 80 FF FF */ li r4, -1 /* 8024B7B8 00248718 4B EC B2 95 */ bl __dt__10CModelDataFv -/* 8024B7BC 0024871C 3C 60 80 3F */ lis r3, lbl_803E8C40@ha +/* 8024B7BC 0024871C 3C 60 80 3F */ lis r3, __vt__24CScriptCameraHintTrigger@ha /* 8024B7C0 00248720 7F A4 EB 78 */ mr r4, r29 -/* 8024B7C4 00248724 38 03 8C 40 */ addi r0, r3, lbl_803E8C40@l +/* 8024B7C4 00248724 38 03 8C 40 */ addi r0, r3, __vt__24CScriptCameraHintTrigger@l /* 8024B7C8 00248728 7F 85 E3 78 */ mr r5, r28 /* 8024B7CC 0024872C 90 18 00 00 */ stw r0, 0(r24) /* 8024B7D0 00248730 38 78 00 E8 */ addi r3, r24, 0xe8 diff --git a/configure.py b/configure.py index a95b1638..8dce90ab 100755 --- a/configure.py +++ b/configure.py @@ -347,7 +347,7 @@ LIBS = [ "MetroidPrime/CLogBookScreen", ["MetroidPrime/CGBASupport", True], "MetroidPrime/Player/CSaveWorld", - "MetroidPrime/ScriptObjects/CScriptCameraHintTrigger", + ["MetroidPrime/ScriptObjects/CScriptCameraHintTrigger", True], ["MetroidPrime/Enemies/CAmbientAI", True], ["MetroidPrime/CMemoryCardDriver", False], "MetroidPrime/CSaveGameScreen", diff --git a/include/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.hpp b/include/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.hpp new file mode 100644 index 00000000..eade3c9a --- /dev/null +++ b/include/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.hpp @@ -0,0 +1,28 @@ +#ifndef _CSCRIPTCAMERAHINTTRIGGER +#define _CSCRIPTCAMERAHINTTRIGGER + +#include "MetroidPrime/CActor.hpp" + +#include "Collision/COBBox.hpp" + +class CScriptCameraHintTrigger : public CActor { + COBBox xe8_obb; + CVector3f x124_scale; + bool x130_24_deactivateOnEnter : 1; + bool x130_25_deactivateOnExit : 1; + bool x130_26_playerInside : 1; + bool x130_27_playerWasInside : 1; + +public: + CScriptCameraHintTrigger(TUniqueId uid, bool active, const rstl::string& name, + const CEntityInfo& info, const CVector3f& scale, const CTransform4f& xf, + bool deactivateOnEnter, bool deactivateOnExit); + ~CScriptCameraHintTrigger(); + + void Accept(IVisitor& visitor) override; + void Think(float dt, CStateManager& mgr) override; + void Touch(CActor& other, CStateManager& mgr) override; + rstl::optional_object< CAABox > GetTouchBounds() const override; +}; + +#endif // _CSCRIPTCAMERAHINTTRIGGER diff --git a/obj_files.mk b/obj_files.mk index 01dbafdf..3512b82c 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -312,7 +312,7 @@ METROIDPRIME :=\ $(BUILD_DIR)/asm/MetroidPrime/CLogBookScreen.o\ $(BUILD_DIR)/src/MetroidPrime/CGBASupport.o\ $(BUILD_DIR)/asm/MetroidPrime/Player/CSaveWorld.o\ - $(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.o\ + $(BUILD_DIR)/src/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CAmbientAI.o\ $(BUILD_DIR)/asm/MetroidPrime/CMemoryCardDriver.o\ $(BUILD_DIR)/asm/MetroidPrime/CSaveGameScreen.o\ diff --git a/src/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.cpp b/src/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.cpp new file mode 100644 index 00000000..9ce88a84 --- /dev/null +++ b/src/MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.cpp @@ -0,0 +1,64 @@ +#include "MetroidPrime/ScriptObjects/CScriptCameraHintTrigger.hpp" + +#include "MetroidPrime/CActorParameters.hpp" + +CScriptCameraHintTrigger::CScriptCameraHintTrigger(TUniqueId uid, bool active, + const rstl::string& name, + const CEntityInfo& info, const CVector3f& scale, + const CTransform4f& xf, bool deactivateOnEnter, + bool deactivateOnExit) +: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(kMT_Trigger), + CActorParameters::None(), kInvalidUniqueId) +, xe8_obb(xf, scale) +, x124_scale(scale) +, x130_24_deactivateOnEnter(deactivateOnEnter) +, x130_25_deactivateOnExit(deactivateOnExit) +, x130_26_playerInside(false) +, x130_27_playerWasInside(false) +{} + +void CScriptCameraHintTrigger::Accept(IVisitor& visitor) { visitor.Visit(*this); } + +rstl::optional_object< CAABox > CScriptCameraHintTrigger::GetTouchBounds() const { + return xe8_obb.CalculateAABox(CTransform4f::Identity()); +} + +void CScriptCameraHintTrigger::Touch(CActor& other, CStateManager& mgr) { + if (TCastToConstPtr< CPlayer >(other)) { + rstl::optional_object< CAABox > bounds = other.GetTouchBounds(); + if (bounds.valid()) { + COBBox otherObb = COBBox::FromAABox(*bounds, CTransform4f::Identity()); + x130_26_playerInside = xe8_obb.OBBIntersectsBox(otherObb); + } + } +} + +void CScriptCameraHintTrigger::Think(float dt, CStateManager& mgr) { + if (!GetActive()) { + return; + } + + if (x130_26_playerInside && !x130_27_playerWasInside) { + x130_27_playerWasInside = true; + SendScriptMsgs(kSS_Entered, mgr, kSM_None); + if (x130_24_deactivateOnEnter) { + mgr.SendScriptMsg(this, kInvalidUniqueId, kSM_Deactivate); + } + } + + if (!x130_26_playerInside && x130_27_playerWasInside) { + x130_27_playerWasInside = false; + SendScriptMsgs(kSS_Exited, mgr, kSM_None); + if (x130_25_deactivateOnExit) { + mgr.SendScriptMsg(this, kInvalidUniqueId, kSM_Deactivate); + } + } + + if (x130_26_playerInside) { + SendScriptMsgs(kSS_Inside, mgr, kSM_None); + } + + x130_26_playerInside = false; +} + +CScriptCameraHintTrigger::~CScriptCameraHintTrigger() {}