From 615e1455b20b1bb552c8fdece3768c6c57fd53a9 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Nov 2023 11:38:08 -0400 Subject: [PATCH] Match MxRegionTopBottom::FUN_100c5280 --- LEGO1/mxlist.h | 52 ++++++++++++++++++++++++++-------------------- LEGO1/mxregion.cpp | 7 +------ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/LEGO1/mxlist.h b/LEGO1/mxlist.h index ed66f9fc..bbe3a41e 100644 --- a/LEGO1/mxlist.h +++ b/LEGO1/mxlist.h @@ -27,9 +27,12 @@ class MxListEntry { } T GetValue() { return this->m_obj; } + MxListEntry* GetNext() { return m_next; } + MxListEntry* GetPrev() { return m_prev; } - friend class MxList; - friend class MxListCursor; + void SetValue(T p_obj) { m_obj = p_obj; } + void SetNext(MxListEntry* p_next) { m_next = p_next; } + void SetPrev(MxListEntry* p_prev) { m_prev = p_prev; } private: T m_obj; @@ -100,7 +103,7 @@ class MxListCursor : public MxCore { void Destroy(); MxBool Next(T& p_obj); MxBool Current(T& p_obj); - void Advance(); + MxBool Advance(); MxBool HasMatch() { return m_match != NULL; } void SetValue(T p_obj); void Head() { m_match = m_list->m_first; } @@ -139,7 +142,7 @@ inline void MxList::DeleteAll() if (!t) break; - MxListEntry* next = t->m_next; + MxListEntry* next = t->GetNext(); this->m_customDestructor(t->GetValue()); delete t; t = next; @@ -157,7 +160,7 @@ inline void MxList::Append(T p_newobj) MxListEntry* newEntry = new MxListEntry(p_newobj, currentLast); if (currentLast) - currentLast->m_next = newEntry; + currentLast->SetNext(newEntry); else this->m_first = newEntry; @@ -171,12 +174,12 @@ inline MxListEntry* MxList::_InsertEntry(T p_newobj, MxListEntry* p_pre MxListEntry* newEntry = new MxListEntry(p_newobj, p_prev, p_next); if (p_prev) - p_prev->m_next = newEntry; + p_prev->SetNext(newEntry); else this->m_first = newEntry; if (p_next) - p_next->m_prev = newEntry; + p_next->SetPrev(newEntry); else this->m_last = newEntry; @@ -187,18 +190,15 @@ inline MxListEntry* MxList::_InsertEntry(T p_newobj, MxListEntry* p_pre template inline void MxList::_DeleteEntry(MxListEntry* match) { - MxListEntry** pPrev = &match->m_prev; - MxListEntry** pNext = &match->m_next; - - if (match->m_prev) - match->m_prev->m_next = *pNext; + if (match->GetPrev()) + match->GetPrev()->SetNext(match->GetNext()); else - m_first = *pNext; + m_first = match->GetNext(); - if (*pNext) - (*pNext)->m_prev = *pPrev; + if (match->GetNext()) + match->GetNext()->SetPrev(match->GetPrev()); else - m_last = *pPrev; + m_last = match->GetPrev(); delete match; this->m_count--; @@ -207,7 +207,8 @@ inline void MxList::_DeleteEntry(MxListEntry* match) template inline MxBool MxListCursor::Find(T p_obj) { - for (m_match = m_list->m_first; m_match && m_list->Compare(m_match->m_obj, p_obj); m_match = m_match->m_next) + for (m_match = m_list->m_first; m_match && m_list->Compare(m_match->GetValue(), p_obj); + m_match = m_match->GetNext()) ; return m_match != NULL; @@ -223,7 +224,10 @@ inline void MxListCursor::Detach() template inline void MxListCursor::Destroy() { - m_list->m_customDestructor(m_match->GetValue()); + if (m_match) { + m_list->m_customDestructor(m_match->GetValue()); + Detach(); + } } template @@ -232,7 +236,7 @@ inline MxBool MxListCursor::Next(T& p_obj) if (!m_match) m_match = m_list->m_first; else - m_match = m_match->m_next; + m_match = m_match->GetNext(); if (m_match) p_obj = m_match->GetValue(); @@ -250,26 +254,28 @@ inline MxBool MxListCursor::Current(T& p_obj) } template -inline void MxListCursor::Advance() +inline MxBool MxListCursor::Advance() { if (!m_match) m_match = m_list->m_first; else - m_match = m_match->m_next; + m_match = m_match->GetNext(); + + return m_match != NULL; } template inline void MxListCursor::SetValue(T p_obj) { if (m_match) - m_match->m_obj = p_obj; + m_match->SetValue(p_obj); } template inline void MxListCursor::Prepend(T p_newobj) { if (m_match) - m_list->_InsertEntry(p_newobj, m_match->m_prev, m_match); + m_list->_InsertEntry(p_newobj, m_match->GetPrev(), m_match); } #endif // MXLIST_H diff --git a/LEGO1/mxregion.cpp b/LEGO1/mxregion.cpp index bd2a5f5a..6bb57280 100644 --- a/LEGO1/mxregion.cpp +++ b/LEGO1/mxregion.cpp @@ -157,14 +157,9 @@ void MxRegionTopBottom::FUN_100c5280(MxS32 p_left, MxS32 p_right) if (p_right < leftRight->m_right) p_right = leftRight->m_right; - // TODO: Currently inlined, shouldn't be b = a; b.Advance(); - - if (a.HasMatch()) { - a.Destroy(); - a.Detach(); - } + a.Destroy(); if (!b.Current(leftRight)) break;