From 91093305d65305722e380c0087c71469363a8396 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Mon, 18 Jan 2021 21:06:59 +0200 Subject: Get rid of RwMatrix in CMatrix --- src/core/Camera.cpp | 45 +++++++++++++++++++++++++++++++++++++-------- src/core/Camera.h | 6 +++++- 2 files changed, 42 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 7a831068..9d169716 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -3629,9 +3629,17 @@ CCamera::CalculateDerivedValues(void) bool CCamera::IsPointVisible(const CVector ¢er, const CMatrix *mat) { - RwV3d c; - c = center; - RwV3dTransformPoints(&c, &c, 1, &mat->m_matrix); +#ifdef GTA_PS2 + CVuVector c; + TransformPoint(c, *mat, center); +#else + CVector c = center; + #ifdef FIX_BUGS + c = *mat * center; + #else + RwV3dTransformPoints(&c, &c, 1, (RwMatrix*)mat); + #endif +#endif if(c.y < CDraw::GetNearClipZ()) return false; if(c.y > CDraw::GetFarClipZ()) return false; if(c.x*m_vecFrustumNormals[0].x + c.y*m_vecFrustumNormals[0].y > 0.0f) return false; @@ -3644,9 +3652,17 @@ CCamera::IsPointVisible(const CVector ¢er, const CMatrix *mat) bool CCamera::IsSphereVisible(const CVector ¢er, float radius, const CMatrix *mat) { - RwV3d c; - c = center; - RwV3dTransformPoints(&c, &c, 1, &mat->m_matrix); +#ifdef GTA_PS2 + CVuVector c; + TransformPoint(c, *mat, center); +#else + CVector c = center; + #ifdef FIX_BUGS + c = *mat * center; + #else + RwV3dTransformPoints(&c, &c, 1, (RwMatrix*)mat); + #endif +#endif if(c.y + radius < CDraw::GetNearClipZ()) return false; if(c.y - radius > CDraw::GetFarClipZ()) return false; if(c.x*m_vecFrustumNormals[0].x + c.y*m_vecFrustumNormals[0].y > radius) return false; @@ -3664,11 +3680,24 @@ CCamera::IsSphereVisible(const CVector ¢er, float radius) } bool -CCamera::IsBoxVisible(RwV3d *box, const CMatrix *mat) +#ifdef GTA_PS2 +CCamera::IsBoxVisible(CVuVector *box, const CMatrix *mat) +#else +CCamera::IsBoxVisible(CVector *box, const CMatrix *mat) +#endif { int i; int frustumTests[6] = { 0 }; - RwV3dTransformPoints(box, box, 8, &mat->m_matrix); +#ifdef GTA_PS2 + TransformPoints(box, 8, *mat, box); +#else + #ifdef FIX_BUGS + for (i = 0; i < 8; i++) + box[i] = *mat * box[i]; + #else + RwV3dTransformPoints(box, box, 8, (RwMatrix*)mat); + #endif +#endif for(i = 0; i < 8; i++){ if(box[i].y < CDraw::GetNearClipZ()) frustumTests[0]++; diff --git a/src/core/Camera.h b/src/core/Camera.h index ca1bd135..d7293e20 100644 --- a/src/core/Camera.h +++ b/src/core/Camera.h @@ -641,7 +641,11 @@ public: bool IsPointVisible(const CVector ¢er, const CMatrix *mat); bool IsSphereVisible(const CVector ¢er, float radius, const CMatrix *mat); bool IsSphereVisible(const CVector ¢er, float radius); - bool IsBoxVisible(RwV3d *box, const CMatrix *mat); +#ifdef GTA_PS2 + bool IsBoxVisible(CVuVector *box, const CMatrix *mat); +#else + bool IsBoxVisible(CVector *box, const CMatrix *mat); +#endif }; VALIDATE_SIZE(CCamera, 0xE9D8); -- cgit v1.2.3 From a9b8d30ce0e4e40dc5b5410c85bd0987548c6772 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Tue, 19 Jan 2021 21:32:55 +0200 Subject: Get rid of bitfields in CPool --- src/core/Pools.cpp | 2 +- src/core/templates.h | 71 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 27 deletions(-) (limited to 'src/core') diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp index d3801a2a..39cfb1d4 100644 --- a/src/core/Pools.cpp +++ b/src/core/Pools.cpp @@ -102,7 +102,7 @@ CPools::CheckPoolsEmpty() void CPools::MakeSureSlotInObjectPoolIsEmpty(int32 slot) { - if (ms_pObjectPool->IsFreeSlot(slot)) return; + if (ms_pObjectPool->GetIsFree(slot)) return; CObject *object = ms_pObjectPool->GetSlot(slot); if (object->ObjectCreatedBy == TEMP_OBJECT) { diff --git a/src/core/templates.h b/src/core/templates.h index 3a5b314f..545dac39 100644 --- a/src/core/templates.h +++ b/src/core/templates.h @@ -29,39 +29,59 @@ public: } }; +#define POOLFLAG_ID 0x7f +#define POOLFLAG_ISFREE 0x80 + template class CPool { U *m_entries; - union Flags { - struct { - uint8 id : 7; - uint8 free : 1; - }; - uint8 u; - } *m_flags; + uint8 *m_flags; int32 m_size; int32 m_allocPtr; public: CPool(int32 size){ m_entries = (U*)new uint8[sizeof(U)*size]; - m_flags = (Flags*)new uint8[sizeof(Flags)*size]; + m_flags = new uint8[size]; m_size = size; m_allocPtr = 0; for(int i = 0; i < size; i++){ - m_flags[i].id = 0; - m_flags[i].free = 1; + SetId(i, 0); + SetIsFree(i, true); } } + int GetId(int i) const + { + return m_flags[i] & POOLFLAG_ID; + } + + bool GetIsFree(int i) const + { + return !!(m_flags[i] & POOLFLAG_ISFREE); + } + + void SetId(int i, int id) + { + m_flags[i] = (m_flags[i] & POOLFLAG_ISFREE) | (id & POOLFLAG_ID); + } + + void SetIsFree(int i, bool isFree) + { + if (isFree) + m_flags[i] |= POOLFLAG_ISFREE; + else + m_flags[i] &= ~POOLFLAG_ISFREE; + } + ~CPool() { Flush(); } void Flush() { if (m_size > 0) { delete[] (uint8*)m_entries; - delete[] (uint8*)m_flags; + delete[] m_flags; m_entries = nil; m_flags = nil; m_size = 0; @@ -87,9 +107,9 @@ public: m_allocPtr = 0; } #endif - while(!m_flags[m_allocPtr].free); - m_flags[m_allocPtr].free = 0; - m_flags[m_allocPtr].id++; + while(!GetIsFree(m_allocPtr)); + SetIsFree(m_allocPtr, false); + SetId(m_allocPtr, GetId(m_allocPtr)+1); return (T*)&m_entries[m_allocPtr]; } T *New(int32 handle){ @@ -99,36 +119,36 @@ public: } void SetNotFreeAt(int32 handle){ int idx = handle>>8; - m_flags[idx].free = 0; - m_flags[idx].id = handle & 0x7F; + SetIsFree(idx, false); + SetId(idx, handle & POOLFLAG_ID); for(m_allocPtr = 0; m_allocPtr < m_size; m_allocPtr++) - if(m_flags[m_allocPtr].free) + if(GetIsFree(m_allocPtr)) return; } void Delete(T *entry){ int i = GetJustIndex(entry); - m_flags[i].free = 1; + SetIsFree(i, true); if(i < m_allocPtr) m_allocPtr = i; } T *GetSlot(int i){ - return m_flags[i].free ? nil : (T*)&m_entries[i]; + return GetIsFree(i) ? nil : (T*)&m_entries[i]; } T *GetAt(int handle){ #ifdef FIX_BUGS if (handle == -1) return nil; #endif - return m_flags[handle>>8].u == (handle & 0xFF) ? + return m_flags[handle>>8] == (handle & 0xFF) ? (T*)&m_entries[handle >> 8] : nil; } int32 GetIndex(T *entry){ int i = GetJustIndex_NoFreeAssert(entry); - return m_flags[i].u + (i<<8); + return m_flags[i] + (i<<8); } int32 GetJustIndex(T *entry){ int index = GetJustIndex_NoFreeAssert(entry); - assert(!IsFreeSlot(index)); + assert(!GetIsFree(index)); return index; } int32 GetJustIndex_NoFreeAssert(T* entry){ @@ -140,13 +160,12 @@ public: int i; int n = 0; for(i = 0; i < m_size; i++) - if(!m_flags[i].free) + if(!GetIsFree(i)) n++; return n; } - bool IsFreeSlot(int i) { return !!m_flags[i].free; } void ClearStorage(uint8 *&flags, U *&entries){ - delete[] (uint8*)flags; + delete[] flags; delete[] (uint8*)entries; flags = nil; entries = nil; @@ -155,7 +174,7 @@ public: void CopyBack(uint8 *&flags, U *&entries){ memcpy(m_flags, flags, sizeof(uint8)*m_size); memcpy(m_entries, entries, sizeof(U)*m_size); - debug("Size copied:%d (%d)\n", sizeof(U)*m_size, sizeof(Flags)*m_size); + debug("Size copied:%d (%d)\n", sizeof(U)*m_size, m_size); m_allocPtr = 0; ClearStorage(flags, entries); debug("CopyBack:%d (/%d)\n", GetNoOfUsedSpaces(), m_size); /* Assumed inlining */ -- cgit v1.2.3 From bb66028e74d5a8d9e75f2448caa876ac35d4f700 Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 19 Jan 2021 21:33:09 +0100 Subject: pc radar fix --- src/core/Radar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index 816da6b9..a5acdfad 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -778,7 +778,7 @@ void CRadar::DrawRadarMask() CVector2D(-1.0, -1.0f) }; - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void*)nil); RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEFLAT); -- cgit v1.2.3 From 8e825fa629dc3a0d82d1bc3ea8807ac10c986c82 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Wed, 20 Jan 2021 22:16:11 +0300 Subject: fixed saving --- src/core/Zones.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index 2e3e0f6e..cdae85e1 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -649,7 +649,7 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) WriteSaveHeader(buffer, 'Z', 'N', 'S', '\0', *size - SAVE_HEADER_SIZE); - WriteSaveBuf(buffer, GetIndexForZonePointer(m_pPlayersZone)); + WriteSaveBuf(buffer, (int32)GetIndexForZonePointer(m_pPlayersZone)); WriteSaveBuf(buffer, m_CurrLevel); WriteSaveBuf(buffer, FindIndex); WriteSaveBuf(buffer, (int16)0); // padding -- cgit v1.2.3