Match MxRegionTopBottom::FUN_100c5280

This commit is contained in:
Christian Semmler 2023-11-03 11:38:08 -04:00
parent 24e889ee3d
commit 615e1455b2
2 changed files with 30 additions and 29 deletions

View File

@ -27,9 +27,12 @@ class MxListEntry {
} }
T GetValue() { return this->m_obj; } T GetValue() { return this->m_obj; }
MxListEntry* GetNext() { return m_next; }
MxListEntry* GetPrev() { return m_prev; }
friend class MxList<T>; void SetValue(T p_obj) { m_obj = p_obj; }
friend class MxListCursor<T>; void SetNext(MxListEntry* p_next) { m_next = p_next; }
void SetPrev(MxListEntry* p_prev) { m_prev = p_prev; }
private: private:
T m_obj; T m_obj;
@ -100,7 +103,7 @@ class MxListCursor : public MxCore {
void Destroy(); void Destroy();
MxBool Next(T& p_obj); MxBool Next(T& p_obj);
MxBool Current(T& p_obj); MxBool Current(T& p_obj);
void Advance(); MxBool Advance();
MxBool HasMatch() { return m_match != NULL; } MxBool HasMatch() { return m_match != NULL; }
void SetValue(T p_obj); void SetValue(T p_obj);
void Head() { m_match = m_list->m_first; } void Head() { m_match = m_list->m_first; }
@ -139,7 +142,7 @@ inline void MxList<T>::DeleteAll()
if (!t) if (!t)
break; break;
MxListEntry<T>* next = t->m_next; MxListEntry<T>* next = t->GetNext();
this->m_customDestructor(t->GetValue()); this->m_customDestructor(t->GetValue());
delete t; delete t;
t = next; t = next;
@ -157,7 +160,7 @@ inline void MxList<T>::Append(T p_newobj)
MxListEntry<T>* newEntry = new MxListEntry<T>(p_newobj, currentLast); MxListEntry<T>* newEntry = new MxListEntry<T>(p_newobj, currentLast);
if (currentLast) if (currentLast)
currentLast->m_next = newEntry; currentLast->SetNext(newEntry);
else else
this->m_first = newEntry; this->m_first = newEntry;
@ -171,12 +174,12 @@ inline MxListEntry<T>* MxList<T>::_InsertEntry(T p_newobj, MxListEntry<T>* p_pre
MxListEntry<T>* newEntry = new MxListEntry<T>(p_newobj, p_prev, p_next); MxListEntry<T>* newEntry = new MxListEntry<T>(p_newobj, p_prev, p_next);
if (p_prev) if (p_prev)
p_prev->m_next = newEntry; p_prev->SetNext(newEntry);
else else
this->m_first = newEntry; this->m_first = newEntry;
if (p_next) if (p_next)
p_next->m_prev = newEntry; p_next->SetPrev(newEntry);
else else
this->m_last = newEntry; this->m_last = newEntry;
@ -187,18 +190,15 @@ inline MxListEntry<T>* MxList<T>::_InsertEntry(T p_newobj, MxListEntry<T>* p_pre
template <class T> template <class T>
inline void MxList<T>::_DeleteEntry(MxListEntry<T>* match) inline void MxList<T>::_DeleteEntry(MxListEntry<T>* match)
{ {
MxListEntry<T>** pPrev = &match->m_prev; if (match->GetPrev())
MxListEntry<T>** pNext = &match->m_next; match->GetPrev()->SetNext(match->GetNext());
if (match->m_prev)
match->m_prev->m_next = *pNext;
else else
m_first = *pNext; m_first = match->GetNext();
if (*pNext) if (match->GetNext())
(*pNext)->m_prev = *pPrev; match->GetNext()->SetPrev(match->GetPrev());
else else
m_last = *pPrev; m_last = match->GetPrev();
delete match; delete match;
this->m_count--; this->m_count--;
@ -207,7 +207,8 @@ inline void MxList<T>::_DeleteEntry(MxListEntry<T>* match)
template <class T> template <class T>
inline MxBool MxListCursor<T>::Find(T p_obj) inline MxBool MxListCursor<T>::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; return m_match != NULL;
@ -223,7 +224,10 @@ inline void MxListCursor<T>::Detach()
template <class T> template <class T>
inline void MxListCursor<T>::Destroy() inline void MxListCursor<T>::Destroy()
{ {
m_list->m_customDestructor(m_match->GetValue()); if (m_match) {
m_list->m_customDestructor(m_match->GetValue());
Detach();
}
} }
template <class T> template <class T>
@ -232,7 +236,7 @@ inline MxBool MxListCursor<T>::Next(T& p_obj)
if (!m_match) if (!m_match)
m_match = m_list->m_first; m_match = m_list->m_first;
else else
m_match = m_match->m_next; m_match = m_match->GetNext();
if (m_match) if (m_match)
p_obj = m_match->GetValue(); p_obj = m_match->GetValue();
@ -250,26 +254,28 @@ inline MxBool MxListCursor<T>::Current(T& p_obj)
} }
template <class T> template <class T>
inline void MxListCursor<T>::Advance() inline MxBool MxListCursor<T>::Advance()
{ {
if (!m_match) if (!m_match)
m_match = m_list->m_first; m_match = m_list->m_first;
else else
m_match = m_match->m_next; m_match = m_match->GetNext();
return m_match != NULL;
} }
template <class T> template <class T>
inline void MxListCursor<T>::SetValue(T p_obj) inline void MxListCursor<T>::SetValue(T p_obj)
{ {
if (m_match) if (m_match)
m_match->m_obj = p_obj; m_match->SetValue(p_obj);
} }
template <class T> template <class T>
inline void MxListCursor<T>::Prepend(T p_newobj) inline void MxListCursor<T>::Prepend(T p_newobj)
{ {
if (m_match) 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 #endif // MXLIST_H

View File

@ -157,14 +157,9 @@ void MxRegionTopBottom::FUN_100c5280(MxS32 p_left, MxS32 p_right)
if (p_right < leftRight->m_right) if (p_right < leftRight->m_right)
p_right = leftRight->m_right; p_right = leftRight->m_right;
// TODO: Currently inlined, shouldn't be
b = a; b = a;
b.Advance(); b.Advance();
a.Destroy();
if (a.HasMatch()) {
a.Destroy();
a.Detach();
}
if (!b.Current(leftRight)) if (!b.Current(leftRight))
break; break;