From c5e1c9faf7a8b45e33b0706be32580a6c4887691 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Thu, 5 Jan 2023 17:19:20 +0200 Subject: [PATCH] Improve CScriptActorRotate Former-commit-id: f2fa19ab38de72e48db2082c8f8ea242cba75e77 --- .../ScriptObjects/CScriptActorRotate.s | 12 +++---- .../ScriptObjects/CScriptActorRotate.cpp | 34 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/asm/MetroidPrime/ScriptObjects/CScriptActorRotate.s b/asm/MetroidPrime/ScriptObjects/CScriptActorRotate.s index 89c1fbc1..2b56b30f 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptActorRotate.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptActorRotate.s @@ -218,7 +218,7 @@ lbl_80153CB4: /* 80153CDC 00150C3C 90 A1 00 30 */ stw r5, 0x30(r1) /* 80153CE0 00150C40 90 01 00 34 */ stw r0, 0x34(r1) /* 80153CE4 00150C44 83 77 00 4C */ lwz r27, 0x4c(r23) -/* 80153CE8 00150C48 48 00 08 B9 */ bl "distance,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl195red_black_tree<13TGameScriptId,Q24rstl32pair<13TGameScriptId,9TUniqueId>,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl195red_black_tree<13TGameScriptId,Q24rstl32" +/* 80153CE8 00150C48 48 00 08 B9 */ bl "distance,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iterator" /* 80153CEC 00150C4C 7C 60 1B 78 */ mr r0, r3 /* 80153CF0 00150C50 38 77 00 48 */ addi r3, r23, 0x48 /* 80153CF4 00150C54 7C 9B 02 14 */ add r4, r27, r0 @@ -825,8 +825,8 @@ lbl_80154480: /* 80154598 001514F8 38 21 00 30 */ addi r1, r1, 0x30 /* 8015459C 001514FC 4E 80 00 20 */ blr -.global "distance,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl195red_black_tree<13TGameScriptId,Q24rstl32pair<13TGameScriptId,9TUniqueId>,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl195red_black_tree<13TGameScriptId,Q24rstl32" -"distance,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl195red_black_tree<13TGameScriptId,Q24rstl32pair<13TGameScriptId,9TUniqueId>,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl195red_black_tree<13TGameScriptId,Q24rstl32": +.global "distance,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iterator" +"distance,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iterator": /* 801545A0 00151500 94 21 FF E0 */ stwu r1, -0x20(r1) /* 801545A4 00151504 7C 08 02 A6 */ mflr r0 /* 801545A8 00151508 90 01 00 24 */ stw r0, 0x24(r1) @@ -843,14 +843,14 @@ lbl_80154480: /* 801545D4 00151534 90 E1 00 14 */ stw r7, 0x14(r1) /* 801545D8 00151538 90 C1 00 18 */ stw r6, 0x18(r1) /* 801545DC 0015153C 90 01 00 1C */ stw r0, 0x1c(r1) -/* 801545E0 00151540 48 00 00 15 */ bl "__distance,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl195red_black_tree<13TGameScriptId,Q24rstl32pair<13TGameScriptId,9TUniqueId>,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl195red_black_tree<13TGameScriptId,Q24rstl" +/* 801545E0 00151540 48 00 00 15 */ bl "__distance,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iteratorQ24rstl20forward_iterator_tag" /* 801545E4 00151544 80 01 00 24 */ lwz r0, 0x24(r1) /* 801545E8 00151548 7C 08 03 A6 */ mtlr r0 /* 801545EC 0015154C 38 21 00 20 */ addi r1, r1, 0x20 /* 801545F0 00151550 4E 80 00 20 */ blr -.global "__distance,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl195red_black_tree<13TGameScriptId,Q24rstl32pair<13TGameScriptId,9TUniqueId>,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl195red_black_tree<13TGameScriptId,Q24rstl" -"__distance,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl195red_black_tree<13TGameScriptId,Q24rstl32pair<13TGameScriptId,9TUniqueId>,1,Q24rstl52select1st>,Q24rstl21less<13TGameScriptId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl195red_black_tree<13TGameScriptId,Q24rstl": +.global "__distance,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iteratorQ24rstl20forward_iterator_tag" +"__distance,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iterator>__4rstlFQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iteratorQ34rstl175red_black_tree<9TEditorId,Q24rstl27pair<9TEditorId,9TUniqueId>,0,Q24rstl47select1st>,Q24rstl16less<9TEditorId>,Q24rstl17rmemory_allocator>14const_iteratorQ24rstl20forward_iterator_tag": /* 801545F4 00151554 94 21 FF E0 */ stwu r1, -0x20(r1) /* 801545F8 00151558 7C 08 02 A6 */ mflr r0 /* 801545FC 0015155C 90 01 00 24 */ stw r0, 0x24(r1) diff --git a/src/MetroidPrime/ScriptObjects/CScriptActorRotate.cpp b/src/MetroidPrime/ScriptObjects/CScriptActorRotate.cpp index f748ec27..d5c0d4bb 100644 --- a/src/MetroidPrime/ScriptObjects/CScriptActorRotate.cpp +++ b/src/MetroidPrime/ScriptObjects/CScriptActorRotate.cpp @@ -29,13 +29,13 @@ void CScriptActorRotate::UpdatePlatformRiders(rstl::vector< SRiders >& riders, 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(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()); - + CTransform4f riderXf(act->GetTransform()); + riderXf.SetTranslation(act->GetTranslation() - plat.GetTranslation()); + rider->x8_transform = riderXf; if (TCastToConstPtr< CScriptSpiderBallWaypoint >(act)) { x58_25_updateSpiderBallWaypoints = true; } @@ -129,16 +129,14 @@ void CScriptActorRotate::UpdateActors(bool next, CStateManager& mgr) { } 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 (!(search.first == search.second)) { + x48_actors.reserve(x48_actors.size() + rstl::distance(search.first, search.second)); + for (CStateManager::TIdList::const_iterator it = search.first; it != search.second; ++it) { + if (const CActor* act = TCastToConstPtr< CActor >(mgr.ObjectById(it->second))) { + x48_actors.push_back( + rstl::pair< TUniqueId, CTransform4f >(it->second, act->GetTransform().GetRotation())); } } - if (const CActor* act = TCastToConstPtr< CActor >(mgr.ObjectById(it->second))) { - x48_actors.push_back( - rstl::pair< TUniqueId, CTransform4f >(it->second, act->GetTransform().GetRotation())); - } } } @@ -156,10 +154,11 @@ void CScriptActorRotate::UpdateActors(bool next, CStateManager& mgr) { void CScriptActorRotate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { + bool didAccept = false; switch (msg) { case kSM_Activate: CEntity::AcceptScriptMsg(msg, uid, mgr); - break; + didAccept = true; case kSM_Registered: if (!x58_27_updateOnCreation) { @@ -167,11 +166,14 @@ void CScriptActorRotate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid } case kSM_Action: case kSM_Next: - UpdateActors(msg == kSM_Next, mgr); - - CEntity::AcceptScriptMsg(msg, uid, mgr); + if (GetActive()) { + UpdateActors(msg == kSM_Next, mgr); + } break; } + if (!didAccept) { + CEntity::AcceptScriptMsg(msg, uid, mgr); + } } void CScriptActorRotate::Accept(IVisitor& visitor) { visitor.Visit(*this); }