Add CScriptActorRotate

This commit is contained in:
Henrique Gemignani Passos Lima 2022-12-23 22:50:36 -03:00
parent f7623bd219
commit 521b2d5413
6 changed files with 250 additions and 15 deletions

View File

@ -3,8 +3,8 @@
.section .data .section .data
.balign 8 .balign 8
.global lbl_803E2D08 .global __vt__18CScriptActorRotate
lbl_803E2D08: __vt__18CScriptActorRotate:
# ROM: 0x3DFD08 # ROM: 0x3DFD08
.4byte 0 .4byte 0
.4byte 0 .4byte 0
@ -28,9 +28,9 @@ __dt__18CScriptActorRotateFv:
/* 80153A40 001509A0 93 C1 00 18 */ stw r30, 0x18(r1) /* 80153A40 001509A0 93 C1 00 18 */ stw r30, 0x18(r1)
/* 80153A44 001509A4 7C 7E 1B 79 */ or. r30, r3, r3 /* 80153A44 001509A4 7C 7E 1B 79 */ or. r30, r3, r3
/* 80153A48 001509A8 41 82 00 74 */ beq lbl_80153ABC /* 80153A48 001509A8 41 82 00 74 */ beq lbl_80153ABC
/* 80153A4C 001509AC 3C 60 80 3E */ lis r3, lbl_803E2D08@ha /* 80153A4C 001509AC 3C 60 80 3E */ lis r3, __vt__18CScriptActorRotate@ha
/* 80153A50 001509B0 34 1E 00 48 */ addic. r0, r30, 0x48 /* 80153A50 001509B0 34 1E 00 48 */ addic. r0, r30, 0x48
/* 80153A54 001509B4 38 03 2D 08 */ addi r0, r3, lbl_803E2D08@l /* 80153A54 001509B4 38 03 2D 08 */ addi r0, r3, __vt__18CScriptActorRotate@l
/* 80153A58 001509B8 90 1E 00 00 */ stw r0, 0(r30) /* 80153A58 001509B8 90 1E 00 00 */ stw r0, 0(r30)
/* 80153A5C 001509BC 41 82 00 44 */ beq lbl_80153AA0 /* 80153A5C 001509BC 41 82 00 44 */ beq lbl_80153AA0
/* 80153A60 001509C0 80 1E 00 4C */ lwz r0, 0x4c(r30) /* 80153A60 001509C0 80 1E 00 4C */ lwz r0, 0x4c(r30)
@ -458,7 +458,7 @@ lbl_80153EF8:
/* 80154054 00150FB4 7F C3 F3 78 */ mr r3, r30 /* 80154054 00150FB4 7F C3 F3 78 */ mr r3, r30
/* 80154058 00150FB8 7F E6 FB 78 */ mr r6, r31 /* 80154058 00150FB8 7F E6 FB 78 */ mr r6, r31
/* 8015405C 00150FBC 38 A1 01 7C */ addi r5, r1, 0x17c /* 8015405C 00150FBC 38 A1 01 7C */ addi r5, r1, 0x17c
/* 80154060 00150FC0 48 00 01 D1 */ bl sub_80154230 /* 80154060 00150FC0 48 00 01 D1 */ bl UpdatePlatformRiders__18CScriptActorRotateFR15CScriptPlatformRC12CTransform4fR13CStateManager
lbl_80154064: lbl_80154064:
/* 80154064 00150FC4 3B BD 00 34 */ addi r29, r29, 0x34 /* 80154064 00150FC4 3B BD 00 34 */ addi r29, r29, 0x34
lbl_80154068: lbl_80154068:
@ -592,8 +592,8 @@ lbl_80154214:
/* 80154228 00151188 38 21 08 30 */ addi r1, r1, 0x830 /* 80154228 00151188 38 21 08 30 */ addi r1, r1, 0x830
/* 8015422C 0015118C 4E 80 00 20 */ blr /* 8015422C 0015118C 4E 80 00 20 */ blr
.global sub_80154230 .global UpdatePlatformRiders__18CScriptActorRotateFR15CScriptPlatformRC12CTransform4fR13CStateManager
sub_80154230: UpdatePlatformRiders__18CScriptActorRotateFR15CScriptPlatformRC12CTransform4fR13CStateManager:
/* 80154230 00151190 94 21 FF E0 */ stwu r1, -0x20(r1) /* 80154230 00151190 94 21 FF E0 */ stwu r1, -0x20(r1)
/* 80154234 00151194 7C 08 02 A6 */ mflr r0 /* 80154234 00151194 7C 08 02 A6 */ mflr r0
/* 80154238 00151198 90 01 00 24 */ stw r0, 0x24(r1) /* 80154238 00151198 90 01 00 24 */ stw r0, 0x24(r1)
@ -609,13 +609,13 @@ sub_80154230:
/* 80154260 001511C0 93 81 00 10 */ stw r28, 0x10(r1) /* 80154260 001511C0 93 81 00 10 */ stw r28, 0x10(r1)
/* 80154264 001511C4 7C 7C 1B 78 */ mr r28, r3 /* 80154264 001511C4 7C 7C 1B 78 */ mr r28, r3
/* 80154268 001511C8 38 9D 03 28 */ addi r4, r29, 0x328 /* 80154268 001511C8 38 9D 03 28 */ addi r4, r29, 0x328
/* 8015426C 001511CC 48 00 00 3D */ bl sub_801542a8 /* 8015426C 001511CC 48 00 00 3D */ bl "UpdatePlatformRiders__18CScriptActorRotateFRQ24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>R15CScriptPlatformRC12CTransform4fR13CStateManager"
/* 80154270 001511D0 7F 83 E3 78 */ mr r3, r28 /* 80154270 001511D0 7F 83 E3 78 */ mr r3, r28
/* 80154274 001511D4 7F A5 EB 78 */ mr r5, r29 /* 80154274 001511D4 7F A5 EB 78 */ mr r5, r29
/* 80154278 001511D8 7F C6 F3 78 */ mr r6, r30 /* 80154278 001511D8 7F C6 F3 78 */ mr r6, r30
/* 8015427C 001511DC 7F E7 FB 78 */ mr r7, r31 /* 8015427C 001511DC 7F E7 FB 78 */ mr r7, r31
/* 80154280 001511E0 38 9D 03 38 */ addi r4, r29, 0x338 /* 80154280 001511E0 38 9D 03 38 */ addi r4, r29, 0x338
/* 80154284 001511E4 48 00 00 25 */ bl sub_801542a8 /* 80154284 001511E4 48 00 00 25 */ bl "UpdatePlatformRiders__18CScriptActorRotateFRQ24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>R15CScriptPlatformRC12CTransform4fR13CStateManager"
/* 80154288 001511E8 80 01 00 24 */ lwz r0, 0x24(r1) /* 80154288 001511E8 80 01 00 24 */ lwz r0, 0x24(r1)
/* 8015428C 001511EC 83 E1 00 1C */ lwz r31, 0x1c(r1) /* 8015428C 001511EC 83 E1 00 1C */ lwz r31, 0x1c(r1)
/* 80154290 001511F0 83 C1 00 18 */ lwz r30, 0x18(r1) /* 80154290 001511F0 83 C1 00 18 */ lwz r30, 0x18(r1)
@ -625,8 +625,8 @@ sub_80154230:
/* 801542A0 00151200 38 21 00 20 */ addi r1, r1, 0x20 /* 801542A0 00151200 38 21 00 20 */ addi r1, r1, 0x20
/* 801542A4 00151204 4E 80 00 20 */ blr /* 801542A4 00151204 4E 80 00 20 */ blr
.global sub_801542a8 .global "UpdatePlatformRiders__18CScriptActorRotateFRQ24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>R15CScriptPlatformRC12CTransform4fR13CStateManager"
sub_801542a8: "UpdatePlatformRiders__18CScriptActorRotateFRQ24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>R15CScriptPlatformRC12CTransform4fR13CStateManager":
/* 801542A8 00151208 94 21 FF 40 */ stwu r1, -0xc0(r1) /* 801542A8 00151208 94 21 FF 40 */ stwu r1, -0xc0(r1)
/* 801542AC 0015120C 7C 08 02 A6 */ mflr r0 /* 801542AC 0015120C 7C 08 02 A6 */ mflr r0
/* 801542B0 00151210 90 01 00 C4 */ stw r0, 0xc4(r1) /* 801542B0 00151210 90 01 00 C4 */ stw r0, 0xc4(r1)
@ -745,7 +745,7 @@ lbl_80154440:
/* 8015446C 001513CC 7F 03 C3 78 */ mr r3, r24 /* 8015446C 001513CC 7F 03 C3 78 */ mr r3, r24
/* 80154470 001513D0 7F 65 DB 78 */ mr r5, r27 /* 80154470 001513D0 7F 65 DB 78 */ mr r5, r27
/* 80154474 001513D4 7F 86 E3 78 */ mr r6, r28 /* 80154474 001513D4 7F 86 E3 78 */ mr r6, r28
/* 80154478 001513D8 4B FF FD B9 */ bl sub_80154230 /* 80154478 001513D8 4B FF FD B9 */ bl UpdatePlatformRiders__18CScriptActorRotateFR15CScriptPlatformRC12CTransform4fR13CStateManager
lbl_8015447C: lbl_8015447C:
/* 8015447C 001513DC 3B FF 00 38 */ addi r31, r31, 0x38 /* 8015447C 001513DC 3B FF 00 38 */ addi r31, r31, 0x38
lbl_80154480: lbl_80154480:
@ -785,9 +785,9 @@ lbl_80154480:
/* 801544F8 00151458 7D 46 53 78 */ mr r6, r10 /* 801544F8 00151458 7D 46 53 78 */ mr r6, r10
/* 801544FC 0015145C 38 81 00 08 */ addi r4, r1, 8 /* 801544FC 0015145C 38 81 00 08 */ addi r4, r1, 8
/* 80154500 00151460 4B EF CE 25 */ bl "__ct__7CEntityF9TUniqueIdRC11CEntityInfobRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>" /* 80154500 00151460 4B EF CE 25 */ bl "__ct__7CEntityF9TUniqueIdRC11CEntityInfobRCQ24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>"
/* 80154504 00151464 3C 60 80 3E */ lis r3, lbl_803E2D08@ha /* 80154504 00151464 3C 60 80 3E */ lis r3, __vt__18CScriptActorRotate@ha
/* 80154508 00151468 C0 02 9D F8 */ lfs f0, lbl_805ABB18@sda21(r2) /* 80154508 00151468 C0 02 9D F8 */ lfs f0, lbl_805ABB18@sda21(r2)
/* 8015450C 0015146C 38 03 2D 08 */ addi r0, r3, lbl_803E2D08@l /* 8015450C 0015146C 38 03 2D 08 */ addi r0, r3, __vt__18CScriptActorRotate@l
/* 80154510 00151470 38 C0 00 00 */ li r6, 0 /* 80154510 00151470 38 C0 00 00 */ li r6, 0
/* 80154514 00151474 90 1C 00 00 */ stw r0, 0(r28) /* 80154514 00151474 90 1C 00 00 */ stw r0, 0(r28)
/* 80154518 00151478 7F 83 E3 78 */ mr r3, r28 /* 80154518 00151478 7F 83 E3 78 */ mr r3, r28

