Make ped comments update position and volume + fix cPedComments::Process

This commit is contained in:
Sergeanur 2021-08-23 11:16:53 +03:00
parent 09f693b9b9
commit ef0ba763b9
3 changed files with 82 additions and 54 deletions

View File

@ -7829,9 +7829,8 @@ cPedComments::Process()
uint32 sampleIndex; uint32 sampleIndex;
uint8 actualUsedBank; uint8 actualUsedBank;
tPedComment *comment; tPedComment *comment;
bool8 prevUsed = FALSE;
static uint8 counter = 0; static uint8 counter = 0;
static int32 prevSamples[10]; static int32 prevSamples[10] = { NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE, NO_SAMPLE };
if(AudioManager.m_nUserPause) return; if(AudioManager.m_nUserPause) return;
@ -7840,18 +7839,18 @@ cPedComments::Process()
if(m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nSampleIndex == if(m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nSampleIndex ==
prevSamples[(counter + 1 + i) % ARRAY_SIZE(prevSamples)]) { prevSamples[(counter + 1 + i) % ARRAY_SIZE(prevSamples)]) {
m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nProcess = -1; m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nProcess = -1;
prevUsed = TRUE; goto PedCommentAlreadyAdded;
break;
} }
} }
if(!prevUsed) {
sampleIndex = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nSampleIndex; sampleIndex = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nSampleIndex;
if(!SampleManager.IsPedCommentLoaded(sampleIndex)) { switch(SampleManager.IsPedCommentLoaded(sampleIndex)) { // yes, this was a switch
case FALSE:
#if defined(GTA_PC) && !defined(FIX_BUGS) #if defined(GTA_PC) && !defined(FIX_BUGS)
if(!m_bDelay) if(!m_bDelay)
#endif #endif
SampleManager.LoadPedComment(sampleIndex); SampleManager.LoadPedComment(sampleIndex);
} else { break;
case TRUE:
AudioManager.m_sQueueSample.m_nEntityIndex = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nEntityIndex; AudioManager.m_sQueueSample.m_nEntityIndex = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_nEntityIndex;
AudioManager.m_sQueueSample.m_nCounter = 0; AudioManager.m_sQueueSample.m_nCounter = 0;
AudioManager.m_sQueueSample.m_nSampleIndex = sampleIndex; AudioManager.m_sQueueSample.m_nSampleIndex = sampleIndex;
@ -7871,7 +7870,13 @@ cPedComments::Process()
AudioManager.m_sQueueSample.m_nEmittingVolume = MAX_VOLUME; AudioManager.m_sQueueSample.m_nEmittingVolume = MAX_VOLUME;
#endif // FIX_BUGS #endif // FIX_BUGS
#endif // EXTERNAL_3D_SOUND #endif // EXTERNAL_3D_SOUND
#ifdef ATTACH_PED_COMMENTS_TO_ENTITIES
// let's disable doppler because if sounds funny as the sound moves
// originally position of ped comment doesn't change so this has no effect anyway
AudioManager.m_sQueueSample.m_fSpeedMultiplier = 0.0f;
#else
AudioManager.m_sQueueSample.m_fSpeedMultiplier = 3.0f; AudioManager.m_sQueueSample.m_fSpeedMultiplier = 3.0f;
#endif
AudioManager.m_sQueueSample.m_MaxDistance = 40.0f; AudioManager.m_sQueueSample.m_MaxDistance = 40.0f;
AudioManager.m_sQueueSample.m_bStatic = TRUE; AudioManager.m_sQueueSample.m_bStatic = TRUE;
AudioManager.m_sQueueSample.m_vecPos = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_vecPos; AudioManager.m_sQueueSample.m_vecPos = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_vecPos;
@ -7886,10 +7891,12 @@ cPedComments::Process()
if((sampleIndex >= SFX_POLICE_BOAT_1 && sampleIndex <= SFX_POLICE_BOAT_23) || if((sampleIndex >= SFX_POLICE_BOAT_1 && sampleIndex <= SFX_POLICE_BOAT_23) ||
(sampleIndex >= SFX_POLICE_HELI_1 && sampleIndex <= SFX_POLICE_HELI_20)) (sampleIndex >= SFX_POLICE_HELI_1 && sampleIndex <= SFX_POLICE_HELI_20))
AudioManager.m_sQueueSample.m_MaxDistance = 400.0f; AudioManager.m_sQueueSample.m_MaxDistance = 400.0f;
#ifndef ATTACH_PED_COMMENTS_TO_ENTITIES
else if (sampleIndex >= SFX_PLAYER_ANGRY_BUSTED_1 && sampleIndex <= SFX_PLAYER_ON_FIRE_16) { // check if player sfx else if (sampleIndex >= SFX_PLAYER_ANGRY_BUSTED_1 && sampleIndex <= SFX_PLAYER_ON_FIRE_16) { // check if player sfx
AudioManager.m_sQueueSample.m_bIs2D = TRUE; AudioManager.m_sQueueSample.m_bIs2D = TRUE;
AudioManager.m_sQueueSample.m_nPan = 63; AudioManager.m_sQueueSample.m_nPan = 63;
} }
#endif // ATTACH_PED_COMMENTS_TO_ENTITIES
#endif // FIX_BUGS #endif // FIX_BUGS
AudioManager.m_sQueueSample.m_nFrequency = AudioManager.m_sQueueSample.m_nFrequency =
SampleManager.GetSampleBaseFrequency(AudioManager.m_sQueueSample.m_nSampleIndex) + AudioManager.RandomDisplacement(750); SampleManager.GetSampleBaseFrequency(AudioManager.m_sQueueSample.m_nSampleIndex) + AudioManager.RandomDisplacement(750);
@ -7902,10 +7909,12 @@ cPedComments::Process()
m_nDelayTimer = CTimer::GetTimeInMilliseconds(); m_nDelayTimer = CTimer::GetTimeInMilliseconds();
m_bDelay = TRUE; m_bDelay = TRUE;
#endif #endif
break;
default:
break;
} }
} }
} PedCommentAlreadyAdded:
// Switch bank // Switch bank
if (m_nActiveBank == 0) { if (m_nActiveBank == 0) {
actualUsedBank = 0; actualUsedBank = 0;

View File

@ -1013,7 +1013,7 @@ cAudioManager::ProcessActiveQueues()
for (int32 j = 0; j < m_nActiveSamples; j++) { for (int32 j = 0; j < m_nActiveSamples; j++) {
if (sample.m_nEntityIndex == m_asActiveSamples[j].m_nEntityIndex && sample.m_nCounter == m_asActiveSamples[j].m_nCounter && if (sample.m_nEntityIndex == m_asActiveSamples[j].m_nEntityIndex && sample.m_nCounter == m_asActiveSamples[j].m_nCounter &&
sample.m_nSampleIndex == m_asActiveSamples[j].m_nSampleIndex) { sample.m_nSampleIndex == m_asActiveSamples[j].m_nSampleIndex) {
if (sample.m_nLoopCount) { if (sample.m_nLoopCount > 0) {
if (m_FrameCounter & 1) if (m_FrameCounter & 1)
flag = !!(j & 1); flag = !!(j & 1);
else else
@ -1047,6 +1047,24 @@ cAudioManager::ProcessActiveQueues()
SampleManager.SetChannelVolume(j, emittingVol); SampleManager.SetChannelVolume(j, emittingVol);
#endif #endif
} else { } else {
#ifdef ATTACH_PED_COMMENTS_TO_ENTITIES
if (sample.m_nCounter <= 255 && sample.m_nSampleIndex >= SAMPLEBANK_PED_START && sample.m_nSampleIndex <= SAMPLEBANK_PED_END) {
CEntity* entity = (CEntity*)GetEntityPointer(sample.m_nEntityIndex);
if (entity && m_asAudioEntities[sample.m_nEntityIndex].m_nType == AUDIOTYPE_PHYSICAL) {
sample.m_vecPos = entity->GetPosition();
sample.m_fDistance = Sqrt(GetDistanceSquared(sample.m_vecPos));
uint8 vol;
if (CWorld::GetIsLineOfSightClear(TheCamera.GetPosition(), sample.m_vecPos, true, false, false, false, false, false))
vol = MAX_VOLUME;
else
vol = 31;
#ifdef EXTERNAL_3D_SOUND
sample.m_nEmittingVolume = vol;
#endif
sample.m_nVolume = ComputeVolume(vol, sample.m_MaxDistance, sample.m_fDistance);
}
}
#endif
position2 = sample.m_fDistance; position2 = sample.m_fDistance;
position1 = m_asActiveSamples[j].m_fDistance; position1 = m_asActiveSamples[j].m_fDistance;
m_asActiveSamples[j].m_fDistance = sample.m_fDistance; m_asActiveSamples[j].m_fDistance = sample.m_fDistance;

View File

@ -448,8 +448,9 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually
#define PS2_AUDIO_PATHS // changes audio paths for cutscenes and radio to PS2 paths (needs vbdec on MSS builds) #define PS2_AUDIO_PATHS // changes audio paths for cutscenes and radio to PS2 paths (needs vbdec on MSS builds)
//#define AUDIO_OAL_USE_SNDFILE // use libsndfile to decode WAVs instead of our internal decoder //#define AUDIO_OAL_USE_SNDFILE // use libsndfile to decode WAVs instead of our internal decoder
#define AUDIO_OAL_USE_MPG123 // use mpg123 to support mp3 files #define AUDIO_OAL_USE_MPG123 // use mpg123 to support mp3 files
#define MULTITHREADED_AUDIO // for streams. requires C++11 or later
#define PAUSE_RADIO_IN_FRONTEND // pause radio when game is paused #define PAUSE_RADIO_IN_FRONTEND // pause radio when game is paused
#define ATTACH_PED_COMMENTS_TO_ENTITIES // ped comments coordinates would update following ped entity
#define MULTITHREADED_AUDIO // for streams. requires C++11 or later
#ifdef AUDIO_OPUS #ifdef AUDIO_OPUS
#define AUDIO_OAL_USE_OPUS // enable support of opus files #define AUDIO_OAL_USE_OPUS // enable support of opus files