From 890d2bb2d1ff608c3b3c06746c0bd36f601fc24a Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 21 Oct 2022 19:43:17 +0300 Subject: [PATCH] Add almost matching CScriptCameraWaypoint --- .../ScriptObjects/CScriptCameraWaypoint.s | 12 ++-- configure.py | 2 +- .../ScriptObjects/CScriptCameraWaypoint.hpp | 24 ++++++++ .../ScriptObjects/CScriptCameraWaypoint.cpp | 56 +++++++++++++++++++ 4 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 include/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.hpp create mode 100644 src/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.cpp diff --git a/asm/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.s b/asm/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.s index 6c1abfa9..ed017fd9 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803DF348 -lbl_803DF348: +.global __vt__21CScriptCameraWaypoint +__vt__21CScriptCameraWaypoint: # ROM: 0x3DC348 .4byte 0 .4byte 0 @@ -243,9 +243,9 @@ __dt__21CScriptCameraWaypointFv: /* 800B5450 000B23B0 93 C1 00 08 */ stw r30, 8(r1) /* 800B5454 000B23B4 7C 7E 1B 79 */ or. r30, r3, r3 /* 800B5458 000B23B8 41 82 00 28 */ beq lbl_800B5480 -/* 800B545C 000B23BC 3C A0 80 3E */ lis r5, lbl_803DF348@ha +/* 800B545C 000B23BC 3C A0 80 3E */ lis r5, __vt__21CScriptCameraWaypoint@ha /* 800B5460 000B23C0 38 80 00 00 */ li r4, 0 -/* 800B5464 000B23C4 38 05 F3 48 */ addi r0, r5, lbl_803DF348@l +/* 800B5464 000B23C4 38 05 F3 48 */ addi r0, r5, __vt__21CScriptCameraWaypoint@l /* 800B5468 000B23C8 90 1E 00 00 */ stw r0, 0(r30) /* 800B546C 000B23CC 4B FA 02 85 */ bl __dt__6CActorFv /* 800B5470 000B23D0 7F E0 07 35 */ extsh. r0, r31 @@ -316,9 +316,9 @@ lbl_800B5480: /* 800B5564 000B24C4 38 61 00 88 */ addi r3, r1, 0x88 /* 800B5568 000B24C8 38 80 FF FF */ li r4, -1 /* 800B556C 000B24CC 48 06 14 E1 */ bl __dt__10CModelDataFv -/* 800B5570 000B24D0 3C 80 80 3E */ lis r4, lbl_803DF348@ha +/* 800B5570 000B24D0 3C 80 80 3E */ lis r4, __vt__21CScriptCameraWaypoint@ha /* 800B5574 000B24D4 7F E3 FB 78 */ mr r3, r31 -/* 800B5578 000B24D8 38 04 F3 48 */ addi r0, r4, lbl_803DF348@l +/* 800B5578 000B24D8 38 04 F3 48 */ addi r0, r4, __vt__21CScriptCameraWaypoint@l /* 800B557C 000B24DC 90 1F 00 00 */ stw r0, 0(r31) /* 800B5580 000B24E0 D3 FF 00 E8 */ stfs f31, 0xe8(r31) /* 800B5584 000B24E4 93 DF 00 EC */ stw r30, 0xec(r31) diff --git a/configure.py b/configure.py index 69f930c6..4f97c69e 100755 --- a/configure.py +++ b/configure.py @@ -111,7 +111,7 @@ LIBS = [ ["MetroidPrime/ScriptObjects/CScriptPlatform", False], ["MetroidPrime/UserNames", True], "MetroidPrime/ScriptObjects/CScriptGenerator", - "MetroidPrime/ScriptObjects/CScriptCameraWaypoint", + ["MetroidPrime/ScriptObjects/CScriptCameraWaypoint", False], ["MetroidPrime/CGameLight", True], "MetroidPrime/Tweaks/CTweakTargeting", ["MetroidPrime/Tweaks/CTweakAutoMapper", True], diff --git a/include/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.hpp b/include/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.hpp new file mode 100644 index 00000000..4f7ff9f3 --- /dev/null +++ b/include/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.hpp @@ -0,0 +1,24 @@ +#ifndef _CSCRIPTCAMERAWAYPOINT +#define _CSCRIPTCAMERAWAYPOINT + +#include "MetroidPrime/CActor.hpp" + +class CScriptCameraWaypoint : public CActor { + float xe8_hfov; + uint xec_; + +public: + CScriptCameraWaypoint(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, + const CTransform4f& xf, bool active, float hfov, uint); + ~CScriptCameraWaypoint(); + + void Accept(IVisitor& visitor) override; + void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) override; + void AddToRenderer(const CFrustumPlanes&, const CStateManager&) override const; + void Render(const CStateManager&) override const; + + TUniqueId GetRandomNextWaypointId(const CStateManager& mgr) const; + float GetHFov() const { return xe8_hfov; } +}; + +#endif // _CSCRIPTCAMERAWAYPOINT diff --git a/src/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.cpp b/src/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.cpp new file mode 100644 index 00000000..2f962281 --- /dev/null +++ b/src/MetroidPrime/ScriptObjects/CScriptCameraWaypoint.cpp @@ -0,0 +1,56 @@ +#include "MetroidPrime/ScriptObjects/CScriptCameraWaypoint.hpp" + +#include "MetroidPrime/CActorParameters.hpp" + +CScriptCameraWaypoint::CScriptCameraWaypoint(TUniqueId uid, const rstl::string& name, + const CEntityInfo& info, const CTransform4f& xf, + bool active, float hfov, uint w1) +: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(kMT_NoStepLogic), + CActorParameters::None(), kInvalidUniqueId) +, xe8_hfov(hfov) +, xec_(w1) {} + +CScriptCameraWaypoint::~CScriptCameraWaypoint() {} + +void CScriptCameraWaypoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, + CStateManager& mgr) { + CActor::AcceptScriptMsg(msg, uid, mgr); + if (GetActive()) { + switch (msg) { + case kSM_Arrived: + SendScriptMsgs(kSS_Arrived, mgr, kSM_None); + break; + default: + break; + } + } +} + +TUniqueId CScriptCameraWaypoint::GetRandomNextWaypointId(const CStateManager& mgr) const { + rstl::vector< TUniqueId > candidateIds; + + rstl::vector< SConnection >::const_iterator conn = x20_conns.begin(); + + for (; conn != x20_conns.end(); ++conn) { + if (conn->x0_state == kSS_Arrived && conn->x4_msg == kSM_Next) { + TUniqueId uid = mgr.GetIdForScript(conn->x8_objId); + if (uid == kInvalidUniqueId) + continue; + + candidateIds.reserve(candidateIds.size() + 1); + candidateIds.push_back(uid); + } + } + + if (candidateIds.empty()) + return kInvalidUniqueId; + + return candidateIds[mgr.GetActiveRandom()->Range(0, s32(candidateIds.size() - 1))]; +} + +void CScriptCameraWaypoint::AddToRenderer(const CFrustumPlanes&, + const CStateManager&) override const {} + +void CScriptCameraWaypoint::Render(const CStateManager&) override const {} + +void CScriptCameraWaypoint::Accept(IVisitor& visitor) { visitor.Visit(*this); }