View File

@ -196,7 +196,7 @@ LIBS = [
["MetroidPrime/Enemies/CMetaree", False], ["MetroidPrime/Enemies/CMetaree", False],
["MetroidPrime/ScriptObjects/CScriptDockAreaChange", False], ["MetroidPrime/ScriptObjects/CScriptDockAreaChange", False],
["MetroidPrime/ScriptObjects/CScriptSpecialFunction", False], ["MetroidPrime/ScriptObjects/CScriptSpecialFunction", False],
"MetroidPrime/ScriptObjects/CScriptActorRotate", ["MetroidPrime/ScriptObjects/CScriptActorRotate", False],
["MetroidPrime/Player/CFidget", True], ["MetroidPrime/Player/CFidget", True],
"MetroidPrime/Enemies/CSpankWeed", "MetroidPrime/Enemies/CSpankWeed",
"MetroidPrime/Enemies/CParasite", "MetroidPrime/Enemies/CParasite",

View File

@ -0,0 +1,40 @@
#ifndef _CSCRIPTACTORROTATE
#define _CSCRIPTACTORROTATE
#include "MetroidPrime/CEntity.hpp"
#include "rstl/map.hpp"
struct SRiders;
class CScriptPlatform;
class CScriptActorRotate : public CEntity {
public:
CScriptActorRotate(TUniqueId, const rstl::string&, const CEntityInfo&, const CVector3f&, float,
bool, bool, bool);
~CScriptActorRotate();
void Accept(IVisitor& visitor) override;
void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) override;
void Think(float, CStateManager&) override;
private:
CVector3f x34_rotation;
float x40_maxTime;
float x44_currentTime; // = 0.f;
// rstl::map< TUniqueId, CTransform4f > x48_actors;
rstl::vector< rstl::pair<TUniqueId, CTransform4f> > x48_actors;
bool x58_24_updateRotation : 1; // = false;
bool x58_25_updateSpiderBallWaypoints : 1; // = false;
bool x58_26_updateActors : 1;
bool x58_27_updateOnCreation : 1;
void UpdateActors(bool, CStateManager&);
void RebuildSpiderBallWaypoints(CStateManager&);
void UpdatePlatformRiders(CScriptPlatform&, const CTransform4f&, CStateManager&);
void UpdatePlatformRiders(rstl::vector< SRiders >&, CScriptPlatform&, const CTransform4f&,
CStateManager&);
};
#endif // _CSCRIPTACTORROTATE

