From 337924c7944115a9212edfb1097a8f83e7f6daf0 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Fri, 28 Feb 2020 18:34:39 +0100 Subject: Cleanup audio code + fixes for review --- src/audio/AudioCollision.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/audio/AudioCollision.cpp') diff --git a/src/audio/AudioCollision.cpp b/src/audio/AudioCollision.cpp index 6c998a34..0e4fb748 100644 --- a/src/audio/AudioCollision.cpp +++ b/src/audio/AudioCollision.cpp @@ -8,6 +8,8 @@ #include "SurfaceTable.h" #include "sampman.h" +constexpr int CollisionSoundIntensity = 60; + void cAudioCollisionManager::AddCollisionToRequestedQueue() { @@ -146,7 +148,8 @@ cAudioManager::SetUpLoopingCollisionSound(cAudioCollision *col, uint8 counter) uint8 emittingVol = SetLoopingCollisionRequestedSfxFreqAndGetVol(col); if(emittingVol) { m_sQueueSample.m_fDistance = Sqrt(col->m_fDistance); - m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 60.f, m_sQueueSample.m_fDistance); + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, CollisionSoundIntensity, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_counter = counter; m_sQueueSample.m_vecPos = col->m_vecPosition; @@ -160,7 +163,7 @@ cAudioManager::SetUpLoopingCollisionSound(cAudioCollision *col, uint8 counter) m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); m_sQueueSample.field_48 = 4.0f; - m_sQueueSample.m_fSoundIntensity = 60.0f; + m_sQueueSample.m_fSoundIntensity = CollisionSoundIntensity; m_sQueueSample.field_56 = 0; m_sQueueSample.field_76 = 5; m_sQueueSample.m_bReverbFlag = true; @@ -212,7 +215,8 @@ cAudioManager::SetUpOneShotCollisionSound(cAudioCollision *col) emittingVol = 40.f * ratio; if(emittingVol) { m_sQueueSample.m_fDistance = Sqrt(col->m_fDistance); - m_sQueueSample.m_bVolume = ComputeVolume(emittingVol, 60.f, m_sQueueSample.m_fDistance); + m_sQueueSample.m_bVolume = + ComputeVolume(emittingVol, CollisionSoundIntensity, m_sQueueSample.m_fDistance); if(m_sQueueSample.m_bVolume) { m_sQueueSample.m_nSampleIndex = gOneShotCol[s1]; switch(m_sQueueSample.m_nSampleIndex) { @@ -277,7 +281,7 @@ cAudioManager::SetUpOneShotCollisionSound(cAudioCollision *col) m_sQueueSample.m_nLoopStart = 0; m_sQueueSample.m_nLoopEnd = -1; m_sQueueSample.field_48 = 4.0f; - m_sQueueSample.m_fSoundIntensity = 60.0f; + m_sQueueSample.m_fSoundIntensity = CollisionSoundIntensity; m_sQueueSample.field_56 = 1; m_sQueueSample.m_bReverbFlag = true; m_sQueueSample.m_bRequireReflection = false; @@ -356,7 +360,7 @@ void cAudioManager::ReportCollision(CEntity *entity1, CEntity *entity2, uint8 surface1, uint8 surface2, float collisionPower, float velocity) { - float dist; + float distSquared; CVector v1; CVector v2; @@ -373,8 +377,8 @@ cAudioManager::ReportCollision(CEntity *entity1, CEntity *entity2, uint8 surface v2 = entity2->GetPosition(); } CVector pos = (v1 + v2) * 0.5f; - dist = GetDistanceSquared(&pos); - if(dist < SQR(60.f)) { + distSquared = GetDistanceSquared(&pos); + if(distSquared < SQR(CollisionSoundIntensity)) { m_sCollisionManager.m_sQueue.m_pEntity1 = entity1; m_sCollisionManager.m_sQueue.m_pEntity2 = entity2; m_sCollisionManager.m_sQueue.m_bSurface1 = surface1; @@ -382,7 +386,7 @@ cAudioManager::ReportCollision(CEntity *entity1, CEntity *entity2, uint8 surface m_sCollisionManager.m_sQueue.m_fIntensity1 = collisionPower; m_sCollisionManager.m_sQueue.m_fIntensity2 = velocity; m_sCollisionManager.m_sQueue.m_vecPosition = pos; - m_sCollisionManager.m_sQueue.m_fDistance = dist; + m_sCollisionManager.m_sQueue.m_fDistance = distSquared; m_sCollisionManager.AddCollisionToRequestedQueue(); } } @@ -396,4 +400,4 @@ InjectHook(0x5686D0, &cAudioManager::ServiceCollisions, PATCH_JUMP); InjectHook(0x568E20, &cAudioManager::SetLoopingCollisionRequestedSfxFreqAndGetVol, PATCH_JUMP); InjectHook(0x568D30, &cAudioManager::SetUpLoopingCollisionSound, PATCH_JUMP); InjectHook(0x5689D0, &cAudioManager::SetUpOneShotCollisionSound, PATCH_JUMP); -ENDPATCHES \ No newline at end of file +ENDPATCHES -- cgit v1.2.3