diff options
author | Nikolay Korolev <nickvnuk@gmail.com> | 2021-06-25 09:15:19 +0200 |
---|---|---|
committer | Nikolay Korolev <nickvnuk@gmail.com> | 2021-06-25 09:15:19 +0200 |
commit | 8a5afd0db2fa2616556ed953c5c464c6930d6f47 (patch) | |
tree | 0747c8742ffb38488e7d3569d92ff5ba1c3a5e39 /src/objects/Object.cpp | |
parent | Merge remote-tracking branch 'upstream/lcs' into lcs (diff) | |
parent | Merge remote-tracking branch 'origin/miami' into lcs (diff) | |
download | re3-8a5afd0db2fa2616556ed953c5c464c6930d6f47.tar re3-8a5afd0db2fa2616556ed953c5c464c6930d6f47.tar.gz re3-8a5afd0db2fa2616556ed953c5c464c6930d6f47.tar.bz2 re3-8a5afd0db2fa2616556ed953c5c464c6930d6f47.tar.lz re3-8a5afd0db2fa2616556ed953c5c464c6930d6f47.tar.xz re3-8a5afd0db2fa2616556ed953c5c464c6930d6f47.tar.zst re3-8a5afd0db2fa2616556ed953c5c464c6930d6f47.zip |
Diffstat (limited to 'src/objects/Object.cpp')
-rw-r--r-- | src/objects/Object.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/objects/Object.cpp b/src/objects/Object.cpp index 0605f54f..575c592c 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) { @@ -77,7 +99,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 +212,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 +378,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 +675,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 +768,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 |