summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/audio/AudioLogic.cpp110
-rw-r--r--src/audio/AudioManager.h32
-rw-r--r--src/audio/PolRadio.cpp84
-rw-r--r--src/audio/PolRadio.h48
4 files changed, 141 insertions, 133 deletions
diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp
index b1f269ec..d09352be 100644
--- a/src/audio/AudioLogic.cpp
+++ b/src/audio/AudioLogic.cpp
@@ -154,13 +154,13 @@ cAudioManager::PostInitialiseGameSpecificSetup()
if (m_nBridgeEntity >= 0)
SetEntityStatus(m_nBridgeEntity, TRUE);
- m_sMissionAudio.m_nSampleIndex = NO_SAMPLE;
- m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_NOT_LOADED;
- m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_STOPPED;
- m_sMissionAudio.m_bIsPlaying = FALSE;
- m_sMissionAudio.m_bIsPlayed = FALSE;
- m_sMissionAudio.m_bPredefinedProperties = TRUE;
- m_sMissionAudio.m_nMissionAudioCounter = 0;
+ m_nMissionAudioSampleIndex = NO_SAMPLE;
+ m_nMissionAudioLoadingStatus = LOADING_STATUS_NOT_LOADED;
+ m_nMissionAudioPlayStatus = PLAY_STATUS_STOPPED;
+ m_bIsMissionAudioPlaying = FALSE;
+ m_bIsMissionAudioAllowedToPlay = FALSE;
+ m_bIsMissionAudio2D = TRUE;
+ m_nMissionAudioFramesToPlay = 0;
ResetAudioLogicTimers(CTimer::GetTimeInMilliseconds());
}
@@ -8479,14 +8479,14 @@ cAudioManager::PreloadMissionAudio(Const char *name)
if (m_bIsInitialised) {
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.m_bIsPlaying = FALSE;
- m_sMissionAudio.m_nMissionAudioCounter = m_nTimeSpent * SampleManager.GetStreamedFileLength(missionAudioSfx) / 1000;
- m_sMissionAudio.m_nMissionAudioCounter *= 4;
- m_sMissionAudio.m_bIsPlayed = FALSE;
- m_sMissionAudio.m_bPredefinedProperties = TRUE;
+ m_nMissionAudioSampleIndex = missionAudioSfx;
+ m_nMissionAudioLoadingStatus = LOADING_STATUS_NOT_LOADED;
+ m_nMissionAudioPlayStatus = PLAY_STATUS_STOPPED;
+ m_bIsMissionAudioPlaying = FALSE;
+ m_nMissionAudioFramesToPlay = m_nTimeSpent * SampleManager.GetStreamedFileLength(missionAudioSfx) / 1000;
+ m_nMissionAudioFramesToPlay *= 4;
+ m_bIsMissionAudioAllowedToPlay = FALSE;
+ m_bIsMissionAudio2D = TRUE;
g_bMissionAudioLoadFailed = FALSE;
}
}
@@ -8496,7 +8496,7 @@ uint8
cAudioManager::GetMissionAudioLoadingStatus()
{
if (m_bIsInitialised)
- return m_sMissionAudio.m_nLoadingStatus;
+ return m_nMissionAudioLoadingStatus;
return LOADING_STATUS_LOADED;
}
@@ -8505,24 +8505,24 @@ void
cAudioManager::SetMissionAudioLocation(float x, float y, float z)
{
if (m_bIsInitialised) {
- m_sMissionAudio.m_bPredefinedProperties = FALSE;
- m_sMissionAudio.m_vecPos = CVector(x, y, z);
+ m_bIsMissionAudio2D = FALSE;
+ m_vecMissionAudioPosition = CVector(x, y, z);
}
}
void
cAudioManager::PlayLoadedMissionAudio()
{
- 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 && m_nMissionAudioSampleIndex != NO_SAMPLE && m_nMissionAudioLoadingStatus == LOADING_STATUS_LOADED &&
+ m_nMissionAudioPlayStatus == PLAY_STATUS_STOPPED)
+ m_bIsMissionAudioAllowedToPlay = TRUE;
}
bool8
cAudioManager::IsMissionAudioSampleFinished()
{
if (m_bIsInitialised)
- return m_sMissionAudio.m_nPlayStatus == PLAY_STATUS_FINISHED;
+ return m_nMissionAudioPlayStatus == PLAY_STATUS_FINISHED;
static int32 cPretendFrame = 1;
@@ -8533,13 +8533,13 @@ void
cAudioManager::ClearMissionAudio()
{
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.m_bIsPlaying = FALSE;
- m_sMissionAudio.m_bIsPlayed = FALSE;
- m_sMissionAudio.m_bPredefinedProperties = TRUE;
- m_sMissionAudio.m_nMissionAudioCounter = 0;
+ m_nMissionAudioSampleIndex = NO_SAMPLE;
+ m_nMissionAudioLoadingStatus = LOADING_STATUS_NOT_LOADED;
+ m_nMissionAudioPlayStatus = PLAY_STATUS_STOPPED;
+ m_bIsMissionAudioPlaying = FALSE;
+ m_bIsMissionAudioAllowedToPlay = FALSE;
+ m_bIsMissionAudio2D = TRUE;
+ m_nMissionAudioFramesToPlay = 0;
}
}
@@ -8557,16 +8557,16 @@ cAudioManager::ProcessMissionAudio()
static uint8 nFramesForPretendPlaying = 0;
if (!m_bIsInitialised) return;
- if (m_sMissionAudio.m_nSampleIndex == NO_SAMPLE) return;
+ if (m_nMissionAudioSampleIndex == NO_SAMPLE) return;
- switch (m_sMissionAudio.m_nLoadingStatus) {
+ switch (m_nMissionAudioLoadingStatus) {
case LOADING_STATUS_NOT_LOADED:
- SampleManager.PreloadStreamedFile(m_sMissionAudio.m_nSampleIndex, 1);
- m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_LOADED;
+ SampleManager.PreloadStreamedFile(m_nMissionAudioSampleIndex, 1);
+ m_nMissionAudioLoadingStatus = LOADING_STATUS_LOADED;
nFramesUntilFailedLoad = 0;
break;
case LOADING_STATUS_LOADED:
- if (!m_sMissionAudio.m_bIsPlayed)
+ if (!m_bIsMissionAudioAllowedToPlay)
return;
if (g_bMissionAudioLoadFailed) {
if (m_bTimerJustReset) {
@@ -8577,39 +8577,39 @@ cAudioManager::ProcessMissionAudio()
nFramesUntilFailedLoad = 0;
} else if (!m_nUserPause) {
if (++nFramesForPretendPlaying < 120) {
- m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_PLAYING;
+ m_nMissionAudioPlayStatus = PLAY_STATUS_PLAYING;
} else {
- m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_FINISHED;
- m_sMissionAudio.m_nSampleIndex = NO_SAMPLE;
+ m_nMissionAudioPlayStatus = PLAY_STATUS_FINISHED;
+ m_nMissionAudioSampleIndex = NO_SAMPLE;
}
}
break;
}
- switch (m_sMissionAudio.m_nPlayStatus) {
+ switch (m_nMissionAudioPlayStatus) {
case PLAY_STATUS_STOPPED:
- if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex)) {
- SetMissionScriptPoliceAudio(m_sMissionAudio.m_nSampleIndex);
+ if (MissionScriptAudioUsesPoliceChannel(m_nMissionAudioSampleIndex)) {
+ SetMissionScriptPoliceAudio(m_nMissionAudioSampleIndex);
} else {
if (m_nUserPause)
SampleManager.PauseStream(TRUE, 1);
- if (m_sMissionAudio.m_bPredefinedProperties) {
+ if (m_bIsMissionAudio2D) {
SampleManager.SetStreamedVolumeAndPan(80, 63, TRUE, 1);
} else {
- distSquared = GetDistanceSquared(m_sMissionAudio.m_vecPos);
+ distSquared = GetDistanceSquared(m_vecMissionAudioPosition);
if (distSquared >= SQR(50.0f)) {
emittingVol = 0;
pan = 63;
} else {
dist = Sqrt(distSquared);
emittingVol = ComputeVolume(80, 50.0f, dist);
- TranslateEntity(&m_sMissionAudio.m_vecPos, &vec);
+ TranslateEntity(&m_vecMissionAudioPosition, &vec);
pan = ComputePan(50.f, &vec);
}
SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, TRUE, 1);
}
SampleManager.StartPreloadedStreamedFile(1);
}
- m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_PLAYING;
+ m_nMissionAudioPlayStatus = PLAY_STATUS_PLAYING;
nCheckPlayingDelay = 30;
break;
case PLAY_STATUS_PLAYING:
@@ -8618,28 +8618,28 @@ cAudioManager::ProcessMissionAudio()
SampleManager.StopStreamedFile(1);
break;
}
- if (MissionScriptAudioUsesPoliceChannel(m_sMissionAudio.m_nSampleIndex)) {
+ if (MissionScriptAudioUsesPoliceChannel(m_nMissionAudioSampleIndex)) {
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;
+ } else if (GetMissionScriptPoliceAudioPlayingStatus() == PLAY_STATUS_FINISHED || m_nMissionAudioFramesToPlay-- == 0) {
+ m_nMissionAudioPlayStatus = PLAY_STATUS_FINISHED;
+ m_nMissionAudioSampleIndex = NO_SAMPLE;
SampleManager.StopStreamedFile(1);
- m_sMissionAudio.m_nMissionAudioCounter = 0;
+ m_nMissionAudioFramesToPlay = 0;
}
}
- } else if (m_sMissionAudio.m_bIsPlaying) {
+ } else if (m_bIsMissionAudioPlaying) {
if (SampleManager.IsStreamPlaying(1) || m_nUserPause || m_nPreviousUserPause) {
if (m_nUserPause)
SampleManager.PauseStream(TRUE, 1);
else
SampleManager.PauseStream(FALSE, 1);
} else {
- m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_FINISHED;
- m_sMissionAudio.m_nSampleIndex = NO_SAMPLE;
+ m_nMissionAudioPlayStatus = PLAY_STATUS_FINISHED;
+ m_nMissionAudioSampleIndex = NO_SAMPLE;
SampleManager.StopStreamedFile(1);
- m_sMissionAudio.m_nMissionAudioCounter = 0;
+ m_nMissionAudioFramesToPlay = 0;
}
} else {
if (m_nUserPause)
@@ -8649,7 +8649,7 @@ cAudioManager::ProcessMissionAudio()
break;
nCheckPlayingDelay = 0;
}
- m_sMissionAudio.m_bIsPlaying = TRUE;
+ m_bIsMissionAudioPlaying = TRUE;
}
break;
default:
@@ -8661,7 +8661,7 @@ cAudioManager::ProcessMissionAudio()
nFramesForPretendPlaying = 0;
g_bMissionAudioLoadFailed = TRUE;
nFramesUntilFailedLoad = 0;
- m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_LOADED;
+ m_nMissionAudioLoadingStatus = LOADING_STATUS_LOADED;
}
break;
default:
diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h
index efff4f39..39fa9288 100644
--- a/src/audio/AudioManager.h
+++ b/src/audio/AudioManager.h
@@ -123,22 +123,6 @@ public:
VALIDATE_SIZE(cPedComments, 1164);
-class CEntity;
-
-class cMissionAudio
-{
-public:
- CVector m_vecPos;
- bool8 m_bPredefinedProperties;
- uint32 m_nSampleIndex;
- uint8 m_nLoadingStatus;
- uint8 m_nPlayStatus;
- bool8 m_bIsPlaying;
- int32 m_nMissionAudioCounter;
- bool8 m_bIsPlayed;
-};
-VALIDATE_SIZE(cMissionAudio, 32);
-
// name made up
class cAudioScriptObjectManager
{
@@ -152,6 +136,7 @@ public:
class cTransmission;
+class CEntity;
class CPlane;
class CVehicle;
class CPed;
@@ -247,12 +232,23 @@ public:
int32 m_nWaterCannonEntity;
int32 m_nPoliceChannelEntity;
cPoliceRadioQueue m_sPoliceRadioQueue;
+ cAMCrime m_aCrimes[10];
int32 m_nFrontEndEntity;
int32 m_nCollisionEntity;
cAudioCollisionManager m_sCollisionManager;
int32 m_nProjectileEntity;
int32 m_nBridgeEntity;
- cMissionAudio m_sMissionAudio;
+
+ // Mission audio stuff
+ CVector m_vecMissionAudioPosition;
+ bool8 m_bIsMissionAudio2D;
+ uint32 m_nMissionAudioSampleIndex;
+ uint8 m_nMissionAudioLoadingStatus;
+ uint8 m_nMissionAudioPlayStatus;
+ bool8 m_bIsMissionAudioPlaying;
+ int32 m_nMissionAudioFramesToPlay;
+ bool8 m_bIsMissionAudioAllowedToPlay;
+
int32 m_anRandomTable[5];
uint8 m_nTimeSpent;
bool8 m_nUserPause;
@@ -510,7 +506,7 @@ public:
void SetMissionAudioLocation(float x, float y, float z);
void PlayLoadedMissionAudio();
bool8 IsMissionAudioSampleFinished();
- bool8 IsMissionAudioSamplePlaying() { return m_sMissionAudio.m_nPlayStatus == PLAY_STATUS_PLAYING; }
+ bool8 IsMissionAudioSamplePlaying() { return m_nMissionAudioPlayStatus == PLAY_STATUS_PLAYING; }
bool8 ShouldDuckMissionAudio() { return IsMissionAudioSamplePlaying(); }
void ClearMissionAudio();
void ProcessMissionAudio();
diff --git a/src/audio/PolRadio.cpp b/src/audio/PolRadio.cpp
index 76a87137..553cf287 100644
--- a/src/audio/PolRadio.cpp
+++ b/src/audio/PolRadio.cpp
@@ -85,11 +85,9 @@ cAudioManager::InitialisePoliceRadioZones()
void
cAudioManager::InitialisePoliceRadio()
{
- m_sPoliceRadioQueue.policeChannelTimer = 0;
- m_sPoliceRadioQueue.policeChannelTimerSeconds = 0;
- m_sPoliceRadioQueue.policeChannelCounterSeconds = 0;
- for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++)
- m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE;
+ m_sPoliceRadioQueue.Reset();
+ for (int32 i = 0; i < ARRAY_SIZE(m_aCrimes); i++)
+ m_aCrimes[i].type = CRIME_NONE;
SampleManager.SetChannelReverbFlag(CHANNEL_POLICE_RADIO, FALSE);
gSpecialSuspectLastSeenReport = FALSE;
@@ -201,7 +199,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
bMissionAudioPhysicalPlayingStatus == PLAY_STATUS_PLAYING) {
SampleManager.PauseStream(FALSE, 1);
}
- if (m_sPoliceRadioQueue.policeChannelTimer == 0) bChannelOpen = FALSE;
+ if (m_sPoliceRadioQueue.m_nSamplesInQueue == 0) bChannelOpen = FALSE;
if (cWait) {
#ifdef FIX_BUGS
cWait -= CTimer::GetLogicalFramesPassed();
@@ -238,14 +236,8 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel)
}
if (bChannelOpen) DoPoliceRadioCrackle();
if ((g_nMissionAudioSfx == TOTAL_AUDIO_SAMPLES || g_nMissionAudioPlayingStatus != PLAY_STATUS_PLAYING) &&
- !SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO) && m_sPoliceRadioQueue.policeChannelTimer) {
- if (m_sPoliceRadioQueue.policeChannelTimer) {
- sample = m_sPoliceRadioQueue.crimesSamples[m_sPoliceRadioQueue.policeChannelCounterSeconds];
- m_sPoliceRadioQueue.policeChannelTimer--;
- m_sPoliceRadioQueue.policeChannelCounterSeconds = (m_sPoliceRadioQueue.policeChannelCounterSeconds + 1) % 60;
- } else {
- sample = TOTAL_AUDIO_SAMPLES;
- }
+ !SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO) && m_sPoliceRadioQueue.m_nSamplesInQueue != 0) {
+ sample = m_sPoliceRadioQueue.Remove();
if (wantedLevel == 0) {
if (gSpecialSuspectLastSeenReport) {
gSpecialSuspectLastSeenReport = FALSE;
@@ -299,18 +291,18 @@ cAudioManager::SetupCrimeReport()
if (MusicManager.m_nMusicMode == MUSICMODE_CUTSCENE) return FALSE;
- if (60 - m_sPoliceRadioQueue.policeChannelTimer <= 9) {
+ if (POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue <= 9) {
AgeCrimes();
return TRUE;
}
- for (i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) {
- if (m_sPoliceRadioQueue.crimes[i].type != CRIME_NONE)
+ for (i = 0; i < ARRAY_SIZE(m_aCrimes); i++) {
+ if (m_aCrimes[i].type != CRIME_NONE)
break;
}
- if (i == ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) return FALSE;
- audioZoneId = CTheZones::FindAudioZone(&m_sPoliceRadioQueue.crimes[i].position);
+ if (i == ARRAY_SIZE(m_aCrimes)) return FALSE;
+ audioZoneId = CTheZones::FindAudioZone(&m_aCrimes[i].position);
if (audioZoneId >= 0 && audioZoneId < NUMAUDIOZONES) {
zone = CTheZones::GetAudioZone(audioZoneId);
for (int j = 0; j < NUMAUDIOZONES; j++) {
@@ -319,14 +311,14 @@ cAudioManager::SetupCrimeReport()
m_sPoliceRadioQueue.Add(m_anRandomTable[4] % 3 + SFX_POLICE_RADIO_MESSAGE_NOISE_1);
m_sPoliceRadioQueue.Add(m_anRandomTable[0] % 3 + SFX_WEVE_GOT);
m_sPoliceRadioQueue.Add(m_anRandomTable[1] % 2 + SFX_A_10_1);
- switch (m_sPoliceRadioQueue.crimes[i].type) {
- case CRIME_PED_BURNED: m_sPoliceRadioQueue.crimes[i].type = CRIME_HIT_PED; break;
- case CRIME_COP_BURNED: m_sPoliceRadioQueue.crimes[i].type = CRIME_HIT_COP; break;
- case CRIME_VEHICLE_BURNED: m_sPoliceRadioQueue.crimes[i].type = CRIME_STEAL_CAR; break;
- case CRIME_DESTROYED_CESSNA: m_sPoliceRadioQueue.crimes[i].type = CRIME_SHOOT_HELI; break;
+ switch (m_aCrimes[i].type) {
+ case CRIME_PED_BURNED: m_aCrimes[i].type = CRIME_HIT_PED; break;
+ case CRIME_COP_BURNED: m_aCrimes[i].type = CRIME_HIT_COP; break;
+ case CRIME_VEHICLE_BURNED: m_aCrimes[i].type = CRIME_STEAL_CAR; break;
+ case CRIME_DESTROYED_CESSNA: m_aCrimes[i].type = CRIME_SHOOT_HELI; break;
default: break;
}
- m_sPoliceRadioQueue.Add(m_sPoliceRadioQueue.crimes[i].type + SFX_CRIME_1 - 1);
+ m_sPoliceRadioQueue.Add(m_aCrimes[i].type + SFX_CRIME_1 - 1);
m_sPoliceRadioQueue.Add(SFX_IN);
if (sampleIndex == SFX_POLICE_RADIO_SHORESIDE_VALE &&
(strcmp(zone->name, SubZo2Label) == 0 || strcmp(zone->name, SubZo3Label) == 0)) {
@@ -340,17 +332,17 @@ cAudioManager::SetupCrimeReport()
quarterX = 0.25f * rangeX;
quarterY = 0.25f * rangeY;
- if (m_sPoliceRadioQueue.crimes[i].position.y > halfY + quarterY) {
+ if (m_aCrimes[i].position.y > halfY + quarterY) {
m_sPoliceRadioQueue.Add(SFX_NORTH);
processed = TRUE;
- } else if (m_sPoliceRadioQueue.crimes[i].position.y < halfY - quarterY) {
+ } else if (m_aCrimes[i].position.y < halfY - quarterY) {
m_sPoliceRadioQueue.Add(SFX_SOUTH);
processed = TRUE;
}
- if (m_sPoliceRadioQueue.crimes[i].position.x > halfX + quarterX)
+ if (m_aCrimes[i].position.x > halfX + quarterX)
m_sPoliceRadioQueue.Add(SFX_EAST);
- else if (m_sPoliceRadioQueue.crimes[i].position.x < halfX - quarterX)
+ else if (m_aCrimes[i].position.x < halfX - quarterX)
m_sPoliceRadioQueue.Add(SFX_WEST);
else if (!processed)
m_sPoliceRadioQueue.Add(SFX_CENTRAL);
@@ -363,7 +355,7 @@ cAudioManager::SetupCrimeReport()
}
}
}
- m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE;
+ m_aCrimes[i].type = CRIME_NONE;
AgeCrimes();
return TRUE;
}
@@ -536,7 +528,7 @@ cAudioManager::SetupSuspectLastSeenReport()
if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE) {
veh = FindPlayerVehicle();
if (veh != nil) {
- if (60 - m_sPoliceRadioQueue.policeChannelTimer > 9) {
+ if (POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue > 9) {
color1 = veh->m_currentColour1;
if (color1 >= ARRAY_SIZE(gCarColourTable)) {
debug("\n *** UNKNOWN CAR COLOUR %d *** ", color1);
@@ -669,7 +661,7 @@ cAudioManager::SetupSuspectLastSeenReport()
m_sPoliceRadioQueue.Add(TOTAL_AUDIO_SAMPLES);
}
}
- } else if (60 - m_sPoliceRadioQueue.policeChannelTimer > 4) {
+ } else if (POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue > 4) {
m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_MESSAGE_NOISE_1);
m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_SUSPECT);
m_sPoliceRadioQueue.Add(SFX_POLICE_RADIO_ON_FOOT);
@@ -682,14 +674,14 @@ cAudioManager::SetupSuspectLastSeenReport()
void
cAudioManager::ReportCrime(eCrimeType type, const CVector &pos)
{
- int32 lastCrime = ARRAY_SIZE(m_sPoliceRadioQueue.crimes);
+ int32 lastCrime = ARRAY_SIZE(m_aCrimes);
if (m_bIsInitialised && MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && FindPlayerPed()->m_pWanted->GetWantedLevel() > 0 &&
(type > CRIME_NONE || type < NUM_CRIME_TYPES) && m_FrameCounter >= gMinTimeToNextReport[type]) {
- for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) {
- if (m_sPoliceRadioQueue.crimes[i].type) {
- if (m_sPoliceRadioQueue.crimes[i].type == type) {
- m_sPoliceRadioQueue.crimes[i].position = pos;
- m_sPoliceRadioQueue.crimes[i].timer = 0;
+ for (int32 i = 0; i < ARRAY_SIZE(m_aCrimes); i++) {
+ if (m_aCrimes[i].type != CRIME_NONE) {
+ if (m_aCrimes[i].type == type) {
+ m_aCrimes[i].position = pos;
+ m_aCrimes[i].timer = 0;
return;
}
} else {
@@ -697,10 +689,10 @@ cAudioManager::ReportCrime(eCrimeType type, const CVector &pos)
}
}
- if (lastCrime < ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) {
- m_sPoliceRadioQueue.crimes[lastCrime].type = type;
- m_sPoliceRadioQueue.crimes[lastCrime].position = pos;
- m_sPoliceRadioQueue.crimes[lastCrime].timer = 0;
+ if (lastCrime < ARRAY_SIZE(m_aCrimes)) {
+ m_aCrimes[lastCrime].type = type;
+ m_aCrimes[lastCrime].position = pos;
+ m_aCrimes[lastCrime].timer = 0;
gMinTimeToNextReport[type] = m_FrameCounter + 500;
}
}
@@ -723,7 +715,7 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z)
if (!m_bIsInitialised) return;
- if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && 60 - m_sPoliceRadioQueue.policeChannelTimer > 9) {
+ if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && POLICE_RADIO_QUEUE_MAX_SAMPLES - m_sPoliceRadioQueue.m_nSamplesInQueue > 9) {
audioZone = CTheZones::FindAudioZone(&vec);
if (audioZone >= 0 && audioZone < NUMAUDIOZONES) {
zone = CTheZones::GetAudioZone(audioZone);
@@ -776,9 +768,9 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z)
void
cAudioManager::AgeCrimes()
{
- for (uint8 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) {
- if (m_sPoliceRadioQueue.crimes[i].type != CRIME_NONE) {
- if (++m_sPoliceRadioQueue.crimes[i].timer > 1500) m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE;
+ for (uint8 i = 0; i < ARRAY_SIZE(m_aCrimes); i++) {
+ if (m_aCrimes[i].type != CRIME_NONE) {
+ if (++m_aCrimes[i].timer > 1500) m_aCrimes[i].type = CRIME_NONE;
}
}
}
diff --git a/src/audio/PolRadio.h b/src/audio/PolRadio.h
index 368708b6..f402c200 100644
--- a/src/audio/PolRadio.h
+++ b/src/audio/PolRadio.h
@@ -1,6 +1,7 @@
#pragma once
#include "Crime.h"
+#include "AudioSamples.h"
struct cAMCrime {
int32 type;
@@ -17,30 +18,49 @@ struct cAMCrime {
VALIDATE_SIZE(cAMCrime, 20);
+#define POLICE_RADIO_QUEUE_MAX_SAMPLES 60
+
class cPoliceRadioQueue
{
public:
- int32 crimesSamples[60];
- uint8 policeChannelTimer;
- uint8 policeChannelTimerSeconds;
- uint8 policeChannelCounterSeconds;
- cAMCrime crimes[10];
+ int32 m_aSamples[POLICE_RADIO_QUEUE_MAX_SAMPLES];
+ uint8 m_nSamplesInQueue;
+ uint8 m_nAddOffset;
+ uint8 m_nRemoveOffset;
cPoliceRadioQueue()
{
- policeChannelTimerSeconds = 0;
- policeChannelCounterSeconds = 0;
- policeChannelTimer = 0;
+ Reset();
+ }
+
+ void Reset()
+ {
+ m_nAddOffset = 0;
+ m_nRemoveOffset = 0;
+ m_nSamplesInQueue = 0;
+ }
+
+ bool8 Add(uint32 sample)
+ {
+ if (m_nSamplesInQueue != POLICE_RADIO_QUEUE_MAX_SAMPLES) {
+ m_aSamples[m_nAddOffset] = sample;
+ m_nSamplesInQueue++;
+ m_nAddOffset = (m_nAddOffset + 1) % POLICE_RADIO_QUEUE_MAX_SAMPLES;
+ return TRUE;
+ }
+ return FALSE;
}
- void Add(uint32 sample)
+ uint32 Remove()
{
- if (policeChannelTimer != 60) {
- crimesSamples[policeChannelTimerSeconds] = sample;
- policeChannelTimer++;
- policeChannelTimerSeconds = (policeChannelTimerSeconds + 1) % 60;
+ if (m_nSamplesInQueue != 0) {
+ uint32 sample = m_aSamples[m_nRemoveOffset];
+ m_nSamplesInQueue--;
+ m_nRemoveOffset = (m_nRemoveOffset + 1) % POLICE_RADIO_QUEUE_MAX_SAMPLES;
+ return sample;
}
+ return TOTAL_AUDIO_SAMPLES;
}
};
-VALIDATE_SIZE(cPoliceRadioQueue, 444);
+VALIDATE_SIZE(cPoliceRadioQueue, 244);