From 01b60994cbf86eed594264257ba830ac3ec77e12 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Mon, 13 Nov 2023 15:41:51 -0800 Subject: [PATCH] Initial CSortedLists matching Former-commit-id: a322c29e91f35ad778af21b670d594dfd868dd9e --- config/GM8E01_00/symbols.txt | 4 +- config/GM8E01_01/symbols.txt | 4 +- include/MetroidPrime/CSortedLists.hpp | 41 +++++++++ src/MetroidPrime/CSortedLists.cpp | 127 ++++++++++++++++++++++++++ 4 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 src/MetroidPrime/CSortedLists.cpp diff --git a/config/GM8E01_00/symbols.txt b/config/GM8E01_00/symbols.txt index 41a61a01..67fc8c44 100644 --- a/config/GM8E01_00/symbols.txt +++ b/config/GM8E01_00/symbols.txt @@ -7391,7 +7391,7 @@ FindInListLower__Q22SL18CSortedListManagerCFQ22SL12ESortedListsf = .text:0x8014A ActorInLists__Q22SL18CSortedListManagerCFPC6CActor = .text:0x8014A4EC; // type:function size:0x34 scope:global Reset__Q22SL18CSortedListManagerFv = .text:0x8014A520; // type:function size:0x508 scope:global __ct__Q22SL18CSortedListManagerFv = .text:0x8014AA28; // type:function size:0x6C scope:global -__ct__Q22SL11SSortedListFv = .text:0x8014AA94; // type:function size:0xA4 scope:global +__ct__Q22SL11SSortedListFv = .text:0x8014AA94; // type:function size:0xA4 scope:weak __ct__Q22SL5SNodeFP6CActorRC6CAABox = .text:0x8014AB38; // type:function size:0x60 scope:global __ct__Q22SL5SNodeFv = .text:0x8014AB98; // type:function size:0x4C scope:global __dt__26CScriptDebugCameraWaypointFv = .text:0x8014ABE4; // type:function size:0x60 scope:global @@ -10404,7 +10404,7 @@ OnSliderChanged__14COptionsScreenFP15CGuiSliderGroupf = .text:0x8024309C; // typ UpdateOptionView__14COptionsScreenFv = .text:0x80243100; // type:function size:0x248 scope:global ResetOptionWidgetVisibility__14COptionsScreenFv = .text:0x80243348; // type:function size:0x74 scope:global RightTableSelectionChanged__14COptionsScreenFii = .text:0x802433BC; // type:function size:0x20 scope:global -ChangedMode__14COptionsScreenQ216CPauseScreenBase5EMode = .text:0x802433DC; // type:function size:0x6C scope:global +ChangedMode__14COptionsScreenFQ216CPauseScreenBase5EMode = .text:0x802433DC; // type:function size:0x6C scope:global UpdateRightTable__14COptionsScreenFv = .text:0x80243448; // type:function size:0xDC scope:global GetRightTableCount__14COptionsScreenCFv = .text:0x80243524; // type:function size:0x1C scope:global ShouldLeftTableAdvance__14COptionsScreenFv = .text:0x80243540; // type:function size:0x1C scope:global diff --git a/config/GM8E01_01/symbols.txt b/config/GM8E01_01/symbols.txt index ac925a66..0793702f 100644 --- a/config/GM8E01_01/symbols.txt +++ b/config/GM8E01_01/symbols.txt @@ -7394,7 +7394,7 @@ FindInListLower__Q22SL18CSortedListManagerCFQ22SL12ESortedListsf = .text:0x8014A ActorInLists__Q22SL18CSortedListManagerCFPC6CActor = .text:0x8014A568; // type:function size:0x34 scope:global Reset__Q22SL18CSortedListManagerFv = .text:0x8014A59C; // type:function size:0x508 scope:global __ct__Q22SL18CSortedListManagerFv = .text:0x8014AAA4; // type:function size:0x6C scope:global -__ct__Q22SL11SSortedListFv = .text:0x8014AB10; // type:function size:0xA4 scope:global +__ct__Q22SL11SSortedListFv = .text:0x8014AB10; // type:function size:0xA4 scope:weak __ct__Q22SL5SNodeFP6CActorRC6CAABox = .text:0x8014ABB4; // type:function size:0x60 scope:global __ct__Q22SL5SNodeFv = .text:0x8014AC14; // type:function size:0x4C scope:global __dt__26CScriptDebugCameraWaypointFv = .text:0x8014AC60; // type:function size:0x60 scope:global @@ -10414,7 +10414,7 @@ OnSliderChanged__14COptionsScreenFP15CGuiSliderGroupf = .text:0x80243118; // typ UpdateOptionView__14COptionsScreenFv = .text:0x8024317C; // type:function size:0x248 scope:global ResetOptionWidgetVisibility__14COptionsScreenFv = .text:0x802433C4; // type:function size:0x74 scope:global RightTableSelectionChanged__14COptionsScreenFii = .text:0x80243438; // type:function size:0x20 scope:global -ChangedMode__14COptionsScreenQ216CPauseScreenBase5EMode = .text:0x80243458; // type:function size:0x6C scope:global +ChangedMode__14COptionsScreenFQ216CPauseScreenBase5EMode = .text:0x80243458; // type:function size:0x6C scope:global UpdateRightTable__14COptionsScreenFv = .text:0x802434C4; // type:function size:0xDC scope:global GetRightTableCount__14COptionsScreenCFv = .text:0x802435A0; // type:function size:0x1C scope:global ShouldLeftTableAdvance__14COptionsScreenFv = .text:0x802435BC; // type:function size:0x1C scope:global diff --git a/include/MetroidPrime/CSortedLists.hpp b/include/MetroidPrime/CSortedLists.hpp index 278c3266..5c3e8298 100644 --- a/include/MetroidPrime/CSortedLists.hpp +++ b/include/MetroidPrime/CSortedLists.hpp @@ -10,24 +10,65 @@ class CActor; namespace SL { +enum ESortedLists { + kSL_MinX, + kSL_MinY, + kSL_MinZ, + kSL_MaxX, + kSL_MaxY, + kSL_MaxZ, +}; + struct SNode { CActor* x0_actor; CAABox x4_box; short x1c_selfIdxs[6]; short x28_next; bool x2a_populated; + + SNode(); + SNode(CActor* actor, const CAABox& box); }; CHECK_SIZEOF(SNode, 0x2c); struct SSortedList { short x0_ids[kMaxObjects]; uint x800_size; + + SSortedList() : x800_size(0) { + for (int i = 0; i < kMaxObjects; ++i) { + x0_ids[i] = -1; + } + } }; CHECK_SIZEOF(SSortedList, 0x804); class CSortedListManager { public: CSortedListManager(); + void Reset(); + bool ActorInLists(const CActor* actor) const; + short FindInListLower(ESortedLists list, f32 value) const; + short FindInListUpper(ESortedLists list, f32 value) const; + void InsertInList(ESortedLists list, SNode& node); + void RemoveFromList(ESortedLists list, short idx); + void MoveInList(ESortedLists list, short idx); + void Insert(CActor* actor, const CAABox& box); + void Remove(const CActor* actor); + void Move(const CActor* actor, const CAABox& box); + void AddToLinkedList(short nodeId, short& headId, short& tailId) const; + short CalculateIntersections(ESortedLists la, ESortedLists lb, short a, short b, short c, short d, + ESortedLists slA, ESortedLists slB, ESortedLists slC, + ESortedLists slD, const CAABox& aabb) const; + short ConstructIntersectionArray(const CAABox& aabb) const; + void BuildNearList(rstl::reserved_vector< TUniqueId, 1024 >& nearListOut, const CAABox& box, + const CMaterialFilter& filter, const CActor* actor) const; + + void BuildNearList(rstl::reserved_vector< TUniqueId, 1024 >& nearListOut, const CActor& actor, + const CAABox& box) const; + void BuildNearList(rstl::reserved_vector< TUniqueId, 1024 >& nearListOut, const CVector3f& pos, + const CVector3f& dir, f32 mag, const CMaterialFilter& filter, + const CActor* actor) const; private: SNode x0_nodes[kMaxObjects]; diff --git a/src/MetroidPrime/CSortedLists.cpp b/src/MetroidPrime/CSortedLists.cpp new file mode 100644 index 00000000..33ae8ae7 --- /dev/null +++ b/src/MetroidPrime/CSortedLists.cpp @@ -0,0 +1,127 @@ +#include +#include + +namespace SL { +SNode::SNode() +: x0_actor(nullptr), x4_box(CAABox::Identity()), x28_next(-1), x2a_populated(false) {} + +SNode::SNode(CActor* actor, const CAABox& box) +: x0_actor(actor), x4_box(box), x28_next(-1), x2a_populated(true) { + for (int i = 0; i < 6; ++i) { + x1c_selfIdxs[i] = -1; + } +} + +CSortedListManager::CSortedListManager() { Reset(); } + +void CSortedListManager::Reset() { + SNode node; + + for (uint i = 0; i < kMaxObjects; ++i) { + x0_nodes[i] = node; + } + + for (int i = 0; i < 6; ++i) { + xb000_sortedLists[i] = SSortedList(); + } +} + +bool CSortedListManager::ActorInLists(const CActor* actor) const { + bool ret = false; + if (actor != nullptr && x0_nodes[actor->GetUniqueId().Value()].x2a_populated) { + ret = true; + } + + return ret; +} + +short CSortedListManager::FindInListLower(ESortedLists list, f32 value) const {} + +short CSortedListManager::FindInListUpper(ESortedLists list, f32 value) const {} + +void CSortedListManager::InsertInList(ESortedLists list, SNode& node) {} + +void CSortedListManager::RemoveFromList(ESortedLists list, short idx) {} + +void CSortedListManager::MoveInList(ESortedLists list, short idx) {} + +void CSortedListManager::Insert(CActor* actor, const CAABox& box) { + if (x0_nodes[actor->GetUniqueId().Value()].x2a_populated) { + Move(actor, box); + return; + } + SNode node(actor, box); + + InsertInList(kSL_MinX, node); + InsertInList(kSL_MaxX, node); + InsertInList(kSL_MinY, node); + InsertInList(kSL_MaxY, node); + InsertInList(kSL_MinZ, node); + InsertInList(kSL_MaxZ, node); + x0_nodes[actor->GetUniqueId().Value()] = node; +} + +void CSortedListManager::Remove(const CActor* actor) { + if (actor == nullptr) { + return; + } + + SNode& node = x0_nodes[actor->GetUniqueId().Value()]; + if (node.x2a_populated) { + RemoveFromList(kSL_MinX, node.x1c_selfIdxs[kSL_MinX]); + RemoveFromList(kSL_MaxX, node.x1c_selfIdxs[kSL_MaxX]); + RemoveFromList(kSL_MinY, node.x1c_selfIdxs[kSL_MinY]); + RemoveFromList(kSL_MaxY, node.x1c_selfIdxs[kSL_MaxY]); + RemoveFromList(kSL_MinZ, node.x1c_selfIdxs[kSL_MinZ]); + RemoveFromList(kSL_MaxZ, node.x1c_selfIdxs[kSL_MaxZ]); + node.x2a_populated = false; + } +} + +void CSortedListManager::Move(const CActor* actor, const CAABox& box) { + SNode& node = x0_nodes[actor->GetUniqueId().Value()]; + node.x4_box = box; + MoveInList(kSL_MinX, node.x1c_selfIdxs[kSL_MinX]); + MoveInList(kSL_MaxX, node.x1c_selfIdxs[kSL_MaxX]); + MoveInList(kSL_MinY, node.x1c_selfIdxs[kSL_MinY]); + MoveInList(kSL_MaxY, node.x1c_selfIdxs[kSL_MaxY]); + MoveInList(kSL_MinZ, node.x1c_selfIdxs[kSL_MinZ]); + MoveInList(kSL_MaxZ, node.x1c_selfIdxs[kSL_MaxZ]); +} + +void CSortedListManager::AddToLinkedList(short nodeId, short& headId, short& tailId) const { + if (headId == -1) { + const_cast(x0_nodes[nodeId]).x28_next = headId; + tailId = nodeId; + headId = nodeId; + return; + } + if (x0_nodes[nodeId].x28_next != -1) { + return; + } + if (nodeId == tailId) { + return; + } + const_cast(x0_nodes[nodeId]).x28_next = headId; + headId = nodeId; +} + +short CSortedListManager::CalculateIntersections(ESortedLists la, ESortedLists lb, short a, short b, + short c, short d, ESortedLists slA, + ESortedLists slB, ESortedLists slC, + ESortedLists slD, const CAABox& aabb) const {} + +short CSortedListManager::ConstructIntersectionArray(const CAABox& aabb) const {} + +void CSortedListManager::BuildNearList(rstl::reserved_vector< TUniqueId, 1024 >& nearListOut, + const CAABox& box, const CMaterialFilter& filter, + const CActor* actor) const {} + +void CSortedListManager::BuildNearList(rstl::reserved_vector< TUniqueId, 1024 >& nearListOut, + const CActor& actor, const CAABox& box) const {} + +void CSortedListManager::BuildNearList(rstl::reserved_vector< TUniqueId, 1024 >& nearListOut, + const CVector3f& pos, const CVector3f& dir, f32 mag, + const CMaterialFilter& filter, const CActor* actor) const {} + +} // namespace SL