From 0a366855bc7015a092f1d5eab612b5d344048d7e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 29 Mar 2020 21:16:48 -0400 Subject: [PATCH] CSortedLists: Add names to all function prototypes More self-documenting and allows parameter inspection in IDEs to function nicer. --- Runtime/CSortedLists.cpp | 46 +++++++++++++++++++++------------------- Runtime/CSortedLists.hpp | 36 +++++++++++++++---------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/Runtime/CSortedLists.cpp b/Runtime/CSortedLists.cpp index 0f4954256..87439ec28 100644 --- a/Runtime/CSortedLists.cpp +++ b/Runtime/CSortedLists.cpp @@ -116,19 +116,19 @@ void CSortedListManager::InsertInList(ESortedList list, SNode& node) { ++sl.x800_size; } -s16 CSortedListManager::FindInListUpper(ESortedList list, float val) const { +s16 CSortedListManager::FindInListUpper(ESortedList list, float value) const { const auto listIndex = static_cast(list); const SSortedList& sl = xb000_sortedLists[listIndex]; int idx = 0; for (int i = sl.x800_size; i > 0;) { - /* Binary search cycle to find index */ - if (!(val < AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + i / 2)).x4_box[listIndex])) { - /* Upper */ + // Binary search cycle to find index + if (!(value < AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + i / 2)).x4_box[listIndex])) { + // Upper idx = idx + i / 2 + 1; i = i - i / 2 - 1; } else { - /* Lower */ + // Lower i /= 2; } } @@ -136,19 +136,19 @@ s16 CSortedListManager::FindInListUpper(ESortedList list, float val) const { return idx; } -s16 CSortedListManager::FindInListLower(ESortedList list, float val) const { +s16 CSortedListManager::FindInListLower(ESortedList list, float value) const { const auto listIndex = static_cast(list); const SSortedList& sl = xb000_sortedLists[listIndex]; int idx = 0; for (int i = sl.x800_size; i > 0;) { - /* Binary search cycle to find index */ - if (AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + i / 2)).x4_box[listIndex] < val) { - /* Upper */ + // Binary search cycle to find index + if (AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + i / 2)).x4_box[listIndex] < value) { + // Upper idx = idx + i / 2 + 1; i = i - i / 2 - 1; } else { - /* Lower */ + // Lower i /= 2; } } @@ -273,10 +273,11 @@ void CSortedListManager::BuildNearList(rstl::reserved_vector& o } } -void CSortedListManager::Remove(const CActor* act) { - SNode& node = AccessElement(x0_nodes, act->GetUniqueId().Value()); - if (!node.x2a_populated) +void CSortedListManager::Remove(const CActor* actor) { + SNode& node = AccessElement(x0_nodes, actor->GetUniqueId().Value()); + if (!node.x2a_populated) { return; + } RemoveFromList(ESortedList::MinX, node.x1c_selfIdxs[0]); RemoveFromList(ESortedList::MaxX, node.x1c_selfIdxs[3]); @@ -287,8 +288,8 @@ void CSortedListManager::Remove(const CActor* act) { node.x2a_populated = false; } -void CSortedListManager::Move(const CActor* act, const zeus::CAABox& aabb) { - SNode& node = AccessElement(x0_nodes, act->GetUniqueId().Value()); +void CSortedListManager::Move(const CActor* actor, const zeus::CAABox& aabb) { + SNode& node = AccessElement(x0_nodes, actor->GetUniqueId().Value()); node.x4_box = aabb; MoveInList(ESortedList::MinX, node.x1c_selfIdxs[0]); @@ -299,14 +300,14 @@ void CSortedListManager::Move(const CActor* act, const zeus::CAABox& aabb) { MoveInList(ESortedList::MaxZ, node.x1c_selfIdxs[5]); } -void CSortedListManager::Insert(const CActor* act, const zeus::CAABox& aabb) { - SNode& node = AccessElement(x0_nodes, act->GetUniqueId().Value()); +void CSortedListManager::Insert(const CActor* actor, const zeus::CAABox& aabb) { + SNode& node = AccessElement(x0_nodes, actor->GetUniqueId().Value()); if (node.x2a_populated) { - Move(act, aabb); + Move(actor, aabb); return; } - SNode newNode(act, aabb); + SNode newNode(actor, aabb); InsertInList(ESortedList::MinX, newNode); InsertInList(ESortedList::MaxX, newNode); InsertInList(ESortedList::MinY, newNode); @@ -316,10 +317,11 @@ void CSortedListManager::Insert(const CActor* act, const zeus::CAABox& aabb) { node = newNode; } -bool CSortedListManager::ActorInLists(const CActor* act) const { - if (!act) +bool CSortedListManager::ActorInLists(const CActor* actor) const { + if (!actor) { return false; - const SNode& node = AccessElement(x0_nodes, act->GetUniqueId().Value()); + } + const SNode& node = AccessElement(x0_nodes, actor->GetUniqueId().Value()); return node.x2a_populated; } diff --git a/Runtime/CSortedLists.hpp b/Runtime/CSortedLists.hpp index 9b14ff706..9307529a0 100644 --- a/Runtime/CSortedLists.hpp +++ b/Runtime/CSortedLists.hpp @@ -31,27 +31,27 @@ class CSortedListManager { std::array x0_nodes; std::array xb000_sortedLists; void Reset(); - void AddToLinkedList(s16 a, s16& b, s16& c); - void RemoveFromList(ESortedList, s16); - void MoveInList(ESortedList, s16); - void InsertInList(ESortedList, SNode& node); - s16 FindInListUpper(ESortedList, float) const; - s16 FindInListLower(ESortedList, float) const; - s16 ConstructIntersectionArray(const zeus::CAABox&); - s16 CalculateIntersections(ESortedList, ESortedList, s16, s16, s16, s16, ESortedList, ESortedList, ESortedList, - ESortedList, const zeus::CAABox&); + void AddToLinkedList(s16 nodeId, s16& headId, s16& tailId); + void RemoveFromList(ESortedList list, s16 idx); + void MoveInList(ESortedList list, s16 idx); + void InsertInList(ESortedList list, SNode& node); + s16 FindInListUpper(ESortedList list, float value) const; + s16 FindInListLower(ESortedList list, float value) const; + s16 ConstructIntersectionArray(const zeus::CAABox& aabb); + s16 CalculateIntersections(ESortedList la, ESortedList lb, s16 a, s16 b, s16 c, s16 d, ESortedList slA, + ESortedList slB, ESortedList slC, ESortedList slD, const zeus::CAABox& aabb); public: CSortedListManager(); - void BuildNearList(rstl::reserved_vector&, const zeus::CVector3f&, const zeus::CVector3f&, float, - const CMaterialFilter&, const CActor*) const; - void BuildNearList(rstl::reserved_vector&, const CActor&, const zeus::CAABox&) const; - void BuildNearList(rstl::reserved_vector&, const zeus::CAABox&, const CMaterialFilter&, - const CActor*) const; - void Remove(const CActor*); - void Move(const CActor* act, const zeus::CAABox& aabb); - void Insert(const CActor* act, const zeus::CAABox& aabb); - bool ActorInLists(const CActor* act) const; + void BuildNearList(rstl::reserved_vector& out, const zeus::CVector3f& pos, + const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter, const CActor* actor) const; + void BuildNearList(rstl::reserved_vector& out, const CActor& actor, const zeus::CAABox& aabb) const; + void BuildNearList(rstl::reserved_vector& out, const zeus::CAABox& aabb, + const CMaterialFilter& filter, const CActor* actor) const; + void Remove(const CActor* actor); + void Move(const CActor* actor, const zeus::CAABox& aabb); + void Insert(const CActor* actor, const zeus::CAABox& aabb); + bool ActorInLists(const CActor* actor) const; }; } // namespace urde