View File

@ -75,6 +75,9 @@ public:
bool IsSlave(TUniqueId id) const; bool IsSlave(TUniqueId id) const;
void BuildSlaveList(CStateManager& mgr); void BuildSlaveList(CStateManager& mgr);
rstl::vector< SRiders >& GetStaticSlaves() { return x328_slavesStatic; }
rstl::vector< SRiders >& GetDynamicSlaves() { return x338_slavesDynamic; }
void SetControlledAnimation(bool controlled) { x356_25_controlledAnimation = controlled; } void SetControlledAnimation(bool controlled) { x356_25_controlledAnimation = controlled; }
static void AddRider(rstl::vector< SRiders >& riders, TUniqueId riderId, static void AddRider(rstl::vector< SRiders >& riders, TUniqueId riderId,

View File

@ -0,0 +1,19 @@
#ifndef _CSCRIPTSPIDERBALLWAYPOINT
#define _CSCRIPTSPIDERBALLWAYPOINT
#include "MetroidPrime/CActor.hpp"
class CScriptSpiderBallWaypoint : public CActor {
public:
void ClearWaypoints();
void BuildWaypointListAndBounds(CStateManager& mgr);
private:
enum ECheckActiveWaypoint { kCAW_Check, kCAW_SkipCheck };
uint xe8_;
rstl::vector< TUniqueId > xec_waypoints;
rstl::optional_object< CAABox > xfc_aabox;
};
#endif // _CSCRIPTSPIDERBALLWAYPOINT

View File

@ -0,0 +1,173 @@
#include "MetroidPrime/ScriptObjects/CScriptActorRotate.hpp"
#include "MetroidPrime/CStateManager.hpp"
#include "MetroidPrime/ScriptObjects/CScriptPlatform.hpp"
#include "MetroidPrime/ScriptObjects/CScriptSpiderBallWaypoint.hpp"
#include "Kyoto/Math/CMath.hpp"
#include "Kyoto/Math/CRelAngle.hpp"
#include "Kyoto/Math/CTransform4f.hpp"
#include "rstl/algorithm.hpp"
CScriptActorRotate::CScriptActorRotate(TUniqueId uid, const rstl::string& name,
const CEntityInfo& info, const CVector3f& rotation,
float maxTime, bool updateActors, bool updateOnCreation,
bool active)
: CEntity(uid, info, active, name)
, x34_rotation(rotation)
, x40_maxTime(maxTime)
, x44_currentTime(0.f)
, x58_26_updateActors(updateActors)
, x58_27_updateOnCreation(updateOnCreation)
, x58_24_updateRotation(false)
, x58_25_updateSpiderBallWaypoints(false) {}
void CScriptActorRotate::UpdatePlatformRiders(rstl::vector< SRiders >& riders,
CScriptPlatform& plat, const CTransform4f& xf,
CStateManager& mgr) {
for (rstl::vector< SRiders >::iterator rider = riders.begin(); rider != riders.end(); ++rider) {
if (CActor* act = TCastToPtr< CActor >(mgr.ObjectById(rider->x0_uid))) {
CTransform4f& riderXf = rider->x8_transform;
act->SetTransform(xf * rider->x8_transform);
act->SetTranslation(act->GetTranslation() + plat.GetTranslation());
if (!x58_24_updateRotation) {
riderXf = CTransform4f(act->GetTransform().BuildMatrix3f(),
act->GetTranslation() - plat.GetTranslation());
if (TCastToConstPtr< CScriptSpiderBallWaypoint >(act)) {
x58_25_updateSpiderBallWaypoints = true;
}
}
if (CScriptPlatform* plat2 = TCastToPtr< CScriptPlatform >(mgr.ObjectById(rider->x0_uid))) {
UpdatePlatformRiders(*plat2, xf, mgr);
}
}
}
}
void CScriptActorRotate::UpdatePlatformRiders(CScriptPlatform& plat, const CTransform4f& xf,
CStateManager& mgr) {
UpdatePlatformRiders(plat.GetStaticSlaves(), plat, xf, mgr);
UpdatePlatformRiders(plat.GetDynamicSlaves(), plat, xf, mgr);
}
void CScriptActorRotate::RebuildSpiderBallWaypoints(CStateManager& mgr) {
TEntityList waypointIds;
CObjectList& objectList = mgr.ObjectListById(kOL_All);
for (int i = 0; i != waypointIds.capacity(); ++i) {
if (CScriptSpiderBallWaypoint* wp = TCastToPtr< CScriptSpiderBallWaypoint >(objectList[i])) {
waypointIds.push_back(wp->GetUniqueId());
wp->ClearWaypoints();
}
}
for (TEntityList::iterator it = waypointIds.begin(); it != waypointIds.end(); ++it) {
CScriptSpiderBallWaypoint* wp = static_cast< CScriptSpiderBallWaypoint* >(mgr.ObjectById(*it));
if (wp) {
wp->BuildWaypointListAndBounds(mgr);
wp->SetTransformDirty(false);
}
}
x58_25_updateSpiderBallWaypoints = false;
}
void CScriptActorRotate::Think(float dt, CStateManager& mgr) {
if (x58_24_updateRotation && GetActive()) {
x44_currentTime += dt;
if (x44_currentTime >= x40_maxTime) {
x58_24_updateRotation = false;
x44_currentTime = x40_maxTime;
}
const float timeOffset = x44_currentTime / x40_maxTime;
rstl::vector< rstl::pair< TUniqueId, CTransform4f > >::const_iterator it = x48_actors.begin();
for (; it != x48_actors.end(); ++it) {
if (CActor* act = TCastToPtr< CActor >(mgr.ObjectById(it->first))) {
const CTransform4f xf =
CTransform4f::RotateX(CRelAngle::FromDegrees(timeOffset * x34_rotation.GetX())) *
CTransform4f::RotateY(CRelAngle::FromDegrees(timeOffset * x34_rotation.GetY())) *
CTransform4f::RotateZ(CRelAngle::FromDegrees(timeOffset * x34_rotation.GetZ()));
CTransform4f localRot = it->second * xf;
localRot.SetTranslation(localRot.GetTranslation() + act->GetTranslation());
act->SetTransform(localRot);
if (CScriptPlatform* plat = TCastToPtr< CScriptPlatform >(mgr.ObjectById(it->first))) {
UpdatePlatformRiders(*plat, xf, mgr);
}
}
}
if (!x58_24_updateRotation) {
if (x58_25_updateSpiderBallWaypoints) {
RebuildSpiderBallWaypoints(mgr);
}
if (x58_26_updateActors) {
UpdateActors(false, mgr);
}
}
}
}
void CScriptActorRotate::UpdateActors(bool next, CStateManager& mgr) {
if (x58_24_updateRotation) {
return;
}
x48_actors.clear();
rstl::vector< SConnection >::const_iterator conn = GetConnectionList().begin();
for (; conn != GetConnectionList().end(); ++conn) {
if (conn->x0_state != kSS_Play || conn->x4_msg != kSM_Play) {
continue;
}
CStateManager::TIdListResult search = mgr.GetIdListForScript(conn->x8_objId);
for (CStateManager::TIdList::const_iterator it = search.first; it != search.second; ++it) {
// TODO is this for loop real?
for (int i = 0; i < x48_actors.size(); ++i) {
if (x48_actors[i].first == it->second) {
}
}
if (const CActor* act = TCastToConstPtr< CActor >(mgr.ObjectById(it->second))) {
x48_actors.push_back(
rstl::pair< TUniqueId, CTransform4f >(it->second, act->GetTransform().GetRotation()));
}
}
}
SendScriptMsgs(kSS_Play, mgr, kSM_None);
if (!x48_actors.empty()) {
x58_24_updateRotation = true;
x44_currentTime = (next ? x40_maxTime : 0.f);
}
}
void CScriptActorRotate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid,
CStateManager& mgr) {
switch (msg) {
case kSM_Activate:
CEntity::AcceptScriptMsg(msg, uid, mgr);
break;
case kSM_Registered:
if (!x58_27_updateOnCreation) {
break;
}
case kSM_Action:
case kSM_Next:
UpdateActors(msg == kSM_Next, mgr);
CEntity::AcceptScriptMsg(msg, uid, mgr);
break;
}
}
void CScriptActorRotate::Accept(IVisitor& visitor) { visitor.Visit(*this); }
CScriptActorRotate::~CScriptActorRotate() {}