diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp index 7df52b18..68f597bc 100644 --- a/src/audio/AudioLogic.cpp +++ b/src/audio/AudioLogic.cpp @@ -149,27 +149,58 @@ cAudioManager::PostInitialiseGameSpecificSetup() m_nPoliceChannelEntity = CreateEntity(AUDIOTYPE_POLICERADIO, (void *)1); if (m_nPoliceChannelEntity >= 0) SetEntityStatus(m_nPoliceChannelEntity, 1); - - m_nBridgeEntity = CreateEntity(AUDIOTYPE_BRIDGE, (void *)1); +#ifdef GTA_BRIDGE + m_nBridgeEntity = CreateEntity(AUDIOTYPE_BRIDGE, (void*)1); if (m_nBridgeEntity >= 0) SetEntityStatus(m_nBridgeEntity, 1); +#endif // GTA_BRIDGE + m_nEscalatorEntity = CreateEntity(AUDIOTYPE_ESCALATOR, (void*)1); + if (m_nEscalatorEntity >= 0) + SetEntityStatus(m_nEscalatorEntity, 1); + + m_nExtraSoundsEntity = CreateEntity(AUDIOTYPE_EXTRA_SOUNDS, (void*)1); + if (m_nExtraSoundsEntity >= 0) + SetEntityStatus(m_nExtraSoundsEntity, 1); + + + m_sMissionAudio.m_nSampleIndex[0] = NO_SAMPLE; + m_sMissionAudio.m_nLoadingStatus[0] = LOADING_STATUS_NOT_LOADED; + m_sMissionAudio.m_nPlayStatus[0] = PLAY_STATUS_STOPPED; + m_sMissionAudio.field_22[0] = 0; + m_sMissionAudio.m_bIsPlayed[0] = false; + m_sMissionAudio.m_bPredefinedProperties[0] = true; + m_sMissionAudio.m_nMissionAudioCounter[0] = 0; + m_sMissionAudio.m_bIsMobile[0] = false; + field_5538 = 127; + m_sMissionAudio.m_nSampleIndex[1] = NO_SAMPLE; + m_sMissionAudio.m_nLoadingStatus[1] = LOADING_STATUS_NOT_LOADED; + m_sMissionAudio.m_nPlayStatus[1] = PLAY_STATUS_STOPPED; + m_sMissionAudio.field_22[1] = 0; + m_sMissionAudio.m_bIsPlayed[1] = false; + m_sMissionAudio.m_bPredefinedProperties[1] = true; + m_sMissionAudio.m_nMissionAudioCounter[1] = 0; + m_sMissionAudio.m_bIsMobile[1] = false; + field_5538 = 127; - m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; - m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_NOT_LOADED; - m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_STOPPED; - m_sMissionAudio.field_22 = 0; - m_sMissionAudio.m_bIsPlayed = false; - m_sMissionAudio.m_bPredefinedProperties = true; - m_sMissionAudio.m_nMissionAudioCounter = 0; ResetAudioLogicTimers(CTimer::GetTimeInMilliseconds()); } void cAudioManager::PreTerminateGameSpecificShutdown() { +#ifdef GTA_BRIDGE if (m_nBridgeEntity >= 0) { DestroyEntity(m_nBridgeEntity); m_nBridgeEntity = AEHANDLE_NONE; } +#endif + if (m_nEscalatorEntity >= 0) { + DestroyEntity(m_nEscalatorEntity); + m_nEscalatorEntity = AEHANDLE_NONE; + } + if (m_nExtraSoundsEntity >= 0) { + DestroyEntity(m_nExtraSoundsEntity); + m_nExtraSoundsEntity = AEHANDLE_NONE; + } if (m_nPoliceChannelEntity >= 0) { DestroyEntity(m_nPoliceChannelEntity); m_nPoliceChannelEntity = AEHANDLE_NONE; @@ -223,7 +254,8 @@ cAudioManager::ResetAudioLogicTimers(uint32 timer) } } } - ClearMissionAudio(); + ClearMissionAudio(0); + ClearMissionAudio(1); SampleManager.StopChannel(policeChannel); } @@ -5203,7 +5235,7 @@ cAudioManager::ProcessBridgeOneShots() #endif #pragma region MISSION_AUDIO -bool g_bMissionAudioLoadFailed; +bool g_bMissionAudioLoadFailed[MISSION_AUDIO_SLOTS]; struct MissionAudioData { const char *m_pName; @@ -5605,77 +5637,104 @@ cAudioManager::MissionScriptAudioUsesPoliceChannel(int32 soundMission) const } void -cAudioManager::PreloadMissionAudio(Const char *name) +cAudioManager::PreloadMissionAudio(uint8 slot, Const char *name) { - if (m_bIsInitialised) { + if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS) { int32 missionAudioSfx = FindMissionAudioSfx(name); if (missionAudioSfx != NO_SAMPLE) { - m_sMissionAudio.m_nSampleIndex = missionAudioSfx; - m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_NOT_LOADED; - m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_STOPPED; - m_sMissionAudio.field_22 = 0; - m_sMissionAudio.m_nMissionAudioCounter = m_nTimeSpent * SampleManager.GetStreamedFileLength(missionAudioSfx) / 1000; - m_sMissionAudio.m_nMissionAudioCounter *= 4; - m_sMissionAudio.m_bIsPlayed = false; - m_sMissionAudio.m_bPredefinedProperties = 1; - g_bMissionAudioLoadFailed = false; + m_sMissionAudio.m_nSampleIndex[slot] = missionAudioSfx; + m_sMissionAudio.m_nLoadingStatus[slot] = LOADING_STATUS_NOT_LOADED; + m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_STOPPED; + m_sMissionAudio.field_22[slot] = 0; + m_sMissionAudio.m_nMissionAudioCounter[slot] = m_nTimeSpent * SampleManager.GetStreamedFileLength(missionAudioSfx) / 1000; + m_sMissionAudio.m_nMissionAudioCounter[slot] *= 4; + m_sMissionAudio.m_bIsPlayed[slot] = false; + m_sMissionAudio.m_bPredefinedProperties[slot] = true; + g_bMissionAudioLoadFailed[slot] = false; } } } uint8 -cAudioManager::GetMissionAudioLoadingStatus() const +cAudioManager::GetMissionAudioLoadingStatus(uint8 slot) const { - if (m_bIsInitialised) - return m_sMissionAudio.m_nLoadingStatus; + if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS) + return m_sMissionAudio.m_nLoadingStatus[slot]; return LOADING_STATUS_LOADED; } void -cAudioManager::SetMissionAudioLocation(float x, float y, float z) +cAudioManager::SetMissionAudioLocation(uint8 slot, float x, float y, float z) { - if (m_bIsInitialised) { - m_sMissionAudio.m_bPredefinedProperties = false; - m_sMissionAudio.m_vecPos = CVector(x, y, z); + if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS) { + m_sMissionAudio.m_bPredefinedProperties[slot] = false; + m_sMissionAudio.m_vecPos[slot] = CVector(x, y, z); } } void -cAudioManager::PlayLoadedMissionAudio() +cAudioManager::PlayLoadedMissionAudio(uint8 slot) { - if (m_bIsInitialised && m_sMissionAudio.m_nSampleIndex != NO_SAMPLE && m_sMissionAudio.m_nLoadingStatus == LOADING_STATUS_LOADED && - m_sMissionAudio.m_nPlayStatus == PLAY_STATUS_STOPPED) - m_sMissionAudio.m_bIsPlayed = true; + if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS && m_sMissionAudio.m_nSampleIndex[slot] != NO_SAMPLE && m_sMissionAudio.m_nLoadingStatus[slot] == LOADING_STATUS_LOADED && + m_sMissionAudio.m_nPlayStatus[slot] == PLAY_STATUS_STOPPED) + m_sMissionAudio.m_bIsPlayed[slot] = true; } bool -cAudioManager::IsMissionAudioSampleFinished() +cAudioManager::ShouldDuckMissionAudio(uint8 slot) const { - if (m_bIsInitialised) - return m_sMissionAudio.m_nPlayStatus == PLAY_STATUS_FINISHED; + if (IsMissionAudioSamplePlaying(slot)) + return m_sMissionAudio.m_nSampleIndex[slot] != STREAMED_SOUND_MISSION_ROK2_01; + return false; +} - static int32 cPretendFrame = 1; +bool +cAudioManager::IsMissionAudioSamplePlaying(uint8 slot) const +{ + if (m_bIsInitialised) { + if (slot < MISSION_AUDIO_SLOTS) + return m_sMissionAudio.m_nPlayStatus[slot] == PLAY_STATUS_PLAYING; + else + return true; + } else { + static int32 cPretendFrame[MISSION_AUDIO_SLOTS] = { 1, 1 }; - return (cPretendFrame++ & 63) == 0; + return (cPretendFrame[slot]++ % 64) != 0; + } } -void -cAudioManager::ClearMissionAudio() +bool +cAudioManager::IsMissionAudioSampleFinished(uint8 slot) { if (m_bIsInitialised) { - m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; - m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_NOT_LOADED; - m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_STOPPED; - m_sMissionAudio.field_22 = 0; - m_sMissionAudio.m_bIsPlayed = false; - m_sMissionAudio.m_bPredefinedProperties = true; - m_sMissionAudio.m_nMissionAudioCounter = 0; + if (slot < MISSION_AUDIO_SLOTS) + return m_sMissionAudio.m_nPlayStatus[slot] == PLAY_STATUS_FINISHED; + else + return true; } + + static int32 cPretendFrame[MISSION_AUDIO_SLOTS] = { 1, 1 }; + + return (cPretendFrame[slot]++ % 64) == 0; } void -cAudioManager::ProcessMissionAudio() +cAudioManager::ClearMissionAudio(uint8 slot) +{ + if (m_bIsInitialised && slot < MISSION_AUDIO_SLOTS) { + m_sMissionAudio.m_nSampleIndex[slot] = NO_SAMPLE; + m_sMissionAudio.m_nLoadingStatus[slot] = LOADING_STATUS_NOT_LOADED; + m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_STOPPED; + m_sMissionAudio.field_22[slot] = 0; + m_sMissionAudio.m_bIsPlayed[slot] = false; + m_sMissionAudio.m_bPredefinedProperties[slot] = true; + m_sMissionAudio.m_nMissionAudioCounter[slot] = 0; + } +} + +void +cAudioManager::ProcessMissionAudioSlot(uint8 slot) { float dist; uint8 emittingVol; @@ -5683,104 +5742,135 @@ cAudioManager::ProcessMissionAudio() float distSquared; CVector vec; - static uint8 nCheckPlayingDelay = 0; - static uint8 nFramesUntilFailedLoad = 0; - static uint8 nFramesForPretendPlaying = 0; + static uint8 nCheckPlayingDelay[MISSION_AUDIO_SLOTS] = { 0, 0 }; + static uint8 nFramesUntilFailedLoad[MISSION_AUDIO_SLOTS] = { 0, 0 }; + static uint8 nFramesForPretendPlaying[MISSION_AUDIO_SLOTS] = { 0, 0 }; - if (!m_bIsInitialised) return; - if (m_sMissionAudio.m_nSampleIndex == NO_SAMPLE) return; + if (m_sMissionAudio.m_nSampleIndex[slot] == NO_SAMPLE) return; - switch (m_sMissionAudio.m_nLoadingStatus) { + switch (m_sMissionAudio.m_nLoadingStatus[slot]) { case LOADING_STATUS_NOT_LOADED: - SampleManager.PreloadStreamedFile(m_sMissionAudio.m_nSampleIndex, 1); - m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_LOADED; - nFramesUntilFailedLoad = 0; + SampleManager.PreloadStreamedFile(m_sMissionAudio.m_nSampleIndex[slot], slot + 1); + m_sMissionAudio.m_nLoadingStatus[slot] = LOADING_STATUS_LOADED; + nFramesUntilFailedLoad[slot] = 0; break; case LOADING_STATUS_LOADED: - if (!m_sMissionAudio.m_bIsPlayed) + if (!m_sMissionAudio.m_bIsPlayed[slot]) return; - if (g_bMissionAudioLoadFailed) { + if (g_bMissionAudioLoadFailed[slot]) { if (m_bTimerJustReset) { - ClearMissionAudio(); - SampleManager.StopStreamedFile(1); - nFramesForPretendPlaying = 0; - nCheckPlayingDelay = 0; - nFramesUntilFailedLoad = 0; + ClearMissionAudio(slot); + SampleManager.StopStreamedFile(slot + 1); + nFramesForPretendPlaying[slot] = 0; + nCheckPlayingDelay[slot] = 0; + nFramesUntilFailedLoad[slot] = 0; } else if (!m_nUserPause) { - if (++nFramesForPretendPlaying < 120) { - m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_PLAYING; + if (++nFramesForPretendPlaying[slot] < 120) { + m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_PLAYING; } else { - m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_FINISHED; - m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; + m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_FINISHED; + m_sMissionAudio.m_nSampleIndex[slot] = NO_SAMPLE; } } break; } - switch (m_sMissionAudio.m_nPlayStatus) { + switch (m_sMissionAudio.m_nPlayStatus[slot]) { case PLAY_STATUS_STOPPED: - if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex)) { - SetMissionScriptPoliceAudio(m_sMissionAudio.m_nSampleIndex); + if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex[slot])) { + SetMissionScriptPoliceAudio(m_sMissionAudio.m_nSampleIndex[slot]); } else { if (m_nUserPause) - SampleManager.PauseStream(1, 1); + SampleManager.PauseStream(1, slot + 1); if (m_sMissionAudio.m_bPredefinedProperties) { - SampleManager.SetStreamedVolumeAndPan(80, 63, 1, 1); + if (m_sMissionAudio.m_nSampleIndex[slot] == STREAMED_SOUND_MISSION_CAMERAL) + SampleManager.SetStreamedVolumeAndPan(80, 0, 1, slot + 1); + else if (m_sMissionAudio.m_nSampleIndex[slot] == STREAMED_SOUND_MISSION_CAMERAR) + SampleManager.SetStreamedVolumeAndPan(80, 127, 1, slot + 1); + else + SampleManager.SetStreamedVolumeAndPan(80, 63, 1, slot + 1); } else { - distSquared = GetDistanceSquared(m_sMissionAudio.m_vecPos); - if (distSquared >= SQR(50.0f)) { + distSquared = GetDistanceSquared(m_sMissionAudio.m_vecPos[slot]); + if (distSquared >= SQR(80.0f)) { emittingVol = 0; pan = 63; } else { - dist = Sqrt(distSquared); - emittingVol = ComputeVolume(80, 50.0f, dist); - TranslateEntity(&m_sMissionAudio.m_vecPos, &vec); - pan = ComputePan(50.f, &vec); + emittingVol = 80; + if (distSquared > 0.0f) { + dist = Sqrt(distSquared); + emittingVol = ComputeVolume(80, 80.0f, dist); + } + TranslateEntity(&m_sMissionAudio.m_vecPos[slot], &vec); + pan = ComputePan(80.f, &vec); } - SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, 1, 1); + SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, 1, slot + 1); } - SampleManager.StartPreloadedStreamedFile(1); + SampleManager.StartPreloadedStreamedFile(slot + 1); } - m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_PLAYING; - nCheckPlayingDelay = 30; + m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_PLAYING; + nCheckPlayingDelay[slot] = 30; + if (m_sMissionAudio.m_nSampleIndex[slot] >= STREAMED_SOUND_MISSION_MOB_01A && m_sMissionAudio.m_nSampleIndex[slot] <= STREAMED_SOUND_MISSION_MOB_99A) + m_sMissionAudio.m_bIsMobile[slot] = true; break; case PLAY_STATUS_PLAYING: if (m_bTimerJustReset) { - ClearMissionAudio(); - SampleManager.StopStreamedFile(1); + ClearMissionAudio(slot); + SampleManager.StopStreamedFile(slot + 1); break; } - if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex)) { + if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex[slot])) { if (!m_nUserPause) { - if (nCheckPlayingDelay) { - --nCheckPlayingDelay; - } else if (GetMissionScriptPoliceAudioPlayingStatus() == PLAY_STATUS_FINISHED || m_sMissionAudio.m_nMissionAudioCounter-- == 0) { - m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_FINISHED; - m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; - SampleManager.StopStreamedFile(1); - m_sMissionAudio.m_nMissionAudioCounter = 0; + if (nCheckPlayingDelay[slot]) { + --nCheckPlayingDelay[slot]; + } else if (GetMissionScriptPoliceAudioPlayingStatus() == PLAY_STATUS_FINISHED || m_sMissionAudio.m_nMissionAudioCounter[slot]-- == 0) { + m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_FINISHED; + m_sMissionAudio.m_nSampleIndex[slot] = NO_SAMPLE; + SampleManager.StopStreamedFile(slot + 1); + m_sMissionAudio.m_nMissionAudioCounter[slot] = 0; } } - } else if (m_sMissionAudio.field_22) { - if (SampleManager.IsStreamPlaying(1) || m_nUserPause || m_nPreviousUserPause) { + } else if (m_sMissionAudio.field_22[slot]) { + if (SampleManager.IsStreamPlaying(slot + 1) || m_nUserPause || m_nPreviousUserPause) { if (m_nUserPause) - SampleManager.PauseStream(1, 1); + SampleManager.PauseStream(1, slot + 1); else - SampleManager.PauseStream(0, 1); + { + SampleManager.PauseStream(0, slot + 1); + if (!m_sMissionAudio.m_bPredefinedProperties) { + distSquared = GetDistanceSquared(m_sMissionAudio.m_vecPos[slot]); + if (distSquared >= SQR(80.0f)) { + emittingVol = 0; + pan = 63; + } else { + emittingVol = 127; + if (distSquared > 0.0f) { + dist = Sqrt(distSquared); + emittingVol = ComputeVolume(127, 80.0f, dist); + } + TranslateEntity(&m_sMissionAudio.m_vecPos[slot], &vec); + pan = ComputePan(80.f, &vec); + } + SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, 1, slot + 1); + } + } + } else if (m_sMissionAudio.m_nSampleIndex[slot] == STREAMED_SOUND_MISSION_ROK2_01) { + m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_STOPPED; } else { - m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_FINISHED; - m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; - SampleManager.StopStreamedFile(1); - m_sMissionAudio.m_nMissionAudioCounter = 0; + m_sMissionAudio.m_nPlayStatus[slot] = PLAY_STATUS_FINISHED; + if (m_sMissionAudio.m_nSampleIndex[slot] >= STREAMED_SOUND_MISSION_MOB_01A && m_sMissionAudio.m_nSampleIndex[slot] <= STREAMED_SOUND_MISSION_MOB_99A) + m_sMissionAudio.m_bIsMobile[slot] = false; + m_sMissionAudio.m_nSampleIndex[slot] = NO_SAMPLE; + SampleManager.StopStreamedFile(slot + 1); + m_sMissionAudio.m_nMissionAudioCounter[slot] = 0; } } else { if (m_nUserPause) break; - if (nCheckPlayingDelay--) { - if (!SampleManager.IsStreamPlaying(1)) + if (nCheckPlayingDelay[slot]--) { + if (!SampleManager.IsStreamPlaying(slot + 1)) break; - nCheckPlayingDelay = 0; + nCheckPlayingDelay[slot] = 0; } - m_sMissionAudio.field_22 = 1; + m_sMissionAudio.field_22[slot] = 1; } break; default: @@ -5788,15 +5878,32 @@ cAudioManager::ProcessMissionAudio() } break; case LOADING_STATUS_FAILED: - if (++nFramesUntilFailedLoad >= 90) { - nFramesForPretendPlaying = 0; - g_bMissionAudioLoadFailed = true; - nFramesUntilFailedLoad = 0; - m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_LOADED; + if (++nFramesUntilFailedLoad[slot] >= 90) { + nFramesForPretendPlaying[slot] = 0; + g_bMissionAudioLoadFailed[slot] = true; + nFramesUntilFailedLoad[slot] = 0; + m_sMissionAudio.m_nLoadingStatus[slot] = LOADING_STATUS_LOADED; } break; default: break; } } + +void +cAudioManager::ProcessMissionAudio() +{ + if (!m_bIsInitialised) return; + + for (int i = 0; i < MISSION_AUDIO_SLOTS; i++) + ProcessMissionAudioSlot(i); + + if (m_sMissionAudio.m_bIsMobile[0] || m_sMissionAudio.m_bIsMobile[1]) + field_5538 = 64; + else if (field_5538 < 127) { + field_5538 += 5; + if (field_5538 > 127) + field_5538 = 127; + } +} #pragma endregion All the mission audio stuff \ No newline at end of file diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index c34ad90a..d8d28e1e 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -257,7 +257,8 @@ cAudioManager::ResetTimers(uint32 time) m_nActiveSampleQueue = 0; } ClearActiveSamples(); - ClearMissionAudio(); + ClearMissionAudio(0); + ClearMissionAudio(1); SampleManager.StopChannel(policeChannel); SampleManager.SetEffectsFadeVolume(0); SampleManager.SetMusicFadeVolume(0); @@ -280,7 +281,7 @@ cAudioManager::DestroyAllGameCreatedEntities() case AUDIOTYPE_PHYSICAL: case AUDIOTYPE_EXPLOSION: case AUDIOTYPE_WEATHER: - case AUDIOTYPE_CRANE: + //case AUDIOTYPE_CRANE: case AUDIOTYPE_GARAGE: case AUDIOTYPE_FIREHYDRANT: DestroyEntity(i); diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index b31d960c..e89efbd2 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -28,6 +28,7 @@ public: uint8 m_nLoopsRemaining; bool m_bRequireReflection; // Used for oneshots uint8 m_nOffset; + uint8 field_4C; int32 m_nReleasingVolumeDivider; bool m_bIsProcessed; bool m_bLoopEnded; @@ -35,7 +36,7 @@ public: int8 m_nVolumeChange; }; -VALIDATE_SIZE(tSound, 92); +VALIDATE_SIZE(tSound, 96); class CPhysical; class CAutomobile; @@ -95,19 +96,24 @@ VALIDATE_SIZE(cPedComments, 1164); class CEntity; +#define MISSION_AUDIO_SLOTS (2) + +// So instead of doing cMissionAudio [2] they've added [2] to every field of the struct... +// Only someone with a VERY EXTRAORDINARY mind could have come up with that class cMissionAudio { public: - CVector m_vecPos; - bool m_bPredefinedProperties; - int32 m_nSampleIndex; - uint8 m_nLoadingStatus; - uint8 m_nPlayStatus; - uint8 field_22; // todo find a name - int32 m_nMissionAudioCounter; - bool m_bIsPlayed; + CVector m_vecPos[MISSION_AUDIO_SLOTS]; + bool m_bPredefinedProperties[MISSION_AUDIO_SLOTS]; + int32 m_nSampleIndex[MISSION_AUDIO_SLOTS]; + uint8 m_nLoadingStatus[MISSION_AUDIO_SLOTS]; + uint8 m_nPlayStatus[MISSION_AUDIO_SLOTS]; + uint8 field_22[MISSION_AUDIO_SLOTS]; // todo find a name + int32 m_nMissionAudioCounter[MISSION_AUDIO_SLOTS]; + bool m_bIsPlayed[MISSION_AUDIO_SLOTS]; + bool m_bIsMobile[MISSION_AUDIO_SLOTS]; }; -VALIDATE_SIZE(cMissionAudio, 32); +VALIDATE_SIZE(cMissionAudio, 0x38); // name made up class cAudioScriptObjectManager @@ -188,6 +194,14 @@ public: CVector m_avecReflectionsPos[NUM_AUDIO_REFLECTIONS]; float m_afReflectionsDistances[NUM_AUDIO_REFLECTIONS]; cAudioScriptObjectManager m_sAudioScriptObjectManager; + + // miami + uint8 field_4B30; + uint8 m_bPlayerMood; + uint32 field_4B34; + uint8 field_rest[4]; + uint8 field_4B3C; + cPedComments m_sPedComments; int32 m_nFireAudioEntity; int32 m_nWaterCannonEntity; @@ -197,13 +211,19 @@ public: int32 m_nCollisionEntity; cAudioCollisionManager m_sCollisionManager; int32 m_nProjectileEntity; +#ifdef GTA_BRIDGE int32 m_nBridgeEntity; +#endif + int32 m_nEscalatorEntity; + int32 m_nExtraSoundsEntity; cMissionAudio m_sMissionAudio; + uint8 field_5538; // something related to phone dialogues int32 m_anRandomTable[5]; uint8 m_nTimeSpent; uint8 m_nUserPause; uint8 m_nPreviousUserPause; uint32 m_FrameCounter; + uint32 field_5554; cAudioManager(); ~cAudioManager(); @@ -213,7 +233,8 @@ public: float GetReflectionsDistance(int32 idx) const { return m_afReflectionsDistances[idx]; } int32 GetRandomNumber(int32 idx) const { return m_anRandomTable[idx]; } int32 GetRandomNumberInRange(int32 idx, int32 low, int32 high) const { return (m_anRandomTable[idx] % (high - low + 1)) + low; } - bool IsMissionAudioSamplePlaying() const { return m_sMissionAudio.m_nPlayStatus == 1; } + bool IsMissionAudioSamplePlaying(uint8 slot) const;// { return m_sMissionAudio.m_nPlayStatus == 1; } + bool ShouldDuckMissionAudio(uint8 slot) const; // "Should" be in alphabetic order, except "getXTalkSfx" void AddDetailsToRequestedOrderList(uint8 sample); @@ -227,7 +248,7 @@ public: void CalculateDistance(bool &condition, float dist); bool CheckForAnAudioFileOnCD() const; void ClearActiveSamples(); - void ClearMissionAudio(); + void ClearMissionAudio(uint8 slot); void ClearRequestedQueue(); int32 ComputeDopplerEffectedFrequency(uint32 oldFreq, float position1, float position2, float speedMultiplier) const; @@ -253,7 +274,7 @@ public: float GetCollisionRatio(float a, float b, float c, float d) const; float GetDistanceSquared(const CVector &v) const; int32 GetJumboTaxiFreq() const; - uint8 GetMissionAudioLoadingStatus() const; + uint8 GetMissionAudioLoadingStatus(uint8 slot) const; int8 GetMissionScriptPoliceAudioPlayingStatus() const; uint8 GetNum3DProvidersAvailable() const; int32 GetPedCommentSfx(CPed *ped, int32 sound); @@ -270,12 +291,12 @@ public: void InitialisePoliceRadioZones(); void InterrogateAudioEntities(); bool IsAudioInitialised() const; - bool IsMissionAudioSampleFinished(); + bool IsMissionAudioSampleFinished(uint8 slot); bool IsMP3RadioChannelAvailable() const; bool MissionScriptAudioUsesPoliceChannel(int32 soundMission) const; - void PlayLoadedMissionAudio(); + void PlayLoadedMissionAudio(uint8 slot); void PlayOneShot(int32 index, int16 sound, float vol); void PlaySuspectLastSeen(float x, float y, float z); void PlayerJustGotInCar() const; @@ -283,7 +304,7 @@ public: void PostInitialiseGameSpecificSetup(); void PostTerminateGameSpecificShutdown(); void PreInitialiseGameSpecificSetup() const; - void PreloadMissionAudio(Const char *name); + void PreloadMissionAudio(uint8 slot, Const char *name); void PreTerminateGameSpecificShutdown(); /// processX - main logic of adding new sounds void ProcessActiveQueues(); @@ -316,6 +337,7 @@ public: void ProcessJumboTaxi(); void ProcessLoopingScriptObject(uint8 sound); void ProcessMissionAudio(); + void ProcessMissionAudioSlot(uint8 slot); void ProcessModelCarEngine(cVehicleParams *params); void ProcessOneShotScriptObject(uint8 sound); void ProcessPed(CPhysical *ped); @@ -366,7 +388,7 @@ public: void SetEffectsMasterVolume(uint8 volume) const; void SetEntityStatus(int32 id, uint8 status); uint32 SetLoopingCollisionRequestedSfxFreqAndGetVol(const cAudioCollision &audioCollision); - void SetMissionAudioLocation(float x, float y, float z); + void SetMissionAudioLocation(uint8 slot, float x, float y, float z); void SetMissionScriptPoliceAudio(int32 sfx) const; void SetMonoMode(uint8); // todo (mobile) void SetMusicFadeVol(uint8 volume) const; @@ -400,7 +422,7 @@ public: }; #ifdef AUDIO_MSS -static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error"); +static_assert(sizeof(cAudioManager) == 0x5558, "cAudioManager: error"); #endif extern cAudioManager AudioManager; diff --git a/src/audio/DMAudio.cpp b/src/audio/DMAudio.cpp index 76b134ec..7f2dd176 100644 --- a/src/audio/DMAudio.cpp +++ b/src/audio/DMAudio.cpp @@ -290,39 +290,39 @@ cDMAudio::StopCutSceneMusic(void) } void -cDMAudio::PreloadMissionAudio(Const char *missionAudio) +cDMAudio::PreloadMissionAudio(uint8 slot, Const char *missionAudio) { - AudioManager.PreloadMissionAudio(missionAudio); + AudioManager.PreloadMissionAudio(slot, missionAudio); } uint8 -cDMAudio::GetMissionAudioLoadingStatus(void) +cDMAudio::GetMissionAudioLoadingStatus(uint8 slot) { - return AudioManager.GetMissionAudioLoadingStatus(); + return AudioManager.GetMissionAudioLoadingStatus(slot); } void -cDMAudio::SetMissionAudioLocation(float x, float y, float z) +cDMAudio::SetMissionAudioLocation(uint8 slot, float x, float y, float z) { - AudioManager.SetMissionAudioLocation(x, y, z); + AudioManager.SetMissionAudioLocation(slot, x, y, z); } void -cDMAudio::PlayLoadedMissionAudio(void) +cDMAudio::PlayLoadedMissionAudio(uint8 slot) { - AudioManager.PlayLoadedMissionAudio(); + AudioManager.PlayLoadedMissionAudio(slot); } bool -cDMAudio::IsMissionAudioSampleFinished(void) +cDMAudio::IsMissionAudioSampleFinished(uint8 slot) { - return AudioManager.IsMissionAudioSampleFinished(); + return AudioManager.IsMissionAudioSampleFinished(slot); } void -cDMAudio::ClearMissionAudio(void) +cDMAudio::ClearMissionAudio(uint8 slot) { - AudioManager.ClearMissionAudio(); + AudioManager.ClearMissionAudio(slot); } uint8 diff --git a/src/audio/DMAudio.h b/src/audio/DMAudio.h index c0e1de1d..378b90b2 100644 --- a/src/audio/DMAudio.h +++ b/src/audio/DMAudio.h @@ -76,12 +76,12 @@ public: void PlayPreloadedCutSceneMusic(void); void StopCutSceneMusic(void); - void PreloadMissionAudio(Const char *missionAudio); - uint8 GetMissionAudioLoadingStatus(void); - void SetMissionAudioLocation(float x, float y, float z); - void PlayLoadedMissionAudio(void); - bool IsMissionAudioSampleFinished(void); - void ClearMissionAudio(void); + void PreloadMissionAudio(uint8 slot, Const char *missionAudio); + uint8 GetMissionAudioLoadingStatus(uint8 slot); + void SetMissionAudioLocation(uint8 slot, float x, float y, float z); + void PlayLoadedMissionAudio(uint8 slot); + bool IsMissionAudioSampleFinished(uint8 slot); + void ClearMissionAudio(uint8 slot); uint8 GetRadioInCar(void); void SetRadioInCar(uint32 radio); diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp index ca253fba..9fb1991e 100644 --- a/src/audio/MusicManager.cpp +++ b/src/audio/MusicManager.cpp @@ -524,7 +524,7 @@ cMusicManager::ServiceGameMode() } else if (dist >= 100.0f) { int8 volume = ((45.0f - (Sqrt(dist) - 10.0f)) / 45.0f * 100.0f); int8 pan; - if (AudioManager.IsMissionAudioSamplePlaying()) + if (AudioManager.ShouldDuckMissionAudio(0) || AudioManager.ShouldDuckMissionAudio(1)) volume /= 4; if (volume != 0) { CVector trVec; @@ -536,7 +536,7 @@ cMusicManager::ServiceGameMode() if (gRetuneCounter) volume /= 4; SampleManager.SetStreamedVolumeAndPan(volume, pan, 0, 0); - } else if (AudioManager.IsMissionAudioSamplePlaying()) { + } else if (AudioManager.ShouldDuckMissionAudio(0) || AudioManager.ShouldDuckMissionAudio(1)) { SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0); } else if (gRetuneCounter) { SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0); @@ -544,7 +544,7 @@ cMusicManager::ServiceGameMode() SampleManager.SetStreamedVolumeAndPan(100, 63, 0, 0); } } - } else if (AudioManager.IsMissionAudioSamplePlaying()) { + } else if (AudioManager.ShouldDuckMissionAudio(0) || AudioManager.ShouldDuckMissionAudio(1)) { SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0); nFramesSinceCutsceneEnded = 0; } else { @@ -830,7 +830,7 @@ cMusicManager::ServiceAnnouncement() SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0); if (SampleManager.StartStreamedFile(m_nAnnouncement, 0, 0)) { - SampleManager.SetStreamedVolumeAndPan(AudioManager.IsMissionAudioSamplePlaying() ? 25 : 100, 63, 0, 0); + SampleManager.SetStreamedVolumeAndPan((AudioManager.IsMissionAudioSamplePlaying(0) || AudioManager.IsMissionAudioSamplePlaying(1)) ? 25 : 100, 63, 0, 0); m_bAnnouncementInProgress = true; m_nPreviousStreamedSound = m_nCurrentStreamedSound; m_nCurrentStreamedSound = m_nAnnouncement; @@ -903,7 +903,7 @@ cMusicManager::ChangeRadioChannel() return false; if (!SampleManager.StartStreamedFile(m_nCurrentStreamedSound, GetTrackStartPos(m_nCurrentStreamedSound), 0)) return false; - SampleManager.SetStreamedVolumeAndPan(AudioManager.IsMissionAudioSamplePlaying() ? 25 : 100, 63, 0, 0); + SampleManager.SetStreamedVolumeAndPan((AudioManager.IsMissionAudioSamplePlaying(0) || AudioManager.IsMissionAudioSamplePlaying(1)) ? 25 : 100, 63, 0, 0); } return true; } diff --git a/src/audio/audio_enums.h b/src/audio/audio_enums.h index 90b87f1d..1f13521b 100644 --- a/src/audio/audio_enums.h +++ b/src/audio/audio_enums.h @@ -1267,18 +1267,21 @@ enum AudioEntityHandle { enum eAudioType : int32 { AUDIOTYPE_PHYSICAL = 0, - AUDIOTYPE_EXPLOSION = 1, - AUDIOTYPE_FIRE = 2, - AUDIOTYPE_WEATHER = 3, - AUDIOTYPE_CRANE = 4, - AUDIOTYPE_SCRIPTOBJECT = 5, - AUDIOTYPE_BRIDGE = 6, - AUDIOTYPE_COLLISION = 7, - AUDIOTYPE_FRONTEND = 8, - AUDIOTYPE_PROJECTILE = 9, - AUDIOTYPE_GARAGE = 10, - AUDIOTYPE_FIREHYDRANT = 11, - AUDIOTYPE_WATERCANNON = 12, - AUDIOTYPE_POLICERADIO = 13, - TOTAL_AUDIO_TYPES = 14, + AUDIOTYPE_EXPLOSION, + AUDIOTYPE_FIRE, + AUDIOTYPE_WEATHER, + AUDIOTYPE_SCRIPTOBJECT, +#ifdef GTA_BRIDGE + AUDIOTYPE_BRIDGE, +#endif + AUDIOTYPE_COLLISION, + AUDIOTYPE_FRONTEND, + AUDIOTYPE_PROJECTILE, + AUDIOTYPE_GARAGE, + AUDIOTYPE_FIREHYDRANT, + AUDIOTYPE_WATERCANNON, + AUDIOTYPE_ESCALATOR, + AUDIOTYPE_EXTRA_SOUNDS, + AUDIOTYPE_POLICERADIO, + TOTAL_AUDIO_TYPES, }; diff --git a/src/audio/sampman.h b/src/audio/sampman.h index 6ed239b1..04f2e0c4 100644 --- a/src/audio/sampman.h +++ b/src/audio/sampman.h @@ -105,7 +105,7 @@ enum #define MAX2DCHANNELS 1 #define CHANNEL2D MAXCHANNELS -#define MAX_STREAMS 2 +#define MAX_STREAMS 3 #define DIGITALRATE 32000 #define DIGITALBITS 16 diff --git a/src/control/GameLogic.cpp b/src/control/GameLogic.cpp index a98315e2..50e5584d 100644 --- a/src/control/GameLogic.cpp +++ b/src/control/GameLogic.cpp @@ -193,15 +193,15 @@ CGameLogic::Update() pPlayerInfo.m_nBustedAudioStatus = BUSTEDAUDIO_LOADING; char name[12]; sprintf(name, pPlayerInfo.m_nCurrentBustedAudio >= 10 ? "bust_%d" : "bust_0%d", pPlayerInfo.m_nCurrentBustedAudio); - DMAudio.ClearMissionAudio(); // TODO(MIAMI): argument is 0 - DMAudio.PreloadMissionAudio(name); // TODO(MIAMI): argument is 0 + DMAudio.ClearMissionAudio(0); + DMAudio.PreloadMissionAudio(0, name); pPlayerInfo.m_nCurrentBustedAudio = pPlayerInfo.m_nCurrentBustedAudio % 28 + 1; // enum? const? TODO } } if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > 4000 && pPlayerInfo.m_nBustedAudioStatus == BUSTEDAUDIO_LOADING && - DMAudio.GetMissionAudioLoadingStatus() == 1) { // TODO: argument is 0 - DMAudio.PlayLoadedMissionAudio(); // TODO: argument is 0 + DMAudio.GetMissionAudioLoadingStatus(0) == 1) { + DMAudio.PlayLoadedMissionAudio(0); pPlayerInfo.m_nBustedAudioStatus = BUSTEDAUDIO_DONE; } diff --git a/src/control/Script.cpp b/src/control/Script.cpp index ff516136..d25fb173 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -318,8 +318,8 @@ void CMissionCleanup::Process() //CSpecialFX::bLiftCam = false; //CSpecialFX::bVideoCam = false; //CTimeCycle::StopExtraColour(0); - // TODO(MIAMI): change this to loop when it supports parameters - DMAudio.ClearMissionAudio(); + for (int i = 0; i < MISSION_AUDIO_SLOTS; i++) + DMAudio.ClearMissionAudio(i); CWeather::ReleaseWeather(); for (int i = 0; i < NUM_OF_SPECIAL_CHARS; i++) CStreaming::SetMissionDoesntRequireSpecialChar(i); @@ -8662,42 +8662,24 @@ int8 CRunningScript::ProcessCommands900To999(int32 command) strncpy(str, (char*)&CTheScripts::ScriptSpace[m_nIp], KEY_LENGTH_IN_SCRIPT); for (int i = 0; i < KEY_LENGTH_IN_SCRIPT; i++) str[i] = tolower(str[i]); - static bool bShowed = false; m_nIp += KEY_LENGTH_IN_SCRIPT; - if (!bShowed) { - debug("LOAD_MISSION_AUDIO not implemented\n"); - bShowed = true; - } - //DMAudio.PreloadMissionAudio(str); + DMAudio.PreloadMissionAudio(ScriptParams[0] - 1, str); return 0; } case COMMAND_HAS_MISSION_AUDIO_LOADED: { CollectParameters(&m_nIp, 1); - static bool bShowed = false; - if (!bShowed) { - debug("HAS_MISSION_AUDIO_LOADED not implemented, default to TRUE\n"); - bShowed = true; - } - UpdateCompareFlag(true); - //UpdateCompareFlag(DMAudio.GetMissionAudioLoadingStatus() == 1); + UpdateCompareFlag(DMAudio.GetMissionAudioLoadingStatus(ScriptParams[0] - 1) == 1); return 0; } case COMMAND_PLAY_MISSION_AUDIO: CollectParameters(&m_nIp, 1); - debug("PLAY_MISSION_AUDIO doesn't support parameter yet, skipping\n"); - //DMAudio.PlayLoadedMissionAudio(); + DMAudio.PlayLoadedMissionAudio(ScriptParams[0] - 1); return 0; case COMMAND_HAS_MISSION_AUDIO_FINISHED: { CollectParameters(&m_nIp, 1); - static bool bShowed = false; - if (!bShowed) { - debug("HAS_MISSION_AUDIO_FINISHED not implemented, default to TRUE\n"); - bShowed = true; - } - UpdateCompareFlag(true); - //UpdateCompareFlag(DMAudio.IsMissionAudioSampleFinished()); + UpdateCompareFlag(DMAudio.IsMissionAudioSampleFinished(ScriptParams[0] - 1)); return 0; } case COMMAND_GET_CLOSEST_CAR_NODE_WITH_HEADING: @@ -8735,12 +8717,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command) { CollectParameters(&m_nIp, 4); CVector pos = *(CVector*)&ScriptParams[1]; - static bool bShowed = false; - if (!bShowed) { - debug("SET_MISSION_AUDIO_POSITION not implemented\n"); - bShowed = true; - } - //DMAudio.SetMissionAudioLocation(pos.x, pos.y, pos.z); + DMAudio.SetMissionAudioLocation(ScriptParams[0] - 1, pos.x, pos.y, pos.z); return 0; } case COMMAND_ACTIVATE_SAVE_MENU: diff --git a/src/core/config.h b/src/core/config.h index b0ef3f67..104c78c9 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -126,9 +126,9 @@ enum Config { NUM_SOUNDS_SAMPLES_BANKS = 2, NUM_SOUNDS_SAMPLES_SLOTS = 27, - NUM_AUDIOENTITIES = 200, + NUM_AUDIOENTITIES = 250, - NUM_AUDIO_REFLECTIONS = 5, + NUM_AUDIO_REFLECTIONS = 8, NUM_SCRIPT_MAX_ENTITIES = 40, NUM_GARAGE_STORED_CARS = 4, diff --git a/src/vehicles/Cranes.cpp b/src/vehicles/Cranes.cpp index db7b514f..c8fa1c22 100644 --- a/src/vehicles/Cranes.cpp +++ b/src/vehicles/Cranes.cpp @@ -84,9 +84,6 @@ void CCranes::AddThisOneCrane(CEntity* pEntity) pCrane->m_nTimeForNextCheck = 0; pCrane->m_nCraneState = CCrane::IDLE; pCrane->m_bWasMilitaryCrane = false; - pCrane->m_nAudioEntity = DMAudio.CreateEntity(AUDIOTYPE_CRANE, &aCranes[NumCranes]); - if (pCrane->m_nAudioEntity >= 0) - DMAudio.SetEntityStatus(pCrane->m_nAudioEntity, 1); pCrane->m_bIsTop = (MODELID_CRANE_1 != pEntity->GetModelIndex()); #if 0 // Is this used to avoid military crane? @@ -669,11 +666,11 @@ void CCranes::Load(uint8* buf, uint32 size) if (pCrane->m_pVehiclePickedUp != nil) pCrane->m_pVehiclePickedUp = CPools::GetVehiclePool()->GetSlot((uintptr)pCrane->m_pVehiclePickedUp - 1); } - for (int i = 0; i < NUM_CRANES; i++) { + /*for (int i = 0; i < NUM_CRANES; i++) { aCranes[i].m_nAudioEntity = DMAudio.CreateEntity(AUDIOTYPE_CRANE, &aCranes[i]); if (aCranes[i].m_nAudioEntity != 0) DMAudio.SetEntityStatus(aCranes[i].m_nAudioEntity, 1); - } + }*/ VALIDATESAVEBUF(size); }