diff --git a/SilentPatchSA/LinkListSA.h b/SilentPatchSA/LinkListSA.h index 151ab06..65f859f 100644 --- a/SilentPatchSA/LinkListSA.h +++ b/SilentPatchSA/LinkListSA.h @@ -13,6 +13,14 @@ public: m_pNext = pAttach; } + inline void InsertBefore(CLinkSA* pAttach) { + pAttach->m_pPrev = m_pPrev; + m_pPrev->m_pNext = pAttach; + + pAttach->m_pNext = this; + m_pPrev = pAttach; + } + inline void Remove(void) { m_pNext->m_pPrev = m_pPrev; m_pPrev->m_pNext = m_pNext; @@ -38,7 +46,7 @@ public: { } - void Init(int nNumLinks) { + void Init(size_t nNumLinks) { m_plnLinks = new CLinkSA[nNumLinks]; m_lnListHead.m_pNext = &m_lnListTail; @@ -47,8 +55,8 @@ public: m_lnFreeListHead.m_pNext = &m_lnFreeListTail; m_lnFreeListTail.m_pPrev = &m_lnFreeListHead; - for(int i = nNumLinks - 1; i >= 0; i--) { - m_lnFreeListHead.Insert(&m_plnLinks[i]); + for(size_t i = nNumLinks; i > 0; --i) { + m_lnFreeListHead.Insert(&m_plnLinks[i - 1]); } } @@ -95,9 +103,28 @@ public: return pLink; } + CLinkSA* InsertFront(const T& pItem) { + return Insert(pItem); + } + + CLinkSA* InsertBack(const T& pItem) { + CLinkSA* pLink = m_lnFreeListHead.m_pNext; + + if(pLink == &m_lnFreeListTail) { + return nullptr; + } + + pLink->m_pItem = pItem; + + pLink->Remove(); + m_lnListTail.InsertBefore(pLink); + + return pLink; + } + void Clear(void) { while(m_lnListHead.m_pNext != &m_lnListTail) { - m_lnListHead.m_pNext->Remove(); + Remove( m_lnListHead.m_pNext ); } } @@ -107,18 +134,31 @@ public: } CLinkSA* Next(CLinkSA* pCurrent) { - if(pCurrent == 0) { + if(pCurrent == nullptr) { pCurrent = &m_lnListHead; } if(pCurrent->m_pNext == &m_lnListTail) { - return 0; + return nullptr; } else { return pCurrent->m_pNext; } } + CLinkSA* Prev(CLinkSA* pCurrent) { + if(pCurrent == nullptr) { + pCurrent = &m_lnListTail; + } + + if(pCurrent->m_pPrev == &m_lnListHead) { + return nullptr; + } + else { + return pCurrent->m_pPrev; + } + } + CLinkSA m_lnListHead; // 0-12 //head of the list of active links CLinkSA m_lnListTail; // 12-24 diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 18314f6..cde4300 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -401,7 +401,7 @@ void RenderVehicleHiDetailAlphaCB_HunterDoor(RpAtomic* pAtomic) NewObject.fCompareValue = -std::numeric_limits::infinity(); NewObject.pAtomic = pAtomic; - m_alphaList.InsertSorted(NewObject); + m_alphaList.InsertFront(NewObject); } template @@ -431,7 +431,7 @@ void RenderWeaponPedsForPC() RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); - for ( auto it = ms_weaponPedsForPC.m_lnListHead.m_pNext; it != &ms_weaponPedsForPC.m_lnListTail; it = it->m_pNext ) + for ( auto it = ms_weaponPedsForPC.Next( nullptr ); it != nullptr; it = ms_weaponPedsForPC.Next( it ) ) { it->V()->SetupLighting(); it->V()->RenderWeapon(true, false);