From 62b8f0f553917bf2db467941b5a055e08872913f Mon Sep 17 00:00:00 2001 From: erorcun Date: Sat, 6 Mar 2021 19:28:59 +0300 Subject: Pool fixes + peds not forming circle fix --- src/objects/Object.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/objects/Object.cpp') diff --git a/src/objects/Object.cpp b/src/objects/Object.cpp index 0605f54f..807ff301 100644 --- a/src/objects/Object.cpp +++ b/src/objects/Object.cpp @@ -25,10 +25,32 @@ int16 CObject::nNoTempObjects; //int16 CObject::nBodyCastHealth = 1000; float CObject::fDistToNearestTree; -void *CObject::operator new(size_t sz) { return CPools::GetObjectPool()->New(); } -void *CObject::operator new(size_t sz, int handle) { return CPools::GetObjectPool()->New(handle);}; -void CObject::operator delete(void *p, size_t sz) { CPools::GetObjectPool()->Delete((CObject*)p); } -void CObject::operator delete(void *p, int handle) { CPools::GetObjectPool()->Delete((CObject*)p); } +// Object pools tends to be full sometimes, let's free a temp. object in this case. +#ifdef FIX_BUGS +void *CObject::operator new(size_t sz) throw() { + CObject *obj = CPools::GetObjectPool()->New(); + if (!obj) { + CObjectPool *objectPool = CPools::GetObjectPool(); + for (int32 i = 0; i < objectPool->GetSize(); i++) { + CObject *existing = objectPool->GetSlot(i); + if (existing && existing->ObjectCreatedBy == TEMP_OBJECT) { + int32 handle = objectPool->GetIndex(existing); + CWorld::Remove(existing); + delete existing; + obj = objectPool->New(handle); + break; + } + } + } + return obj; +} +#else +void *CObject::operator new(size_t sz) throw() { return CPools::GetObjectPool()->New(); } +#endif +void *CObject::operator new(size_t sz, int handle) throw() { return CPools::GetObjectPool()->New(handle); }; + +void CObject::operator delete(void *p, size_t sz) throw() { CPools::GetObjectPool()->Delete((CObject*)p); } +void CObject::operator delete(void *p, int handle) throw() { CPools::GetObjectPool()->Delete((CObject*)p); } CObject::CObject(void) { -- cgit v1.2.3 From 3dda658e4296c0b009f0670d6a9c6d2da2878569 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Mon, 10 May 2021 02:34:21 +0300 Subject: Use some GetMatrix/SetMatrix logic based on SA # Conflicts: # src/control/Pickups.cpp # src/control/RoadBlocks.cpp # src/core/World.cpp # src/entities/Entity.cpp # src/objects/CutsceneHead.cpp # src/objects/Object.cpp --- src/objects/Object.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/objects/Object.cpp') diff --git a/src/objects/Object.cpp b/src/objects/Object.cpp index 0605f54f..0721725d 100644 --- a/src/objects/Object.cpp +++ b/src/objects/Object.cpp @@ -77,7 +77,7 @@ CObject::CObject(CDummyObject *dummy) if (dummy->m_rwObject) AttachToRwObject(dummy->m_rwObject); else - GetMatrix() = dummy->GetMatrix(); + SetMatrix(dummy->GetMatrix()); m_objectMatrix = dummy->GetMatrix(); dummy->DetachFromRwObject(); @@ -190,8 +190,8 @@ void CObject::Teleport(CVector vecPos) { CWorld::Remove(this); - m_matrix.GetPosition() = vecPos; - m_matrix.UpdateRW(); + GetMatrix().GetPosition() = vecPos; + GetMatrix().UpdateRW(); UpdateRwFrame(); CWorld::Add(this); } @@ -356,7 +356,7 @@ CObject::ObjectDamage(float amount) } #endif if ((amount * m_fCollisionDamageMultiplier > 150.0f || bBodyCastDamageEffect) && m_nCollisionDamageEffect) { - const CVector &vecPos = m_matrix.GetPosition(); + const CVector& vecPos = GetMatrix().GetPosition(); const float fDirectionZ = 0.0002f * amount; switch (m_nCollisionDamageEffect) { case DAMAGE_EFFECT_CHANGE_MODEL: @@ -653,7 +653,7 @@ CObject::ObjectDamage(float amount) CParticle::AddParticle(PARTICLE_CAR_DEBRIS, particlePos, particleDir, nil, fSize, particleColor, nRotationSpeed, 0, nCurFrame, 0); if ((i % 7) == 0) { static RwRGBA secondaryColor = { 0x9A, 0x99, 0x99, 0x3E }; - CParticle::AddParticle(PARTICLE_DEBRIS, particlePos, particleDir, nil, 0.3, secondaryColor, nRotationSpeed, 0, 0, 0); + CParticle::AddParticle(PARTICLE_DEBRIS, particlePos, particleDir, nil, 0.3f, secondaryColor, nRotationSpeed); } } PlayOneShotScriptObject(SCRIPT_SOUND_BOX_DESTROYED_2, vecPos); @@ -746,7 +746,7 @@ CObject::Init(void) m_pCollidingEntity = nil; CColPoint point; CEntity *outEntity = nil; - const CVector &vecPos = m_matrix.GetPosition(); + const CVector& vecPos = GetMatrix().GetPosition(); if (CWorld::ProcessVerticalLine(vecPos, vecPos.z - 10.0f, point, outEntity, true, false, false, false, false, false, nil)) m_pCurSurface = outEntity; else -- cgit v1.2.3