From e14252914e9bd4cf7702479b5e0b050b935ba4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 3 Aug 2020 04:00:12 +0300 Subject: Squeeze performance option, minor fixes Fixes are already in miami --- src/weapons/BulletInfo.cpp | 39 +++++++++++++++++++++++++++++++++-- src/weapons/ProjectileInfo.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++ src/weapons/ShotInfo.cpp | 20 +++++++++++++++++- 3 files changed, 102 insertions(+), 3 deletions(-) (limited to 'src/weapons') diff --git a/src/weapons/BulletInfo.cpp b/src/weapons/BulletInfo.cpp index 26fc459d..15dde011 100644 --- a/src/weapons/BulletInfo.cpp +++ b/src/weapons/BulletInfo.cpp @@ -24,6 +24,10 @@ #include "World.h" #include "SurfaceTable.h" +#ifdef SQUEEZE_PERFORMANCE +uint32 bulletInfoInUse; +#endif + #define BULLET_LIFETIME (1000) #define NUM_PED_BLOOD_PARTICLES (8) #define BLOOD_PARTICLE_OFFSET (CVector(0.0f, 0.0f, 0.0f)) @@ -47,6 +51,9 @@ void CBulletInfo::Initialise(void) gaBulletInfo[i].m_pSource = nil; } debug("CBulletInfo ready\n"); +#ifdef SQUEEZE_PERFORMANCE + bulletInfoInUse = 0; +#endif } void CBulletInfo::Shutdown(void) @@ -71,11 +78,19 @@ bool CBulletInfo::AddBullet(CEntity* pSource, eWeaponType type, CVector vecPosit gaBulletInfo[i].m_vecSpeed = vecSpeed; gaBulletInfo[i].m_fTimer = CTimer::GetTimeInMilliseconds() + BULLET_LIFETIME; gaBulletInfo[i].m_bInUse = true; + +#ifdef SQUEEZE_PERFORMANCE + bulletInfoInUse++; +#endif return true; } void CBulletInfo::Update(void) { +#ifdef SQUEEZE_PERFORMANCE + if (bulletInfoInUse == 0) + return; +#endif bool bAddSound = true; bPlayerSniperBullet = false; for (int i = 0; i < NUM_BULLETS; i++) { @@ -84,8 +99,12 @@ void CBulletInfo::Update(void) pBullet->m_pSource = nil; if (!pBullet->m_bInUse) continue; - if (CTimer::GetTimeInMilliseconds() > pBullet->m_fTimer) + if (CTimer::GetTimeInMilliseconds() > pBullet->m_fTimer) { pBullet->m_bInUse = false; +#ifdef SQUEEZE_PERFORMANCE + bulletInfoInUse--; +#endif + } CVector vecOldPos = pBullet->m_vecPosition; CVector vecNewPos = pBullet->m_vecPosition + pBullet->m_vecSpeed * CTimer::GetTimeStep() * 0.5f; CWorld::bIncludeCarTyres = true; @@ -108,6 +127,9 @@ void CBulletInfo::Update(void) pPed->InflictDamage(pBullet->m_pSource, pBullet->m_eWeaponType, pBullet->m_nDamage, (ePedPieceTypes)point.pieceB, pPed->GetLocalDirection(pPed->GetPosition() - point.point)); CEventList::RegisterEvent(pPed->m_nPedType == PEDTYPE_COP ? EVENT_SHOOT_COP : EVENT_SHOOT_PED, EVENT_ENTITY_PED, pPed, (CPed*)pBullet->m_pSource, 1000); pBullet->m_bInUse = false; +#ifdef SQUEEZE_PERFORMANCE + bulletInfoInUse--; +#endif vecNewPos = point.point; } else { @@ -134,6 +156,9 @@ void CBulletInfo::Update(void) } } pBullet->m_bInUse = false; +#ifdef SQUEEZE_PERFORMANCE + bulletInfoInUse--; +#endif vecNewPos = point.point; } } @@ -148,6 +173,9 @@ void CBulletInfo::Update(void) } #ifdef FIX_BUGS pBullet->m_bInUse = false; +#ifdef SQUEEZE_PERFORMANCE + bulletInfoInUse--; +#endif vecNewPos = point.point; #endif } @@ -167,6 +195,9 @@ void CBulletInfo::Update(void) } #ifdef FIX_BUGS pBullet->m_bInUse = false; +#ifdef SQUEEZE_PERFORMANCE + bulletInfoInUse--; +#endif vecNewPos = point.point; #endif } @@ -217,8 +248,12 @@ void CBulletInfo::Update(void) } pBullet->m_vecPosition = vecNewPos; if (pBullet->m_vecPosition.x < -MAP_BORDER || pBullet->m_vecPosition.x > MAP_BORDER || - pBullet->m_vecPosition.y < -MAP_BORDER || pBullet->m_vecPosition.y > MAP_BORDER) + pBullet->m_vecPosition.y < -MAP_BORDER || pBullet->m_vecPosition.y > MAP_BORDER) { pBullet->m_bInUse = false; +#ifdef SQUEEZE_PERFORMANCE + bulletInfoInUse--; +#endif + } } } diff --git a/src/weapons/ProjectileInfo.cpp b/src/weapons/ProjectileInfo.cpp index 47bc65ac..b56e3a29 100644 --- a/src/weapons/ProjectileInfo.cpp +++ b/src/weapons/ProjectileInfo.cpp @@ -13,6 +13,10 @@ #include "Weapon.h" #include "World.h" +#ifdef SQUEEZE_PERFORMANCE +uint32 projectileInUse; +#endif + CProjectileInfo gaProjectileInfo[NUM_PROJECTILES]; CProjectile *CProjectileInfo::ms_apProjectile[NUM_PROJECTILES]; @@ -30,6 +34,10 @@ CProjectileInfo::Initialise() } debug("CProjectileInfo ready\n"); + +#ifdef SQUEEZE_PERFORMANCE + projectileInUse = 0; +#endif } void @@ -154,6 +162,10 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, ms_apProjectile[i]->m_fElasticity = elasticity; ms_apProjectile[i]->m_nSpecialCollisionResponseCases = SpecialCollisionResponseCase; +#ifdef SQUEEZE_PERFORMANCE + projectileInUse++; +#endif + gaProjectileInfo[i].m_bInUse = true; CWorld::Add(ms_apProjectile[i]); @@ -165,6 +177,9 @@ void CProjectileInfo::RemoveProjectile(CProjectileInfo *info, CProjectile *projectile) { RemoveNotAdd(info->m_pSource, info->m_eWeaponType, projectile->GetPosition()); +#ifdef SQUEEZE_PERFORMANCE + projectileInUse--; +#endif info->m_bInUse = false; CWorld::Remove(projectile); @@ -192,6 +207,11 @@ CProjectileInfo::RemoveNotAdd(CEntity *entity, eWeaponType weaponType, CVector p void CProjectileInfo::Update() { +#ifdef SQUEEZE_PERFORMANCE + if (projectileInUse == 0) + return; +#endif + for (int i = 0; i < ARRAY_SIZE(gaProjectileInfo); i++) { if (!gaProjectileInfo[i].m_bInUse) continue; @@ -200,6 +220,10 @@ CProjectileInfo::Update() gaProjectileInfo[i].m_pSource = nil; if (ms_apProjectile[i] == nil) { +#ifdef SQUEEZE_PERFORMANCE + projectileInUse--; +#endif + gaProjectileInfo[i].m_bInUse = false; continue; } @@ -252,6 +276,10 @@ CProjectileInfo::IsProjectileInRange(float x1, float x2, float y1, float y2, flo if (pos.x >= x1 && pos.x <= x2 && pos.y >= y1 && pos.y <= y2 && pos.z >= z1 && pos.z <= z2) { result = true; if (remove) { +#ifdef SQUEEZE_PERFORMANCE + projectileInUse--; +#endif + gaProjectileInfo[i].m_bInUse = false; CWorld::Remove(ms_apProjectile[i]); delete ms_apProjectile[i]; @@ -266,8 +294,17 @@ CProjectileInfo::IsProjectileInRange(float x1, float x2, float y1, float y2, flo void CProjectileInfo::RemoveAllProjectiles() { +#ifdef SQUEEZE_PERFORMANCE + if (projectileInUse == 0) + return; +#endif + for (int i = 0; i < ARRAY_SIZE(ms_apProjectile); i++) { if (gaProjectileInfo[i].m_bInUse) { +#ifdef SQUEEZE_PERFORMANCE + projectileInUse--; +#endif + gaProjectileInfo[i].m_bInUse = false; CWorld::Remove(ms_apProjectile[i]); delete ms_apProjectile[i]; @@ -278,12 +315,21 @@ CProjectileInfo::RemoveAllProjectiles() bool CProjectileInfo::RemoveIfThisIsAProjectile(CObject *object) { +#ifdef SQUEEZE_PERFORMANCE + if (projectileInUse == 0) + return false; +#endif + int i = 0; while (ms_apProjectile[i++] != object) { if (i >= ARRAY_SIZE(ms_apProjectile)) return false; } +#ifdef SQUEEZE_PERFORMANCE + projectileInUse--; +#endif + gaProjectileInfo[i].m_bInUse = false; CWorld::Remove(ms_apProjectile[i]); delete ms_apProjectile[i]; diff --git a/src/weapons/ShotInfo.cpp b/src/weapons/ShotInfo.cpp index f09ae052..c0ab9ac1 100644 --- a/src/weapons/ShotInfo.cpp +++ b/src/weapons/ShotInfo.cpp @@ -13,6 +13,9 @@ CShotInfo gaShotInfo[NUMSHOTINFOS]; float CShotInfo::ms_afRandTable[20]; +#ifdef SQUEEZE_PERFORMANCE +uint32 shotInfoInUse; +#endif /* Used for flamethrower. I don't know why it's name is CShotInfo. @@ -41,6 +44,9 @@ CShotInfo::Initialise() nextVal += 0.005f; } debug("CShotInfo ready\n"); +#ifdef SQUEEZE_PERFORMANCE + shotInfoInUse = 0; +#endif } bool @@ -54,6 +60,10 @@ CShotInfo::AddShot(CEntity *sourceEntity, eWeaponType weapon, CVector startPos, if (slot == ARRAY_SIZE(gaShotInfo)) return false; +#ifdef SQUEEZE_PERFORMANCE + shotInfoInUse++; +#endif + gaShotInfo[slot].m_inUse = true; gaShotInfo[slot].m_weapon = weapon; gaShotInfo[slot].m_startPos = startPos; @@ -87,6 +97,10 @@ CShotInfo::Shutdown() void CShotInfo::Update() { +#ifdef SQUEEZE_PERFORMANCE + if (shotInfoInUse == 0) + return; +#endif for (int slot = 0; slot < ARRAY_SIZE(gaShotInfo); slot++) { CShotInfo &shot = gaShotInfo[slot]; if (shot.m_sourceEntity && shot.m_sourceEntity->IsPed() && !((CPed*)shot.m_sourceEntity)->IsPointerValid()) @@ -96,8 +110,12 @@ CShotInfo::Update() continue; CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(shot.m_weapon); - if (CTimer::GetTimeInMilliseconds() > shot.m_timeout) + if (CTimer::GetTimeInMilliseconds() > shot.m_timeout) { +#ifdef SQUEEZE_PERFORMANCE + shotInfoInUse--; +#endif shot.m_inUse = false; + } if (weaponInfo->m_bSlowsDown) shot.m_areaAffected *= pow(0.96, CTimer::GetTimeStep()); // FRAMERATE -- cgit v1.2.3