diff options
Diffstat (limited to 'src')
128 files changed, 3585 insertions, 2928 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c81873fd..35b7ec11 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ if(LIBRW_PLATFORM_D3D9) endif() target_compile_definitions(${EXECUTABLE} PRIVATE CMAKE_BUILD) +target_compile_definitions(${EXECUTABLE} PRIVATE USE_OUR_VERSIONING) if(${PROJECT}_AUDIO STREQUAL "OAL") find_package(OpenAL REQUIRED) diff --git a/src/audio/AudioCollision.cpp b/src/audio/AudioCollision.cpp index 6ce7bbac..fd819641 100644 --- a/src/audio/AudioCollision.cpp +++ b/src/audio/AudioCollision.cpp @@ -166,20 +166,17 @@ cAudioManager::SetUpLoopingCollisionSound(const cAudioCollision &col, uint8 coun m_sQueueSample.m_nCounter = counter; m_sQueueSample.m_vecPos = col.m_vecPosition; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 7; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = - SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = - SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_fSpeedMultiplier = 4.0f; m_sQueueSample.m_fSoundIntensity = CollisionSoundIntensity; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 5; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -307,17 +304,16 @@ cAudioManager::SetUpOneShotCollisionSound(const cAudioCollision &col) if(counter >= 255) counter = 28; m_sQueueSample.m_vecPos = col.m_vecPosition; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 11; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS m_sQueueSample.m_fSpeedMultiplier = 4.0f; m_sQueueSample.m_fSoundIntensity = CollisionSoundIntensity; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -328,13 +324,13 @@ void cAudioManager::ServiceCollisions() { int i, j; - bool abRepeatedCollision1[NUMAUDIOCOLLISIONS]; - bool abRepeatedCollision2[NUMAUDIOCOLLISIONS]; + bool8 abRepeatedCollision1[NUMAUDIOCOLLISIONS]; + bool8 abRepeatedCollision2[NUMAUDIOCOLLISIONS]; m_sQueueSample.m_nEntityIndex = m_nCollisionEntity; for (int i = 0; i < NUMAUDIOCOLLISIONS; i++) - abRepeatedCollision1[i] = abRepeatedCollision2[i] = false; + abRepeatedCollision1[i] = abRepeatedCollision2[i] = FALSE; for (i = 0; i < m_sCollisionManager.m_bCollisionsInQueue; i++) { for (j = 0; j < NUMAUDIOCOLLISIONS; j++) { @@ -344,8 +340,8 @@ cAudioManager::ServiceCollisions() && (m_sCollisionManager.m_asCollisions1[index].m_bSurface1 == m_sCollisionManager.m_asCollisions2[j].m_bSurface1) && (m_sCollisionManager.m_asCollisions1[index].m_bSurface2 == m_sCollisionManager.m_asCollisions2[j].m_bSurface2) ) { - abRepeatedCollision1[index] = true; - abRepeatedCollision2[j] = true; + abRepeatedCollision1[index] = TRUE; + abRepeatedCollision2[j] = TRUE; m_sCollisionManager.m_asCollisions1[index].m_nBaseVolume = ++m_sCollisionManager.m_asCollisions2[j].m_nBaseVolume; SetUpLoopingCollisionSound(m_sCollisionManager.m_asCollisions1[index], j); break; diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp index ec364c27..fdc7305b 100644 --- a/src/audio/AudioLogic.cpp +++ b/src/audio/AudioLogic.cpp @@ -38,9 +38,9 @@ #include "ZoneCull.h" #include "sampman.h" -const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples); -const int policeChannel = channels + 1; -const int allChannels = channels + 2; +#ifndef GTA_PS2 +#define CHANNEL_PLAYER_VEHICLE_ENGINE m_nActiveSamples +#endif uint32 gPornNextTime; uint32 gSawMillNextTime; @@ -128,38 +128,38 @@ cAudioManager::PostInitialiseGameSpecificSetup() { m_nFireAudioEntity = CreateEntity(AUDIOTYPE_FIRE, &gFireManager); if (m_nFireAudioEntity >= 0) - SetEntityStatus(m_nFireAudioEntity, true); + SetEntityStatus(m_nFireAudioEntity, TRUE); m_nCollisionEntity = CreateEntity(AUDIOTYPE_COLLISION, (void *)1); if (m_nCollisionEntity >= 0) - SetEntityStatus(m_nCollisionEntity, true); + SetEntityStatus(m_nCollisionEntity, TRUE); m_nFrontEndEntity = CreateEntity(AUDIOTYPE_FRONTEND, (void *)1); if (m_nFrontEndEntity >= 0) - SetEntityStatus(m_nFrontEndEntity, true); + SetEntityStatus(m_nFrontEndEntity, TRUE); m_nProjectileEntity = CreateEntity(AUDIOTYPE_PROJECTILE, (void *)1); if (m_nProjectileEntity >= 0) - SetEntityStatus(m_nProjectileEntity, true); + SetEntityStatus(m_nProjectileEntity, TRUE); m_nWaterCannonEntity = CreateEntity(AUDIOTYPE_WATERCANNON, (void *)1); if (m_nWaterCannonEntity >= 0) - SetEntityStatus(m_nWaterCannonEntity, true); + SetEntityStatus(m_nWaterCannonEntity, TRUE); m_nPoliceChannelEntity = CreateEntity(AUDIOTYPE_POLICERADIO, (void *)1); if (m_nPoliceChannelEntity >= 0) - SetEntityStatus(m_nPoliceChannelEntity, true); + SetEntityStatus(m_nPoliceChannelEntity, TRUE); m_nBridgeEntity = CreateEntity(AUDIOTYPE_BRIDGE, (void *)1); if (m_nBridgeEntity >= 0) - SetEntityStatus(m_nBridgeEntity, true); + 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_bIsPlaying = FALSE; + m_sMissionAudio.m_bIsPlayed = FALSE; + m_sMissionAudio.m_bPredefinedProperties = TRUE; m_sMissionAudio.m_nMissionAudioCounter = 0; ResetAudioLogicTimers(CTimer::GetTimeInMilliseconds()); } @@ -224,24 +224,26 @@ cAudioManager::ResetAudioLogicTimers(uint32 timer) } } ClearMissionAudio(); - SampleManager.StopChannel(policeChannel); + SampleManager.StopChannel(CHANNEL_POLICE_RADIO); } void cAudioManager::ProcessReverb() const { if (SampleManager.UpdateReverb() && m_bDynamicAcousticModelingStatus) { +#ifndef GTA_PS2 for (uint32 i = 0; i < #ifdef FIX_BUGS - channels + NUM_CHANNELS_GENERIC #else - 28 + NUM_CHANNELS_GENERIC+1 #endif ; i++) { if (m_asActiveSamples[i].m_bReverbFlag) - SampleManager.SetChannelReverbFlag(i, true); + SampleManager.SetChannelReverbFlag(i, TRUE); } +#endif } } @@ -253,11 +255,11 @@ cAudioManager::GetDistanceSquared(const CVector &v) const } void -cAudioManager::CalculateDistance(bool &distCalculated, float dist) +cAudioManager::CalculateDistance(bool8 &distCalculated, float dist) { if (!distCalculated) { m_sQueueSample.m_fDistance = Sqrt(dist); - distCalculated = true; + distCalculated = TRUE; } } @@ -278,7 +280,7 @@ cAudioManager::ProcessSpecial() CPlayerPed *playerPed = FindPlayerPed(); if (playerPed) { if(playerPed->EnteringCar() && !playerPed->bInVehicle) - SampleManager.StopChannel(m_nActiveSamples); + SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE); } } } @@ -291,53 +293,53 @@ cAudioManager::ProcessEntity(int32 id) switch (m_asAudioEntities[id].m_nType) { case AUDIOTYPE_PHYSICAL: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessPhysical(id); } break; case AUDIOTYPE_EXPLOSION: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessExplosions(id); } break; case AUDIOTYPE_FIRE: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessFires(id); } break; case AUDIOTYPE_WEATHER: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessWeather(id); } break; case AUDIOTYPE_CRANE: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessCrane(); } break; case AUDIOTYPE_SCRIPTOBJECT: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessScriptObject(id); } break; case AUDIOTYPE_BRIDGE: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessBridge(); } break; case AUDIOTYPE_FRONTEND: - m_sQueueSample.m_bReverbFlag = false; + m_sQueueSample.m_bReverbFlag = FALSE; ProcessFrontEnd(); break; case AUDIOTYPE_PROJECTILE: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessProjectiles(); } break; @@ -347,13 +349,13 @@ cAudioManager::ProcessEntity(int32 id) break; case AUDIOTYPE_FIREHYDRANT: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessFireHydrant(); } break; case AUDIOTYPE_WATERCANNON: if (!m_nUserPause) { - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; ProcessWaterCannon(id); } break; @@ -548,25 +550,25 @@ const tVehicleSampleData aVehicleSettings[MAX_CARS] = { {SFX_CAR_REV_1, SFX_BANK_PACARD, SFX_CAR_HORN_JEEP, 21043, SFX_CAR_ALARM_1, 9935, OLD_DOOR}}; -bool bPlayerJustEnteredCar; - -const bool hornPatternsArray[8][44] = { - {false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, - false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false}, - {false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, - true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false}, - {false, false, true, true, true, true, true, true, true, true, true, true, false, false, false, false, true, true, true, true, true, false, - false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false}, - {false, false, true, true, true, true, true, false, false, true, true, true, true, true, false, false, false, true, true, true, true, true, - true, true, true, true, true, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, false}, - {false, false, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, - {false, false, true, true, true, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, - {false, false, true, true, true, true, false, false, false, false, true, true, true, false, false, true, true, true, false, false, true, true, - true, true, true, true, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, false, false}, - {false, false, true, true, true, true, false, false, true, true, true, true, true, false, false, false, true, true, true, true, true, true, - false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false}, +bool8 bPlayerJustEnteredCar; + +const bool8 hornPatternsArray[8][44] = { + {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, + FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE}, + {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, + TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE}, + {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, + FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE}, + {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, + TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE}, + {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, + FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}, + {FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, + FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}, + {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, + TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE}, + {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, + FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE}, }; @@ -578,7 +580,7 @@ cAudioManager::ProcessVehicle(CVehicle *veh) cVehicleParams params; m_sQueueSample.m_vecPos = veh->GetPosition(); - params.m_bDistanceCalculated = false; + params.m_bDistanceCalculated = FALSE; params.m_pVehicle = veh; params.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos); @@ -677,25 +679,24 @@ cAudioManager::ProcessRainOnVehicle(cVehicleParams& params) veh->m_bRainSamplesCounter = 68; m_sQueueSample.m_nSampleIndex = (m_anRandomTable[1] & 3) + SFX_CAR_RAIN_1; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 9; m_sQueueSample.m_nFrequency = m_anRandomTable[1] % 4000 + 28000; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.m_nEmittingVolume = (uint8)emittingVol; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = rainOnVehicleIntensity; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bReverbFlag = false; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bReverbFlag = FALSE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } } } -bool +bool8 cAudioManager::ProcessReverseGear(cVehicleParams& params) { const int reverseGearIntensity = 30; @@ -706,7 +707,7 @@ cAudioManager::ProcessReverseGear(cVehicleParams& params) float modificator; if (params.m_fDistance >= SQR(reverseGearIntensity)) - return false; + return FALSE; veh = params.m_pVehicle; if (veh->bEngineOn && (veh->m_fGasPedal < 0.0f || veh->m_nCurrentGear == 0)) { CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); @@ -730,23 +731,22 @@ cAudioManager::ProcessReverseGear(cVehicleParams& params) m_sQueueSample.m_nSampleIndex = SFX_REVERSE_GEAR; } m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_nFrequency = (6000.f * modificator) + 7000; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 3.0f; m_sQueueSample.m_fSoundIntensity = reverseGearIntensity; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 5; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } - return true; + return TRUE; } void @@ -781,19 +781,18 @@ cAudioManager::ProcessModelCarEngine(cVehicleParams& params) m_sQueueSample.m_nCounter = 2; m_sQueueSample.m_nSampleIndex = SFX_REMOTE_CONTROLLED_CAR; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nFrequency = (11025.f * velocityChange / params.m_pTransmission->fMaxVelocity + 11025.f); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 3.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -804,7 +803,7 @@ cAudioManager::ProcessModelCarEngine(cVehicleParams& params) -bool +bool8 cAudioManager::ProcessVehicleRoadNoise(cVehicleParams& params) { const float SOUND_INTENSITY = 95.0f; @@ -816,7 +815,7 @@ cAudioManager::ProcessVehicleRoadNoise(cVehicleParams& params) float velocity; if (params.m_fDistance >= SQR(SOUND_INTENSITY)) - return false; + return FALSE; if (params.m_pTransmission != nil) { if (((CAutomobile*)params.m_pVehicle)->m_nDriveWheelsOnGround != 0) { velocity = Abs(params.m_fVelocityChange); @@ -827,7 +826,7 @@ cAudioManager::ProcessVehicleRoadNoise(cVehicleParams& params) if (m_sQueueSample.m_nVolume != 0) { m_sQueueSample.m_nCounter = 0; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; if (params.m_pVehicle->m_nSurfaceTouched == SURFACE_WATER) { m_sQueueSample.m_nSampleIndex = SFX_BOAT_WATER_LOOP; @@ -841,23 +840,22 @@ cAudioManager::ProcessVehicleRoadNoise(cVehicleParams& params) m_sQueueSample.m_nFrequency = freq; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 6.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 4; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } } } - return true; + return TRUE; } -bool +bool8 cAudioManager::ProcessWetRoadNoise(cVehicleParams& params) { const float SOUND_INTENSITY = 30.0f; @@ -869,7 +867,7 @@ cAudioManager::ProcessWetRoadNoise(cVehicleParams& params) float velChange; if (params.m_fDistance >= SQR(SOUND_INTENSITY)) - return false; + return FALSE; if (params.m_pTransmission != nil) { if (((CAutomobile *)params.m_pVehicle)->m_nDriveWheelsOnGround != 0) { velChange = Abs(params.m_fVelocityChange); @@ -882,7 +880,7 @@ cAudioManager::ProcessWetRoadNoise(cVehicleParams& params) m_sQueueSample.m_nCounter = 1; m_sQueueSample.m_nSampleIndex = SFX_ROAD_NOISE; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; #ifdef FIX_BUGS multiplier = (m_sQueueSample.m_fDistance / SOUND_INTENSITY) * 0.5f; @@ -893,20 +891,19 @@ cAudioManager::ProcessWetRoadNoise(cVehicleParams& params) m_sQueueSample.m_nFrequency = freq + freq * multiplier; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 6.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 4; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } } } - return true; + return TRUE; } void @@ -931,7 +928,7 @@ cAudioManager::ProcessVehicleEngine(cVehicleParams& params) playerVeh = FindPlayerVehicle(); veh = params.m_pVehicle; if (playerVeh == veh && veh->GetStatus() == STATUS_WRECKED) { - SampleManager.StopChannel(m_nActiveSamples); + SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE); return; } if (veh->bEngineOn) { @@ -1033,21 +1030,20 @@ cAudioManager::ProcessVehicleEngine(cVehicleParams& params) } } m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_nFrequency = freq + 100 * m_sQueueSample.m_nEntityIndex % 1000; if (m_sQueueSample.m_nSampleIndex == SFX_CAR_IDLE_6 || m_sQueueSample.m_nSampleIndex == SFX_CAR_REV_6) m_sQueueSample.m_nFrequency /= 2; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 6.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 8; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -1070,7 +1066,7 @@ void cAudioManager::PlayerJustGotInCar() const { if (m_bIsInitialised) - bPlayerJustEnteredCar = true; + bPlayerJustEnteredCar = TRUE; } void @@ -1080,7 +1076,7 @@ cAudioManager::PlayerJustLeftCar(void) const } void -cAudioManager::AddPlayerCarSample(uint8 emittingVolume, int32 freq, uint32 sample, uint8 bank, uint8 counter, bool notLooping) +cAudioManager::AddPlayerCarSample(uint8 emittingVolume, int32 freq, uint32 sample, uint8 bank, uint8 counter, bool8 notLooping) { m_sQueueSample.m_nVolume = ComputeVolume(emittingVolume, 50.f, m_sQueueSample.m_fDistance); if (m_sQueueSample.m_nVolume != 0) { @@ -1091,7 +1087,7 @@ cAudioManager::AddPlayerCarSample(uint8 emittingVolume, int32 freq, uint32 sampl #else m_sQueueSample.m_nBankIndex = SFX_BANK_0; #endif // GTA_PS2 - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 0; m_sQueueSample.m_nFrequency = freq; if (notLooping) { @@ -1101,13 +1097,12 @@ cAudioManager::AddPlayerCarSample(uint8 emittingVolume, int32 freq, uint32 sampl m_sQueueSample.m_nLoopCount = 1; } m_sQueueSample.m_nEmittingVolume = emittingVolume; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 6.0f; m_sQueueSample.m_fSoundIntensity = 50.0f; - m_sQueueSample.m_bReleasingSoundFlag = false; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -1127,11 +1122,11 @@ cAudioManager::ProcessCesna(cVehicleParams& params) } else if (nAccel < 60) { ++nAccel; } - AddPlayerCarSample(85 * (60 - nAccel) / 60 + 20, 8500 * nAccel / 60 + 17000, SFX_CESNA_IDLE, SFX_BANK_0, 52, true); - AddPlayerCarSample(85 * nAccel / 60 + 20, 8500 * nAccel / 60 + 17000, SFX_CESNA_REV, SFX_BANK_0, 2, true); + AddPlayerCarSample(85 * (60 - nAccel) / 60 + 20, 8500 * nAccel / 60 + 17000, SFX_CESNA_IDLE, SFX_BANK_0, 52, TRUE); + AddPlayerCarSample(85 * nAccel / 60 + 20, 8500 * nAccel / 60 + 17000, SFX_CESNA_REV, SFX_BANK_0, 2, TRUE); } } else if (params.m_nIndex == DODO) { - AddPlayerCarSample(105, 17000, SFX_CESNA_IDLE, SFX_BANK_0, 52, true); + AddPlayerCarSample(105, 17000, SFX_CESNA_IDLE, SFX_BANK_0, 52, TRUE); } else if (params.m_fDistance < SQR(200)) { CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); m_sQueueSample.m_nVolume = ComputeVolume(80, 200.f, m_sQueueSample.m_fDistance); @@ -1139,19 +1134,18 @@ cAudioManager::ProcessCesna(cVehicleParams& params) m_sQueueSample.m_nCounter = 52; m_sQueueSample.m_nSampleIndex = SFX_CESNA_IDLE; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 0; m_sQueueSample.m_nFrequency = 12500; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nReleasingVolumeDivider = 8; m_sQueueSample.m_nEmittingVolume = 80; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 8.0f; m_sQueueSample.m_fSoundIntensity = 200.0f; - m_sQueueSample.m_bReleasingSoundFlag = false; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } if (params.m_fDistance < SQR(90)) { @@ -1160,19 +1154,18 @@ cAudioManager::ProcessCesna(cVehicleParams& params) m_sQueueSample.m_nCounter = 2; m_sQueueSample.m_nSampleIndex = SFX_CESNA_REV; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 0; m_sQueueSample.m_nFrequency = 25000; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nReleasingVolumeDivider = 4; m_sQueueSample.m_nEmittingVolume = 80; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 8.0f; m_sQueueSample.m_fSoundIntensity = 90.0f; - m_sQueueSample.m_bReleasingSoundFlag = false; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -1199,9 +1192,9 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * int soundOffset; uint8 engineSoundType; int16 accelerateState; - bool channelUsed; - bool lostTraction; - bool processedAccelSampleStopped; + bool8 channelUsed; + bool8 lostTraction; + bool8 processedAccelSampleStopped; uint8 currentGear; float gasPedalAudio; CVector pos; @@ -1209,34 +1202,34 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * static int16 LastAccel = 0; static int16 LastBrake = 0; static uint8 CurrentPretendGear = 1; - static bool bLostTractionLastFrame = false; - static bool bHandbrakeOnLastFrame = false; + static bool8 bLostTractionLastFrame = FALSE; + static bool8 bHandbrakeOnLastFrame = FALSE; static int32 nCruising = 0; - static bool bAccelSampleStopped = true; + static bool8 bAccelSampleStopped = TRUE; - lostTraction = false; - processedAccelSampleStopped = false; + lostTraction = FALSE; + processedAccelSampleStopped = FALSE; if (bPlayerJustEnteredCar) { - bAccelSampleStopped = true; - bPlayerJustEnteredCar = false; + bAccelSampleStopped = TRUE; + bPlayerJustEnteredCar = FALSE; nCruising = 0; LastAccel = 0; - bLostTractionLastFrame = false; + bLostTractionLastFrame = FALSE; LastBrake = 0; - bHandbrakeOnLastFrame = false; + bHandbrakeOnLastFrame = FALSE; CurrentPretendGear = 1; } if (CReplay::IsPlayingBack()) - accelerateState = 255.f * clamp(automobile->m_fGasPedal, 0.0f, 1.0f); + accelerateState = 255.f * Clamp(automobile->m_fGasPedal, 0.0f, 1.0f); else accelerateState = Pads[0].GetAccelerate(); - channelUsed = SampleManager.GetChannelUsedFlag(m_nActiveSamples); + channelUsed = SampleManager.GetChannelUsedFlag(CHANNEL_PLAYER_VEHICLE_ENGINE); transmission = params.m_pTransmission; velocityChange = params.m_fVelocityChange; relativeVelocityChange = 2.0f * velocityChange / transmission->fMaxVelocity; - accelerationMultipler = clamp(relativeVelocityChange, 0.0f, 1.0f); + accelerationMultipler = Clamp(relativeVelocityChange, 0.0f, 1.0f); gasPedalAudio = accelerationMultipler; currentGear = params.m_pVehicle->m_nCurrentGear; @@ -1249,16 +1242,16 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * ++wheelInUseCounter; } if (wheelInUseCounter > 2) - lostTraction = true; + lostTraction = TRUE; break; case 'F': if ((automobile->m_aWheelState[CARWHEEL_FRONT_LEFT] != WHEEL_STATE_NORMAL || automobile->m_aWheelState[CARWHEEL_FRONT_RIGHT] != WHEEL_STATE_NORMAL) && (automobile->m_aWheelState[CARWHEEL_REAR_LEFT] != WHEEL_STATE_NORMAL || automobile->m_aWheelState[CARWHEEL_REAR_RIGHT] != WHEEL_STATE_NORMAL)) - lostTraction = true; + lostTraction = TRUE; break; case 'R': if ((automobile->m_aWheelState[CARWHEEL_REAR_LEFT] != WHEEL_STATE_NORMAL) || (automobile->m_aWheelState[CARWHEEL_REAR_RIGHT] != WHEEL_STATE_NORMAL)) - lostTraction = true; + lostTraction = TRUE; break; } @@ -1278,8 +1271,8 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * if (accelerateState <= 0) { if (params.m_fVelocityChange < -0.001f) { if (channelUsed) { - SampleManager.StopChannel(m_nActiveSamples); - bAccelSampleStopped = true; + SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE); + bAccelSampleStopped = TRUE; } if (automobile->m_nWheelsOnGround == 0 || automobile->bIsHandbrakeOn || lostTraction) gasPedalAudio = automobile->m_fGasPedalAudio; @@ -1290,8 +1283,8 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * automobile->m_fGasPedalAudio = gasPedalAudio; } else if (LastAccel > 0) { if (channelUsed) { - SampleManager.StopChannel(m_nActiveSamples); - bAccelSampleStopped = true; + SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE); + bAccelSampleStopped = TRUE; } nCruising = 0; if (automobile->m_nWheelsOnGround == 0 || automobile->bIsHandbrakeOn || lostTraction || @@ -1304,13 +1297,13 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * if (engineSoundType == SFX_BANK_TRUCK) freq /= 2; AddPlayerCarSample((25.f * (gasPedalAudio - 0.05f) * 20.f / 19) + 40, freq, (soundOffset + SFX_CAR_FINGER_OFF_ACCEL_1), engineSoundType, 63, - false); + FALSE); } } freq = (10000.f * gasPedalAudio) + 22050; if (engineSoundType == SFX_BANK_TRUCK) freq /= 2; - AddPlayerCarSample(110 - (40.f * gasPedalAudio), freq, (engineSoundType - CAR_SFX_BANKS_OFFSET + SFX_CAR_IDLE_1), SFX_BANK_0, 52, true); + AddPlayerCarSample(110 - (40.f * gasPedalAudio), freq, (engineSoundType - CAR_SFX_BANKS_OFFSET + SFX_CAR_IDLE_1), SFX_BANK_0, 52, TRUE); CurrentPretendGear = Max(1, currentGear); } else { @@ -1334,10 +1327,10 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * if (engineSoundType == SFX_BANK_TRUCK) freq /= 2; if (channelUsed) { - SampleManager.StopChannel(m_nActiveSamples); - bAccelSampleStopped = true; + SampleManager.StopChannel(CHANNEL_PLAYER_VEHICLE_ENGINE); + bAccelSampleStopped = TRUE; } - AddPlayerCarSample(vol, freq, (engineSoundType - CAR_SFX_BANKS_OFFSET + SFX_CAR_REV_1), SFX_BANK_0, 2, true); + AddPlayerCarSample(vol, freq, (engineSoundType - CAR_SFX_BANKS_OFFSET + SFX_CAR_REV_1), SFX_BANK_0, 2, TRUE); } else { TranslateEntity(&m_sQueueSample.m_vecPos, &pos); if (bAccelSampleStopped) { @@ -1347,8 +1340,8 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * gearNr = 1; CurrentPretendGear = gearNr; } - processedAccelSampleStopped = true; - bAccelSampleStopped = false; + processedAccelSampleStopped = TRUE; + bAccelSampleStopped = FALSE; } if (!channelUsed) { @@ -1361,28 +1354,28 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * } } - if (!SampleManager.InitialiseChannel(m_nActiveSamples, soundOffset + SFX_CAR_ACCEL_1, SFX_BANK_0)) + if (!SampleManager.InitialiseChannel(CHANNEL_PLAYER_VEHICLE_ENGINE, soundOffset + SFX_CAR_ACCEL_1, SFX_BANK_0)) return; - SampleManager.SetChannelLoopCount(m_nActiveSamples, 1); - SampleManager.SetChannelLoopPoints(m_nActiveSamples, 0, -1); + SampleManager.SetChannelLoopCount(CHANNEL_PLAYER_VEHICLE_ENGINE, 1); + SampleManager.SetChannelLoopPoints(CHANNEL_PLAYER_VEHICLE_ENGINE, 0, -1); } - SampleManager.SetChannelEmittingVolume(m_nActiveSamples, 85); - SampleManager.SetChannel3DPosition(m_nActiveSamples, pos.x, pos.y, pos.z); - SampleManager.SetChannel3DDistances(m_nActiveSamples, 50.f, 12.5f); + SampleManager.SetChannelEmittingVolume(CHANNEL_PLAYER_VEHICLE_ENGINE, 85); + SampleManager.SetChannel3DPosition(CHANNEL_PLAYER_VEHICLE_ENGINE, pos.x, pos.y, pos.z); + SampleManager.SetChannel3DDistances(CHANNEL_PLAYER_VEHICLE_ENGINE, 50.f, 12.5f); freq = GearFreqAdj[CurrentPretendGear] + freqModifier + 22050; if (engineSoundType == SFX_BANK_TRUCK) freq /= 2; - SampleManager.SetChannelFrequency(m_nActiveSamples, freq); + SampleManager.SetChannelFrequency(CHANNEL_PLAYER_VEHICLE_ENGINE, freq); if (!channelUsed) { - SampleManager.SetChannelReverbFlag(m_nActiveSamples, m_bDynamicAcousticModelingStatus != false); - SampleManager.StartChannel(m_nActiveSamples); + SampleManager.SetChannelReverbFlag(CHANNEL_PLAYER_VEHICLE_ENGINE, m_bDynamicAcousticModelingStatus != FALSE); + SampleManager.StartChannel(CHANNEL_PLAYER_VEHICLE_ENGINE); } } break; } if (nCruising != 0) { - bAccelSampleStopped = true; + bAccelSampleStopped = TRUE; if (accelerateState < 150 || automobile->m_nWheelsOnGround == 0 || automobile->bIsHandbrakeOn || lostTraction || currentGear < params.m_pTransmission->nNumberOfGears - 1) { nCruising = 0; @@ -1396,7 +1389,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * freq = 27 * nCruising + freqModifier + 22050; if (engineSoundType == SFX_BANK_TRUCK) freq /= 2; - AddPlayerCarSample(85, freq, (soundOffset + SFX_CAR_AFTER_ACCEL_1), engineSoundType, 64, true); + AddPlayerCarSample(85, freq, (soundOffset + SFX_CAR_AFTER_ACCEL_1), engineSoundType, 64, TRUE); } } } @@ -1406,7 +1399,7 @@ cAudioManager::ProcessPlayersVehicleEngine(cVehicleParams& params, CAutomobile * bLostTractionLastFrame = lostTraction; } -bool +bool8 cAudioManager::ProcessVehicleSkidding(cVehicleParams& params) { const float SOUND_INTENSITY = 40.0f; @@ -1418,10 +1411,10 @@ cAudioManager::ProcessVehicleSkidding(cVehicleParams& params) float skidVal = 0.0f; if (params.m_fDistance >= SQR(SOUND_INTENSITY)) - return false; + return FALSE; automobile = (CAutomobile *)params.m_pVehicle; if (automobile->m_nWheelsOnGround == 0) - return true; + return TRUE; CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); for (int32 i = 0; i < ARRAY_SIZE(automobile->m_aWheelState); i++) { if (automobile->m_aWheelState[i] == WHEEL_STATE_NORMAL || automobile->Damage.GetWheelStatus(i) == WHEEL_STATUS_MISSING) @@ -1462,7 +1455,7 @@ cAudioManager::ProcessVehicleSkidding(cVehicleParams& params) m_sQueueSample.m_nFrequency = 13000.f * skidVal + 35000.f; m_sQueueSample.m_nVolume /= 4; if (m_sQueueSample.m_nVolume == 0) - return true; + return TRUE; break; case SURFACE_GRAVEL: case SURFACE_MUD_DRY: @@ -1479,22 +1472,21 @@ cAudioManager::ProcessVehicleSkidding(cVehicleParams& params) } m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 8; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 3.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } - return true; + return TRUE; } float @@ -1569,19 +1561,18 @@ cAudioManager::ProcessVehicleHorn(cVehicleParams& params) m_sQueueSample.m_nCounter = 4; m_sQueueSample.m_nSampleIndex = aVehicleSettings[params.m_nIndex].m_nHornSample; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 2; m_sQueueSample.m_nFrequency = aVehicleSettings[params.m_nIndex].m_nHornFrequency; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = 80; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 5.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -1589,7 +1580,7 @@ cAudioManager::ProcessVehicleHorn(cVehicleParams& params) } } -bool +bool8 cAudioManager::UsesSiren(int32 model) const { switch (model) { @@ -1599,13 +1590,13 @@ cAudioManager::UsesSiren(int32 model) const case POLICE: case ENFORCER: case PREDATOR: - return true; + return TRUE; default: - return false; + return FALSE; } } -bool +bool8 cAudioManager::UsesSirenSwitching(int32 model) const { switch (model) { @@ -1613,21 +1604,21 @@ cAudioManager::UsesSirenSwitching(int32 model) const case POLICE: case ENFORCER: case PREDATOR: - return true; + return TRUE; default: - return false; + return FALSE; } } -bool +bool8 cAudioManager::ProcessVehicleSirenOrAlarm(cVehicleParams& params) { const float SOUND_INTENSITY = 110.0f; if (params.m_fDistance < SQR(SOUND_INTENSITY)) { CVehicle *veh = params.m_pVehicle; - if (veh->m_bSirenOrAlarm == false && !veh->IsAlarmOn()) - return true; + if (veh->m_bSirenOrAlarm == FALSE && !veh->IsAlarmOn()) + return TRUE; CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); m_sQueueSample.m_nVolume = ComputeVolume(80, SOUND_INTENSITY, m_sQueueSample.m_fDistance); @@ -1635,7 +1626,7 @@ cAudioManager::ProcessVehicleSirenOrAlarm(cVehicleParams& params) m_sQueueSample.m_nCounter = 5; if (UsesSiren(params.m_nIndex)) { if (params.m_pVehicle->GetStatus() == STATUS_ABANDONED) - return true; + return TRUE; if (veh->m_nCarHornTimer && params.m_nIndex != FIRETRUK) { m_sQueueSample.m_nSampleIndex = SFX_SIREN_FAST; if (params.m_nIndex == FBICAR) @@ -1652,33 +1643,32 @@ cAudioManager::ProcessVehicleSirenOrAlarm(cVehicleParams& params) m_sQueueSample.m_nFrequency = aVehicleSettings[params.m_nIndex].m_nSirenOrAlarmFrequency; } m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = 80; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 7.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 5; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); - return true; + return TRUE; } else - return true; + return TRUE; } else - return false; + return FALSE; } -bool +bool8 cAudioManager::UsesReverseWarning(int32 model) const { return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || model == COACH; } -bool +bool8 cAudioManager::ProcessVehicleReverseWarning(cVehicleParams& params) { const float SOUND_INTENSITY = 50.0f; @@ -1686,7 +1676,7 @@ cAudioManager::ProcessVehicleReverseWarning(cVehicleParams& params) CVehicle *veh = params.m_pVehicle; if (params.m_fDistance >= SQR(SOUND_INTENSITY)) - return false; + return FALSE; if (veh->bEngineOn && veh->m_fGasPedal < 0.0f) { CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); @@ -1695,26 +1685,25 @@ cAudioManager::ProcessVehicleReverseWarning(cVehicleParams& params) m_sQueueSample.m_nCounter = 12; m_sQueueSample.m_nSampleIndex = SFX_REVERSE_WARNING; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 2; m_sQueueSample.m_nFrequency = (100 * m_sQueueSample.m_nEntityIndex & 1023) + SampleManager.GetSampleBaseFrequency(SFX_REVERSE_WARNING); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = 60; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 3.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } - return true; + return TRUE; } -bool +bool8 cAudioManager::ProcessVehicleDoors(cVehicleParams& params) { const float SOUND_INTENSITY = 40.0f; @@ -1725,7 +1714,7 @@ cAudioManager::ProcessVehicleDoors(cVehicleParams& params) float velocity; if (params.m_fDistance >= SQR(SOUND_INTENSITY)) - return false; + return FALSE; automobile = (CAutomobile *)params.m_pVehicle; CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); @@ -1742,41 +1731,40 @@ cAudioManager::ProcessVehicleDoors(cVehicleParams& params) m_sQueueSample.m_nSampleIndex = m_anRandomTable[1] % 6 + SFX_COL_CAR_PANEL_1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex) + RandomDisplacement(1000); m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 10; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS m_sQueueSample.m_fSpeedMultiplier = 1.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = TRUE; AddSampleToRequestedQueue(); } } } } } - return true; + return TRUE; } -bool +bool8 cAudioManager::ProcessAirBrakes(cVehicleParams& params) { CAutomobile *automobile; uint8 rand; if (params.m_fDistance > SQR(30)) - return false; + return FALSE; automobile = (CAutomobile *)params.m_pVehicle; if (!automobile->bEngineOn) - return true; + return TRUE; if ((automobile->m_fVelocityChangeForAudio < 0.025f || params.m_fVelocityChange >= 0.025f) && (automobile->m_fVelocityChangeForAudio > -0.025f || params.m_fVelocityChange <= 0.025f)) - return true; + return TRUE; CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); rand = m_anRandomTable[0] % 10 + 70; @@ -1787,30 +1775,29 @@ cAudioManager::ProcessAirBrakes(cVehicleParams& params) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_AIR_BRAKES); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 16); m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 10; m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.m_nEmittingVolume = rand; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = 30.0f; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } - return true; + return TRUE; } -bool +bool8 cAudioManager::HasAirBrakes(int32 model) const { return model == LINERUN || model == FIRETRUK || model == TRASH || model == BUS || model == COACH; } -bool +bool8 cAudioManager::ProcessEngineDamage(cVehicleParams& params) { const int engineDamageIntensity = 40; @@ -1820,12 +1807,12 @@ cAudioManager::ProcessEngineDamage(cVehicleParams& params) uint8 emittingVolume; if (params.m_fDistance >= SQR(engineDamageIntensity)) - return false; + return FALSE; veh = (CAutomobile *)params.m_pVehicle; if (veh->bEngineOn) { engineStatus = veh->Damage.GetEngineStatus(); if (engineStatus > 250 || engineStatus < 100) - return true; + return TRUE; if (engineStatus < 225) { m_sQueueSample.m_nSampleIndex = SFX_JUMBO_TAXI; emittingVolume = 6; @@ -1842,30 +1829,29 @@ cAudioManager::ProcessEngineDamage(cVehicleParams& params) if (m_sQueueSample.m_nVolume != 0) { m_sQueueSample.m_nCounter = 28; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVolume; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = engineDamageIntensity; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } - return true; + return TRUE; } -bool +bool8 cAudioManager::ProcessCarBombTick(cVehicleParams& params) { CAutomobile *automobile; if (params.m_fDistance >= SQR(40.f)) - return false; + return FALSE; automobile = (CAutomobile *)params.m_pVehicle; if (automobile->bEngineOn && automobile->m_bombType == CARBOMB_TIMEDACTIVE) { CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); @@ -1874,23 +1860,22 @@ cAudioManager::ProcessCarBombTick(cVehicleParams& params) m_sQueueSample.m_nCounter = 35; m_sQueueSample.m_nSampleIndex = SFX_COUNTDOWN; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_COUNTDOWN); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = 60; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = 40.0f; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } - return true; + return TRUE; } void @@ -1900,7 +1885,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) uint8 emittingVol; float relVol; float vol; - bool noReflections; + bool8 noReflections; float maxDist; static uint8 WaveIndex = 41; @@ -1910,7 +1895,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) for (int i = 0; i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_AudioEvents; i++) { noReflections = 0; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bRequireReflection = FALSE; event = m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_awAudioEvent[i]; switch (event) { case SOUND_CAR_DOOR_CLOSE_BONNET: @@ -1950,7 +1935,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; break; } case SOUND_CAR_DOOR_OPEN_BONNET: @@ -1988,7 +1973,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; break; } case SOUND_CAR_WINDSHIELD_CRACK: { @@ -2034,7 +2019,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; break; } case SOUND_CAR_LIGHT_BREAK: { @@ -2079,7 +2064,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; m_sQueueSample.m_nReleasingVolumeDivider = 7; - noReflections = true; + noReflections = TRUE; maxDist = SQR(SOUND_INTENSITY); emittingVol = m_anRandomTable[0] % 15 + 55; break; @@ -2161,7 +2146,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; emittingVol = (37.f * vol * 2500.0f / 96.0f) + 90; maxDist = SQR(SOUND_INTENSITY); - noReflections = true; + noReflections = TRUE; break; } case SOUND_CAR_BOMB_TICK: { @@ -2174,7 +2159,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; maxDist = SQR(SOUND_INTENSITY); - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; emittingVol = 60; break; } @@ -2234,7 +2219,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) m_sQueueSample.m_nReleasingVolumeModificator = 0; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; emittingVol = 50; maxDist = SQR(SOUND_INTENSITY); break; @@ -2265,7 +2250,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; maxDist = SQR(SOUND_INTENSITY); - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; emittingVol = m_anRandomTable[4] % 20 + 90; break; } @@ -2282,7 +2267,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) maxDist = SQR(SOUND_INTENSITY); emittingVol = m_anRandomTable[4] % 20 + 55; CrunchOffset %= 2; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; break; } case SOUND_CAR_PED_COLLISION: { @@ -2311,23 +2296,22 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) if (m_sQueueSample.m_nVolume != 0) { if (noReflections) { m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; } else { m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; } - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bIs2D = FALSE; AddSampleToRequestedQueue(); } } } } -bool +bool8 cAudioManager::ProcessTrainNoise(cVehicleParams& params) { const float SOUND_INTENSITY = 300.0f; @@ -2337,7 +2321,7 @@ cAudioManager::ProcessTrainNoise(cVehicleParams& params) float speedMultipler; if (params.m_fDistance >= SQR(SOUND_INTENSITY)) - return false; + return FALSE; if (params.m_fVelocityChange > 0.0f) { CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); @@ -2350,19 +2334,18 @@ cAudioManager::ProcessTrainNoise(cVehicleParams& params) m_sQueueSample.m_nCounter = 32; m_sQueueSample.m_nSampleIndex = SFX_TRAIN_FAR; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 2; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_TRAIN_FAR); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 3.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -2373,27 +2356,26 @@ cAudioManager::ProcessTrainNoise(cVehicleParams& params) m_sQueueSample.m_nCounter = 33; m_sQueueSample.m_nSampleIndex = SFX_TRAIN_NEAR; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 5; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_TRAIN_NEAR) + 100 * m_sQueueSample.m_nEntityIndex % 987; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 6.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } } - return true; + return TRUE; } -bool +bool8 cAudioManager::ProcessBoatEngine(cVehicleParams& params) { CBoat *boat; @@ -2419,18 +2401,17 @@ cAudioManager::ProcessBoatEngine(cVehicleParams& params) m_sQueueSample.m_nFrequency = 10386; m_sQueueSample.m_nFrequency += (m_sQueueSample.m_nEntityIndex * 65536) % 1000; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = 80; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = intensity; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 7; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } if (FindPlayerVehicle() == params.m_pVehicle) { @@ -2454,23 +2435,22 @@ cAudioManager::ProcessBoatEngine(cVehicleParams& params) } m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, intensity, m_sQueueSample.m_fDistance); if (!m_sQueueSample.m_nVolume) - return true; + return TRUE; m_sQueueSample.m_nCounter = 40; m_sQueueSample.m_nSampleIndex = SFX_POLICE_BOAT_ACCEL; m_sQueueSample.m_nFrequency += (m_sQueueSample.m_nEntityIndex * 65536) % 1000; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = intensity; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 7; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; } else { if (FindPlayerVehicle() == params.m_pVehicle) { padAccelerate = Max(Pads[0].GetAccelerate(), Pads[0].GetBrake()); @@ -2512,29 +2492,28 @@ cAudioManager::ProcessBoatEngine(cVehicleParams& params) CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, intensity, m_sQueueSample.m_fDistance); if (!m_sQueueSample.m_nVolume) - return true; + return TRUE; m_sQueueSample.m_nFrequency += (m_sQueueSample.m_nEntityIndex * 65536) % 1000; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = intensity; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 7; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; } AddSampleToRequestedQueue(); - return true; + return TRUE; } - return false; + return FALSE; } -bool +bool8 cAudioManager::ProcessBoatMovingOverWater(cVehicleParams& params) { float velocityChange; @@ -2542,11 +2521,11 @@ cAudioManager::ProcessBoatMovingOverWater(cVehicleParams& params) float multiplier; if (params.m_fDistance > SQR(50)) - return false; + return FALSE; velocityChange = Abs(params.m_fVelocityChange); if (velocityChange <= 0.0005f && ((CBoat*)params.m_pVehicle)->bBoatInWater) - return true; + return TRUE; velocityChange = Min(0.75f, velocityChange); multiplier = (velocityChange - 0.0005f) / (1499.0f / 2000.0f); @@ -2557,23 +2536,22 @@ cAudioManager::ProcessBoatMovingOverWater(cVehicleParams& params) m_sQueueSample.m_nCounter = 38; m_sQueueSample.m_nSampleIndex = SFX_BOAT_WATER_LOOP; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_nFrequency = (6050.f * multiplier) + 16000; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = vol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = 50.0f; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } - return true; + return TRUE; } struct tHelicopterSampleData { @@ -2582,7 +2560,7 @@ struct tHelicopterSampleData { uint8 m_bBaseVolume; }; -bool +bool8 cAudioManager::ProcessHelicopter(cVehicleParams& params) { CHeli *heli; @@ -2593,7 +2571,7 @@ cAudioManager::ProcessHelicopter(cVehicleParams& params) static const tHelicopterSampleData gHeliSfxRanges[3] = {{400.f, 380.f, 100}, {100.f, 70.f, MAX_VOLUME}, {60.f, 30.f, MAX_VOLUME}}; if (SQR(gHeliSfxRanges[0].m_fMaxDistance) <= params.m_fDistance) - return false; + return FALSE; CalculateDistance(params.m_bDistanceCalculated, params.m_fDistance); heli = (CHeli *)params.m_pVehicle; @@ -2601,7 +2579,7 @@ cAudioManager::ProcessHelicopter(cVehicleParams& params) MaxDist = gHeliSfxRanges[i].m_fMaxDistance; dist = m_sQueueSample.m_fDistance; if (dist >= MaxDist) - return true; + return TRUE; baseDist = gHeliSfxRanges[i].m_fBaseDistance; if (dist < baseDist) emittingVol = (gHeliSfxRanges[i].m_bBaseVolume * ((MaxDist - dist) / (MaxDist - baseDist))); @@ -2613,23 +2591,22 @@ cAudioManager::ProcessHelicopter(cVehicleParams& params) m_sQueueSample.m_nCounter = i + 65; m_sQueueSample.m_nSampleIndex = i + SFX_HELI_1; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 0; m_sQueueSample.m_nFrequency = 1200 * heli->m_nHeliId + SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 6.0f; m_sQueueSample.m_fSoundIntensity = gHeliSfxRanges[i].m_fMaxDistance; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } - return true; + return TRUE; } void @@ -2771,12 +2748,12 @@ cAudioManager::ProcessJumboDecel(CPlane *plane) } } -bool +bool8 cAudioManager::SetupJumboTaxiSound(uint8 vol) { const float SOUND_INTENSITY = 180.0f; if (m_sQueueSample.m_fDistance >= SOUND_INTENSITY) - return false; + return FALSE; uint8 emittingVol = (vol / 2) + ((vol / 2) * m_sQueueSample.m_fDistance / SOUND_INTENSITY); @@ -2788,31 +2765,30 @@ cAudioManager::SetupJumboTaxiSound(uint8 vol) m_sQueueSample.m_nCounter = 1; m_sQueueSample.m_nSampleIndex = SFX_JUMBO_TAXI; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nFrequency = GetJumboTaxiFreq(); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 4.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 4; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } - return true; + return TRUE; } -bool +bool8 cAudioManager::SetupJumboWhineSound(uint8 emittingVol, uint32 freq) { const float SOUND_INTENSITY = 170.0f; if (m_sQueueSample.m_fDistance >= SOUND_INTENSITY) - return false; + return FALSE; m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, SOUND_INTENSITY, m_sQueueSample.m_fDistance); @@ -2820,30 +2796,29 @@ cAudioManager::SetupJumboWhineSound(uint8 emittingVol, uint32 freq) m_sQueueSample.m_nCounter = 2; m_sQueueSample.m_nSampleIndex = SFX_JUMBO_WHINE; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nFrequency = freq; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 4.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 4; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } - return true; + return TRUE; } -bool +bool8 cAudioManager::SetupJumboEngineSound(uint8 vol, uint32 freq) { const float SOUND_INTENSITY = 180.0f; if (m_sQueueSample.m_fDistance >= SOUND_INTENSITY) - return false; + return FALSE; uint8 emittingVol = vol - gJumboVolOffsetPercentage / 100; m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, SOUND_INTENSITY, m_sQueueSample.m_fDistance); @@ -2851,60 +2826,59 @@ cAudioManager::SetupJumboEngineSound(uint8 vol, uint32 freq) m_sQueueSample.m_nCounter = 3; m_sQueueSample.m_nSampleIndex = SFX_JUMBO_ENGINE; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nFrequency = freq; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 4.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 4; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } - return true; + return TRUE; } -bool +bool8 cAudioManager::SetupJumboFlySound(uint8 emittingVol) { const float SOUND_INTENSITY = 440.0f; if (m_sQueueSample.m_fDistance >= SOUND_INTENSITY) - return false; + return FALSE; int32 vol = ComputeVolume(emittingVol, SOUND_INTENSITY, m_sQueueSample.m_fDistance); m_sQueueSample.m_nVolume = vol; if (m_sQueueSample.m_nVolume != 0) { - m_sQueueSample.m_nSampleIndex = SFX_JUMBO_DIST_FLY; m_sQueueSample.m_nCounter = 0; + m_sQueueSample.m_nSampleIndex = SFX_JUMBO_DIST_FLY; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 1; - m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_JUMBO_DIST_FLY); - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_nLoopCount = 0; + m_sQueueSample.m_nEmittingVolume = emittingVol; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 4.0f; - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 5; - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } - return true; + return TRUE; } -bool +bool8 cAudioManager::SetupJumboRumbleSound(uint8 emittingVol) { const float SOUND_INTENSITY = 240.0f; if (m_sQueueSample.m_fDistance >= SOUND_INTENSITY) - return false; + return FALSE; m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, SOUND_INTENSITY, m_sQueueSample.m_fDistance); @@ -2912,28 +2886,27 @@ cAudioManager::SetupJumboRumbleSound(uint8 emittingVol) m_sQueueSample.m_nCounter = 5; m_sQueueSample.m_nSampleIndex = SFX_JUMBO_RUMBLE; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = true; + m_sQueueSample.m_bIs2D = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_JUMBO_RUMBLE); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 4.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 12; m_sQueueSample.m_nOffset = 0; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); m_sQueueSample.m_nCounter = 6; m_sQueueSample.m_nSampleIndex = SFX_JUMBO_RUMBLE; m_sQueueSample.m_nFrequency += 200; - m_sQueueSample.m_nOffset = MAX_VOLUME; + m_sQueueSample.m_nOffset = 127; AddSampleToRequestedQueue(); } - return true; + return TRUE; } int32 @@ -2954,7 +2927,7 @@ cAudioManager::ProcessPed(CPhysical *ped) m_sQueueSample.m_vecPos = ped->GetPosition(); - params.m_bDistanceCalculated = false; + params.m_bDistanceCalculated = FALSE; params.m_pPed = (CPed *)ped; params.m_fDistance = GetDistanceSquared(m_sQueueSample.m_vecPos); if (ped->GetModelIndex() == MI_FATMALE02) @@ -2993,19 +2966,18 @@ cAudioManager::ProcessPedHeadphones(cPedParams ¶ms) m_sQueueSample.m_nCounter = 64; m_sQueueSample.m_nSampleIndex = SFX_HEADPHONES; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 5; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_HEADPHONES); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 4.0f; m_sQueueSample.m_fSoundIntensity = 7.0f; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 5; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } return; @@ -3021,9 +2993,9 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) CPed *ped = params.m_pPed; - bool narrowSoundRange; + bool8 narrowSoundRange; int16 sound; - bool stereo; + bool8 stereo; CWeapon *weapon; float maxDist = 0.f; // uninitialized variable @@ -3031,9 +3003,9 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) weapon = params.m_pPed->GetWeapon(); for (uint32 i = 0; i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_AudioEvents; i++) { - stereo = false; - narrowSoundRange = false; - m_sQueueSample.m_bRequireReflection = false; + stereo = FALSE; + narrowSoundRange = FALSE; + m_sQueueSample.m_bRequireReflection = FALSE; sound = m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_awAudioEvent[i]; switch (sound) { case SOUND_STEP_START: @@ -3107,12 +3079,11 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = 20.0f; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bRequireReflection = TRUE; break; case SOUND_FALL_LAND: case SOUND_FALL_COLLAPSE: @@ -3135,12 +3106,11 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = 30.0f; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bRequireReflection = TRUE; break; case SOUND_FIGHT_PUNCH_33: m_sQueueSample.m_nSampleIndex = SFX_FIGHT_1; @@ -3192,42 +3162,40 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) AddFightSound: m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound; - narrowSoundRange = true; + narrowSoundRange = TRUE; ++iSound; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = 30.0f; maxDist = SQR(30); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[3] % 26 + 100; - m_sQueueSample.m_nLoopEnd = -1; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bRequireReflection = TRUE; break; case SOUND_WEAPON_BAT_ATTACK: m_sQueueSample.m_nSampleIndex = SFX_BAT_HIT_LEFT; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = RandomDisplacement(2000) + 22000; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = 30.0f; maxDist = SQR(30); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[2] % 20 + 100; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; if (m_bDynamicAcousticModelingStatus) - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; else - stereo = true; + stereo = TRUE; break; case SOUND_WEAPON_SHOT_FIRED: weapon = ped->GetWeapon(); @@ -3236,7 +3204,7 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_nSampleIndex = SFX_COLT45_LEFT; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_COLT45_LEFT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 32); m_sQueueSample.m_nReleasingVolumeModificator = 3; @@ -3244,22 +3212,21 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 50.0f; maxDist = SQR(50); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[1] % 10 + 90; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; if (m_bDynamicAcousticModelingStatus) - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; else - stereo = true; + stereo = TRUE; break; case WEAPONTYPE_UZI: m_sQueueSample.m_nSampleIndex = SFX_UZI_LEFT; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_UZI_LEFT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 32); m_sQueueSample.m_nReleasingVolumeModificator = 3; @@ -3267,18 +3234,17 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 80.0f; maxDist = SQR(80); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[3] % 15 + 70; - m_sQueueSample.m_nLoopEnd = -1; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; break; case WEAPONTYPE_SHOTGUN: m_sQueueSample.m_nSampleIndex = SFX_SHOTGUN_LEFT; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_SHOTGUN_LEFT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 32); m_sQueueSample.m_nReleasingVolumeModificator = 3; @@ -3286,22 +3252,21 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 60.0f; maxDist = SQR(60); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[2] % 10 + 100; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; if (m_bDynamicAcousticModelingStatus) - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; else - stereo = true; + stereo = TRUE; break; case WEAPONTYPE_AK47: m_sQueueSample.m_nSampleIndex = SFX_AK47_LEFT; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_AK47_LEFT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 32); m_sQueueSample.m_nReleasingVolumeModificator = 3; @@ -3309,18 +3274,17 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 80.0f; maxDist = SQR(80); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[1] % 15 + 70; - m_sQueueSample.m_nLoopEnd = -1; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; break; case WEAPONTYPE_M16: m_sQueueSample.m_nSampleIndex = SFX_M16_LEFT; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_M16_LEFT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 32); m_sQueueSample.m_nReleasingVolumeModificator = 3; @@ -3328,18 +3292,17 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 80.0f; maxDist = SQR(80); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[4] % 15 + 70; - m_sQueueSample.m_nLoopEnd = -1; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; break; case WEAPONTYPE_SNIPERRIFLE: m_sQueueSample.m_nSampleIndex = SFX_SNIPER_LEFT; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_SNIPER_LEFT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 32); m_sQueueSample.m_nReleasingVolumeModificator = 3; @@ -3347,22 +3310,21 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 60.0f; maxDist = SQR(60); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[4] % 10 + 110; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; if (m_bDynamicAcousticModelingStatus) - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; else - stereo = true; + stereo = TRUE; break; case WEAPONTYPE_ROCKETLAUNCHER: m_sQueueSample.m_nSampleIndex = SFX_ROCKET_LEFT; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_ROCKET_LEFT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 32); m_sQueueSample.m_nReleasingVolumeModificator = 1; @@ -3370,16 +3332,15 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 90.0f; maxDist = SQR(90); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[0] % 20 + 80; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; if (m_bDynamicAcousticModelingStatus) - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; else - stereo = true; + stereo = TRUE; break; case WEAPONTYPE_FLAMETHROWER: m_sQueueSample.m_nSampleIndex = SFX_FLAMETHROWER_LEFT; @@ -3392,16 +3353,15 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 60.0f; maxDist = SQR(60); m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_nEmittingVolume = 90; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 6; if (m_bDynamicAcousticModelingStatus) - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; else - stereo = true; + stereo = TRUE; break; default: continue; @@ -3444,7 +3404,7 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) } emittingVol = 75; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency += RandomDisplacement(300); m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nReleasingVolumeModificator = 5; @@ -3452,12 +3412,11 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 30.0f; maxDist = SQR(30); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS m_sQueueSample.m_nEmittingVolume = 75; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bRequireReflection = TRUE; break; case SOUND_WEAPON_AK47_BULLET_ECHO: case SOUND_WEAPON_UZI_BULLET_ECHO: @@ -3465,7 +3424,7 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_nSampleIndex = SFX_UZI_END_LEFT; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_UZI_END_LEFT); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 16); m_sQueueSample.m_nReleasingVolumeModificator = 3; @@ -3473,16 +3432,15 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 80.0f; maxDist = SQR(80); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[4] % 10 + 40; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; if (m_bDynamicAcousticModelingStatus) - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; else - stereo = true; + stereo = TRUE; break; case SOUND_WEAPON_FLAMETHROWER_FIRE: m_sQueueSample.m_nSampleIndex = SFX_FLAMETHROWER_START_LEFT; @@ -3495,18 +3453,17 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 60.0f; maxDist = SQR(60); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS emittingVol = 70; m_sQueueSample.m_nEmittingVolume = 70; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; break; case SOUND_WEAPON_HIT_PED: m_sQueueSample.m_nSampleIndex = SFX_BULLET_PED; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_BULLET_PED); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 8); m_sQueueSample.m_nReleasingVolumeModificator = 7; @@ -3514,31 +3471,29 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) m_sQueueSample.m_fSoundIntensity = 30.0f; maxDist = SQR(30); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[0] % 20 + 90; - m_sQueueSample.m_nLoopEnd = -1; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; break; case SOUND_SPLASH: m_sQueueSample.m_nSampleIndex = SFX_SPLASH_1; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nCounter = iSound++; - narrowSoundRange = true; + narrowSoundRange = TRUE; m_sQueueSample.m_nFrequency = RandomDisplacement(1400) + 20000; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = 40.0f; maxDist = SQR(40); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; + RESET_LOOP_OFFSETS emittingVol = m_anRandomTable[2] % 30 + 70; - m_sQueueSample.m_nLoopEnd = -1; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bRequireReflection = TRUE; break; default: SetupPedComments(params, sound); @@ -3553,13 +3508,13 @@ cAudioManager::ProcessPedOneShots(cPedParams ¶ms) if (m_sQueueSample.m_nVolume != 0) { if (stereo) { if (m_sQueueSample.m_fDistance < 0.2f * m_sQueueSample.m_fSoundIntensity) { - m_sQueueSample.m_bIs2D = true; + m_sQueueSample.m_bIs2D = TRUE; m_sQueueSample.m_nOffset = 0; } else { - stereo = false; + stereo = FALSE; } } - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; AddSampleToRequestedQueue(); if (stereo) { m_sQueueSample.m_nOffset = 127; @@ -6087,8 +6042,10 @@ cPedComments::Process() AudioManager.m_sQueueSample.m_nVolume = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_bVolume; AudioManager.m_sQueueSample.m_fDistance = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_fDistance; AudioManager.m_sQueueSample.m_nLoopCount = 1; +#ifndef GTA_PS2 AudioManager.m_sQueueSample.m_nLoopStart = 0; AudioManager.m_sQueueSample.m_nLoopEnd = -1; +#endif // !GTA_PS2 AudioManager.m_sQueueSample.m_nEmittingVolume = MAX_VOLUME; AudioManager.m_sQueueSample.m_fSpeedMultiplier = 3.0f; switch (sampleIndex) { @@ -6101,18 +6058,18 @@ cPedComments::Process() AudioManager.m_sQueueSample.m_fSoundIntensity = 50.0f; break; } - AudioManager.m_sQueueSample.m_bReleasingSoundFlag = true; + AudioManager.m_sQueueSample.m_bReleasingSoundFlag = TRUE; AudioManager.m_sQueueSample.m_vecPos = m_asPedComments[m_nActiveBank][m_nIndexMap[m_nActiveBank][0]].m_vecPos; if (sampleIndex >= SFX_AMMU_D && sampleIndex <= SFX_AMMU_F) { - AudioManager.m_sQueueSample.m_bReverbFlag = false; - AudioManager.m_sQueueSample.m_bRequireReflection = false; + AudioManager.m_sQueueSample.m_bReverbFlag = FALSE; + AudioManager.m_sQueueSample.m_bRequireReflection = FALSE; } else { - AudioManager.m_sQueueSample.m_bReverbFlag = true; - AudioManager.m_sQueueSample.m_bRequireReflection = true; + AudioManager.m_sQueueSample.m_bReverbFlag = TRUE; + AudioManager.m_sQueueSample.m_bRequireReflection = TRUE; } - AudioManager.m_sQueueSample.m_bIs2D = false; + AudioManager.m_sQueueSample.m_bIs2D = FALSE; AudioManager.m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(AudioManager.m_sQueueSample.m_nSampleIndex) + AudioManager.RandomDisplacement(750); if (CTimer::GetIsSlowMotionActive()) @@ -6122,12 +6079,12 @@ cPedComments::Process() } // Switch bank - if (m_nActiveBank) { - actualUsedBank = SFX_BANK_PED_COMMENTS; - m_nActiveBank = SFX_BANK_0; + if (m_nActiveBank == 0) { + actualUsedBank = 0; + m_nActiveBank = 1; } else { - actualUsedBank = SFX_BANK_0; - m_nActiveBank = SFX_BANK_PED_COMMENTS; + actualUsedBank = 1; + m_nActiveBank = 0; } comment = m_asPedComments[actualUsedBank]; for (uint32 i = 0; i < m_nCommentsInBank[actualUsedBank]; i++) { @@ -6203,15 +6160,14 @@ cAudioManager::ProcessExplosions(int32 explosion) if (m_sQueueSample.m_nVolume != 0) { m_sQueueSample.m_nCounter = i; m_sQueueSample.m_fSpeedMultiplier = 2.0f; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bReverbFlag = TRUE; m_sQueueSample.m_nEmittingVolume = MAX_VOLUME; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = true; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = TRUE; AddSampleToRequestedQueue(); } } @@ -6273,14 +6229,13 @@ cAudioManager::ProcessFires(int32) m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nReleasingVolumeDivider = 10; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -6317,14 +6272,13 @@ cAudioManager::ProcessWaterCannon(int32) m_sQueueSample.m_nCounter = i; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nReleasingVolumeDivider = 8; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nEmittingVolume = 50; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -6386,8 +6340,8 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = 9000; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bRequireReflection = TRUE; emittingVolume = RandomDisplacement(10) + 50; break; case SCRIPT_SOUND_BULLET_HIT_GROUND_1: @@ -6400,7 +6354,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 32); m_sQueueSample.m_nReleasingVolumeModificator = 9; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; emittingVolume = m_anRandomTable[2] % 20 + 90; break; case SCRIPT_SOUND_TRAIN_ANNOUNCEMENT_1: @@ -6414,7 +6368,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_TRAIN_STATION_ANNOUNCE); m_sQueueSample.m_nReleasingVolumeModificator = 0; m_sQueueSample.m_fSpeedMultiplier = 2.0f; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; break; case SCRIPT_SOUND_PAYPHONE_RINGING: m_sQueueSample.m_fSoundIntensity = 80.0f; @@ -6424,8 +6378,8 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_PHONE_RING); m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_fSpeedMultiplier = 2.0f; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bRequireReflection = FALSE; break; case SCRIPT_SOUND_GLASS_BREAK_L: m_sQueueSample.m_fSoundIntensity = 60.0f; @@ -6435,7 +6389,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_GLASS_SMASH); m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; break; case SCRIPT_SOUND_GLASS_BREAK_S: m_sQueueSample.m_fSoundIntensity = 60.0f; @@ -6445,7 +6399,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_GLASS_SMASH); m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; break; case SCRIPT_SOUND_GLASS_CRACK: m_sQueueSample.m_fSoundIntensity = 60.0f; @@ -6455,8 +6409,8 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_GLASS_CRACK); m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bRequireReflection = TRUE; break; case SCRIPT_SOUND_GLASS_LIGHT_BREAK: m_sQueueSample.m_fSoundIntensity = 55.0f; @@ -6465,7 +6419,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = RandomDisplacement(2000) + 19000; m_sQueueSample.m_nReleasingVolumeModificator = 9; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; emittingVolume = RandomDisplacement(11) + 25; break; case SCRIPT_SOUND_BOX_DESTROYED_1: @@ -6475,8 +6429,8 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = RandomDisplacement(1500) + 18600; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bRequireReflection = TRUE; emittingVolume = m_anRandomTable[2] % 20 + 80; break; case SCRIPT_SOUND_BOX_DESTROYED_2: @@ -6486,8 +6440,8 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = RandomDisplacement(1500) + 18600; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bRequireReflection = TRUE; emittingVolume = m_anRandomTable[2] % 20 + 80; break; case SCRIPT_SOUND_METAL_COLLISION: @@ -6498,8 +6452,8 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 16); m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bRequireReflection = TRUE; emittingVolume = m_anRandomTable[2] % 30 + 70; break; case SCRIPT_SOUND_TIRE_COLLISION: @@ -6510,8 +6464,8 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 16); m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bRequireReflection = TRUE; emittingVolume = m_anRandomTable[2] % 30 + 60; break; case SCRIPT_SOUND_GUNSHELL_DROP: @@ -6546,7 +6500,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 20.0f; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; emittingVolume = m_anRandomTable[2] % 20 + 30; break; case SCRIPT_SOUND_GUNSHELL_DROP_SOFT: @@ -6556,7 +6510,7 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) m_sQueueSample.m_fSoundIntensity = 20.0f; m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; emittingVolume = m_anRandomTable[2] % 20 + 30; break; default: @@ -6570,11 +6524,10 @@ cAudioManager::ProcessOneShotScriptObject(uint8 sound) if (m_sQueueSample.m_nVolume != 0) { m_sQueueSample.m_nCounter = iSound++; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nEmittingVolume = emittingVolume; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; AddSampleToRequestedQueue(); } } @@ -7175,14 +7128,13 @@ cAudioManager::ProcessLoopingScriptObject(uint8 sound) m_sQueueSample.m_nVolume = ComputeVolume(emittingVolume, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); if (m_sQueueSample.m_nVolume != 0) { m_sQueueSample.m_nCounter = 0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; - m_sQueueSample.m_bReverbFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; + m_sQueueSample.m_bReverbFlag = TRUE; m_sQueueSample.m_nEmittingVolume = emittingVolume; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -7247,16 +7199,15 @@ cAudioManager::ProcessPornCinema(uint8 sound) if (m_sQueueSample.m_nVolume != 0) { m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nCounter = 0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = MAX_VOLUME; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -7270,15 +7221,14 @@ cAudioManager::ProcessPornCinema(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 16); m_sQueueSample.m_nCounter = rand + 1; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 6; m_sQueueSample.m_fSpeedMultiplier = 0.0f; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); gPornNextTime = time + 2000 + m_anRandomTable[3] % 6000; } @@ -7308,16 +7258,15 @@ cAudioManager::ProcessWorkShopScriptObject(uint8 sound) m_sQueueSample.m_nBankIndex = SFX_BANK_BUILDING_WORKSHOP; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_WORKSHOP_1); m_sQueueSample.m_nCounter = 0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 5; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = 30; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -7347,16 +7296,15 @@ cAudioManager::ProcessSawMillScriptObject(uint8 sound) m_sQueueSample.m_nBankIndex = SFX_BANK_BUILDING_SAWMILL; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_SAWMILL_LOOP); m_sQueueSample.m_nCounter = 0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 5; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = 30; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } time = CTimer::GetTimeInMilliseconds(); @@ -7367,15 +7315,14 @@ cAudioManager::ProcessSawMillScriptObject(uint8 sound) m_sQueueSample.m_nBankIndex = SFX_BANK_BUILDING_SAWMILL; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nCounter = 1; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 2.0f; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); gSawMillNextTime = time + 2000 + m_anRandomTable[3] % 4000; } @@ -7403,16 +7350,15 @@ cAudioManager::ProcessLaunderetteScriptObject(uint8 sound) m_sQueueSample.m_nBankIndex = SFX_BANK_BUILDING_LAUNDERETTE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_LAUNDERETTE_LOOP); m_sQueueSample.m_nCounter = 0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 5; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = 45; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } m_sQueueSample.m_nVolume = ComputeVolume(110, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); @@ -7421,16 +7367,15 @@ cAudioManager::ProcessLaunderetteScriptObject(uint8 sound) m_sQueueSample.m_nBankIndex = SFX_BANK_BUILDING_LAUNDERETTE; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_LAUNDERETTE_SONG_LOOP); m_sQueueSample.m_nCounter = 1; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = 110; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -7460,16 +7405,15 @@ cAudioManager::ProcessShopScriptObject(uint8 sound) m_sQueueSample.m_nBankIndex = SFX_BANK_BUILDING_SHOP; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_SHOP_LOOP); m_sQueueSample.m_nCounter = 0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 5; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = 30; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } time = CTimer::GetTimeInMilliseconds(); @@ -7481,16 +7425,15 @@ cAudioManager::ProcessShopScriptObject(uint8 sound) m_sQueueSample.m_nBankIndex = SFX_BANK_BUILDING_SHOP; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nCounter = rand + 1; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = 70; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); gShopNextTime = time + 3000 + m_anRandomTable[3] % 7000; } @@ -7524,16 +7467,15 @@ cAudioManager::ProcessAirportScriptObject(uint8 sound) m_sQueueSample.m_nBankIndex = SFX_BANK_BUILDING_AIRPORT; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nCounter = iSound++; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = 110; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); gAirportNextTime = time + 10000 + m_anRandomTable[3] % 20000; } @@ -7571,16 +7513,15 @@ cAudioManager::ProcessCinemaScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 4); m_sQueueSample.m_nCounter = iSound++; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = rand; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); gCinemaNextTime = time + 1000 + m_anRandomTable[3] % 4000; } @@ -7620,16 +7561,15 @@ cAudioManager::ProcessDocksScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_DOCKS_FOGHORN); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 8); m_sQueueSample.m_nCounter = iSound++; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_nEmittingVolume = rand; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); gDocksNextTime = time + 10000 + m_anRandomTable[3] % 40000; } @@ -7668,16 +7608,15 @@ cAudioManager::ProcessHomeScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 16); m_sQueueSample.m_nCounter = iSound++; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_nEmittingVolume = rand; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = true; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = TRUE; AddSampleToRequestedQueue(); gHomeNextTime = time + 1000 + m_anRandomTable[3] % 4000; } @@ -7720,19 +7659,18 @@ cAudioManager::ProcessPoliceCellBeatingScriptObject(uint8 sound) m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 16); m_sQueueSample.m_nCounter = iSound++; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); cPedParams params; - params.m_bDistanceCalculated = true; + params.m_bDistanceCalculated = TRUE; params.m_fDistance = distSquared; SetupPedComments(params, SOUND_INJURED_PED_MALE_PRISON); } @@ -7768,14 +7706,13 @@ cAudioManager::ProcessWeather(int32 id) m_sQueueSample.m_nCounter = iSound++; m_sQueueSample.m_nReleasingVolumeModificator = 0; m_sQueueSample.m_nOffset = (m_anRandomTable[2] & 15) + 55; - m_sQueueSample.m_bIs2D = true; + m_sQueueSample.m_bIs2D = TRUE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nEmittingVolume = m_sQueueSample.m_nVolume; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; - m_sQueueSample.m_bReverbFlag = false; - m_sQueueSample.m_bRequireReflection = false; + RESET_LOOP_OFFSETS + m_sQueueSample.m_bReverbFlag = FALSE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } if (CWeather::Rain > 0.0f && (!CCullZones::CamNoRain() || !CCullZones::PlayerNoRain())) { @@ -7786,15 +7723,14 @@ cAudioManager::ProcessWeather(int32 id) m_sQueueSample.m_nBankIndex = SFX_BANK_0; m_sQueueSample.m_nReleasingVolumeModificator = 0; m_sQueueSample.m_nOffset = 63; - m_sQueueSample.m_bIs2D = true; + m_sQueueSample.m_bIs2D = TRUE; m_sQueueSample.m_nLoopCount = 0; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 30; - m_sQueueSample.m_bReverbFlag = false; + m_sQueueSample.m_bReverbFlag = FALSE; m_sQueueSample.m_nEmittingVolume = m_sQueueSample.m_nVolume; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -7802,10 +7738,10 @@ cAudioManager::ProcessWeather(int32 id) void cAudioManager::ProcessFrontEnd() { - bool stereo; - bool processedPickup; - bool processedMission; - bool frontendBank; + bool8 stereo; + bool8 processedPickup; + bool8 processedMission; + bool8 frontendBank; int16 sample; static uint8 iSound = 0; @@ -7813,10 +7749,10 @@ cAudioManager::ProcessFrontEnd() static uint32 cPartMisComNextFrame = 0; for (uint32 i = 0; i < m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_AudioEvents; i++) { - processedPickup = false; - stereo = false; - processedMission = false; - frontendBank = false; + processedPickup = FALSE; + stereo = FALSE; + processedMission = FALSE; + frontendBank = FALSE; switch (m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_awAudioEvent[i]) { case SOUND_WEAPON_SNIPER_SHOT_NO_ZOOM: m_sQueueSample.m_nSampleIndex = SFX_ERROR_FIRE_RIFLE; @@ -7828,7 +7764,7 @@ cAudioManager::ProcessFrontEnd() case SOUND_GARAGE_BAD_VEHICLE: case SOUND_GARAGE_BOMB_ALREADY_SET: m_sQueueSample.m_nSampleIndex = SFX_PICKUP_ERROR_LEFT; - stereo = true; + stereo = TRUE; break; case SOUND_GARAGE_OPENING: case SOUND_GARAGE_BOMB1_SET: @@ -7844,19 +7780,19 @@ cAudioManager::ProcessFrontEnd() case SOUND_EVIDENCE_PICKUP: case SOUND_UNLOAD_GOLD: m_sQueueSample.m_nSampleIndex = SFX_PICKUP_2_LEFT; - processedPickup = true; - stereo = true; + processedPickup = TRUE; + stereo = TRUE; break; case SOUND_PICKUP_WEAPON_BOUGHT: case SOUND_PICKUP_WEAPON: m_sQueueSample.m_nSampleIndex = SFX_PICKUP_1_LEFT; - processedPickup = true; - stereo = true; + processedPickup = TRUE; + stereo = TRUE; break; case SOUND_PICKUP_ERROR: m_sQueueSample.m_nSampleIndex = SFX_PICKUP_ERROR_LEFT; - processedPickup = true; - stereo = true; + processedPickup = TRUE; + stereo = TRUE; break; case SOUND_PICKUP_BONUS: case SOUND_PICKUP_MONEY: @@ -7865,8 +7801,8 @@ cAudioManager::ProcessFrontEnd() case SOUND_PICKUP_PACMAN_PACKAGE: case SOUND_PICKUP_FLOAT_PACKAGE: m_sQueueSample.m_nSampleIndex = SFX_PICKUP_3_LEFT; - processedPickup = true; - stereo = true; + processedPickup = TRUE; + stereo = TRUE; break; case SOUND_PAGER: // TODO: ps2 code @@ -7883,49 +7819,49 @@ cAudioManager::ProcessFrontEnd() break; case SOUND_PART_MISSION_COMPLETE: m_sQueueSample.m_nSampleIndex = SFX_PART_MISSION_COMPLETE; - processedMission = true; + processedMission = TRUE; break; case SOUND_FRONTEND_MENU_STARTING: m_sQueueSample.m_nSampleIndex = SFX_START_BUTTON_LEFT; - stereo = true; + stereo = TRUE; break; case SOUND_FRONTEND_MENU_NEW_PAGE: m_sQueueSample.m_nSampleIndex = SFX_PAGE_CHANGE_AND_BACK_LEFT; - stereo = true; - frontendBank = true; + stereo = TRUE; + frontendBank = TRUE; break; case SOUND_FRONTEND_MENU_NAVIGATION: m_sQueueSample.m_nSampleIndex = SFX_HIGHLIGHT_LEFT; - stereo = true; - frontendBank = true; + stereo = TRUE; + frontendBank = TRUE; break; case SOUND_FRONTEND_MENU_SETTING_CHANGE: m_sQueueSample.m_nSampleIndex = SFX_SELECT_LEFT; - stereo = true; - frontendBank = true; + stereo = TRUE; + frontendBank = TRUE; break; case SOUND_FRONTEND_MENU_BACK: m_sQueueSample.m_nSampleIndex = SFX_SUB_MENU_BACK_LEFT; - stereo = true; - frontendBank = true; + stereo = TRUE; + frontendBank = TRUE; break; case SOUND_FRONTEND_STEREO: m_sQueueSample.m_nSampleIndex = SFX_STEREO_LEFT; - stereo = true; - frontendBank = true; + stereo = TRUE; + frontendBank = TRUE; break; case SOUND_FRONTEND_MONO: m_sQueueSample.m_nSampleIndex = SFX_MONO; - frontendBank = true; + frontendBank = TRUE; break; case SOUND_FRONTEND_AUDIO_TEST: m_sQueueSample.m_nSampleIndex = m_anRandomTable[0] % 3 + SFX_NOISE_BURST_1; - frontendBank = true; + frontendBank = TRUE; break; case SOUND_FRONTEND_FAIL: m_sQueueSample.m_nSampleIndex = SFX_ERROR_LEFT; - frontendBank = true; - stereo = true; + frontendBank = TRUE; + stereo = TRUE; break; case SOUND_FRONTEND_RADIO_TURN_OFF: case SOUND_FRONTEND_RADIO_CHANGE: @@ -7962,24 +7898,23 @@ cAudioManager::ProcessFrontEnd() m_sQueueSample.m_nVolume = 110; m_sQueueSample.m_nCounter = iSound++; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nBankIndex = frontendBank ? SFX_BANK_FRONT_END_MENU : SFX_BANK_0; m_sQueueSample.m_nReleasingVolumeModificator = 0; - m_sQueueSample.m_bIs2D = true; + m_sQueueSample.m_bIs2D = TRUE; m_sQueueSample.m_nEmittingVolume = m_sQueueSample.m_nVolume; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS if (stereo) m_sQueueSample.m_nOffset = m_anRandomTable[0] & 31; else m_sQueueSample.m_nOffset = 63; - m_sQueueSample.m_bReverbFlag = false; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = FALSE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); if (stereo) { ++m_sQueueSample.m_nSampleIndex; m_sQueueSample.m_nCounter = iSound++; - m_sQueueSample.m_nOffset = MAX_VOLUME - m_sQueueSample.m_nOffset; + m_sQueueSample.m_nOffset = 127 - m_sQueueSample.m_nOffset; AddSampleToRequestedQueue(); } } @@ -7990,7 +7925,7 @@ cAudioManager::ProcessCrane() { CCrane *crane = (CCrane *)m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_pEntity; float distSquared; - bool distCalculated = false; + bool8 distCalculated = FALSE; static const int intensity = 80; if (crane) { @@ -8005,19 +7940,18 @@ cAudioManager::ProcessCrane() m_sQueueSample.m_nCounter = 0; m_sQueueSample.m_nSampleIndex = SFX_CRANE_MAGNET; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 2; m_sQueueSample.m_nFrequency = 6000; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = 100; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 4.0f; m_sQueueSample.m_fSoundIntensity = intensity; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } if (m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_AudioEvents) { @@ -8025,9 +7959,9 @@ cAudioManager::ProcessCrane() m_sQueueSample.m_nSampleIndex = SFX_COL_CAR_2; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_COL_CAR_2); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = TRUE; AddSampleToRequestedQueue(); } } @@ -8075,14 +8009,13 @@ cAudioManager::ProcessProjectiles() m_sQueueSample.m_nVolume = ComputeVolume(emittingVol, m_sQueueSample.m_fSoundIntensity, m_sQueueSample.m_fDistance); if (m_sQueueSample.m_nVolume != 0) { m_sQueueSample.m_nCounter = i; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = emittingVol; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_bReleasingSoundFlag = false; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) + m_sQueueSample.m_bReleasingSoundFlag = FALSE; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -8100,7 +8033,7 @@ cAudioManager::ProcessGarages() uint32 sampleIndex; uint8 j; float distSquared; - bool distCalculated; + bool8 distCalculated; static uint8 iSound = 32; @@ -8111,7 +8044,7 @@ cAudioManager::ProcessGarages() if (entity == nil) continue; m_sQueueSample.m_vecPos = entity->GetPosition(); - distCalculated = false; + distCalculated = FALSE; distSquared = GetDistanceSquared(m_sQueueSample.m_vecPos); if (distSquared < SQR(SOUND_INTENSITY)) { state = CGarages::aGarages[i].m_eGarageState; @@ -8131,7 +8064,7 @@ cAudioManager::ProcessGarages() m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex) / 2; m_sQueueSample.m_nFrequency += RandomDisplacement(m_sQueueSample.m_nFrequency / 16); m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nCounter = iSound++; if (iSound < 32) iSound = 32; @@ -8143,7 +8076,7 @@ cAudioManager::ProcessGarages() m_sQueueSample.m_nCounter = i; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; } } else { m_sQueueSample.m_nSampleIndex = SFX_GARAGE_DOOR_LOOP; @@ -8152,19 +8085,18 @@ cAudioManager::ProcessGarages() m_sQueueSample.m_nCounter = i; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; } m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 3; m_sQueueSample.m_nEmittingVolume = 90; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } break; @@ -8193,16 +8125,15 @@ cAudioManager::ProcessGarages() m_sQueueSample.m_nEmittingVolume = 60; m_sQueueSample.m_fSpeedMultiplier = 0.0f; m_sQueueSample.m_fSoundIntensity = SOUND_INTENSITY; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bIs2D = false; - m_sQueueSample.m_bReleasingSoundFlag = true; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bIs2D = FALSE; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; m_sQueueSample.m_nLoopCount = 1; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS m_sQueueSample.m_nCounter = iSound++; if (iSound < 32) iSound = 32; - m_sQueueSample.m_bRequireReflection = true; + m_sQueueSample.m_bRequireReflection = TRUE; AddSampleToRequestedQueue(); } } @@ -8218,7 +8149,7 @@ void cAudioManager::ProcessFireHydrant() { float distSquared; - bool distCalculated = false; + bool8 distCalculated = FALSE; static const int intensity = 35; m_sQueueSample.m_vecPos = ((CEntity *)m_asAudioEntities[m_sQueueSample.m_nEntityIndex].m_pEntity)->GetPosition(); @@ -8230,19 +8161,18 @@ cAudioManager::ProcessFireHydrant() m_sQueueSample.m_nCounter = 0; m_sQueueSample.m_nSampleIndex = SFX_JUMBO_TAXI; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 4; m_sQueueSample.m_nFrequency = 15591; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = 40; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = intensity; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = true; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = TRUE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -8255,7 +8185,7 @@ void cAudioManager::ProcessBridge() { float dist; - bool distCalculated = false; + bool8 distCalculated = FALSE; if (CBridge::pLiftRoad) { m_sQueueSample.m_vecPos = CBridge::pLiftRoad->GetPosition(); @@ -8290,19 +8220,18 @@ cAudioManager::ProcessBridgeWarning() m_sQueueSample.m_nCounter = 0; m_sQueueSample.m_nSampleIndex = SFX_BRIDGE_OPEN_WARNING; m_sQueueSample.m_nBankIndex = SFX_BANK_GENERIC_EXTRA; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_BRIDGE_OPEN_WARNING); m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = 100; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = 450.0f; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 8; - m_sQueueSample.m_bReverbFlag = false; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReverbFlag = FALSE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -8317,18 +8246,17 @@ cAudioManager::ProcessBridgeMotor() m_sQueueSample.m_nCounter = 1; m_sQueueSample.m_nSampleIndex = SFX_FISHING_BOAT_IDLE; // todo check sfx name m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nFrequency = 5500; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = MAX_VOLUME; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(m_sQueueSample.m_nSampleIndex); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(m_sQueueSample.m_nSampleIndex); + SET_LOOP_OFFSETS(m_sQueueSample.m_nSampleIndex) m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = bridgeIntensity; - m_sQueueSample.m_bReleasingSoundFlag = false; + m_sQueueSample.m_bReleasingSoundFlag = FALSE; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bReverbFlag = false; + m_sQueueSample.m_bReverbFlag = FALSE; AddSampleToRequestedQueue(); } } @@ -8352,18 +8280,17 @@ cAudioManager::ProcessBridgeOneShots() if (m_sQueueSample.m_nVolume != 0) { m_sQueueSample.m_nCounter = 2; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = false; + m_sQueueSample.m_bIs2D = FALSE; m_sQueueSample.m_nReleasingVolumeModificator = 1; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(m_sQueueSample.m_nSampleIndex); m_sQueueSample.m_nLoopCount = 1; m_sQueueSample.m_nEmittingVolume = MAX_VOLUME; - m_sQueueSample.m_nLoopStart = 0; - m_sQueueSample.m_nLoopEnd = -1; + RESET_LOOP_OFFSETS m_sQueueSample.m_fSpeedMultiplier = 2.0f; m_sQueueSample.m_fSoundIntensity = bridgeIntensity; - m_sQueueSample.m_bReleasingSoundFlag = true; - m_sQueueSample.m_bReverbFlag = false; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bReleasingSoundFlag = TRUE; + m_sQueueSample.m_bReverbFlag = FALSE; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } } @@ -8371,7 +8298,7 @@ cAudioManager::ProcessBridgeOneShots() #pragma endregion #pragma region MISSION_AUDIO -bool g_bMissionAudioLoadFailed; +bool8 g_bMissionAudioLoadFailed; struct MissionAudioData { const char *m_pName; @@ -8425,7 +8352,7 @@ FindMissionAudioSfx(const char *name) return NO_SAMPLE; } -bool +bool8 cAudioManager::MissionScriptAudioUsesPoliceChannel(int32 soundMission) const { switch (soundMission) { @@ -8441,9 +8368,9 @@ cAudioManager::MissionScriptAudioUsesPoliceChannel(int32 soundMission) const case STREAMED_SOUND_MISSION_R5_A: case STREAMED_SOUND_MISSION_LO2_A: case STREAMED_SOUND_MISSION_LO6_A: - return true; + return TRUE; default: - return false; + return FALSE; } } @@ -8456,12 +8383,12 @@ cAudioManager::PreloadMissionAudio(Const char *name) 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_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; - g_bMissionAudioLoadFailed = false; + m_sMissionAudio.m_bIsPlayed = FALSE; + m_sMissionAudio.m_bPredefinedProperties = TRUE; + g_bMissionAudioLoadFailed = FALSE; } } } @@ -8479,7 +8406,7 @@ void cAudioManager::SetMissionAudioLocation(float x, float y, float z) { if (m_bIsInitialised) { - m_sMissionAudio.m_bPredefinedProperties = false; + m_sMissionAudio.m_bPredefinedProperties = FALSE; m_sMissionAudio.m_vecPos = CVector(x, y, z); } } @@ -8489,10 +8416,10 @@ 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; + m_sMissionAudio.m_bIsPlayed = TRUE; } -bool +bool8 cAudioManager::IsMissionAudioSampleFinished() { if (m_bIsInitialised) @@ -8510,9 +8437,9 @@ cAudioManager::ClearMissionAudio() 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_bIsPlaying = FALSE; + m_sMissionAudio.m_bIsPlayed = FALSE; + m_sMissionAudio.m_bPredefinedProperties = TRUE; m_sMissionAudio.m_nMissionAudioCounter = 0; } } @@ -8565,9 +8492,9 @@ cAudioManager::ProcessMissionAudio() SetMissionScriptPoliceAudio(m_sMissionAudio.m_nSampleIndex); } else { if (m_nUserPause) - SampleManager.PauseStream(1, 1); + SampleManager.PauseStream(TRUE, 1); if (m_sMissionAudio.m_bPredefinedProperties) { - SampleManager.SetStreamedVolumeAndPan(80, 63, 1, 1); + SampleManager.SetStreamedVolumeAndPan(80, 63, TRUE, 1); } else { distSquared = GetDistanceSquared(m_sMissionAudio.m_vecPos); if (distSquared >= SQR(50.0f)) { @@ -8579,7 +8506,7 @@ cAudioManager::ProcessMissionAudio() TranslateEntity(&m_sMissionAudio.m_vecPos, &vec); pan = ComputePan(50.f, &vec); } - SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, 1, 1); + SampleManager.SetStreamedVolumeAndPan(emittingVol, pan, TRUE, 1); } SampleManager.StartPreloadedStreamedFile(1); } @@ -8606,9 +8533,9 @@ cAudioManager::ProcessMissionAudio() } else if (m_sMissionAudio.m_bIsPlaying) { if (SampleManager.IsStreamPlaying(1) || m_nUserPause || m_nPreviousUserPause) { if (m_nUserPause) - SampleManager.PauseStream(1, 1); + SampleManager.PauseStream(TRUE, 1); else - SampleManager.PauseStream(0, 1); + SampleManager.PauseStream(FALSE, 1); } else { m_sMissionAudio.m_nPlayStatus = PLAY_STATUS_FINISHED; m_sMissionAudio.m_nSampleIndex = NO_SAMPLE; @@ -8623,7 +8550,7 @@ cAudioManager::ProcessMissionAudio() break; nCheckPlayingDelay = 0; } - m_sMissionAudio.m_bIsPlaying = true; + m_sMissionAudio.m_bIsPlaying = TRUE; } break; default: @@ -8633,7 +8560,7 @@ cAudioManager::ProcessMissionAudio() case LOADING_STATUS_FAILED: if (++nFramesUntilFailedLoad >= 90) { nFramesForPretendPlaying = 0; - g_bMissionAudioLoadFailed = true; + g_bMissionAudioLoadFailed = TRUE; nFramesUntilFailedLoad = 0; m_sMissionAudio.m_nLoadingStatus = LOADING_STATUS_LOADED; } diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index f61350fb..2e391349 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -13,20 +13,16 @@ cAudioManager AudioManager; -const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples); -const int policeChannel = channels + 1; -const int allChannels = channels + 2; - #define SPEED_OF_SOUND 343.f #define TIME_SPENT 50 cAudioManager::cAudioManager() { - m_bIsInitialised = false; - m_bReverb = true; + m_bIsInitialised = FALSE; + m_bReverb = TRUE; m_fSpeedOfSound = SPEED_OF_SOUND / TIME_SPENT; m_nTimeSpent = TIME_SPENT; - m_nActiveSamples = NUM_SOUNDS_SAMPLES_SLOTS; + m_nActiveSamples = NUM_CHANNELS_GENERIC; m_nActiveSampleQueue = 1; ClearRequestedQueue(); m_nActiveSampleQueue = 0; @@ -34,16 +30,16 @@ cAudioManager::cAudioManager() ClearActiveSamples(); GenerateIntegerRandomNumberTable(); field_4 = 0; - m_bDynamicAcousticModelingStatus = true; + m_bDynamicAcousticModelingStatus = TRUE; for (int i = 0; i < NUM_AUDIOENTITIES; i++) { - m_asAudioEntities[i].m_bIsUsed = false; + m_asAudioEntities[i].m_bIsUsed = FALSE; m_anAudioEntityIndices[i] = NUM_AUDIOENTITIES; } m_nAudioEntitiesTotal = 0; m_FrameCounter = 0; - m_bFifthFrameFlag = false; - m_bTimerJustReset = false; + m_bFifthFrameFlag = FALSE; + m_bTimerJustReset = FALSE; m_nTimer = 0; } @@ -81,7 +77,7 @@ cAudioManager::Terminate() MusicManager.Terminate(); for (uint32 i = 0; i < NUM_AUDIOENTITIES; i++) { - m_asAudioEntities[i].m_bIsUsed = false; + m_asAudioEntities[i].m_bIsUsed = FALSE; m_anAudioEntityIndices[i] = ARRAY_SIZE(m_anAudioEntityIndices); } @@ -96,7 +92,7 @@ cAudioManager::Terminate() SampleManager.Terminate(); - m_bIsInitialised = false; + m_bIsInitialised = FALSE; PostTerminateGameSpecificShutdown(); } } @@ -108,7 +104,7 @@ cAudioManager::Service() if (m_bTimerJustReset) { ResetAudioLogicTimers(m_nTimer); MusicManager.ResetTimers(m_nTimer); - m_bTimerJustReset = false; + m_bTimerJustReset = FALSE; } if (m_bIsInitialised) { m_nPreviousUserPause = m_nUserPause; @@ -130,8 +126,8 @@ cAudioManager::CreateEntity(eAudioType type, void *entity) return AEHANDLE_ERROR_BADAUDIOTYPE; for (uint32 i = 0; i < ARRAY_SIZE(m_asAudioEntities); i++) { if (!m_asAudioEntities[i].m_bIsUsed) { - m_asAudioEntities[i].m_bIsUsed = true; - m_asAudioEntities[i].m_bStatus = false; + m_asAudioEntities[i].m_bIsUsed = TRUE; + m_asAudioEntities[i].m_bStatus = FALSE; m_asAudioEntities[i].m_nType = type; m_asAudioEntities[i].m_pEntity = entity; m_asAudioEntities[i].m_awAudioEvent[0] = SOUND_NO_SOUND; @@ -150,7 +146,7 @@ void cAudioManager::DestroyEntity(int32 id) { if (m_bIsInitialised && id >= 0 && id < NUM_AUDIOENTITIES && m_asAudioEntities[id].m_bIsUsed) { - m_asAudioEntities[id].m_bIsUsed = false; + m_asAudioEntities[id].m_bIsUsed = FALSE; for (int32 i = 0; i < m_nAudioEntitiesTotal; ++i) { if (id == m_anAudioEntityIndices[i]) { if (i < NUM_AUDIOENTITIES - 1) @@ -163,7 +159,7 @@ cAudioManager::DestroyEntity(int32 id) } void -cAudioManager::SetEntityStatus(int32 id, uint8 status) +cAudioManager::SetEntityStatus(int32 id, bool8 status) { if (m_bIsInitialised && id >= 0 && id < NUM_AUDIOENTITIES && m_asAudioEntities[id].m_bIsUsed) m_asAudioEntities[id].m_bStatus = status; @@ -191,7 +187,7 @@ cAudioManager::PlayOneShot(int32 index, uint16 sound, float vol) } } else { int32 i = 0; - while (true) { + while (TRUE) { if (i >= entity.m_AudioEvents) { if (entity.m_AudioEvents < ARRAY_SIZE(entity.m_awAudioEvent)) { entity.m_awAudioEvent[i] = sound; @@ -238,7 +234,7 @@ cAudioManager::SetEffectsFadeVol(uint8 volume) const } void -cAudioManager::SetMonoMode(uint8 mono) +cAudioManager::SetMonoMode(bool8 mono) { SampleManager.SetMonoMode(mono); } @@ -253,7 +249,7 @@ void cAudioManager::ResetTimers(uint32 time) { if (m_bIsInitialised) { - m_bTimerJustReset = true; + m_bTimerJustReset = TRUE; m_nTimer = time; ClearRequestedQueue(); if (m_nActiveSampleQueue) { @@ -267,7 +263,7 @@ cAudioManager::ResetTimers(uint32 time) } ClearActiveSamples(); ClearMissionAudio(); - SampleManager.StopChannel(policeChannel); + SampleManager.StopChannel(CHANNEL_POLICE_RADIO); SampleManager.SetEffectsFadeVolume(0); SampleManager.SetMusicFadeVolume(0); MusicManager.ResetMusicAfterReload(); @@ -325,7 +321,7 @@ cAudioManager::Get3DProviderName(uint8 id) const if (!m_bIsInitialised) return nil; #ifdef AUDIO_OAL - id = clamp(id, 0, SampleManager.GetNum3DProvidersAvailable() - 1); + id = Clamp(id, 0, SampleManager.GetNum3DProvidersAvailable() - 1); #else // We don't want that either since it will crash the game, but skipping for now if (id >= SampleManager.GetNum3DProvidersAvailable()) @@ -372,13 +368,13 @@ cAudioManager::SetSpeakerConfig(int32 conf) const SampleManager.SetSpeakerConfig(conf); } -bool +bool8 cAudioManager::IsMP3RadioChannelAvailable() const { if (m_bIsInitialised) return SampleManager.IsMP3RadioChannelAvailable(); - return false; + return FALSE; } void @@ -398,27 +394,27 @@ cAudioManager::ReacquireDigitalHandle() const } void -cAudioManager::SetDynamicAcousticModelingStatus(uint8 status) +cAudioManager::SetDynamicAcousticModelingStatus(bool8 status) { - m_bDynamicAcousticModelingStatus = status!=0; + m_bDynamicAcousticModelingStatus = status; } -bool +bool8 cAudioManager::CheckForAnAudioFileOnCD() const { return SampleManager.CheckForAnAudioFileOnCD(); } -uint8 +char cAudioManager::GetCDAudioDriveLetter() const { if (m_bIsInitialised) return SampleManager.GetCDAudioDriveLetter(); - return 0; + return '\0'; } -bool +bool8 cAudioManager::IsAudioInitialised() const { return m_bIsInitialised; @@ -427,9 +423,12 @@ cAudioManager::IsAudioInitialised() const void cAudioManager::ServiceSoundEffects() { +#ifdef FIX_BUGS + if(CTimer::GetLogicalFramesPassed() != 0) +#endif m_bFifthFrameFlag = (m_FrameCounter++ % 5) == 0; if (m_nUserPause && !m_nPreviousUserPause) { - for (int32 i = 0; i < allChannels; i++) + for (int32 i = 0; i < NUM_CHANNELS; i++) SampleManager.StopChannel(i); ClearRequestedQueue(); @@ -527,7 +526,7 @@ cAudioManager::RandomDisplacement(uint32 seed) const { int32 value; - static bool bPos = true; + static bool8 bPos = TRUE; static uint32 Adjustment = 0; if (!seed) @@ -558,7 +557,7 @@ cAudioManager::AddSampleToRequestedQueue() { int32 calculatedVolume; uint8 sampleIndex; - bool bReflections; + bool8 bReflections; if (m_sQueueSample.m_nSampleIndex < TOTAL_AUDIO_SAMPLES) { calculatedVolume = m_sQueueSample.m_nReleasingVolumeModificator * (MAX_VOLUME - m_sQueueSample.m_nVolume); @@ -571,21 +570,21 @@ cAudioManager::AddSampleToRequestedQueue() ++m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; } m_sQueueSample.m_nCalculatedVolume = calculatedVolume; - m_sQueueSample.m_bLoopEnded = false; + m_sQueueSample.m_bLoopEnded = FALSE; if (m_sQueueSample.m_bIs2D) { - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bRequireReflection = FALSE; m_sQueueSample.m_nLoopsRemaining = 0; } if (m_bDynamicAcousticModelingStatus && m_sQueueSample.m_nLoopCount) { bReflections = m_sQueueSample.m_bRequireReflection; } else { - bReflections = false; + bReflections = FALSE; m_sQueueSample.m_nLoopsRemaining = 0; } - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bRequireReflection = FALSE; if (!m_bDynamicAcousticModelingStatus) - m_sQueueSample.m_bReverbFlag = false; + m_sQueueSample.m_bReverbFlag = FALSE; m_asSamples[m_nActiveSampleQueue][sampleIndex] = m_sQueueSample; @@ -692,7 +691,12 @@ cAudioManager::UpdateReflections() void cAudioManager::AddReleasingSounds() { - bool toProcess[44]; // why not 27? + // in case someone would want to increase it +#ifdef FIX_BUGS + bool8 toProcess[NUM_CHANNELS_GENERIC]; +#else + bool8 toProcess[44]; +#endif int8 queue = m_nActiveSampleQueue == 0 ? 1 : 0; @@ -701,19 +705,19 @@ cAudioManager::AddReleasingSounds() if (sample.m_bLoopEnded) continue; - toProcess[i] = false; + toProcess[i] = FALSE; for (int32 j = 0; j < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; j++) { if (sample.m_nEntityIndex == m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][j]].m_nEntityIndex && sample.m_nCounter == m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][j]].m_nCounter) { - toProcess[i] = true; + toProcess[i] = TRUE; break; } } if (!toProcess[i]) { if (sample.m_nCounter <= 255 || !sample.m_nLoopsRemaining) { - if (!sample.m_nReleasingVolumeDivider) + if (sample.m_nReleasingVolumeDivider == 0) continue; - if (!sample.m_nLoopCount) { + if (sample.m_nLoopCount == 0) { if (sample.m_nVolumeChange == -1) { sample.m_nVolumeChange = sample.m_nVolume / sample.m_nReleasingVolumeDivider; if (sample.m_nVolumeChange <= 0) @@ -725,6 +729,9 @@ cAudioManager::AddReleasingSounds() } sample.m_nVolume -= sample.m_nVolumeChange; } +#ifdef FIX_BUGS + if(CTimer::GetLogicalFramesPassed() != 0) +#endif --sample.m_nReleasingVolumeDivider; if (m_bFifthFrameFlag) { if (sample.m_nReleasingVolumeModificator < 20) @@ -741,7 +748,7 @@ cAudioManager::AddReleasingSounds() void cAudioManager::ProcessActiveQueues() { - bool flag; + bool8 flag; float position2; float position1; @@ -758,8 +765,8 @@ cAudioManager::ProcessActiveQueues() CVector position; for (int32 i = 0; i < m_nActiveSamples; i++) { - m_asSamples[m_nActiveSampleQueue][i].m_bIsProcessed = false; - m_asActiveSamples[i].m_bIsProcessed = false; + m_asSamples[m_nActiveSampleQueue][i].m_bIsProcessed = FALSE; + m_asActiveSamples[i].m_bIsProcessed = FALSE; } for (int32 i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; ++i) { @@ -775,15 +782,15 @@ cAudioManager::ProcessActiveQueues() flag = !(j & 1); } if (flag && !SampleManager.GetChannelUsedFlag(j)) { - sample.m_bLoopEnded = true; - m_asActiveSamples[j].m_bLoopEnded = true; + sample.m_bLoopEnded = TRUE; + m_asActiveSamples[j].m_bLoopEnded = TRUE; m_asActiveSamples[j].m_nSampleIndex = NO_SAMPLE; m_asActiveSamples[j].m_nEntityIndex = AEHANDLE_NONE; continue; } } - sample.m_bIsProcessed = true; - m_asActiveSamples[j].m_bIsProcessed = true; + sample.m_bIsProcessed = TRUE; + m_asActiveSamples[j].m_bIsProcessed = TRUE; sample.m_nVolumeChange = -1; if (!sample.m_bReleasingSoundFlag) { if (sample.m_bIs2D) { @@ -837,8 +844,8 @@ cAudioManager::ProcessActiveQueues() SampleManager.SetChannelReverbFlag(j, sample.m_bReverbFlag); break; } - sample.m_bIsProcessed = false; - m_asActiveSamples[j].m_bIsProcessed = false; + sample.m_bIsProcessed = FALSE; + m_asActiveSamples[j].m_bIsProcessed = FALSE; } } } @@ -902,8 +909,8 @@ cAudioManager::ProcessActiveQueues() SampleManager.SetChannel3DDistances(j, m_asActiveSamples[j].m_fSoundIntensity, 0.25f * m_asActiveSamples[j].m_fSoundIntensity); SampleManager.StartChannel(j); } - m_asActiveSamples[j].m_bIsProcessed = true; - sample.m_bIsProcessed = true; + m_asActiveSamples[j].m_bIsProcessed = TRUE; + sample.m_bIsProcessed = TRUE; sample.m_nVolumeChange = -1; break; } @@ -930,28 +937,30 @@ cAudioManager::ClearActiveSamples() m_asActiveSamples[i].m_nCounter = 0; m_asActiveSamples[i].m_nSampleIndex = NO_SAMPLE; m_asActiveSamples[i].m_nBankIndex = INVALID_SFX_BANK; - m_asActiveSamples[i].m_bIs2D = false; + m_asActiveSamples[i].m_bIs2D = FALSE; m_asActiveSamples[i].m_nReleasingVolumeModificator = 5; m_asActiveSamples[i].m_nFrequency = 0; m_asActiveSamples[i].m_nVolume = 0; m_asActiveSamples[i].m_nEmittingVolume = 0; m_asActiveSamples[i].m_fDistance = 0.0f; - m_asActiveSamples[i].m_bIsProcessed = false; - m_asActiveSamples[i].m_bLoopEnded = false; + m_asActiveSamples[i].m_bIsProcessed = FALSE; + m_asActiveSamples[i].m_bLoopEnded = FALSE; m_asActiveSamples[i].m_nLoopCount = 1; +#ifndef GTA_PS2 m_asActiveSamples[i].m_nLoopStart = 0; m_asActiveSamples[i].m_nLoopEnd = -1; +#endif m_asActiveSamples[i].m_fSpeedMultiplier = 0.0f; m_asActiveSamples[i].m_fSoundIntensity = 200.0f; m_asActiveSamples[i].m_nOffset = 63; - m_asActiveSamples[i].m_bReleasingSoundFlag = false; + m_asActiveSamples[i].m_bReleasingSoundFlag = FALSE; m_asActiveSamples[i].m_nCalculatedVolume = 0; m_asActiveSamples[i].m_nReleasingVolumeDivider = 0; m_asActiveSamples[i].m_nVolumeChange = -1; m_asActiveSamples[i].m_vecPos = CVector(0.0f, 0.0f, 0.0f); - m_asActiveSamples[i].m_bReverbFlag = false; + m_asActiveSamples[i].m_bReverbFlag = FALSE; m_asActiveSamples[i].m_nLoopsRemaining = 0; - m_asActiveSamples[i].m_bRequireReflection = false; + m_asActiveSamples[i].m_bRequireReflection = FALSE; } } @@ -968,7 +977,7 @@ void cAudioManager::AdjustSamplesVolume() { for (int i = 0; i < m_SampleRequestQueuesStatus[m_nActiveSampleQueue]; i++) { - tSound *pSample = &m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i] + 1]; + tSound *pSample = &m_asSamples[m_nActiveSampleQueue][m_abSampleQueueIndexTable[m_nActiveSampleQueue][i]]; if (!pSample->m_bIs2D) pSample->m_nEmittingVolume = ComputeEmittingVolume(pSample->m_nEmittingVolume, pSample->m_fSoundIntensity, pSample->m_fDistance); diff --git a/src/audio/AudioManager.h b/src/audio/AudioManager.h index 2f86ee98..70302745 100644 --- a/src/audio/AudioManager.h +++ b/src/audio/AudioManager.h @@ -2,7 +2,7 @@ #include "audio_enums.h" #include "AudioCollision.h" -#include "PoliceRadio.h" +#include "PolRadio.h" class tSound { @@ -11,26 +11,28 @@ public: int32 m_nCounter; int32 m_nSampleIndex; uint8 m_nBankIndex; - bool m_bIs2D; + bool8 m_bIs2D; int32 m_nReleasingVolumeModificator; uint32 m_nFrequency; uint8 m_nVolume; float m_fDistance; int32 m_nLoopCount; +#ifndef GTA_PS2 int32 m_nLoopStart; int32 m_nLoopEnd; +#endif uint8 m_nEmittingVolume; float m_fSpeedMultiplier; float m_fSoundIntensity; - bool m_bReleasingSoundFlag; + bool8 m_bReleasingSoundFlag; CVector m_vecPos; - bool m_bReverbFlag; + bool8 m_bReverbFlag; uint8 m_nLoopsRemaining; - bool m_bRequireReflection; // Used for oneshots + bool8 m_bRequireReflection; // Used for oneshots uint8 m_nOffset; int32 m_nReleasingVolumeDivider; - bool m_bIsProcessed; - bool m_bLoopEnded; + bool8 m_bIsProcessed; + bool8 m_bLoopEnded; int32 m_nCalculatedVolume; int8 m_nVolumeChange; }; @@ -45,7 +47,7 @@ class tAudioEntity public: eAudioType m_nType; void *m_pEntity; - bool m_bIsUsed; + bool8 m_bIsUsed; uint8 m_bStatus; int16 m_awAudioEvent[NUM_AUDIOENTITY_EVENTS]; float m_afVolume[NUM_AUDIOENTITY_EVENTS]; @@ -99,13 +101,13 @@ class cMissionAudio { public: CVector m_vecPos; - bool m_bPredefinedProperties; + bool8 m_bPredefinedProperties; int32 m_nSampleIndex; uint8 m_nLoadingStatus; uint8 m_nPlayStatus; - bool m_bIsPlaying; + bool8 m_bIsPlaying; int32 m_nMissionAudioCounter; - bool m_bIsPlayed; + bool8 m_bIsPlayed; }; VALIDATE_SIZE(cMissionAudio, 32); @@ -129,7 +131,7 @@ class CPed; class cPedParams { public: - bool m_bDistanceCalculated; + bool8 m_bDistanceCalculated; float m_fDistance; CPed *m_pPed; @@ -144,7 +146,7 @@ public: class cVehicleParams { public: - bool m_bDistanceCalculated; + bool8 m_bDistanceCalculated; float m_fDistance; CVehicle *m_pVehicle; cTransmission *m_pTransmission; @@ -184,21 +186,21 @@ enum { class cAudioManager { public: - bool m_bIsInitialised; - bool m_bReverb; // unused - bool m_bFifthFrameFlag; + bool8 m_bIsInitialised; + bool8 m_bReverb; // unused + bool8 m_bFifthFrameFlag; uint8 m_nActiveSamples; uint8 field_4; // unused - bool m_bDynamicAcousticModelingStatus; + bool8 m_bDynamicAcousticModelingStatus; float m_fSpeedOfSound; - bool m_bTimerJustReset; + bool8 m_bTimerJustReset; int32 m_nTimer; tSound m_sQueueSample; uint8 m_nActiveSampleQueue; - tSound m_asSamples[NUM_SOUNDS_SAMPLES_BANKS][NUM_SOUNDS_SAMPLES_SLOTS]; - uint8 m_abSampleQueueIndexTable[NUM_SOUNDS_SAMPLES_BANKS][NUM_SOUNDS_SAMPLES_SLOTS]; + tSound m_asSamples[NUM_SOUNDS_SAMPLES_BANKS][NUM_CHANNELS_GENERIC]; + uint8 m_abSampleQueueIndexTable[NUM_SOUNDS_SAMPLES_BANKS][NUM_CHANNELS_GENERIC]; uint8 m_SampleRequestQueuesStatus[NUM_SOUNDS_SAMPLES_BANKS]; - tSound m_asActiveSamples[NUM_SOUNDS_SAMPLES_SLOTS]; + tSound m_asActiveSamples[NUM_CHANNELS_GENERIC]; tAudioEntity m_asAudioEntities[NUM_AUDIOENTITIES]; int32 m_anAudioEntityIndices[NUM_AUDIOENTITIES]; int32 m_nAudioEntitiesTotal; @@ -230,19 +232,19 @@ 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 ShouldDuckMissionAudio() const { return m_sMissionAudio.m_nPlayStatus == 1; } + bool8 ShouldDuckMissionAudio() const { return m_sMissionAudio.m_nPlayStatus == 1; } // "Should" be in alphabetic order, except "getXTalkSfx" void AddDetailsToRequestedOrderList(uint8 sample); void AddPlayerCarSample(uint8 emittingVolume, int32 freq, uint32 sample, uint8 bank, - uint8 counter, bool notLooping); + uint8 counter, bool8 notLooping); void AddReflectionsToRequestedQueue(); void AddReleasingSounds(); void AddSampleToRequestedQueue(); void AgeCrimes(); - void CalculateDistance(bool &condition, float dist); - bool CheckForAnAudioFileOnCD() const; + void CalculateDistance(bool8 &condition, float dist); + bool8 CheckForAnAudioFileOnCD() const; void ClearActiveSamples(); void ClearMissionAudio(); void ClearRequestedQueue(); @@ -338,7 +340,7 @@ public: void GenerateIntegerRandomNumberTable(); char *Get3DProviderName(uint8 id) const; - uint8 GetCDAudioDriveLetter() const; + char GetCDAudioDriveLetter() const; int8 GetCurrent3DProviderIndex() const; float GetCollisionLoopingRatio(uint32 a, uint32 b, float c) const; // not used float GetCollisionOneShotRatio(int32 a, float b) const; @@ -355,17 +357,17 @@ public: float GetVehicleNonDriveWheelSkidValue(uint8 wheel, CAutomobile *automobile, cTransmission *transmission, float velocityChange); - bool HasAirBrakes(int32 model) const; + bool8 HasAirBrakes(int32 model) const; void Initialise(); void InitialisePoliceRadio(); void InitialisePoliceRadioZones(); void InterrogateAudioEntities(); - bool IsAudioInitialised() const; - bool IsMissionAudioSampleFinished(); - bool IsMP3RadioChannelAvailable() const; + bool8 IsAudioInitialised() const; + bool8 IsMissionAudioSampleFinished(); + bool8 IsMP3RadioChannelAvailable() const; - bool MissionScriptAudioUsesPoliceChannel(int32 soundMission) const; + bool8 MissionScriptAudioUsesPoliceChannel(int32 soundMission) const; void PlayLoadedMissionAudio(); void PlayOneShot(int32 index, uint16 sound, float vol); @@ -379,27 +381,27 @@ public: void PreTerminateGameSpecificShutdown(); /// processX - main logic of adding new sounds void ProcessActiveQueues(); - bool ProcessAirBrakes(cVehicleParams& params); + bool8 ProcessAirBrakes(cVehicleParams& params); void ProcessAirportScriptObject(uint8 sound); - bool ProcessBoatEngine(cVehicleParams& params); - bool ProcessBoatMovingOverWater(cVehicleParams& params); + bool8 ProcessBoatEngine(cVehicleParams& params); + bool8 ProcessBoatMovingOverWater(cVehicleParams& params); void ProcessBridge(); void ProcessBridgeMotor(); void ProcessBridgeOneShots(); void ProcessBridgeWarning(); - bool ProcessCarBombTick(cVehicleParams& params); + bool8 ProcessCarBombTick(cVehicleParams& params); void ProcessCesna(cVehicleParams& params); void ProcessCinemaScriptObject(uint8 sound); void ProcessCrane(); void ProcessDocksScriptObject(uint8 sound); - bool ProcessEngineDamage(cVehicleParams& params); + bool8 ProcessEngineDamage(cVehicleParams& params); void ProcessEntity(int32 sound); void ProcessExplosions(int32 explosion); void ProcessFireHydrant(); void ProcessFires(int32 entity); void ProcessFrontEnd(); void ProcessGarages(); - bool ProcessHelicopter(cVehicleParams& params); + bool8 ProcessHelicopter(cVehicleParams& params); void ProcessHomeScriptObject(uint8 sound); void ProcessJumbo(cVehicleParams& params); void ProcessJumboAccel(CPlane *plane); @@ -424,24 +426,24 @@ public: void ProcessProjectiles(); void ProcessRainOnVehicle(cVehicleParams& params); void ProcessReverb() const; - bool ProcessReverseGear(cVehicleParams& params); + bool8 ProcessReverseGear(cVehicleParams& params); void ProcessSawMillScriptObject(uint8 sound); void ProcessScriptObject(int32 id); void ProcessShopScriptObject(uint8 sound); void ProcessSpecial(); - bool ProcessTrainNoise(cVehicleParams& params); + bool8 ProcessTrainNoise(cVehicleParams& params); void ProcessVehicle(CVehicle *vehicle); - bool ProcessVehicleDoors(cVehicleParams& params); + bool8 ProcessVehicleDoors(cVehicleParams& params); void ProcessVehicleEngine(cVehicleParams& params); void ProcessVehicleHorn(cVehicleParams& params); void ProcessVehicleOneShots(cVehicleParams& params); - bool ProcessVehicleReverseWarning(cVehicleParams& params); - bool ProcessVehicleRoadNoise(cVehicleParams& params); - bool ProcessVehicleSirenOrAlarm(cVehicleParams& params); - bool ProcessVehicleSkidding(cVehicleParams& params); + bool8 ProcessVehicleReverseWarning(cVehicleParams& params); + bool8 ProcessVehicleRoadNoise(cVehicleParams& params); + bool8 ProcessVehicleSirenOrAlarm(cVehicleParams& params); + bool8 ProcessVehicleSkidding(cVehicleParams& params); void ProcessWaterCannon(int32); void ProcessWeather(int32 id); - bool ProcessWetRoadNoise(cVehicleParams& params); + bool8 ProcessWetRoadNoise(cVehicleParams& params); void ProcessWorkShopScriptObject(uint8 sound); int32 RandomDisplacement(uint32 seed) const; @@ -460,25 +462,25 @@ public: void ServicePoliceRadioChannel(uint8 wantedLevel); void ServiceSoundEffects(); int8 SetCurrent3DProvider(uint8 which); - void SetDynamicAcousticModelingStatus(uint8 status); + void SetDynamicAcousticModelingStatus(bool8 status); void SetEffectsFadeVol(uint8 volume) const; void SetEffectsMasterVolume(uint8 volume) const; - void SetEntityStatus(int32 id, uint8 status); + void SetEntityStatus(int32 id, bool8 status); uint32 SetLoopingCollisionRequestedSfxFreqAndGetVol(const cAudioCollision &audioCollision); void SetMissionAudioLocation(float x, float y, float z); void SetMissionScriptPoliceAudio(int32 sfx) const; - void SetMonoMode(uint8 mono); + void SetMonoMode(bool8 mono); void SetMusicFadeVol(uint8 volume) const; void SetMusicMasterVolume(uint8 volume) const; void SetSpeakerConfig(int32 conf) const; void SetUpLoopingCollisionSound(const cAudioCollision &col, uint8 counter); void SetUpOneShotCollisionSound(const cAudioCollision &col); - bool SetupCrimeReport(); - bool SetupJumboEngineSound(uint8 vol, uint32 freq); - bool SetupJumboFlySound(uint8 emittingVol); - bool SetupJumboRumbleSound(uint8 emittingVol); - bool SetupJumboTaxiSound(uint8 vol); - bool SetupJumboWhineSound(uint8 emittingVol, uint32 freq); + bool8 SetupCrimeReport(); + bool8 SetupJumboEngineSound(uint8 vol, uint32 freq); + bool8 SetupJumboFlySound(uint8 emittingVol); + bool8 SetupJumboRumbleSound(uint8 emittingVol); + bool8 SetupJumboTaxiSound(uint8 vol); + bool8 SetupJumboWhineSound(uint8 emittingVol, uint32 freq); void SetupPedComments(cPedParams ¶ms, uint16 sound); void SetupSuspectLastSeenReport(); @@ -487,9 +489,9 @@ public: void UpdateGasPedalAudio(CAutomobile *automobile); void UpdateReflections(); - bool UsesReverseWarning(int32 model) const; - bool UsesSiren(int32 model) const; - bool UsesSirenSwitching(int32 model) const; + bool8 UsesReverseWarning(int32 model) const; + bool8 UsesSiren(int32 model) const; + bool8 UsesSirenSwitching(int32 model) const; #ifdef GTA_PC // only used in pc @@ -498,7 +500,24 @@ public: #endif }; -#ifdef AUDIO_MSS +/* + Manual loop points are not on PS2 so let's have these macros to avoid massive ifndefs. + Setting these manually was pointless anyway since they never change from sdt values. + What were they thinking? +*/ +#ifndef GTA_PS2 +#define RESET_LOOP_OFFSETS \ + m_sQueueSample.m_nLoopStart = 0; \ + m_sQueueSample.m_nLoopEnd = -1; +#define SET_LOOP_OFFSETS(sample) \ + m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(sample); \ + m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(sample); +#else +#define RESET_LOOP_OFFSETS +#define SET_LOOP_OFFSETS(sample) +#endif + +#if defined(AUDIO_MSS) && !defined(PS2_AUDIO_CHANNELS) static_assert(sizeof(cAudioManager) == 19220, "cAudioManager: error"); #endif diff --git a/src/audio/AudioScriptObject.cpp b/src/audio/AudioScriptObject.cpp index ac30f757..03efdea9 100644 --- a/src/audio/AudioScriptObject.cpp +++ b/src/audio/AudioScriptObject.cpp @@ -3,6 +3,7 @@ #include "AudioScriptObject.h" #include "Pools.h" #include "DMAudio.h" +#include "SaveBuf.h" cAudioScriptObject::cAudioScriptObject() { @@ -23,25 +24,25 @@ cAudioScriptObject::Reset() } void * -cAudioScriptObject::operator new(size_t sz) +cAudioScriptObject::operator new(size_t sz) throw() { return CPools::GetAudioScriptObjectPool()->New(); } void * -cAudioScriptObject::operator new(size_t sz, int handle) +cAudioScriptObject::operator new(size_t sz, int handle) throw() { return CPools::GetAudioScriptObjectPool()->New(handle); } void -cAudioScriptObject::operator delete(void *p, size_t sz) +cAudioScriptObject::operator delete(void *p, size_t sz) throw() { CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p); } void -cAudioScriptObject::operator delete(void *p, int handle) +cAudioScriptObject::operator delete(void *p, int handle) throw() { CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p); } @@ -53,12 +54,14 @@ cAudioScriptObject::LoadAllAudioScriptObjects(uint8 *buf, uint32 size) CheckSaveHeader(buf, 'A', 'U', 'D', '\0', size - SAVE_HEADER_SIZE); - int32 pool_size = ReadSaveBuf<int32>(buf); + int32 pool_size; + ReadSaveBuf(&pool_size, buf); for (int32 i = 0; i < pool_size; i++) { - int handle = ReadSaveBuf<int32>(buf); + int32 handle; + ReadSaveBuf(&handle, buf); cAudioScriptObject *p = new(handle) cAudioScriptObject; assert(p != nil); - *p = ReadSaveBuf<cAudioScriptObject>(buf); + ReadSaveBuf(p, buf); p->AudioEntity = DMAudio.CreateLoopingScriptObject(p); } diff --git a/src/audio/AudioScriptObject.h b/src/audio/AudioScriptObject.h index 8110b2bb..b9a7e61b 100644 --- a/src/audio/AudioScriptObject.h +++ b/src/audio/AudioScriptObject.h @@ -12,10 +12,10 @@ public: void Reset(); /// ok - static void* operator new(size_t); - static void* operator new(size_t, int); - static void operator delete(void*, size_t); - static void operator delete(void*, int); + static void* operator new(size_t) throw(); + static void* operator new(size_t, int) throw(); + static void operator delete(void*, size_t) throw(); + static void operator delete(void*, int) throw(); static void LoadAllAudioScriptObjects(uint8 *buf, uint32 size); static void SaveAllAudioScriptObjects(uint8 *buf, uint32 *size); diff --git a/src/audio/DMAudio.cpp b/src/audio/DMAudio.cpp index 1027a084..eea91bd1 100644 --- a/src/audio/DMAudio.cpp +++ b/src/audio/DMAudio.cpp @@ -39,7 +39,7 @@ cDMAudio::DestroyEntity(int32 audioEntity) } void -cDMAudio::SetEntityStatus(int32 audioEntity, uint8 status) +cDMAudio::SetEntityStatus(int32 audioEntity, bool8 status) { AudioManager.SetEntityStatus(audioEntity, status); } @@ -57,7 +57,7 @@ cDMAudio::DestroyAllGameCreatedEntities(void) } void -cDMAudio::SetMonoMode(uint8 mono) +cDMAudio::SetMonoMode(bool8 mono) { AudioManager.SetMonoMode(mono); } @@ -128,7 +128,7 @@ cDMAudio::SetSpeakerConfig(int32 config) AudioManager.SetSpeakerConfig(config); } -bool +bool8 cDMAudio::IsMP3RadioChannelAvailable(void) { return AudioManager.IsMP3RadioChannelAvailable(); @@ -147,12 +147,12 @@ cDMAudio::ReacquireDigitalHandle(void) } void -cDMAudio::SetDynamicAcousticModelingStatus(uint8 status) +cDMAudio::SetDynamicAcousticModelingStatus(bool8 status) { AudioManager.SetDynamicAcousticModelingStatus(status); } -bool +bool8 cDMAudio::CheckForAnAudioFileOnCD(void) { return AudioManager.CheckForAnAudioFileOnCD(); @@ -164,7 +164,7 @@ cDMAudio::GetCDAudioDriveLetter(void) return AudioManager.GetCDAudioDriveLetter(); } -bool +bool8 cDMAudio::IsAudioInitialised(void) { return AudioManager.IsAudioInitialised(); @@ -182,7 +182,7 @@ cDMAudio::CreateLoopingScriptObject(cAudioScriptObject *scriptObject) int32 audioEntity = AudioManager.CreateEntity(AUDIOTYPE_SCRIPTOBJECT, scriptObject); if ( AEHANDLE_IS_OK(audioEntity) ) - AudioManager.SetEntityStatus(audioEntity, true); + AudioManager.SetEntityStatus(audioEntity, TRUE); return audioEntity; } @@ -200,7 +200,7 @@ cDMAudio::CreateOneShotScriptObject(cAudioScriptObject *scriptObject) if ( AEHANDLE_IS_OK(audioEntity) ) { - AudioManager.SetEntityStatus(audioEntity, true); + AudioManager.SetEntityStatus(audioEntity, TRUE); AudioManager.PlayOneShot(audioEntity, scriptObject->AudioId, 0.0f); } } @@ -230,7 +230,7 @@ cDMAudio::PlayRadioAnnouncement(uint8 announcement) } void -cDMAudio::PlayFrontEndTrack(uint8 track, uint8 frontendFlag) +cDMAudio::PlayFrontEndTrack(uint8 track, bool8 frontendFlag) { MusicManager.PlayFrontEndTrack(track, frontendFlag); } @@ -295,7 +295,7 @@ cDMAudio::PlayLoadedMissionAudio(void) AudioManager.PlayLoadedMissionAudio(); } -bool +bool8 cDMAudio::IsMissionAudioSampleFinished(void) { return AudioManager.IsMissionAudioSampleFinished(); diff --git a/src/audio/DMAudio.h b/src/audio/DMAudio.h index 3e6d5603..19689fab 100644 --- a/src/audio/DMAudio.h +++ b/src/audio/DMAudio.h @@ -22,11 +22,11 @@ public: int32 CreateEntity(eAudioType type, void *UID); void DestroyEntity(int32 audioEntity); - void SetEntityStatus(int32 audioEntity, uint8 status); + void SetEntityStatus(int32 audioEntity, bool8 status); void PlayOneShot(int32 audioEntity, uint16 oneShot, float volume); void DestroyAllGameCreatedEntities(void); - void SetMonoMode(uint8 mono); + void SetMonoMode(bool8 mono); void SetEffectsMasterVolume(uint8 volume); void SetMusicMasterVolume(uint8 volume); void SetEffectsFadeVol(uint8 volume); @@ -40,17 +40,17 @@ public: void SetSpeakerConfig(int32 config); - bool IsMP3RadioChannelAvailable(void); + bool8 IsMP3RadioChannelAvailable(void); void ReleaseDigitalHandle(void); void ReacquireDigitalHandle(void); - void SetDynamicAcousticModelingStatus(uint8 status); + void SetDynamicAcousticModelingStatus(bool8 status); - bool CheckForAnAudioFileOnCD(void); + bool8 CheckForAnAudioFileOnCD(void); char GetCDAudioDriveLetter(void); - bool IsAudioInitialised(void); + bool8 IsAudioInitialised(void); void ReportCrime(eCrimeType crime, CVector const &pos); @@ -64,7 +64,7 @@ public: void PlayFrontEndSound(uint16 frontend, uint32 volume); void PlayRadioAnnouncement(uint8 announcement); - void PlayFrontEndTrack(uint8 track, uint8 frontendFlag); + void PlayFrontEndTrack(uint8 track, bool8 frontendFlag); void StopFrontEndTrack(void); void ResetTimers(uint32 time); @@ -79,7 +79,7 @@ public: uint8 GetMissionAudioLoadingStatus(void); void SetMissionAudioLocation(float x, float y, float z); void PlayLoadedMissionAudio(void); - bool IsMissionAudioSampleFinished(void); + bool8 IsMissionAudioSampleFinished(void); void ClearMissionAudio(void); uint8 GetRadioInCar(void); diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp index 3e1a7384..cb441622 100644 --- a/src/audio/MusicManager.cpp +++ b/src/audio/MusicManager.cpp @@ -22,42 +22,42 @@ static_assert(false, "RADIO_SCROLL_TO_PREV_STATION and RADIO_OFF_TEXT won't work cMusicManager MusicManager; int32 gNumRetunePresses; int32 gRetuneCounter; -bool bHasStarted; +bool8 bHasStarted; cMusicManager::cMusicManager() { - m_bIsInitialised = false; - m_bDisabled = false; + m_bIsInitialised = FALSE; + m_bDisabled = FALSE; m_nMusicMode = MUSICMODE_DISABLED; m_nNextTrack = NO_TRACK; m_nPlayingTrack = NO_TRACK; - m_bFrontendTrackFinished = false; - m_bPlayInFrontend = false; - m_bSetNextStation = false; + m_bFrontendTrackFinished = FALSE; + m_bPlayInFrontend = FALSE; + m_bSetNextStation = FALSE; m_nAnnouncement = NO_TRACK; - m_bPreviousPlayerInCar = false; - m_bPlayerInCar = false; - m_bAnnouncementInProgress = false; - m_bVerifyAmbienceTrackStartedToPlay = false; - bHasStarted = false; + m_bPreviousPlayerInCar = FALSE; + m_bPlayerInCar = FALSE; + m_bAnnouncementInProgress = FALSE; + m_bVerifyAmbienceTrackStartedToPlay = FALSE; + bHasStarted = FALSE; } -bool +bool8 cMusicManager::PlayerInCar() { if(!FindPlayerVehicle()) - return false; + return FALSE; int32 State = FindPlayerPed()->m_nPedState; if(State == PED_DRAG_FROM_CAR || State == PED_EXIT_CAR || State == PED_ARRESTED) - return false; + return FALSE; if (!FindPlayerVehicle()) - return true; + return TRUE; if (FindPlayerVehicle()->GetStatus() == STATUS_WRECKED) - return false; + return FALSE; switch (FindPlayerVehicle()->GetModelIndex()) { case MI_FIRETRUCK: @@ -67,8 +67,8 @@ cMusicManager::PlayerInCar() case MI_TRAIN: case MI_SPEEDER: case MI_REEFER: - case MI_GHOST: return false; - default: return true; + case MI_GHOST: return FALSE; + default: return TRUE; } } @@ -195,7 +195,11 @@ cMusicManager::DisplayRadioStationName() cDisplay = 60; } else { if(cDisplay == 0) return; +#ifdef FIX_BUGS + cDisplay -= CTimer::GetLogicalFramesPassed(); +#else cDisplay--; +#endif } CFont::SetJustifyOff(); @@ -224,7 +228,7 @@ cMusicManager::DisplayRadioStationName() } } -bool +bool8 cMusicManager::Initialise() { int pos; @@ -265,18 +269,18 @@ cMusicManager::Initialise() m_aTracks[i].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); } - m_bResetTimers = false; + m_bResetTimers = FALSE; m_nResetTime = 0; m_nTimer = m_nLastTrackServiceTime = CTimer::GetTimeInMillisecondsPauseMode(); - m_bDoTrackService = false; - m_bIgnoreTimeDelay = false; - m_bRadioSetByScript = false; + m_bDoTrackService = FALSE; + m_bIgnoreTimeDelay = FALSE; + m_bRadioSetByScript = FALSE; m_nRadioStationScript = HEAD_RADIO; m_nRadioPosition = -1; m_nRadioInCar = NO_TRACK; gNumRetunePresses = 0; gRetuneCounter = 0; - m_bIsInitialised = true; + m_bIsInitialised = TRUE; } return m_bIsInitialised; } @@ -286,12 +290,12 @@ cMusicManager::Terminate() { if (!IsInitialised()) return; - if (SampleManager.IsStreamPlaying(0)) { - SampleManager.StopStreamedFile(0); + if (SampleManager.IsStreamPlaying()) { + SampleManager.StopStreamedFile(); m_nNextTrack = NO_TRACK; m_nPlayingTrack = NO_TRACK; } - m_bIsInitialised = false; + m_bIsInitialised = FALSE; } void @@ -302,7 +306,16 @@ cMusicManager::ChangeMusicMode(uint8 mode) uint8 mode2; switch (mode) { - case MUSICMODE_FRONTEND: mode2 = MUSICMODE_FRONTEND; break; + case MUSICMODE_FRONTEND: + mode2 = MUSICMODE_FRONTEND; +#ifdef PAUSE_RADIO_IN_FRONTEND + // rewind those streams we weren't listening right now + for (uint32 i = STREAMED_SOUND_RADIO_HEAD; i < STREAMED_SOUND_CUTSCENE_LUIGI1_LG; i++) { + m_aTracks[i].m_nPosition = GetTrackStartPos(i); + m_aTracks[i].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); + } +#endif + break; case MUSICMODE_GAME: mode2 = MUSICMODE_GAME; break; case MUSICMODE_CUTSCENE: mode2 = MUSICMODE_CUTSCENE; break; case MUSICMODE_DISABLE: mode2 = MUSICMODE_DISABLED; break; @@ -316,25 +329,25 @@ cMusicManager::ChangeMusicMode(uint8 mode) case MUSICMODE_GAME: case MUSICMODE_CUTSCENE: case MUSICMODE_DISABLED: - if (SampleManager.IsStreamPlaying(0)) { + if (SampleManager.IsStreamPlaying()) { if (m_nNextTrack < TOTAL_STREAMED_SOUNDS) { - m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0); + m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(); m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); } - SampleManager.StopStreamedFile(0); + SampleManager.StopStreamedFile(); } m_nNextTrack = NO_TRACK; m_nPlayingTrack = NO_TRACK; - m_bFrontendTrackFinished = false; - m_bPlayInFrontend = false; - m_bSetNextStation = false; - m_bPreviousPlayerInCar = false; - m_bPlayerInCar = false; - m_bAnnouncementInProgress = false; + m_bFrontendTrackFinished = FALSE; + m_bPlayInFrontend = FALSE; + m_bSetNextStation = FALSE; + m_bPreviousPlayerInCar = FALSE; + m_bPlayerInCar = FALSE; + m_bAnnouncementInProgress = FALSE; m_nTimer = m_nLastTrackServiceTime = CTimer::GetTimeInMillisecondsPauseMode(); - m_bDoTrackService = false; - m_bIgnoreTimeDelay = true; - m_bVerifyAmbienceTrackStartedToPlay = false; + m_bDoTrackService = FALSE; + m_bIgnoreTimeDelay = TRUE; + m_bVerifyAmbienceTrackStartedToPlay = FALSE; m_nMusicMode = mode2; break; default: return; @@ -383,7 +396,7 @@ void cMusicManager::SetRadioChannelByScript(uint8 station, int32 pos) { if (m_bIsInitialised && station < RADIO_OFF) { - m_bRadioSetByScript = true; + m_bRadioSetByScript = TRUE; m_nRadioStationScript = station; m_nRadioPosition = pos == -1 ? -1 : pos % m_aTracks[station].m_nLength; } @@ -393,12 +406,12 @@ cMusicManager::SetRadioChannelByScript(uint8 station, int32 pos) void cMusicManager::ResetMusicAfterReload() { - m_bRadioSetByScript = false; + m_bRadioSetByScript = FALSE; m_nRadioStationScript = 0; m_nRadioPosition = -1; m_nAnnouncement = NO_TRACK; - m_bAnnouncementInProgress = false; - m_bSetNextStation = false; + m_bAnnouncementInProgress = FALSE; + m_bSetNextStation = FALSE; gRetuneCounter = 0; gNumRetunePresses = 0; } @@ -407,7 +420,7 @@ cMusicManager::ResetMusicAfterReload() void cMusicManager::ResetTimers(int32 time) { - m_bResetTimers = true; + m_bResetTimers = TRUE; m_nResetTime = time; } @@ -415,26 +428,26 @@ void cMusicManager::Service() { if (m_bResetTimers) { - m_bResetTimers = false; + m_bResetTimers = FALSE; m_nLastTrackServiceTime = m_nResetTime; } if (!m_bIsInitialised || m_bDisabled) return; if (m_nMusicMode == MUSICMODE_CUTSCENE) { - SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, 1, 0); + SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, TRUE); return; } m_nTimer = CTimer::GetTimeInMillisecondsPauseMode(); if (m_nTimer > (m_nLastTrackServiceTime + 2000) || m_bIgnoreTimeDelay) { - m_bIgnoreTimeDelay = false; - m_bDoTrackService = true; + m_bIgnoreTimeDelay = FALSE; + m_bDoTrackService = TRUE; m_nLastTrackServiceTime = m_nTimer; - } else m_bDoTrackService = false; + } else m_bDoTrackService = FALSE; - if (m_nNextTrack == NO_TRACK && SampleManager.IsStreamPlaying(0)) - SampleManager.StopStreamedFile(0); + if (m_nNextTrack == NO_TRACK && SampleManager.IsStreamPlaying()) + SampleManager.StopStreamedFile(); else switch (m_nMusicMode) { case MUSICMODE_FRONTEND: ServiceFrontEndMode(); break; case MUSICMODE_GAME: ServiceGameMode(); break; @@ -444,9 +457,15 @@ cMusicManager::Service() void cMusicManager::ServiceFrontEndMode() { +#ifdef PAUSE_RADIO_IN_FRONTEND + // pause radio + for (uint32 i = STREAMED_SOUND_RADIO_HEAD; i < STREAMED_SOUND_CUTSCENE_LUIGI1_LG; i++) + m_aTracks[i].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); +#endif + if (m_nNextTrack < TOTAL_STREAMED_SOUNDS) { if (m_bFrontendTrackFinished) { - if (!SampleManager.IsStreamPlaying(0)) { + if (!SampleManager.IsStreamPlaying()) { switch (m_nNextTrack) { case STREAMED_SOUND_MISSION_COMPLETED: @@ -463,25 +482,25 @@ cMusicManager::ServiceFrontEndMode() m_nPlayingTrack = NO_TRACK; } } else if (bHasStarted) { - if (!SampleManager.IsStreamPlaying(0)) - SampleManager.StartStreamedFile(m_nNextTrack, 0, 0); + if (!SampleManager.IsStreamPlaying()) + SampleManager.StartStreamedFile(m_nNextTrack, 0); } else { - SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0); - if (!SampleManager.StartStreamedFile(m_nNextTrack, m_nNextTrack < NUM_RADIOS ? GetTrackStartPos(m_nNextTrack) : 0, 0)) + SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE); + if (!SampleManager.StartStreamedFile(m_nNextTrack, m_nNextTrack < NUM_RADIOS ? GetTrackStartPos(m_nNextTrack) : 0)) return; - SampleManager.SetStreamedVolumeAndPan(100, 63, 0, 0); - if (m_bPlayInFrontend) bHasStarted = true; - else m_bFrontendTrackFinished = true; + SampleManager.SetStreamedVolumeAndPan(100, 63, FALSE); + if (m_bPlayInFrontend) bHasStarted = TRUE; + else m_bFrontendTrackFinished = TRUE; } } - if (SampleManager.IsStreamPlaying(0)) - SampleManager.SetStreamedVolumeAndPan((CPad::GetPad(0)->bDisplayNoControllerMessage || CPad::GetPad(0)->bObsoleteControllerMessage) ? 0 : 100, 63, 0, 0); + if (SampleManager.IsStreamPlaying()) + SampleManager.SetStreamedVolumeAndPan((CPad::GetPad(0)->bDisplayNoControllerMessage || CPad::GetPad(0)->bObsoleteControllerMessage) ? 0 : 100, 63, FALSE); } void cMusicManager::ServiceGameMode() { - bool bRadioOff = false; + bool8 bRadioOff = FALSE; static int8 nFramesSinceCutsceneEnded = -1; uint8 volume; @@ -525,7 +544,7 @@ cMusicManager::ServiceGameMode() } if (AudioManager.m_nPreviousUserPause) - m_bPreviousPlayerInCar = false; + m_bPreviousPlayerInCar = FALSE; if (!m_bPlayerInCar) { if (m_bPreviousPlayerInCar) { if (m_nNextTrack != STREAMED_SOUND_RADIO_POLICE) @@ -541,7 +560,7 @@ cMusicManager::ServiceGameMode() && ServiceAnnouncement()) { if (m_bAnnouncementInProgress) { - m_bSetNextStation = false; + m_bSetNextStation = FALSE; return; } m_nPlayingTrack = m_nNextTrack; @@ -558,7 +577,7 @@ cMusicManager::ServiceGameMode() AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 1.0f); gRetuneCounter = 0; gNumRetunePresses = 0; - m_bSetNextStation = false; + m_bSetNextStation = FALSE; } // Because when you switch radio back and forth, gNumRetunePresses will be 0 but gRetuneCounter won't. #ifdef RADIO_SCROLL_TO_PREV_STATION @@ -566,24 +585,24 @@ cMusicManager::ServiceGameMode() if (gRetuneCounter > 1) gRetuneCounter--; else if (gRetuneCounter == 1) gRetuneCounter = -1; else if (gRetuneCounter == -1) { - m_bSetNextStation = true; + m_bSetNextStation = TRUE; gRetuneCounter = 0; } } #else if (gNumRetunePresses) { if (gRetuneCounter != 0) gRetuneCounter--; - else m_bSetNextStation = true; + else m_bSetNextStation = TRUE; } #endif if (gRetuneCounter) AudioManager.DoPoliceRadioCrackle(); if (m_bSetNextStation) { - m_bSetNextStation = false; + m_bSetNextStation = FALSE; m_nPlayingTrack = m_nNextTrack; m_nNextTrack = GetNextCarTuning(); if (m_nNextTrack == STREAMED_SOUND_CITY_AMBIENT || m_nNextTrack == STREAMED_SOUND_WATER_AMBIENT) - bRadioOff = true; + bRadioOff = TRUE; if (m_nPlayingTrack == STREAMED_SOUND_CITY_AMBIENT || m_nPlayingTrack == STREAMED_SOUND_WATER_AMBIENT) AudioManager.PlayOneShot(AudioManager.m_nFrontEndEntity, SOUND_FRONTEND_RADIO_CHANGE, 0.0f); @@ -592,7 +611,7 @@ cMusicManager::ServiceGameMode() if (ChangeRadioChannel()) { ServiceTrack(); } else { - m_bPlayerInCar = false; + m_bPlayerInCar = FALSE; if (FindPlayerVehicle()) FindPlayerVehicle()->m_nRadioStation = m_nNextTrack; m_nNextTrack = NO_TRACK; @@ -601,7 +620,7 @@ cMusicManager::ServiceGameMode() if (TheCamera.pTargetEntity != nil) { float DistToTargetSq = (TheCamera.pTargetEntity->GetPosition() - TheCamera.GetPosition()).MagnitudeSqr(); if (DistToTargetSq >= SQR(55.0f)) { - SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0); + SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE); } else if (DistToTargetSq >= SQR(10.0f)) { volume = ((45.0f - (Sqrt(DistToTargetSq) - 10.0f)) / 45.0f * 100.0f); uint8 pan; @@ -616,17 +635,17 @@ cMusicManager::ServiceGameMode() } if (gRetuneCounter) volume /= 4; - SampleManager.SetStreamedVolumeAndPan(volume, pan, 0, 0); + SampleManager.SetStreamedVolumeAndPan(volume, pan, FALSE); } else if (AudioManager.ShouldDuckMissionAudio()) { - SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0); + SampleManager.SetStreamedVolumeAndPan(25, 63, FALSE); } else if (gRetuneCounter) { - SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0); + SampleManager.SetStreamedVolumeAndPan(25, 63, FALSE); } else { - SampleManager.SetStreamedVolumeAndPan(100, 63, 0, 0); + SampleManager.SetStreamedVolumeAndPan(100, 63, FALSE); } } } else if (AudioManager.ShouldDuckMissionAudio()) { - SampleManager.SetStreamedVolumeAndPan(25, 63, 0, 0); + SampleManager.SetStreamedVolumeAndPan(25, 63, FALSE); nFramesSinceCutsceneEnded = 0; } else { if (nFramesSinceCutsceneEnded == -1) { @@ -643,7 +662,7 @@ cMusicManager::ServiceGameMode() } if (gRetuneCounter != 0) volume /= 4; - SampleManager.SetStreamedVolumeAndPan(volume, 63, 0, 0); + SampleManager.SetStreamedVolumeAndPan(volume, 63, FALSE); } return; } @@ -663,8 +682,8 @@ cMusicManager::ServiceGameMode() m_nNextTrack = m_nRadioStationScript; if (FindPlayerVehicle()->m_nRadioStation == m_nNextTrack) { m_nPlayingTrack = NO_TRACK; - SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0); - SampleManager.StopStreamedFile(0); + SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE); + SampleManager.StopStreamedFile(); } if (m_nRadioPosition != -1) { m_aTracks[m_nNextTrack].m_nPosition = m_nRadioPosition; @@ -680,11 +699,11 @@ cMusicManager::ServiceGameMode() } if (ChangeRadioChannel()) { if (m_bRadioSetByScript) { - m_bRadioSetByScript = false; + m_bRadioSetByScript = FALSE; FindPlayerVehicle()->m_nRadioStation = m_nNextTrack; } } else { - m_bPlayerInCar = false; + m_bPlayerInCar = FALSE; m_nNextTrack = NO_TRACK; } } @@ -693,9 +712,9 @@ void cMusicManager::StopFrontEndTrack() { if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_FRONTEND && m_nNextTrack != NO_TRACK) { - m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0); + m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(); m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); - SampleManager.StopStreamedFile(0); + SampleManager.StopStreamedFile(); m_nPlayingTrack = NO_TRACK; m_nNextTrack = NO_TRACK; } @@ -709,33 +728,33 @@ cMusicManager::PlayAnnouncement(uint8 announcement) } void -cMusicManager::PlayFrontEndTrack(uint8 track, uint8 bPlayInFrontend) +cMusicManager::PlayFrontEndTrack(uint8 track, bool8 bPlayInFrontend) { if (IsInitialised() && !m_bDisabled && track < TOTAL_STREAMED_SOUNDS) { if (m_nMusicMode == MUSICMODE_GAME) { if (m_nNextTrack != NO_TRACK) { if (m_bAnnouncementInProgress) { m_nAnnouncement = NO_TRACK; - m_bAnnouncementInProgress = false; + m_bAnnouncementInProgress = FALSE; } - m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0); + m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(); m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); } - SampleManager.StopStreamedFile(0); + SampleManager.StopStreamedFile(); } else if (m_nMusicMode == MUSICMODE_FRONTEND) { if (m_nNextTrack != NO_TRACK) { - m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0); + m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(); m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); } - SampleManager.StopStreamedFile(0); + SampleManager.StopStreamedFile(); } m_nPlayingTrack = m_nNextTrack; m_nNextTrack = track; - m_bPlayInFrontend = !!bPlayInFrontend; - m_bFrontendTrackFinished = false; - m_bDoTrackService = true; - bHasStarted = false; + m_bPlayInFrontend = bPlayInFrontend; + m_bFrontendTrackFinished = FALSE; + m_bDoTrackService = TRUE; + bHasStarted = FALSE; if (m_nNextTrack < NUM_RADIOS) { gRetuneCounter = 0; gNumRetunePresses = 0; @@ -748,10 +767,10 @@ cMusicManager::PreloadCutSceneMusic(uint8 track) { if (IsInitialised() && !m_bDisabled && track < TOTAL_STREAMED_SOUNDS && m_nMusicMode == MUSICMODE_CUTSCENE) { AudioManager.ResetPoliceRadio(); - while (SampleManager.IsStreamPlaying(0)) - SampleManager.StopStreamedFile(0); - SampleManager.PreloadStreamedFile(track, 0); - SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, 1, 0); + while (SampleManager.IsStreamPlaying()) + SampleManager.StopStreamedFile(); + SampleManager.PreloadStreamedFile(track); + SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, TRUE); m_nNextTrack = track; } } @@ -760,14 +779,14 @@ void cMusicManager::PlayPreloadedCutSceneMusic(void) { if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_CUTSCENE) - SampleManager.StartPreloadedStreamedFile(0); + SampleManager.StartPreloadedStreamedFile(); } void cMusicManager::StopCutSceneMusic(void) { if (IsInitialised() && !m_bDisabled && m_nMusicMode == MUSICMODE_CUTSCENE) { - SampleManager.StopStreamedFile(0); + SampleManager.StopStreamedFile(); m_nNextTrack = NO_TRACK; } } @@ -787,7 +806,7 @@ cMusicManager::GetTrackStartPos(uint8 track) } -bool +bool8 cMusicManager::UsesPoliceRadio(CVehicle *veh) { switch (veh->GetModelIndex()) @@ -798,9 +817,9 @@ cMusicManager::UsesPoliceRadio(CVehicle *veh) case MI_PREDATOR: case MI_RHINO: case MI_BARRACKS: - return true; + return TRUE; } - return false; + return FALSE; } void @@ -810,19 +829,19 @@ cMusicManager::ServiceAmbience() if (m_bAnnouncementInProgress) { m_nAnnouncement = NO_TRACK; - m_bAnnouncementInProgress = false; + m_bAnnouncementInProgress = FALSE; } if (m_nNextTrack < RADIO_OFF) { - if (SampleManager.IsStreamPlaying(0)) { - m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0); + if (SampleManager.IsStreamPlaying()) { + m_aTracks[m_nNextTrack].m_nPosition = SampleManager.GetStreamedFilePosition(); m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); - SampleManager.StopStreamedFile(0); + SampleManager.StopStreamedFile(); m_nNextTrack = NO_TRACK; return; } m_nNextTrack = RADIO_OFF; } - if (CWorld::Players[CWorld::PlayerInFocus].m_WBState != WBSTATE_PLAYING && !SampleManager.IsStreamPlaying(0)) { + if (CWorld::Players[CWorld::PlayerInFocus].m_WBState != WBSTATE_PLAYING && !SampleManager.IsStreamPlaying()) { m_nNextTrack = NO_TRACK; return; } @@ -831,31 +850,31 @@ cMusicManager::ServiceAmbience() m_nNextTrack = TheCamera.DistanceToWater <= 45.0f ? STREAMED_SOUND_WATER_AMBIENT : STREAMED_SOUND_CITY_AMBIENT; if (m_nNextTrack == m_nPlayingTrack) { - ComputeAmbienceVol(false, volume); - SampleManager.SetStreamedVolumeAndPan(volume, 63, 1, 0); + ComputeAmbienceVol(FALSE, volume); + SampleManager.SetStreamedVolumeAndPan(volume, 63, TRUE); if (m_bVerifyAmbienceTrackStartedToPlay) { - if (SampleManager.IsStreamPlaying(0)) - m_bVerifyAmbienceTrackStartedToPlay = false; + if (SampleManager.IsStreamPlaying()) + m_bVerifyAmbienceTrackStartedToPlay = FALSE; } else ServiceTrack(); } else { if (m_nPlayingTrack < TOTAL_STREAMED_SOUNDS) { - m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0); + m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition(); m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); - SampleManager.StopStreamedFile(0); + SampleManager.StopStreamedFile(); } uint32 pos = GetTrackStartPos(m_nNextTrack); - SampleManager.SetStreamedVolumeAndPan(0, 63, 1, 0); - if (SampleManager.StartStreamedFile(m_nNextTrack, pos, 0)) { - ComputeAmbienceVol(true, volume); - SampleManager.SetStreamedVolumeAndPan(volume, 63, 1, 0); - m_bVerifyAmbienceTrackStartedToPlay = true; + SampleManager.SetStreamedVolumeAndPan(0, 63, TRUE); + if (SampleManager.StartStreamedFile(m_nNextTrack, pos)) { + ComputeAmbienceVol(TRUE, volume); + SampleManager.SetStreamedVolumeAndPan(volume, 63, TRUE); + m_bVerifyAmbienceTrackStartedToPlay = TRUE; } else m_nNextTrack = NO_TRACK; } } void -cMusicManager::ComputeAmbienceVol(uint8 reset, uint8 &outVolume) +cMusicManager::ComputeAmbienceVol(bool8 reset, uint8 &outVolume) { static float fVol = 0.0f; @@ -878,49 +897,49 @@ void cMusicManager::ServiceTrack() { if (m_bDoTrackService) { - if (!SampleManager.IsStreamPlaying(0)) - SampleManager.StartStreamedFile(m_nNextTrack, 0, 0); + if (!SampleManager.IsStreamPlaying()) + SampleManager.StartStreamedFile(m_nNextTrack, 0); } } -bool +bool8 cMusicManager::ServiceAnnouncement() { static int8 cCheck = 0; if (m_bAnnouncementInProgress) { - if (!SampleManager.IsStreamPlaying(0)) { + if (!SampleManager.IsStreamPlaying()) { m_nAnnouncement = NO_TRACK; - m_bAnnouncementInProgress = false; + m_bAnnouncementInProgress = FALSE; } - return true; + return TRUE; } if (++cCheck >= 30) { cCheck = 0; - int pos = SampleManager.GetStreamedFilePosition(0); - if (SampleManager.IsStreamPlaying(0)) { + int pos = SampleManager.GetStreamedFilePosition(); + if (SampleManager.IsStreamPlaying()) { if (m_nNextTrack != NO_TRACK) { m_aTracks[m_nNextTrack].m_nPosition = pos; m_aTracks[m_nNextTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); - SampleManager.StopStreamedFile(0); + SampleManager.StopStreamedFile(); } } - SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0); - if (SampleManager.StartStreamedFile(m_nAnnouncement, 0, 0)) { - SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, 0, 0); - m_bAnnouncementInProgress = true; + SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE); + if (SampleManager.StartStreamedFile(m_nAnnouncement, 0)) { + SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, FALSE); + m_bAnnouncementInProgress = TRUE; m_nPlayingTrack = m_nNextTrack; m_nNextTrack = m_nAnnouncement; - return true; + return TRUE; } if (cCheck != 0) cCheck--; else cCheck = 30; - return false; + return FALSE; } - return false; + return FALSE; } uint8 @@ -987,21 +1006,21 @@ cMusicManager::GetNextCarTuning() return veh->m_nRadioStation; } -bool +bool8 cMusicManager::ChangeRadioChannel() { if (m_nNextTrack != m_nPlayingTrack) { if (m_nPlayingTrack < TOTAL_STREAMED_SOUNDS) { - m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition(0); + m_aTracks[m_nPlayingTrack].m_nPosition = SampleManager.GetStreamedFilePosition(); m_aTracks[m_nPlayingTrack].m_nLastPosCheckTimer = CTimer::GetTimeInMillisecondsPauseMode(); - SampleManager.SetStreamedVolumeAndPan(0, 63, 0, 0); - SampleManager.StopStreamedFile(0); + SampleManager.SetStreamedVolumeAndPan(0, 63, FALSE); + SampleManager.StopStreamedFile(); } - if (SampleManager.IsStreamPlaying(0)) - return false; - if (!SampleManager.StartStreamedFile(m_nNextTrack, GetTrackStartPos(m_nNextTrack), 0)) - return false; - SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, 0, 0); + if (SampleManager.IsStreamPlaying()) + return FALSE; + if (!SampleManager.StartStreamedFile(m_nNextTrack, GetTrackStartPos(m_nNextTrack))) + return FALSE; + SampleManager.SetStreamedVolumeAndPan(AudioManager.ShouldDuckMissionAudio() ? 25 : 100, 63, FALSE); } - return true; + return TRUE; } diff --git a/src/audio/MusicManager.h b/src/audio/MusicManager.h index 5d277f0e..4c4447fe 100644 --- a/src/audio/MusicManager.h +++ b/src/audio/MusicManager.h @@ -15,48 +15,48 @@ class CVehicle; class cMusicManager { public: - bool m_bIsInitialised; - bool m_bDisabled; + bool8 m_bIsInitialised; + bool8 m_bDisabled; uint8 m_nMusicMode; uint8 m_nNextTrack; uint8 m_nPlayingTrack; - bool m_bFrontendTrackFinished; - bool m_bPlayInFrontend; - bool m_bSetNextStation; + bool8 m_bFrontendTrackFinished; + bool8 m_bPlayInFrontend; + bool8 m_bSetNextStation; uint8 m_nAnnouncement; - bool m_bPreviousPlayerInCar; - bool m_bPlayerInCar; - bool m_bAnnouncementInProgress; + bool8 m_bPreviousPlayerInCar; + bool8 m_bPlayerInCar; + bool8 m_bAnnouncementInProgress; tStreamedSample m_aTracks[TOTAL_STREAMED_SOUNDS]; - bool m_bResetTimers; + bool8 m_bResetTimers; uint32 m_nResetTime; uint32 m_nLastTrackServiceTime; uint32 m_nTimer; - bool m_bDoTrackService; - bool m_bIgnoreTimeDelay; - bool m_bVerifyAmbienceTrackStartedToPlay; - bool m_bRadioSetByScript; + bool8 m_bDoTrackService; + bool8 m_bIgnoreTimeDelay; + bool8 m_bVerifyAmbienceTrackStartedToPlay; + bool8 m_bRadioSetByScript; uint8 m_nRadioStationScript; int32 m_nRadioPosition; uint8 m_nRadioInCar; public: cMusicManager(); - bool IsInitialised() { return m_bIsInitialised; } + bool8 IsInitialised() { return m_bIsInitialised; } uint32 GetMusicMode() { return m_nMusicMode; } uint8 GetNextTrack() { return m_nNextTrack; } - bool Initialise(); + bool8 Initialise(); void Terminate(); void ChangeMusicMode(uint8 mode); void StopFrontEndTrack(); - bool PlayerInCar(); + bool8 PlayerInCar(); void DisplayRadioStationName(); void PlayAnnouncement(uint8); - void PlayFrontEndTrack(uint8, uint8); + void PlayFrontEndTrack(uint8, bool8); void PreloadCutSceneMusic(uint8); void PlayPreloadedCutSceneMusic(void); void StopCutSceneMusic(void); @@ -73,15 +73,15 @@ public: void ServiceAmbience(); void ServiceTrack(); - bool UsesPoliceRadio(CVehicle *veh); + bool8 UsesPoliceRadio(CVehicle *veh); uint32 GetTrackStartPos(uint8); - void ComputeAmbienceVol(uint8 reset, uint8& outVolume); - bool ServiceAnnouncement(); + void ComputeAmbienceVol(bool8 reset, uint8& outVolume); + bool8 ServiceAnnouncement(); uint8 GetCarTuning(); uint8 GetNextCarTuning(); - bool ChangeRadioChannel(); + bool8 ChangeRadioChannel(); }; VALIDATE_SIZE(cMusicManager, 0x95C); diff --git a/src/audio/PoliceRadio.cpp b/src/audio/PolRadio.cpp index 785dbf8f..235a53d3 100644 --- a/src/audio/PoliceRadio.cpp +++ b/src/audio/PolRadio.cpp @@ -7,7 +7,7 @@ #include "AudioSamples.h" #include "MusicManager.h" #include "PlayerPed.h" -#include "PoliceRadio.h" +#include "PolRadio.h" #include "Replay.h" #include "Vehicle.h" #include "World.h" @@ -15,9 +15,6 @@ #include "sampman.h" #include "Wanted.h" -const int channels = ARRAY_SIZE(AudioManager.m_asActiveSamples); -const int policeChannel = channels + 1; - struct tPoliceRadioZone { char m_aName[8]; uint32 m_nSampleIndex; @@ -94,8 +91,8 @@ cAudioManager::InitialisePoliceRadio() for (int32 i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE; - SampleManager.SetChannelReverbFlag(policeChannel, false); - gSpecialSuspectLastSeenReport = false; + SampleManager.SetChannelReverbFlag(CHANNEL_POLICE_RADIO, FALSE); + gSpecialSuspectLastSeenReport = FALSE; for (int32 i = 0; i < ARRAY_SIZE(gMinTimeToNextReport); i++) gMinTimeToNextReport[i] = m_FrameCounter; } @@ -104,7 +101,7 @@ void cAudioManager::ResetPoliceRadio() { if (!m_bIsInitialised) return; - if (SampleManager.GetChannelUsedFlag(policeChannel)) SampleManager.StopChannel(policeChannel); + if (SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO)) SampleManager.StopChannel(CHANNEL_POLICE_RADIO); InitialisePoliceRadio(); } @@ -131,19 +128,18 @@ cAudioManager::DoPoliceRadioCrackle() m_sQueueSample.m_nCounter = 0; m_sQueueSample.m_nSampleIndex = SFX_POLICE_RADIO_CRACKLE; m_sQueueSample.m_nBankIndex = SFX_BANK_0; - m_sQueueSample.m_bIs2D = true; + m_sQueueSample.m_bIs2D = TRUE; m_sQueueSample.m_nReleasingVolumeModificator = 10; m_sQueueSample.m_nFrequency = SampleManager.GetSampleBaseFrequency(SFX_POLICE_RADIO_CRACKLE); m_sQueueSample.m_nVolume = m_anRandomTable[2] % 20 + 15; m_sQueueSample.m_nLoopCount = 0; m_sQueueSample.m_nEmittingVolume = m_sQueueSample.m_nVolume; - m_sQueueSample.m_nLoopStart = SampleManager.GetSampleLoopStartOffset(SFX_POLICE_RADIO_CRACKLE); - m_sQueueSample.m_nLoopEnd = SampleManager.GetSampleLoopEndOffset(SFX_POLICE_RADIO_CRACKLE); - m_sQueueSample.m_bReleasingSoundFlag = false; - m_sQueueSample.m_bReverbFlag = false; + SET_LOOP_OFFSETS(SFX_POLICE_RADIO_CRACKLE) + m_sQueueSample.m_bReleasingSoundFlag = FALSE; + m_sQueueSample.m_bReverbFlag = FALSE; m_sQueueSample.m_nOffset = 63; m_sQueueSample.m_nReleasingVolumeDivider = 3; - m_sQueueSample.m_bRequireReflection = false; + m_sQueueSample.m_bRequireReflection = FALSE; AddSampleToRequestedQueue(); } @@ -156,7 +152,7 @@ cAudioManager::ServicePoliceRadio() if(!m_bIsInitialised) return; if(m_nUserPause == 0) { - bool crimeReport = SetupCrimeReport(); + bool8 crimeReport = SetupCrimeReport(); #ifdef FIX_BUGS // Crash at 0x5fe6ef if(CReplay::IsPlayingBack() || !FindPlayerPed() || !FindPlayerPed()->m_pWanted) return; @@ -165,7 +161,11 @@ cAudioManager::ServicePoliceRadio() if(!crimeReport) { if(wantedLevel != 0) { if(nLastSeen != 0) { +#ifdef FIX_BUGS + nLastSeen -= CTimer::GetLogicalFramesPassed(); +#else --nLastSeen; +#endif } else { nLastSeen = m_anRandomTable[1] % 1000 + 2000; SetupSuspectLastSeenReport(); @@ -179,31 +179,35 @@ cAudioManager::ServicePoliceRadio() void cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel) { - bool processed = false; + bool8 processed = FALSE; uint32 sample; int32 freq; static int cWait = 0; - static bool bChannelOpen = false; + static bool8 bChannelOpen = FALSE; static uint8 bMissionAudioPhysicalPlayingStatus = 0; static int32 PoliceChannelFreq = 5500; if (!m_bIsInitialised) return; if (m_nUserPause != 0) { - if (SampleManager.GetChannelUsedFlag(policeChannel)) SampleManager.StopChannel(policeChannel); + if (SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO)) SampleManager.StopChannel(CHANNEL_POLICE_RADIO); if (g_nMissionAudioSfx != TOTAL_AUDIO_SAMPLES && bMissionAudioPhysicalPlayingStatus == 1 && SampleManager.IsStreamPlaying(1)) { - SampleManager.PauseStream(1, 1); + SampleManager.PauseStream(TRUE, 1); } } else { if (m_nPreviousUserPause && g_nMissionAudioSfx != TOTAL_AUDIO_SAMPLES && bMissionAudioPhysicalPlayingStatus == 1) { - SampleManager.PauseStream(0, 1); + SampleManager.PauseStream(FALSE, 1); } - if (m_sPoliceRadioQueue.policeChannelTimer == 0) bChannelOpen = false; + if (m_sPoliceRadioQueue.policeChannelTimer == 0) bChannelOpen = FALSE; if (cWait) { +#ifdef FIX_BUGS + cWait -= CTimer::GetLogicalFramesPassed(); +#else --cWait; +#endif return; } if (g_nMissionAudioSfx != TOTAL_AUDIO_SAMPLES && !bChannelOpen) { @@ -223,9 +227,9 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel) } return; } - } else if (!SampleManager.GetChannelUsedFlag(policeChannel)) { + } else if (!SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO)) { SampleManager.PreloadStreamedFile(g_nMissionAudioSfx, 1); - SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, 1, 1); + SampleManager.SetStreamedVolumeAndPan(MAX_VOLUME, 63, TRUE, 1); SampleManager.StartPreloadedStreamedFile(1); g_nMissionAudioPlayingStatus = 1; bMissionAudioPhysicalPlayingStatus = 0; @@ -234,7 +238,7 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel) } if (bChannelOpen) DoPoliceRadioCrackle(); if ((g_nMissionAudioSfx == TOTAL_AUDIO_SAMPLES || g_nMissionAudioPlayingStatus != 1) && - !SampleManager.GetChannelUsedFlag(policeChannel) && m_sPoliceRadioQueue.policeChannelTimer) { + !SampleManager.GetChannelUsedFlag(CHANNEL_POLICE_RADIO) && m_sPoliceRadioQueue.policeChannelTimer) { if (m_sPoliceRadioQueue.policeChannelTimer) { sample = m_sPoliceRadioQueue.crimesSamples[m_sPoliceRadioQueue.policeChannelCounterSeconds]; m_sPoliceRadioQueue.policeChannelTimer--; @@ -246,37 +250,37 @@ cAudioManager::ServicePoliceRadioChannel(uint8 wantedLevel) if (gSpecialSuspectLastSeenReport) { gSpecialSuspectLastSeenReport = 0; } else if (((sample >= SFX_POLICE_RADIO_MESSAGE_NOISE_1) && (sample <= SFX_POLICE_RADIO_MESSAGE_NOISE_3)) || sample == TOTAL_AUDIO_SAMPLES) { - bChannelOpen = false; - processed = true; + bChannelOpen = FALSE; + processed = TRUE; } } if (sample == TOTAL_AUDIO_SAMPLES) { if (!processed) cWait = 30; } else { - SampleManager.InitialiseChannel(policeChannel, sample, 0); + SampleManager.InitialiseChannel(CHANNEL_POLICE_RADIO, sample, SFX_BANK_0); switch (sample) { case SFX_POLICE_RADIO_MESSAGE_NOISE_1: case SFX_POLICE_RADIO_MESSAGE_NOISE_2: case SFX_POLICE_RADIO_MESSAGE_NOISE_3: freq = m_anRandomTable[4] % 2000 + 10025; - bChannelOpen = bChannelOpen == false; + bChannelOpen = bChannelOpen == FALSE; break; default: freq = SampleManager.GetSampleBaseFrequency(sample); break; } PoliceChannelFreq = freq; - SampleManager.SetChannelFrequency(policeChannel, freq); - SampleManager.SetChannelVolume(policeChannel, 100); - SampleManager.SetChannelPan(policeChannel, 63); - SampleManager.SetChannelLoopCount(policeChannel, 1); - SampleManager.SetChannelLoopPoints(policeChannel, 0, -1); - SampleManager.StartChannel(policeChannel); + SampleManager.SetChannelFrequency(CHANNEL_POLICE_RADIO, freq); + SampleManager.SetChannelVolume(CHANNEL_POLICE_RADIO, 100); + SampleManager.SetChannelPan(CHANNEL_POLICE_RADIO, 63); + SampleManager.SetChannelLoopCount(CHANNEL_POLICE_RADIO, 1); + SampleManager.SetChannelLoopPoints(CHANNEL_POLICE_RADIO, 0, -1); + SampleManager.StartChannel(CHANNEL_POLICE_RADIO); } if (processed) ResetPoliceRadio(); } } } -bool +bool8 cAudioManager::SetupCrimeReport() { int16 audioZoneId; @@ -289,13 +293,13 @@ cAudioManager::SetupCrimeReport() float quarterY; int i; int32 sampleIndex; - bool processed = false; + bool8 processed = FALSE; - if (MusicManager.m_nMusicMode == MUSICMODE_CUTSCENE) return false; + if (MusicManager.m_nMusicMode == MUSICMODE_CUTSCENE) return FALSE; if (60 - m_sPoliceRadioQueue.policeChannelTimer <= 9) { AgeCrimes(); - return true; + return TRUE; } for (i = 0; i < ARRAY_SIZE(m_sPoliceRadioQueue.crimes); i++) { @@ -303,7 +307,7 @@ cAudioManager::SetupCrimeReport() break; } - if (i == ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) return false; + if (i == ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) return FALSE; audioZoneId = CTheZones::FindAudioZone(&m_sPoliceRadioQueue.crimes[i].position); if (audioZoneId >= 0 && audioZoneId < NUMAUDIOZONES) { zone = CTheZones::GetAudioZone(audioZoneId); @@ -336,10 +340,10 @@ cAudioManager::SetupCrimeReport() if (m_sPoliceRadioQueue.crimes[i].position.y > halfY + quarterY) { m_sPoliceRadioQueue.Add(SFX_NORTH); - processed = true; + processed = TRUE; } else if (m_sPoliceRadioQueue.crimes[i].position.y < halfY - quarterY) { m_sPoliceRadioQueue.Add(SFX_SOUTH); - processed = true; + processed = TRUE; } if (m_sPoliceRadioQueue.crimes[i].position.x > halfX + quarterX) @@ -359,7 +363,7 @@ cAudioManager::SetupCrimeReport() } m_sPoliceRadioQueue.crimes[i].type = CRIME_NONE; AgeCrimes(); - return true; + return TRUE; } void @@ -714,7 +718,7 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z) float quarterX; float quarterY; int32 sample; - bool processed = false; + bool8 processed = false; CVector vec = CVector(x, y, z); if (!m_bIsInitialised) return; @@ -745,10 +749,10 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z) if (vec.y > halfY + quarterY) { m_sPoliceRadioQueue.Add(SFX_NORTH); - processed = true; + processed = TRUE; } else if (vec.y < halfY - quarterY) { m_sPoliceRadioQueue.Add(SFX_SOUTH); - processed = true; + processed = TRUE; } if (vec.x > halfX + quarterX) @@ -761,7 +765,7 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z) m_sPoliceRadioQueue.Add(sample); m_sPoliceRadioQueue.Add(m_anRandomTable[2] % 3 + SFX_POLICE_RADIO_MESSAGE_NOISE_1); m_sPoliceRadioQueue.Add(TOTAL_AUDIO_SAMPLES); - gSpecialSuspectLastSeenReport = true; + gSpecialSuspectLastSeenReport = TRUE; break; } } diff --git a/src/audio/PoliceRadio.h b/src/audio/PolRadio.h index 368708b6..368708b6 100644 --- a/src/audio/PoliceRadio.h +++ b/src/audio/PolRadio.h diff --git a/src/audio/audio_enums.h b/src/audio/audio_enums.h index 027042cb..69d37a64 100644 --- a/src/audio/audio_enums.h +++ b/src/audio/audio_enums.h @@ -254,3 +254,25 @@ enum eAudioType AUDIOTYPE_POLICERADIO, TOTAL_AUDIO_TYPES, }; + +#ifdef GTA_PS2 +enum +{ + NUM_CHANNELS_GENERIC = 43, + CHANNEL_POLICE_RADIO = NUM_CHANNELS_GENERIC, + CHANNEL_MISSION_AUDIO, + CHANNEL_PLAYER_VEHICLE_ENGINE, + NUM_CHANNELS +}; +#else +enum +{ +#ifdef PS2_AUDIO_CHANNELS + NUM_CHANNELS_GENERIC = 43, +#else + NUM_CHANNELS_GENERIC = 27, +#endif + CHANNEL_POLICE_RADIO, + NUM_CHANNELS +}; +#endif diff --git a/src/audio/oal/aldlist.cpp b/src/audio/oal/aldlist.cpp index 881418c1..6024adf2 100644 --- a/src/audio/oal/aldlist.cpp +++ b/src/audio/oal/aldlist.cpp @@ -24,12 +24,6 @@ #include "aldlist.h" -#ifndef _WIN32 -#define _stricmp strcasecmp -#define _strnicmp strncasecmp -#define _strdup strdup -#endif - #ifdef AUDIO_OAL /* * Init call @@ -47,8 +41,8 @@ ALDeviceList::ALDeviceList() defaultDeviceIndex = 0; if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) { - devices = (char *)alcGetString(NULL, ALC_DEVICE_SPECIFIER); - defaultDeviceName = (char *)alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); + devices = (char *)alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); + defaultDeviceName = (char *)alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER); index = 0; // go through device list (each device terminated with a single NULL, list terminated with double NULL) @@ -62,17 +56,11 @@ ALDeviceList::ALDeviceList() if (context) { alcMakeContextCurrent(context); // if new actual device name isn't already in the list, then add it... - actualDeviceName = alcGetString(device, ALC_DEVICE_SPECIFIER); - bool bNewName = true; - for (unsigned int i = 0; i < GetNumDevices(); i++) { - if (strcmp(GetDeviceName(i), actualDeviceName) == 0) { - bNewName = false; - } - } - if ((bNewName) && (actualDeviceName != NULL) && (strlen(actualDeviceName) > 0)) { - ALDEVICEINFO ALDeviceInfo; + actualDeviceName = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER); + if ((actualDeviceName != NULL) && (strlen(actualDeviceName) > 0)) { + ALDEVICEINFO &ALDeviceInfo = aDeviceInfo[nNumOfDevices++]; ALDeviceInfo.bSelected = true; - ALDeviceInfo.strDeviceName = _strdup(actualDeviceName); + ALDeviceInfo.SetName(actualDeviceName); alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(int), &ALDeviceInfo.iMajorVersion); alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(int), &ALDeviceInfo.iMinorVersion); @@ -105,8 +93,6 @@ ALDeviceList::ALDeviceList() // Get Source Count ALDeviceInfo.uiSourceCount = GetMaxNumSources(); - - aDeviceInfo[nNumOfDevices++] = ALDeviceInfo; } alcMakeContextCurrent(NULL); alcDestroyContext(context); diff --git a/src/audio/oal/aldlist.h b/src/audio/oal/aldlist.h index 417bd314..3ed12d84 100644 --- a/src/audio/oal/aldlist.h +++ b/src/audio/oal/aldlist.h @@ -21,7 +21,7 @@ enum }; struct ALDEVICEINFO { - const char *strDeviceName; + char *strDeviceName; int iMajorVersion; int iMinorVersion; unsigned int uiSourceCount; @@ -33,6 +33,19 @@ struct ALDEVICEINFO { strDeviceName = NULL; Extensions = 0; } + + ~ALDEVICEINFO() + { + delete[] strDeviceName; + strDeviceName = NULL; + } + + void SetName(const char *name) + { + if(strDeviceName) delete[] strDeviceName; + strDeviceName = new char[strlen(name) + 1]; + strcpy(strDeviceName, name); + } }; typedef ALDEVICEINFO *LPALDEVICEINFO; diff --git a/src/audio/oal/channel.cpp b/src/audio/oal/channel.cpp index d1fd0aea..04e7e529 100644 --- a/src/audio/oal/channel.cpp +++ b/src/audio/oal/channel.cpp @@ -10,20 +10,22 @@ extern bool IsFXSupported(); -ALuint alSources[MAXCHANNELS+MAX2DCHANNELS]; -ALuint alFilters[MAXCHANNELS+MAX2DCHANNELS]; -ALuint alBuffers[MAXCHANNELS+MAX2DCHANNELS]; +ALuint alSources[NUM_CHANNELS]; +ALuint alFilters[NUM_CHANNELS]; +ALuint alBuffers[NUM_CHANNELS]; bool bChannelsCreated = false; int32 CChannel::channelsThatNeedService = 0; +uint8 tempStereoBuffer[PED_BLOCKSIZE * 2]; + void CChannel::InitChannels() { - alGenSources(MAXCHANNELS+MAX2DCHANNELS, alSources); - alGenBuffers(MAXCHANNELS+MAX2DCHANNELS, alBuffers); + alGenSources(NUM_CHANNELS, alSources); + alGenBuffers(NUM_CHANNELS, alBuffers); if (IsFXSupported()) - alGenFilters(MAXCHANNELS + MAX2DCHANNELS, alFilters); + alGenFilters(NUM_CHANNELS, alFilters); bChannelsCreated = true; } @@ -32,13 +34,13 @@ CChannel::DestroyChannels() { if (bChannelsCreated) { - alDeleteSources(MAXCHANNELS + MAX2DCHANNELS, alSources); + alDeleteSources(NUM_CHANNELS, alSources); memset(alSources, 0, sizeof(alSources)); - alDeleteBuffers(MAXCHANNELS + MAX2DCHANNELS, alBuffers); + alDeleteBuffers(NUM_CHANNELS, alBuffers); memset(alBuffers, 0, sizeof(alBuffers)); if (IsFXSupported()) { - alDeleteFilters(MAXCHANNELS + MAX2DCHANNELS, alFilters); + alDeleteFilters(NUM_CHANNELS, alFilters); memset(alFilters, 0, sizeof(alFilters)); } bChannelsCreated = false; @@ -50,6 +52,7 @@ CChannel::CChannel() { Data = nil; DataSize = 0; + bIs2D = false; SetDefault(); } @@ -90,6 +93,7 @@ void CChannel::Init(uint32 _id, bool Is2D) if ( Is2D ) { + bIs2D = true; alSource3f(alSources[id], AL_POSITION, 0.0f, 0.0f, 0.0f); alSourcef(alSources[id], AL_GAIN, 1.0f); } @@ -113,7 +117,20 @@ void CChannel::Start() if ( !HasSource() ) return; if ( !Data ) return; - alBufferData(alBuffers[id], AL_FORMAT_MONO16, Data, DataSize, Frequency); + if ( bIs2D ) + { + // convert mono data to stereo + int16 *monoData = (int16*)Data; + int16 *stereoData = (int16*)tempStereoBuffer; + for (size_t i = 0; i < DataSize / 2; i++) + { + *(stereoData++) = *monoData; + *(stereoData++) = *(monoData++); + } + alBufferData(alBuffers[id], AL_FORMAT_STEREO16, tempStereoBuffer, DataSize * 2, Frequency); + } + else + alBufferData(alBuffers[id], AL_FORMAT_MONO16, Data, DataSize, Frequency); if ( LoopPoints[0] != 0 && LoopPoints[0] != -1 ) alBufferiv(alBuffers[id], AL_LOOP_POINTS_SOFT, LoopPoints); alSourcei(alSources[id], AL_BUFFER, alBuffers[id]); diff --git a/src/audio/oal/channel.h b/src/audio/oal/channel.h index b081be25..872646c8 100644 --- a/src/audio/oal/channel.h +++ b/src/audio/oal/channel.h @@ -20,6 +20,7 @@ class CChannel int32 LoopCount; ALint LoopPoints[2]; ALint LastProcessedOffset; + bool bIs2D; public: static int32 channelsThatNeedService; diff --git a/src/audio/oal/stream.cpp b/src/audio/oal/stream.cpp index 44cc1c93..5d3ff08e 100644 --- a/src/audio/oal/stream.cpp +++ b/src/audio/oal/stream.cpp @@ -134,7 +134,7 @@ public: else StepIndex--; - StepIndex = clamp(StepIndex, 0, 88); + StepIndex = Clamp(StepIndex, 0, 88); int delta = step >> 3; if (adpcm & 1) delta += step >> 2; @@ -143,7 +143,7 @@ public: if (adpcm & 8) delta = -delta; int newSample = Sample + delta; - Sample = clamp(newSample, -32768, 32767); + Sample = Clamp(newSample, -32768, 32767); return Sample; } }; @@ -596,7 +596,7 @@ public: static short quantize(double sample) { int a = int(sample + 0.5); - return short(clamp(a, -32768, 32767)); + return short(Clamp(a, -32768, 32767)); } void Decode(void* _inbuf, int16* _outbuf, size_t size) @@ -1086,10 +1086,10 @@ void CStream::SetVolume(uint32 nVol) void CStream::SetPan(uint8 nPan) { - m_nPan = clamp((int8)nPan - 63, 0, 63); + m_nPan = Clamp((int8)nPan - 63, 0, 63); SetPosition(0, (m_nPan - 63) / 64.0f, 0.0f, Sqrt(1.0f - SQR((m_nPan - 63) / 64.0f))); - m_nPan = clamp((int8)nPan + 64, 64, 127); + m_nPan = Clamp((int8)nPan + 64, 64, 127); SetPosition(1, (m_nPan - 63) / 64.0f, 0.0f, Sqrt(1.0f - SQR((m_nPan - 63) / 64.0f))); m_nPan = nPan; diff --git a/src/audio/sampman.h b/src/audio/sampman.h index a5f6c7e2..d1ad9a26 100644 --- a/src/audio/sampman.h +++ b/src/audio/sampman.h @@ -1,5 +1,6 @@ #pragma once #include "AudioSamples.h" +#include "audio_enums.h" #define MAX_VOLUME 127 #define MAX_FREQ DIGITALRATE @@ -99,10 +100,9 @@ enum #define MAXPROVIDERS 64 -#define MAXCHANNELS 28 -#define MAXCHANNELS_SURROUND 24 +#define MAXCHANNELS (NUM_CHANNELS_GENERIC+1) +#define MAXCHANNELS_SURROUND (MAXCHANNELS-4) #define MAX2DCHANNELS 1 -#define CHANNEL2D MAXCHANNELS #define MAX_STREAMS 2 @@ -110,7 +110,13 @@ enum #define DIGITALBITS 16 #define DIGITALCHANNELS 2 -#define MAX_DIGITAL_MIXER_CHANNELS 32 +#ifdef FIX_BUGS +#define MAX_DIGITAL_MIXER_CHANNELS (MAXCHANNELS+MAX_STREAMS*2+MAX2DCHANNELS) +#else +#define MAX_DIGITAL_MIXER_CHANNELS (MAXCHANNELS+MAX_STREAMS*2) +#endif + +static_assert( NUM_CHANNELS == MAXCHANNELS + MAX2DCHANNELS, "The number of channels doesn't match with an enum" ); class cSampleManager { @@ -118,10 +124,10 @@ class cSampleManager uint8 m_nMusicVolume; uint8 m_nEffectsFadeVolume; uint8 m_nMusicFadeVolume; - uint8 m_nMonoMode; + bool8 m_nMonoMode; char unk; char m_szCDRomRootPath[80]; - bool m_bInitialised; + bool8 m_bInitialised; uint8 m_nNumberOfProviders; char *m_aAudioProviders[MAXPROVIDERS]; tSample m_aSamples[TOTAL_AUDIO_SAMPLES]; @@ -145,16 +151,16 @@ public: int8 GetCurrent3DProviderIndex(void); int8 SetCurrent3DProvider(uint8 which); - bool IsMP3RadioChannelAvailable(void); + bool8 IsMP3RadioChannelAvailable(void); void ReleaseDigitalHandle (void); void ReacquireDigitalHandle(void); - bool Initialise(void); - void Terminate (void); + bool8 Initialise(void); + void Terminate (void); - bool CheckForAnAudioFileOnCD(void); - char GetCDAudioDriveLetter (void); + bool8 CheckForAnAudioFileOnCD(void); + char GetCDAudioDriveLetter (void); void UpdateEffectsVolume(void); @@ -162,14 +168,14 @@ public: void SetMusicMasterVolume (uint8 nVolume); void SetEffectsFadeVolume (uint8 nVolume); void SetMusicFadeVolume (uint8 nVolume); - void SetMonoMode (uint8 nMode); + void SetMonoMode (bool8 nMode); - bool LoadSampleBank (uint8 nBank); - void UnloadSampleBank (uint8 nBank); - bool IsSampleBankLoaded(uint8 nBank); + bool8 LoadSampleBank (uint8 nBank); + void UnloadSampleBank (uint8 nBank); + bool8 IsSampleBankLoaded(uint8 nBank); - bool IsPedCommentLoaded(uint32 nComment); - bool LoadPedComment (uint32 nComment); + bool8 IsPedCommentLoaded(uint32 nComment); + bool8 LoadPedComment (uint32 nComment); int32 GetBankContainingSound(uint32 offset); int32 _GetPedCommentSlot(uint32 nComment); @@ -179,10 +185,10 @@ public: int32 GetSampleLoopEndOffset (uint32 nSample); uint32 GetSampleLength (uint32 nSample); - bool UpdateReverb(void); + bool8 UpdateReverb(void); - void SetChannelReverbFlag (uint32 nChannel, uint8 nReverbFlag); - bool InitialiseChannel (uint32 nChannel, uint32 nSfx, uint8 nBank); + void SetChannelReverbFlag (uint32 nChannel, bool8 nReverbFlag); + bool8 InitialiseChannel (uint32 nChannel, uint32 nSfx, uint8 nBank); void SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume); void SetChannel3DPosition (uint32 nChannel, float fX, float fY, float fZ); void SetChannel3DDistances (uint32 nChannel, float fMax, float fMin); @@ -191,23 +197,23 @@ public: void SetChannelFrequency (uint32 nChannel, uint32 nFreq); void SetChannelLoopPoints (uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd); void SetChannelLoopCount (uint32 nChannel, uint32 nLoopCount); - bool GetChannelUsedFlag (uint32 nChannel); + bool8 GetChannelUsedFlag (uint32 nChannel); void StartChannel (uint32 nChannel); void StopChannel (uint32 nChannel); - void PreloadStreamedFile (uint8 nFile, uint8 nStream); - void PauseStream (uint8 nPauseFlag, uint8 nStream); - void StartPreloadedStreamedFile (uint8 nStream); - bool StartStreamedFile (uint8 nFile, uint32 nPos, uint8 nStream); - void StopStreamedFile (uint8 nStream); - int32 GetStreamedFilePosition (uint8 nStream); - void SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffectFlag, uint8 nStream); - int32 GetStreamedFileLength (uint8 nStream); - bool IsStreamPlaying (uint8 nStream); + void PreloadStreamedFile (uint8 nFile, uint8 nStream = 0); + void PauseStream (bool8 nPauseFlag, uint8 nStream = 0); + void StartPreloadedStreamedFile (uint8 nStream = 0); + bool8 StartStreamedFile (uint8 nFile, uint32 nPos, uint8 nStream = 0); + void StopStreamedFile (uint8 nStream = 0); + int32 GetStreamedFilePosition (uint8 nStream = 0); + void SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, bool8 nEffectFlag, uint8 nStream = 0); + int32 GetStreamedFileLength (uint8 nStream = 0); + bool8 IsStreamPlaying (uint8 nStream = 0); #ifdef AUDIO_OAL void Service(void); #endif - bool InitialiseSampleBanks(void); + bool8 InitialiseSampleBanks(void); }; extern cSampleManager SampleManager; diff --git a/src/audio/sampman_miles.cpp b/src/audio/sampman_miles.cpp index 9b601d52..e820864c 100644 --- a/src/audio/sampman_miles.cpp +++ b/src/audio/sampman_miles.cpp @@ -1,3 +1,4 @@ +#define WITHWINDOWS #include "common.h" #ifdef AUDIO_MSS @@ -28,7 +29,7 @@ char SampleBankDataFilename[] = "AUDIO\\SFX.RAW"; FILE *fpSampleDescHandle; FILE *fpSampleDataHandle; -bool bSampleBankLoaded [MAX_SFX_BANKS]; +bool8 bSampleBankLoaded [MAX_SFX_BANKS]; int32 nSampleBankDiscStartOffset [MAX_SFX_BANKS]; int32 nSampleBankSize [MAX_SFX_BANKS]; int32 nSampleBankMemoryStartAddress[MAX_SFX_BANKS]; @@ -62,16 +63,16 @@ int8 nStreamPan [MAX_STREAMS]; int8 nStreamVolume[MAX_STREAMS]; uint32 _CurMP3Index; int32 _CurMP3Pos; -bool _bIsMp3Active; +bool8 _bIsMp3Active; #if GTA_VERSION >= GTA3_PC_11 || defined(NO_CDCHECK) -bool _bUseHDDAudio; +bool8 _bUseHDDAudio; char _aHDDPath[MAX_PATH]; #endif /////////////////////////////////////////////////////////////// -bool _bSampmanInitialised = false; +bool8 _bSampmanInitialised = FALSE; // // Miscellaneous globals / defines @@ -98,7 +99,7 @@ S32 speaker_type=0; U32 _maxSamples; float _fPrevEaxRatioDestination; -bool _usingMilesFast2D; +bool8 _usingMilesFast2D; float _fEffectsLevel; @@ -170,17 +171,17 @@ release_existing() } _fPrevEaxRatioDestination = 0.0f; - _usingMilesFast2D = false; + _usingMilesFast2D = FALSE; _fEffectsLevel = 0.0f; } -static bool +static bool8 set_new_provider(S32 index) { DWORD result; if ( curprovider == index ) - return true; + return TRUE; //close the already opened provider curprovider = index; @@ -207,7 +208,7 @@ set_new_provider(S32 index) release_existing(); - return false; + return FALSE; } else { @@ -238,7 +239,7 @@ set_new_provider(S32 index) AIL_set_3D_room_type(opened_provider, ENVIRONMENT_CAVE); if ( !strcmp(providers[index].name, "Miles Fast 2D Positional Audio") ) - _usingMilesFast2D = true; + _usingMilesFast2D = TRUE; } AIL_3D_provider_attribute(opened_provider, "Maximum supported samples", &_maxSamples); @@ -256,11 +257,11 @@ set_new_provider(S32 index) AIL_set_3D_sample_effects_level(opened_samples[i], 0.0f); } - return true; + return TRUE; } } - return false; + return FALSE; } cSampleManager::cSampleManager(void) : @@ -353,7 +354,7 @@ cSampleManager::SetCurrent3DProvider(uint8 nProvider) return curprovider; } -static bool +static bool8 _ResolveLink(char const *path, char *out) { IShellLink* psl; @@ -389,7 +390,7 @@ _ResolveLink(char const *path, char *out) ppf->Release(); psl->Release(); #endif - return true; + return TRUE; } } } @@ -399,15 +400,15 @@ _ResolveLink(char const *path, char *out) psl->Release(); } - return false; + return FALSE; } static void _FindMP3s(void) { tMP3Entry *pList; - bool bShortcut; - bool bInitFirstEntry; + bool8 bShortcut; + bool8 bInitFirstEntry; HANDLE hFind; char path[MAX_PATH]; char filepath[MAX_PATH*2]; @@ -474,10 +475,10 @@ _FindMP3s(void) if ( f ) fprintf(f, " - couldn't resolve shortcut"); } - bShortcut = true; + bShortcut = TRUE; } else - bShortcut = false; + bShortcut = FALSE; } mp3Stream[0] = AIL_open_stream(DIG, filepath, 0); @@ -524,7 +525,7 @@ _FindMP3s(void) if ( f ) fprintf(f, " - OK\n"); - bInitFirstEntry = false; + bInitFirstEntry = FALSE; } else { @@ -534,10 +535,10 @@ _FindMP3s(void) if ( f ) fprintf(f, " - not an MP3 or supported MP3 type\n"); - bInitFirstEntry = true; + bInitFirstEntry = TRUE; } - while ( true ) + while ( TRUE ) { if ( !FindNextFile(hFind, &fd) ) break; @@ -569,11 +570,11 @@ _FindMP3s(void) if ( f ) fprintf(f, " - couldn't resolve shortcut"); } - bShortcut = true; + bShortcut = TRUE; } else { - bShortcut = false; + bShortcut = FALSE; if ( filepathlen > MAX_PATH ) { @@ -620,7 +621,7 @@ _FindMP3s(void) if ( f ) fprintf(f, " - OK\n"); - bInitFirstEntry = false; + bInitFirstEntry = FALSE; } else { @@ -658,11 +659,11 @@ _FindMP3s(void) if ( f ) fprintf(f, " - couldn't resolve shortcut"); } - bShortcut = true; + bShortcut = TRUE; } else { - bShortcut = false; + bShortcut = FALSE; } } @@ -784,7 +785,7 @@ _GetMP3EntryByIndex(uint32 idx) return NULL; } -static inline bool +static inline bool8 _GetMP3PosFromStreamPos(uint32 *pPosition, tMP3Entry **pEntry) { _CurMP3Index = 0; @@ -797,7 +798,7 @@ _GetMP3PosFromStreamPos(uint32 *pPosition, tMP3Entry **pEntry) *pPosition -= (*pEntry)->nTrackStreamPos; _CurMP3Pos = *pPosition; - return true; + return TRUE; } _CurMP3Index++; @@ -808,10 +809,10 @@ _GetMP3PosFromStreamPos(uint32 *pPosition, tMP3Entry **pEntry) _CurMP3Pos = 0; _CurMP3Index = 0; - return false; + return FALSE; } -bool +bool8 cSampleManager::IsMP3RadioChannelAvailable(void) { return nNumMP3s != 0; @@ -840,13 +841,13 @@ cSampleManager::ReacquireDigitalHandle(void) } } -bool +bool8 cSampleManager::Initialise(void) { TRACE("start"); if ( _bSampmanInitialised ) - return true; + return TRUE; { for ( int32 i = 0; i < TOTAL_AUDIO_SAMPLES; i++ ) @@ -872,7 +873,7 @@ cSampleManager::Initialise(void) curprovider = -1; prevprovider = -1; - _usingMilesFast2D = false; + _usingMilesFast2D = FALSE; usingEAX=0; usingEAX3=0; @@ -897,7 +898,7 @@ cSampleManager::Initialise(void) for ( int32 i = 0; i < MAX_SFX_BANKS; i++ ) { - bSampleBankLoaded[i] = false; + bSampleBankLoaded[i] = FALSE; nSampleBankDiscStartOffset[i] = 0; nSampleBankSize[i] = 0; nSampleBankMemoryStartAddress[i] = 0; @@ -936,7 +937,7 @@ cSampleManager::Initialise(void) { OutputDebugString(AIL_last_error()); Terminate(); - return false; + return FALSE; } add_providers(); @@ -944,14 +945,14 @@ cSampleManager::Initialise(void) if ( !InitialiseSampleBanks() ) { Terminate(); - return false; + return FALSE; } nSampleBankMemoryStartAddress[SFX_BANK_0] = (int32)AIL_mem_alloc_lock(nSampleBankSize[SFX_BANK_0]); if ( !nSampleBankMemoryStartAddress[SFX_BANK_0] ) { Terminate(); - return false; + return FALSE; } nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] = (int32)AIL_mem_alloc_lock(PED_BLOCKSIZE*MAX_PEDSFX); @@ -964,7 +965,7 @@ cSampleManager::Initialise(void) if (cacheFile) { fread(nStreamLength, sizeof(uint32), TOTAL_STREAMED_SOUNDS, cacheFile); fclose(cacheFile); - m_bInitialised = true; + m_bInitialised = TRUE; }else { #endif TRACE("cdrom"); @@ -973,9 +974,9 @@ cSampleManager::Initialise(void) char filepath[MAX_PATH]; { - m_bInitialised = false; + m_bInitialised = FALSE; - while (true) + while (TRUE) { int32 drive = 'C'; @@ -1000,7 +1001,7 @@ cSampleManager::Initialise(void) { fclose(f); - bool bFileNotFound = false; + bool8 bFileNotFound = FALSE; for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ ) { @@ -1020,19 +1021,19 @@ cSampleManager::Initialise(void) } else { - bFileNotFound = true; + bFileNotFound = TRUE; break; } } if ( !bFileNotFound ) { - m_bInitialised = true; + m_bInitialised = TRUE; break; } else { - m_bInitialised = false; + m_bInitialised = FALSE; continue; } } @@ -1047,11 +1048,11 @@ cSampleManager::Initialise(void) if ( FrontEndMenuManager.m_bQuitGameNoCD ) { Terminate(); - return false; + return FALSE; } continue; #else - m_bInitialised = true; + m_bInitialised = TRUE; #endif } @@ -1071,7 +1072,7 @@ cSampleManager::Initialise(void) { int32 streamLength[TOTAL_STREAMED_SOUNDS]; - bool bFileNotFound = false; + bool8 bFileNotFound = FALSE; char rootpath[MAX_PATH]; strcpy(_aHDDPath, m_szCDRomRootPath); @@ -1101,14 +1102,14 @@ cSampleManager::Initialise(void) } else { - bFileNotFound = true; + bFileNotFound = TRUE; break; } } } else - bFileNotFound = true; + bFileNotFound = TRUE; if ( !bFileNotFound ) { @@ -1117,10 +1118,10 @@ cSampleManager::Initialise(void) for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ ) nStreamLength[i] = streamLength[i]; - _bUseHDDAudio = true; + _bUseHDDAudio = TRUE; } else - _bUseHDDAudio = false; + _bUseHDDAudio = FALSE; } #endif #ifdef AUDIO_CACHE @@ -1152,7 +1153,7 @@ cSampleManager::Initialise(void) TRACE("providerset"); { - _bSampmanInitialised = true; + _bSampmanInitialised = TRUE; U32 n = 0; @@ -1169,7 +1170,7 @@ cSampleManager::Initialise(void) if ( n == m_nNumberOfProviders ) { Terminate(); - return false; + return FALSE; } } @@ -1198,13 +1199,13 @@ cSampleManager::Initialise(void) time_t t = time(NULL); tm *localtm; - bool bUseRandomTable; + bool8 bUseRandomTable; if ( t == -1 ) - bUseRandomTable = true; + bUseRandomTable = TRUE; else { - bUseRandomTable = false; + bUseRandomTable = FALSE; localtm = localtime(&t); } @@ -1236,12 +1237,12 @@ cSampleManager::Initialise(void) else _CurMP3Pos = 0; - _bIsMp3Active = false; + _bIsMp3Active = FALSE; } TRACE("end"); - return true; + return TRUE; } void @@ -1290,10 +1291,10 @@ cSampleManager::Terminate(void) AIL_shutdown(); - _bSampmanInitialised = false; + _bSampmanInitialised = FALSE; } -bool +bool8 cSampleManager::CheckForAnAudioFileOnCD(void) { #if GTA_VERSION < GTA3_PC_STEAM && !defined(NO_CDCHECK) @@ -1316,13 +1317,13 @@ cSampleManager::CheckForAnAudioFileOnCD(void) { fclose(f); - return true; + return TRUE; } - return false; + return FALSE; #else - return true; + return TRUE; #endif // #if GTA_VERSION < GTA3_PC_STEAM && !defined(NO_CDCHECK) } @@ -1415,48 +1416,48 @@ cSampleManager::SetMusicFadeVolume(uint8 nVolume) } void -cSampleManager::SetMonoMode(uint8 nMode) +cSampleManager::SetMonoMode(bool8 nMode) { m_nMonoMode = nMode; } -bool +bool8 cSampleManager::LoadSampleBank(uint8 nBank) { if ( CTimer::GetIsCodePaused() ) - return false; + return FALSE; if ( MusicManager.IsInitialised() && MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE && nBank != SFX_BANK_0 ) { - return false; + return FALSE; } if ( fseek(fpSampleDataHandle, nSampleBankDiscStartOffset[nBank], SEEK_SET) != 0 ) - return false; + return FALSE; if ( fread((void *)nSampleBankMemoryStartAddress[nBank], 1, nSampleBankSize[nBank],fpSampleDataHandle) != nSampleBankSize[nBank] ) - return false; + return FALSE; - bSampleBankLoaded[nBank] = true; + bSampleBankLoaded[nBank] = TRUE; - return true; + return TRUE; } void cSampleManager::UnloadSampleBank(uint8 nBank) { - bSampleBankLoaded[nBank] = false; + bSampleBankLoaded[nBank] = FALSE; } -bool +bool8 cSampleManager::IsSampleBankLoaded(uint8 nBank) { return bSampleBankLoaded[nBank]; } -bool +bool8 cSampleManager::IsPedCommentLoaded(uint32 nComment) { int8 slot; @@ -1469,10 +1470,10 @@ cSampleManager::IsPedCommentLoaded(uint32 nComment) slot += ARRAY_SIZE(nPedSlotSfx); #endif if ( nComment == nPedSlotSfx[slot] ) - return true; + return TRUE; } - return false; + return FALSE; } int32 @@ -1494,11 +1495,11 @@ cSampleManager::_GetPedCommentSlot(uint32 nComment) return -1; } -bool +bool8 cSampleManager::LoadPedComment(uint32 nComment) { if ( CTimer::GetIsCodePaused() ) - return false; + return FALSE; // no talking peds during cutsenes or the game end if ( MusicManager.IsInitialised() ) @@ -1507,7 +1508,7 @@ cSampleManager::LoadPedComment(uint32 nComment) { case MUSICMODE_CUTSCENE: { - return false; + return FALSE; break; } @@ -1515,7 +1516,7 @@ cSampleManager::LoadPedComment(uint32 nComment) case MUSICMODE_FRONTEND: { if ( MusicManager.GetNextTrack() == STREAMED_SOUND_GAME_COMPLETED ) - return false; + return FALSE; break; } @@ -1523,10 +1524,10 @@ cSampleManager::LoadPedComment(uint32 nComment) } if ( fseek(fpSampleDataHandle, m_aSamples[nComment].nOffset, SEEK_SET) != 0 ) - return false; + return FALSE; if ( fread((void *)(nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE*nCurrentPedSlot), 1, m_aSamples[nComment].nSize, fpSampleDataHandle) != m_aSamples[nComment].nSize ) - return false; + return FALSE; nPedSlotSfxAddr[nCurrentPedSlot] = nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE*nCurrentPedSlot; nPedSlotSfx [nCurrentPedSlot] = nComment; @@ -1534,7 +1535,7 @@ cSampleManager::LoadPedComment(uint32 nComment) if ( ++nCurrentPedSlot >= MAX_PEDSFX ) nCurrentPedSlot = 0; - return true; + return TRUE; } int32 @@ -1573,14 +1574,14 @@ cSampleManager::GetSampleLength(uint32 nSample) return m_aSamples[nSample].nSize >> 1; } -bool +bool8 cSampleManager::UpdateReverb(void) { if ( !usingEAX ) - return false; + return FALSE; if ( AudioManager.GetFrameCounter() & 15 ) - return false; + return FALSE; float y = AudioManager.GetReflectionsDistance(REFLECTION_TOP) + AudioManager.GetReflectionsDistance(REFLECTION_BOTTOM); float x = AudioManager.GetReflectionsDistance(REFLECTION_LEFT) + AudioManager.GetReflectionsDistance(REFLECTION_RIGHT); @@ -1624,10 +1625,10 @@ cSampleManager::UpdateReverb(void) } } - fRatio = clamp(fRatio, usingEAX3==1 ? 0.0f : 0.30f, 1.0f); + fRatio = Clamp(fRatio, usingEAX3==1 ? 0.0f : 0.30f, 1.0f); if ( fRatio == _fPrevEaxRatioDestination ) - return false; + return FALSE; if ( usingEAX3 ) { @@ -1647,26 +1648,26 @@ cSampleManager::UpdateReverb(void) _fPrevEaxRatioDestination = fRatio; - return true; + return TRUE; } void -cSampleManager::SetChannelReverbFlag(uint32 nChannel, uint8 nReverbFlag) +cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag) { - bool b2d = false; + bool8 b2d = FALSE; switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { - b2d = true; + b2d = TRUE; break; } } if ( usingEAX ) { - if ( nReverbFlag != 0 ) + if ( nReverbFlag != FALSE ) { if ( !b2d ) AIL_set_3D_sample_effects_level(opened_samples[nChannel], _fEffectsLevel); @@ -1679,16 +1680,16 @@ cSampleManager::SetChannelReverbFlag(uint32 nChannel, uint8 nReverbFlag) } } -bool +bool8 cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank) { - bool b2d = false; + bool8 b2d = FALSE; switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { - b2d = true; + b2d = TRUE; break; } } @@ -1698,14 +1699,14 @@ cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank) if ( nSfx < SAMPLEBANK_MAX ) { if ( !IsSampleBankLoaded(nBank) ) - return false; + return FALSE; addr = nSampleBankMemoryStartAddress[nBank] + m_aSamples[nSfx].nOffset - m_aSamples[BankStartOffset[nBank]].nOffset; } else { if ( !IsPedCommentLoaded(nSfx) ) - return false; + return FALSE; int32 slot = _GetPedCommentSlot(nSfx); @@ -1717,10 +1718,10 @@ cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank) if ( opened_2dsamples[nChannel - MAXCHANNELS] ) { AIL_set_sample_address(opened_2dsamples[nChannel - MAXCHANNELS], (void *)addr, m_aSamples[nSfx].nSize); - return true; + return TRUE; } else - return false; + return FALSE; } else { @@ -1736,10 +1737,10 @@ cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank) if ( AIL_set_3D_sample_info(opened_samples[nChannel], &info) == 0 ) { OutputDebugString(AIL_last_error()); - return false; + return FALSE; } - return true; + return TRUE; } } @@ -1786,7 +1787,7 @@ cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume) switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { nChannelVolume[nChannel] = vol; @@ -1814,7 +1815,7 @@ cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan) { switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { #ifndef FIX_BUGS if ( opened_samples[nChannel - MAXCHANNELS] ) // BUG @@ -1831,13 +1832,13 @@ cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan) void cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq) { - bool b2d = false; + bool8 b2d = FALSE; switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { - b2d = true; + b2d = TRUE; break; } } @@ -1857,13 +1858,13 @@ cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq) void cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd) { - bool b2d = false; + bool8 b2d = FALSE; switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { - b2d = true; + b2d = TRUE; break; } } @@ -1883,13 +1884,13 @@ cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 n void cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount) { - bool b2d = false; + bool8 b2d = FALSE; switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { - b2d = true; + b2d = TRUE; break; } } @@ -1906,16 +1907,16 @@ cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount) } } -bool +bool8 cSampleManager::GetChannelUsedFlag(uint32 nChannel) { - bool b2d = false; + bool8 b2d = FALSE; switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { - b2d = true; + b2d = TRUE; break; } } @@ -1925,14 +1926,14 @@ cSampleManager::GetChannelUsedFlag(uint32 nChannel) if ( opened_2dsamples[nChannel - MAXCHANNELS] ) return AIL_sample_status(opened_2dsamples[nChannel - MAXCHANNELS]) == SMP_PLAYING; else - return false; + return FALSE; } else { if ( opened_samples[nChannel] ) return AIL_3D_sample_status(opened_samples[nChannel]) == SMP_PLAYING; else - return false; + return FALSE; } } @@ -1940,13 +1941,13 @@ cSampleManager::GetChannelUsedFlag(uint32 nChannel) void cSampleManager::StartChannel(uint32 nChannel) { - bool b2d = false; + bool8 b2d = FALSE; switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { - b2d = true; + b2d = TRUE; break; } } @@ -1966,13 +1967,13 @@ cSampleManager::StartChannel(uint32 nChannel) void cSampleManager::StopChannel(uint32 nChannel) { - bool b2d = false; + bool8 b2d = FALSE; switch ( nChannel ) { - case CHANNEL2D: + case CHANNEL_POLICE_RADIO: { - b2d = true; + b2d = TRUE; break; } } @@ -2024,12 +2025,12 @@ cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream) } void -cSampleManager::PauseStream(uint8 nPauseFlag, uint8 nStream) +cSampleManager::PauseStream(bool8 nPauseFlag, uint8 nStream) { if ( m_bInitialised ) { if ( mp3Stream[nStream] ) - AIL_pause_stream(mp3Stream[nStream], nPauseFlag != 0); + AIL_pause_stream(mp3Stream[nStream], nPauseFlag != FALSE); } } @@ -2043,145 +2044,135 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream) } } -bool +bool8 cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) { + int i = 0; uint32 position = nPos; char filename[MAX_PATH]; - if ( m_bInitialised && nFile < TOTAL_STREAMED_SOUNDS ) + if ( !m_bInitialised || nFile >= TOTAL_STREAMED_SOUNDS ) + return FALSE; + + if ( mp3Stream[nStream] ) { - if ( mp3Stream[nStream] ) - { - AIL_pause_stream(mp3Stream[nStream], 1); - AIL_close_stream(mp3Stream[nStream]); - } - - if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER ) + AIL_pause_stream(mp3Stream[nStream], 1); + AIL_close_stream(mp3Stream[nStream]); + } + if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER ) + { + do { - uint32 i = 0; - do { - if(i != 0 || _bIsMp3Active) { - if(++_CurMP3Index >= nNumMP3s) _CurMP3Index = 0; - - _CurMP3Pos = 0; - - tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index); - - if(mp3) { - mp3 = _pMP3List; - if(mp3 == NULL) { - _bIsMp3Active = false; - nFile = 0; - strcpy(filename, m_szCDRomRootPath); - strcat(filename, StreamedNameTable[nFile]); - - mp3Stream[nStream] = - AIL_open_stream(DIG, filename, 0); - if(mp3Stream[nStream]) { - AIL_set_stream_loop_count( - mp3Stream[nStream], 1); - AIL_set_stream_ms_position( - mp3Stream[nStream], position); - AIL_pause_stream(mp3Stream[nStream], - 0); - return true; - } + // Just switched to MP3 player + if ( !_bIsMp3Active && i == 0 ) + { + if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] ) + position = 0; + tMP3Entry *e = _pMP3List; - return false; - } + // Try to continue from previous song, if already started + if(!_GetMP3PosFromStreamPos(&position, &e) && !e) { + nFile = 0; + strcpy(filename, m_szCDRomRootPath); + strcat(filename, StreamedNameTable[nFile]); + + mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0); + if ( mp3Stream[nStream] ) + { + AIL_set_stream_loop_count(mp3Stream[nStream], 1); + AIL_set_stream_ms_position(mp3Stream[nStream], position); + AIL_pause_stream(mp3Stream[nStream], 0); + return TRUE; } + return FALSE; - if(mp3->pLinkPath != NULL) - mp3Stream[nStream] = - AIL_open_stream(DIG, mp3->pLinkPath, 0); + } else { + if ( e->pLinkPath != NULL ) + mp3Stream[nStream] = AIL_open_stream(DIG, e->pLinkPath, 0); else { strcpy(filename, _mp3DirectoryPath); - strcat(filename, mp3->aFilename); - - mp3Stream[nStream] = - AIL_open_stream(DIG, filename, 0); + strcat(filename, e->aFilename); + + mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0); } - - if(mp3Stream[nStream]) { + + if ( mp3Stream[nStream] ) { AIL_set_stream_loop_count(mp3Stream[nStream], 1); - AIL_set_stream_ms_position(mp3Stream[nStream], 0); + AIL_set_stream_ms_position(mp3Stream[nStream], position); AIL_pause_stream(mp3Stream[nStream], 0); - return true; + + _bIsMp3Active = TRUE; + + return TRUE; } - - _bIsMp3Active = false; - continue; + // fall through, start playing from another song } - if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] ) - position = 0; - - tMP3Entry *e; - if ( !_GetMP3PosFromStreamPos(&position, &e) ) + } else { + if(++_CurMP3Index >= nNumMP3s) _CurMP3Index = 0; + + _CurMP3Pos = 0; + + tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index); + if ( !mp3 ) { - if ( e == NULL ) + mp3 = _pMP3List; + if ( !_pMP3List ) { nFile = 0; + _bIsMp3Active = 0; strcpy(filename, m_szCDRomRootPath); strcat(filename, StreamedNameTable[nFile]); - mp3Stream[nStream] = - AIL_open_stream(DIG, filename, 0); - if(mp3Stream[nStream]) { - AIL_set_stream_loop_count( - mp3Stream[nStream], 1); - AIL_set_stream_ms_position( - mp3Stream[nStream], position); + + mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0); + if ( mp3Stream[nStream] ) + { + AIL_set_stream_loop_count(mp3Stream[nStream], 1); + AIL_set_stream_ms_position(mp3Stream[nStream], position); AIL_pause_stream(mp3Stream[nStream], 0); - return true; + return TRUE; } - - return false; + return FALSE; } } - - if ( e->pLinkPath != NULL ) - mp3Stream[nStream] = AIL_open_stream(DIG, e->pLinkPath, 0); - else - { + if(mp3->pLinkPath != NULL) + mp3Stream[nStream] = AIL_open_stream(DIG, mp3->pLinkPath, 0); + else { strcpy(filename, _mp3DirectoryPath); - strcat(filename, e->aFilename); - - mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0); + strcat(filename, mp3->aFilename); + + mp3Stream[nStream] = + AIL_open_stream(DIG, filename, 0); } - - if ( mp3Stream[nStream] ) - { + + if(mp3Stream[nStream]) { AIL_set_stream_loop_count(mp3Stream[nStream], 1); - AIL_set_stream_ms_position(mp3Stream[nStream], position); + AIL_set_stream_ms_position(mp3Stream[nStream], 0); AIL_pause_stream(mp3Stream[nStream], 0); - - _bIsMp3Active = true; - - return true; +#ifdef FIX_BUGS + _bIsMp3Active = TRUE; +#endif + return TRUE; } - - _bIsMp3Active = false; - - } while(++i < nNumMP3s); - position = 0; - nFile = 0; - } - - strcpy(filename, m_szCDRomRootPath); - strcat(filename, StreamedNameTable[nFile]); - - mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0); - if ( mp3Stream[nStream] ) - { - AIL_set_stream_loop_count(mp3Stream[nStream], 1); - AIL_set_stream_ms_position(mp3Stream[nStream], position); - AIL_pause_stream(mp3Stream[nStream], 0); - return true; + } + _bIsMp3Active = 0; } + while ( ++i < nNumMP3s ); + position = 0; + nFile = 0; } + strcpy(filename, m_szCDRomRootPath); + strcat(filename, StreamedNameTable[nFile]); - return false; + mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0); + if ( mp3Stream[nStream] ) + { + AIL_set_stream_loop_count(mp3Stream[nStream], 1); + AIL_set_stream_ms_position(mp3Stream[nStream], position); + AIL_pause_stream(mp3Stream[nStream], 0); + return TRUE; + } + return FALSE; } void @@ -2197,7 +2188,7 @@ cSampleManager::StopStreamedFile(uint8 nStream) mp3Stream[nStream] = NULL; if ( nStream == 0 ) - _bIsMp3Active = false; + _bIsMp3Active = FALSE; } } } @@ -2235,7 +2226,7 @@ cSampleManager::GetStreamedFilePosition(uint8 nStream) } void -cSampleManager::SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffectFlag, uint8 nStream) +cSampleManager::SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, bool8 nEffectFlag, uint8 nStream) { uint8 vol = nVolume; @@ -2268,7 +2259,7 @@ cSampleManager::GetStreamedFileLength(uint8 nStream) return 0; } -bool +bool8 cSampleManager::IsStreamPlaying(uint8 nStream) { if ( m_bInitialised ) @@ -2276,23 +2267,23 @@ cSampleManager::IsStreamPlaying(uint8 nStream) if ( mp3Stream[nStream] ) { if ( AIL_stream_status(mp3Stream[nStream]) == SMP_PLAYING ) - return true; + return TRUE; else - return false; + return FALSE; } } - return false; + return FALSE; } -bool +bool8 cSampleManager::InitialiseSampleBanks(void) { int32 nBank = SFX_BANK_0; fpSampleDescHandle = fopen(SampleBankDescFilename, "rb"); if ( fpSampleDescHandle == NULL ) - return false; + return FALSE; fpSampleDataHandle = fopen(SampleBankDataFilename, "rb"); if ( fpSampleDataHandle == NULL ) @@ -2300,7 +2291,7 @@ cSampleManager::InitialiseSampleBanks(void) fclose(fpSampleDescHandle); fpSampleDescHandle = NULL; - return false; + return FALSE; } fseek(fpSampleDataHandle, 0, SEEK_END); @@ -2327,7 +2318,7 @@ cSampleManager::InitialiseSampleBanks(void) nSampleBankSize[SFX_BANK_0] = nSampleBankDiscStartOffset[SFX_BANK_PED_COMMENTS] - nSampleBankDiscStartOffset[SFX_BANK_0]; nSampleBankSize[SFX_BANK_PED_COMMENTS] = _nSampleDataEndOffset - nSampleBankDiscStartOffset[SFX_BANK_PED_COMMENTS]; - return true; + return TRUE; } #endif diff --git a/src/audio/sampman_null.cpp b/src/audio/sampman_null.cpp index e44e5b57..df912a9a 100644 --- a/src/audio/sampman_null.cpp +++ b/src/audio/sampman_null.cpp @@ -4,7 +4,7 @@ #include "AudioManager.h" cSampleManager SampleManager; -bool _bSampmanInitialised = false; +bool8 _bSampmanInitialised = FALSE; uint32 BankStartOffset[MAX_SFX_BANKS]; uint32 nNumMP3s; @@ -60,7 +60,7 @@ int8 cSampleManager::SetCurrent3DProvider(uint8 nProvider) return 0; } -bool +bool8 cSampleManager::IsMP3RadioChannelAvailable(void) { return nNumMP3s != 0; @@ -75,10 +75,10 @@ void cSampleManager::ReacquireDigitalHandle(void) { } -bool +bool8 cSampleManager::Initialise(void) { - return true; + return TRUE; } void @@ -87,9 +87,9 @@ cSampleManager::Terminate(void) } -bool cSampleManager::CheckForAnAudioFileOnCD(void) +bool8 cSampleManager::CheckForAnAudioFileOnCD(void) { - return true; + return TRUE; } char cSampleManager::GetCDAudioDriveLetter(void) @@ -128,11 +128,11 @@ cSampleManager::SetMonoMode(uint8 nMode) { } -bool +bool8 cSampleManager::LoadSampleBank(uint8 nBank) { ASSERT( nBank < MAX_SFX_BANKS ); - return false; + return FALSE; } void @@ -141,20 +141,20 @@ cSampleManager::UnloadSampleBank(uint8 nBank) ASSERT( nBank < MAX_SFX_BANKS ); } -bool +bool8 cSampleManager::IsSampleBankLoaded(uint8 nBank) { ASSERT( nBank < MAX_SFX_BANKS ); - return false; + return FALSE; } -bool +bool8 cSampleManager::IsPedCommentLoaded(uint32 nComment) { ASSERT( nComment < TOTAL_AUDIO_SAMPLES ); - return false; + return FALSE; } @@ -164,11 +164,11 @@ cSampleManager::_GetPedCommentSlot(uint32 nComment) return -1; } -bool +bool8 cSampleManager::LoadPedComment(uint32 nComment) { ASSERT( nComment < TOTAL_AUDIO_SAMPLES ); - return false; + return FALSE; } int32 @@ -205,56 +205,56 @@ cSampleManager::GetSampleLength(uint32 nSample) return 0; } -bool cSampleManager::UpdateReverb(void) +bool8 cSampleManager::UpdateReverb(void) { - return false; + return FALSE; } void -cSampleManager::SetChannelReverbFlag(uint32 nChannel, uint8 nReverbFlag) +cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag) { ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); } -bool +bool8 cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank) { ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); - return false; + return FALSE; } void cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume) { - ASSERT( nChannel != CHANNEL2D ); + ASSERT( nChannel < MAXCHANNELS ); ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); } void cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float fZ) { - ASSERT( nChannel != CHANNEL2D ); + ASSERT( nChannel < MAXCHANNELS ); ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); } void cSampleManager::SetChannel3DDistances(uint32 nChannel, float fMax, float fMin) { - ASSERT( nChannel != CHANNEL2D ); + ASSERT( nChannel < MAXCHANNELS ); ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); } void cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume) { - ASSERT( nChannel == CHANNEL2D ); + ASSERT( nChannel >= MAXCHANNELS ); ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); } void cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan) { - ASSERT(nChannel == CHANNEL2D); + ASSERT( nChannel >= MAXCHANNELS ); ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); } @@ -276,12 +276,12 @@ cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount) ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); } -bool +bool8 cSampleManager::GetChannelUsedFlag(uint32 nChannel) { ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); - return false; + return FALSE; } void @@ -303,7 +303,7 @@ cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream) } void -cSampleManager::PauseStream(uint8 nPauseFlag, uint8 nStream) +cSampleManager::PauseStream(bool8 nPauseFlag, uint8 nStream) { ASSERT( nStream < MAX_STREAMS ); } @@ -314,12 +314,12 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream) ASSERT( nStream < MAX_STREAMS ); } -bool +bool8 cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) { ASSERT( nStream < MAX_STREAMS ); - return false; + return FALSE; } void @@ -350,19 +350,19 @@ cSampleManager::GetStreamedFileLength(uint8 nStream) return 1; } -bool +bool8 cSampleManager::IsStreamPlaying(uint8 nStream) { ASSERT( nStream < MAX_STREAMS ); - return false; + return FALSE; } -bool +bool8 cSampleManager::InitialiseSampleBanks(void) { - return true; + return TRUE; } #endif diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp index d9adef5b..7fb84965 100644 --- a/src/audio/sampman_oal.cpp +++ b/src/audio/sampman_oal.cpp @@ -45,10 +45,9 @@ #endif //TODO: fix eax3 reverb -//TODO: max channels cSampleManager SampleManager; -bool _bSampmanInitialised = false; +bool8 _bSampmanInitialised = FALSE; uint32 BankStartOffset[MAX_SFX_BANKS]; @@ -61,15 +60,17 @@ ALCdevice *ALDevice = NULL; ALCcontext *ALContext = NULL; unsigned int _maxSamples; float _fPrevEaxRatioDestination; +bool _effectsSupported = false; bool _usingEFX; float _fEffectsLevel; ALuint ALEffect = AL_EFFECT_NULL; ALuint ALEffectSlot = AL_EFFECTSLOT_NULL; struct { - char id[256]; + const char *id; char name[256]; int sources; + bool bSupportsFx; }providers[MAXPROVIDERS]; int defaultProvider; @@ -84,7 +85,7 @@ OggOpusFile *fpSampleDataHandle; #else FILE *fpSampleDataHandle; #endif -bool bSampleBankLoaded [MAX_SFX_BANKS]; +bool8 bSampleBankLoaded [MAX_SFX_BANKS]; int32 nSampleBankDiscStartOffset [MAX_SFX_BANKS]; int32 nSampleBankSize [MAX_SFX_BANKS]; uintptr nSampleBankMemoryStartAddress[MAX_SFX_BANKS]; @@ -94,8 +95,8 @@ int32 nPedSlotSfx [MAX_PEDSFX]; int32 nPedSlotSfxAddr[MAX_PEDSFX]; uint8 nCurrentPedSlot; -CChannel aChannel[MAXCHANNELS+MAX2DCHANNELS]; -uint8 nChannelVolume[MAXCHANNELS+MAX2DCHANNELS]; +CChannel aChannel[NUM_CHANNELS]; +uint8 nChannelVolume[NUM_CHANNELS]; uint32 nStreamLength[TOTAL_STREAMED_SOUNDS]; ALuint ALStreamSources[MAX_STREAMS][2]; @@ -120,7 +121,7 @@ uint8 nStreamPan [MAX_STREAMS]; uint8 nStreamVolume[MAX_STREAMS]; uint32 _CurMP3Index; int32 _CurMP3Pos; -bool _bIsMp3Active; +bool8 _bIsMp3Active; /////////////////////////////////////////////////////////////// // Env Size Diffus Room RoomHF RoomLF DecTm DcHF DcLF Refl RefDel Ref Pan Revb RevDel Rev Pan EchTm EchDp ModTm ModDp AirAbs HFRef LFRef RRlOff FLAGS EAXLISTENERPROPERTIES StartEAX3 = @@ -134,7 +135,7 @@ EAXLISTENERPROPERTIES EAX3Params; bool IsFXSupported() { - return usingEAX || usingEAX3 || _usingEFX; + return _effectsSupported; // usingEAX || usingEAX3 || _usingEFX; } void EAX_SetAll(const EAXLISTENERPROPERTIES *allparameters) @@ -150,47 +151,49 @@ add_providers() { SampleManager.SetNum3DProvidersAvailable(0); - ALDeviceList *pDeviceList = NULL; - pDeviceList = new ALDeviceList(); + static ALDeviceList DeviceList; + ALDeviceList *pDeviceList = &DeviceList; if ((pDeviceList) && (pDeviceList->GetNumDevices())) { const int devNumber = Min(pDeviceList->GetNumDevices(), MAXPROVIDERS); int n = 0; - for (int i = 0; i < devNumber; i++) + //for (int i = 0; i < devNumber; i++) + int i = pDeviceList->GetDefaultDevice(); { if ( n < MAXPROVIDERS ) { - strcpy(providers[n].id, pDeviceList->GetDeviceName(i)); - strncpy(providers[n].name, pDeviceList->GetDeviceName(i), sizeof(providers[n].name)); + providers[n].id = pDeviceList->GetDeviceName(i); + strcpy(providers[n].name, "OPENAL SOFT"); providers[n].sources = pDeviceList->GetMaxNumSources(i); SampleManager.Set3DProviderName(n, providers[n].name); n++; } - + if ( alGetEnumValue("AL_EFFECT_EAXREVERB") != 0 || pDeviceList->IsExtensionSupported(i, ADEXT_EAX2) || pDeviceList->IsExtensionSupported(i, ADEXT_EAX3) || pDeviceList->IsExtensionSupported(i, ADEXT_EAX4) || pDeviceList->IsExtensionSupported(i, ADEXT_EAX5) ) { + providers[n - 1].bSupportsFx = true; if ( n < MAXPROVIDERS ) { - strcpy(providers[n].id, pDeviceList->GetDeviceName(i)); - strncpy(providers[n].name, pDeviceList->GetDeviceName(i), sizeof(providers[n].name)); - strcat(providers[n].name, " EAX"); + providers[n].id = pDeviceList->GetDeviceName(i); + strcpy(providers[n].name, "OPENAL SOFT EAX"); providers[n].sources = pDeviceList->GetMaxNumSources(i); + providers[n].bSupportsFx = true; SampleManager.Set3DProviderName(n, providers[n].name); n++; } if ( n < MAXPROVIDERS ) { - strcpy(providers[n].id, pDeviceList->GetDeviceName(i)); - strncpy(providers[n].name, pDeviceList->GetDeviceName(i), sizeof(providers[n].name)); - strcat(providers[n].name, " EAX3"); + providers[n].id = pDeviceList->GetDeviceName(i); + strcpy(providers[n].name, "OPENAL SOFT EAX3"); providers[n].sources = pDeviceList->GetMaxNumSources(i); + providers[n].bSupportsFx = true; SampleManager.Set3DProviderName(n, providers[n].name); n++; } @@ -201,75 +204,37 @@ add_providers() for(int j=n;j<MAXPROVIDERS;j++) SampleManager.Set3DProviderName(j, NULL); - defaultProvider = pDeviceList->GetDefaultDevice(); - if ( defaultProvider > MAXPROVIDERS ) - defaultProvider = 0; + // devices are gone now + //defaultProvider = pDeviceList->GetDefaultDevice(); + //if ( defaultProvider > MAXPROVIDERS ) + defaultProvider = 0; } - - delete pDeviceList; } static void release_existing() { - for ( int32 i = 0; i < MAXCHANNELS; i++ ) - aChannel[i].Term(); - aChannel[CHANNEL2D].Term(); - if ( IsFXSupported() ) { if ( alIsEffect(ALEffect) ) { alEffecti(ALEffect, AL_EFFECT_TYPE, AL_EFFECT_NULL); - alDeleteEffects(1, &ALEffect); - ALEffect = AL_EFFECT_NULL; } if (alIsAuxiliaryEffectSlot(ALEffectSlot)) { alAuxiliaryEffectSloti(ALEffectSlot, AL_EFFECTSLOT_EFFECT, AL_EFFECT_NULL); - - alDeleteAuxiliaryEffectSlots(1, &ALEffectSlot); - ALEffectSlot = AL_EFFECTSLOT_NULL; } } - for ( int32 i = 0; i < MAX_STREAMS; i++ ) - { - CStream *stream = aStream[i]; - if (stream) - stream->ProviderTerm(); - - alDeleteBuffers(NUM_STREAMBUFFERS, ALStreamBuffers[i]); - } - alDeleteSources(MAX_STREAMS*2, ALStreamSources[0]); - - CChannel::DestroyChannels(); - - if ( ALContext ) - { - alcMakeContextCurrent(NULL); - alcSuspendContext(ALContext); - alcDestroyContext(ALContext); - } - if ( ALDevice ) - alcCloseDevice(ALDevice); - - ALDevice = NULL; - ALContext = NULL; - - _fPrevEaxRatioDestination = 0.0f; - _usingEFX = false; - _fEffectsLevel = 0.0f; - DEV("release_existing()\n"); } -static bool +static bool8 set_new_provider(int index) { if ( curprovider == index ) - return true; + return TRUE; curprovider = index; @@ -279,61 +244,6 @@ set_new_provider(int index) { DEV("set_new_provider()\n"); - //TODO: - _maxSamples = MAXCHANNELS; - - ALCint attr[] = {ALC_FREQUENCY,MAX_FREQ, - ALC_MONO_SOURCES, MAX_STREAMS * 2 + MAXCHANNELS, - 0, - }; - - ALDevice = alcOpenDevice(providers[index].id); - ASSERT(ALDevice != NULL); - - ALContext = alcCreateContext(ALDevice, attr); - ASSERT(ALContext != NULL); - - alcMakeContextCurrent(ALContext); - - const char* ext=(const char*)alGetString(AL_EXTENSIONS); - ASSERT(strstr(ext,"AL_SOFT_loop_points")!=NULL); - if ( strstr(ext,"AL_SOFT_loop_points")==NULL ) - { - curprovider=-1; - release_existing(); - return false; - } - - alListenerf (AL_GAIN, 1.0f); - alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f); - alListener3f(AL_VELOCITY, 0.0f, 0.0f, 0.0f); - ALfloat orientation[6] = { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; - alListenerfv(AL_ORIENTATION, orientation); - - alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); - - if ( alcIsExtensionPresent(ALDevice, (ALCchar*)ALC_EXT_EFX_NAME) ) - { - alGenAuxiliaryEffectSlots(1, &ALEffectSlot); - alGenEffects(1, &ALEffect); - } - - alGenSources(MAX_STREAMS*2, ALStreamSources[0]); - for ( int32 i = 0; i < MAX_STREAMS; i++ ) - { - alGenBuffers(NUM_STREAMBUFFERS, ALStreamBuffers[i]); - alSourcei(ALStreamSources[i][0], AL_SOURCE_RELATIVE, AL_TRUE); - alSource3f(ALStreamSources[i][0], AL_POSITION, 0.0f, 0.0f, 0.0f); - alSourcef(ALStreamSources[i][0], AL_GAIN, 1.0f); - alSourcei(ALStreamSources[i][1], AL_SOURCE_RELATIVE, AL_TRUE); - alSource3f(ALStreamSources[i][1], AL_POSITION, 0.0f, 0.0f, 0.0f); - alSourcef(ALStreamSources[i][1], AL_GAIN, 1.0f); - - CStream *stream = aStream[i]; - if (stream) - stream->ProviderInit(); - } - usingEAX = 0; usingEAX3 = 0; _usingEFX = false; @@ -341,16 +251,16 @@ set_new_provider(int index) if ( !strcmp(&providers[index].name[strlen(providers[index].name) - strlen(" EAX3")], " EAX3") && alcIsExtensionPresent(ALDevice, (ALCchar*)ALC_EXT_EFX_NAME) ) { - EAX_SetAll(&FinishEAX3); usingEAX = 1; usingEAX3 = 1; + alAuxiliaryEffectSloti(ALEffectSlot, AL_EFFECTSLOT_EFFECT, ALEffect); + EAX_SetAll(&FinishEAX3); DEV("EAX3\n"); } else if ( alcIsExtensionPresent(ALDevice, (ALCchar*)ALC_EXT_EFX_NAME) ) { - EAX_SetAll(&EAX30_ORIGINAL_PRESETS[EAX_ENVIRONMENT_CAVE]); if ( !strcmp(&providers[index].name[strlen(providers[index].name) - strlen(" EAX")], " EAX")) { @@ -362,33 +272,25 @@ set_new_provider(int index) _usingEFX = true; DEV("EFX\n"); } + alAuxiliaryEffectSloti(ALEffectSlot, AL_EFFECTSLOT_EFFECT, ALEffect); + EAX_SetAll(&EAX30_ORIGINAL_PRESETS[EAX_ENVIRONMENT_CAVE]); } //SampleManager.SetSpeakerConfig(speaker_type); - - CChannel::InitChannels(); - for ( int32 i = 0; i < MAXCHANNELS; i++ ) - aChannel[i].Init(i); - aChannel[CHANNEL2D].Init(CHANNEL2D, true); - if ( IsFXSupported() ) { - /**/ - alAuxiliaryEffectSloti(ALEffectSlot, AL_EFFECTSLOT_EFFECT, ALEffect); - /**/ - for ( int32 i = 0; i < MAXCHANNELS; i++ ) aChannel[i].SetReverbMix(ALEffectSlot, 0.0f); } - return true; + return TRUE; } - return false; + return FALSE; } -static bool +static bool8 IsThisTrackAt16KHz(uint32 track) { return track == STREAMED_SOUND_RADIO_CHAT; @@ -446,7 +348,7 @@ int8 cSampleManager::SetCurrent3DProvider(uint8 nProvider) { int savedprovider = curprovider; - nProvider = clamp(nProvider, 0, m_nNumberOfProviders - 1); + nProvider = Clamp(nProvider, 0, m_nNumberOfProviders - 1); if ( set_new_provider(nProvider) ) return curprovider; @@ -456,13 +358,13 @@ int8 cSampleManager::SetCurrent3DProvider(uint8 nProvider) return curprovider; } -static bool +static bool8 _ResolveLink(char const *path, char *out) { #ifdef _WIN32 size_t len = strlen(path); if (len < 4 || strcmp(&path[len - 4], ".lnk") != 0) - return false; + return FALSE; IShellLink* psl; WIN32_FIND_DATA fd; @@ -497,7 +399,7 @@ _ResolveLink(char const *path, char *out) ppf->Release(); psl->Release(); #endif - return true; + return TRUE; } } } @@ -507,31 +409,31 @@ _ResolveLink(char const *path, char *out) psl->Release(); } - return false; + return FALSE; #else struct stat sb; if (lstat(path, &sb) == -1) { perror("lstat: "); - return false; + return FALSE; } if (S_ISLNK(sb.st_mode)) { char* linkname = (char*)alloca(sb.st_size + 1); if (linkname == NULL) { fprintf(stderr, "insufficient memory\n"); - return false; + return FALSE; } if (readlink(path, linkname, sb.st_size + 1) < 0) { perror("readlink: "); - return false; + return FALSE; } linkname[sb.st_size] = '\0'; strcpy(out, linkname); - return true; + return TRUE; } else { - return false; + return FALSE; } #endif } @@ -540,22 +442,36 @@ static void _FindMP3s(void) { tMP3Entry *pList; - bool bShortcut; - bool bInitFirstEntry; + bool8 bShortcut; + bool8 bInitFirstEntry; HANDLE hFind; char path[MAX_PATH]; - char filepath[MAX_PATH*2]; int total_ms; WIN32_FIND_DATA fd; + char filepath[MAX_PATH + sizeof(fd.cFileName)]; if (getcwd(_mp3DirectoryPath, MAX_PATH) == NULL) { perror("getcwd: "); return; } + + if (strlen(_mp3DirectoryPath) + 1 > MAX_PATH - 10) { + // This is not gonna end well + printf("MP3 folder path is too long, no place left for file names. MP3 finding aborted.\n"); + return; + } OutputDebugString("Finding MP3s..."); strcpy(path, _mp3DirectoryPath); strcat(path, "\\MP3\\"); + +#if !defined(_WIN32) + char *actualPath = casepath(path); + if (actualPath) { + strcpy(path, actualPath); + free(actualPath); + } +#endif strcpy(_mp3DirectoryPath, path); OutputDebugString(_mp3DirectoryPath); @@ -568,96 +484,33 @@ _FindMP3s(void) { return; } - - strcpy(filepath, _mp3DirectoryPath); - strcat(filepath, fd.cFileName); - - size_t filepathlen = strlen(filepath); - - if ( filepathlen <= 0) - { - FindClose(hFind); - return; - } - if ( _ResolveLink(filepath, filepath) ) - { - OutputDebugString("Resolving Link"); - OutputDebugString(filepath); - bShortcut = true; - } else - bShortcut = false; - - aStream[0] = new CStream(filepath, ALStreamSources[0], ALStreamBuffers[0]); - - if (aStream[0] && aStream[0]->IsOpened()) - { - total_ms = aStream[0]->GetLengthMS(); - delete aStream[0]; - aStream[0] = NULL; + bShortcut = FALSE; + bInitFirstEntry = TRUE; - OutputDebugString(fd.cFileName); - - _pMP3List = new tMP3Entry; - - if ( _pMP3List == NULL ) - { - FindClose(hFind); - return; - } - - nNumMP3s = 1; - - strcpy(_pMP3List->aFilename, fd.cFileName); - - _pMP3List->nTrackLength = total_ms; - - _pMP3List->pNext = NULL; - - pList = _pMP3List; - - if ( bShortcut ) - { - _pMP3List->pLinkPath = new char[MAX_PATH*2]; - strcpy(_pMP3List->pLinkPath, filepath); - } - else - { - _pMP3List->pLinkPath = NULL; - } + do + { + strcpy(filepath, _mp3DirectoryPath); + strcat(filepath, fd.cFileName); + + if (!strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, "..")) + continue; - bInitFirstEntry = false; - } - else - { - strcat(filepath, " - NOT A VALID MP3"); - - OutputDebugString(filepath); + size_t filepathlen = strlen(filepath); - bInitFirstEntry = true; - } - - while ( true ) - { - if ( !FindNextFile(hFind, &fd) ) - break; - if ( bInitFirstEntry ) { - strcpy(filepath, _mp3DirectoryPath); - strcat(filepath, fd.cFileName); - - size_t filepathlen = strlen(filepath); - - if ( filepathlen > 0 ) + if (filepathlen > 0) { - if ( _ResolveLink(filepath, filepath) ) + if (_ResolveLink(filepath, filepath)) { OutputDebugString("Resolving Link"); OutputDebugString(filepath); - bShortcut = true; - } else { - bShortcut = false; + bShortcut = TRUE; + } + else + { + bShortcut = FALSE; if (filepathlen > MAX_PATH) { continue; } @@ -669,34 +522,34 @@ _FindMP3s(void) total_ms = aStream[0]->GetLengthMS(); delete aStream[0]; aStream[0] = NULL; - + OutputDebugString(fd.cFileName); - + _pMP3List = new tMP3Entry; - - if ( _pMP3List == NULL) + + if (_pMP3List == NULL) break; - + nNumMP3s = 1; - + strcpy(_pMP3List->aFilename, fd.cFileName); - + _pMP3List->nTrackLength = total_ms; _pMP3List->pNext = NULL; - - if ( bShortcut ) + + if (bShortcut) { - _pMP3List->pLinkPath = new char [MAX_PATH*2]; + _pMP3List->pLinkPath = new char[MAX_PATH + sizeof(fd.cFileName)]; strcpy(_pMP3List->pLinkPath, filepath); } else { _pMP3List->pLinkPath = NULL; } - + pList = _pMP3List; - bInitFirstEntry = false; + bInitFirstEntry = FALSE; } else { @@ -704,23 +557,21 @@ _FindMP3s(void) OutputDebugString(filepath); } } + else + break; } else { - strcpy(filepath, _mp3DirectoryPath); - strcat(filepath, fd.cFileName); - - size_t filepathlen = strlen(filepath); - if ( filepathlen > 0 ) { if ( _ResolveLink(filepath, filepath) ) { OutputDebugString("Resolving Link"); OutputDebugString(filepath); - bShortcut = true; - } else - bShortcut = false; + bShortcut = TRUE; + } + else + bShortcut = FALSE; aStream[0] = new CStream(filepath, ALStreamSources[0], ALStreamBuffers[0]); @@ -730,8 +581,6 @@ _FindMP3s(void) delete aStream[0]; aStream[0] = NULL; - OutputDebugString(fd.cFileName); - pList->pNext = new tMP3Entry; tMP3Entry *e = pList->pNext; @@ -747,7 +596,7 @@ _FindMP3s(void) if ( bShortcut ) { - e->pLinkPath = new char [MAX_PATH*2]; + e->pLinkPath = new char [MAX_PATH + sizeof(fd.cFileName)]; strcpy(e->pLinkPath, filepath); } else @@ -766,7 +615,7 @@ _FindMP3s(void) } } } - } + } while (FindNextFile(hFind, &fd)); FindClose(hFind); } @@ -832,7 +681,7 @@ _GetMP3EntryByIndex(uint32 idx) return NULL; } -static inline bool +static inline bool8 _GetMP3PosFromStreamPos(uint32 *pPosition, tMP3Entry **pEntry) { _CurMP3Index = 0; @@ -845,7 +694,7 @@ _GetMP3PosFromStreamPos(uint32 *pPosition, tMP3Entry **pEntry) *pPosition -= (*pEntry)->nTrackStreamPos; _CurMP3Pos = *pPosition; - return true; + return TRUE; } _CurMP3Index++; @@ -856,10 +705,10 @@ _GetMP3PosFromStreamPos(uint32 *pPosition, tMP3Entry **pEntry) _CurMP3Pos = 0; _CurMP3Index = 0; - return false; + return FALSE; } -bool +bool8 cSampleManager::IsMP3RadioChannelAvailable(void) { return nNumMP3s != 0; @@ -868,28 +717,19 @@ cSampleManager::IsMP3RadioChannelAvailable(void) void cSampleManager::ReleaseDigitalHandle(void) { - if ( ALDevice ) - { - prevprovider = curprovider; - release_existing(); - curprovider = -1; - } + // TODO? alcSuspendContext } void cSampleManager::ReacquireDigitalHandle(void) { - if ( ALDevice ) - { - if ( prevprovider != -1 ) - set_new_provider(prevprovider); - } + // TODO? alcProcessContext } -bool +bool8 cSampleManager::Initialise(void) { if ( _bSampmanInitialised ) - return true; + return TRUE; EFXInit(); CStream::Initialise(); @@ -899,7 +739,7 @@ cSampleManager::Initialise(void) { m_aSamples[i].nOffset = 0; m_aSamples[i].nSize = 0; - m_aSamples[i].nFrequency = MAX_FREQ; + m_aSamples[i].nFrequency = 22050; m_aSamples[i].nLoopStart = 0; m_aSamples[i].nLoopEnd = -1; } @@ -934,7 +774,7 @@ cSampleManager::Initialise(void) for ( int32 i = 0; i < MAX_SFX_BANKS; i++ ) { - bSampleBankLoaded[i] = false; + bSampleBankLoaded[i] = FALSE; nSampleBankDiscStartOffset[i] = 0; nSampleBankSize[i] = 0; nSampleBankMemoryStartAddress[i] = 0; @@ -952,16 +792,87 @@ cSampleManager::Initialise(void) } { - for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ ) + for ( int32 i = 0; i < NUM_CHANNELS; i++ ) nChannelVolume[i] = 0; } + + add_providers(); + + { + int index = 0; + _maxSamples = Min(MAXCHANNELS, providers[index].sources); + + ALCint attr[] = {ALC_FREQUENCY,MAX_FREQ, + ALC_MONO_SOURCES, MAX_DIGITAL_MIXER_CHANNELS - MAX2DCHANNELS, + ALC_STEREO_SOURCES, MAX2DCHANNELS, + 0, + }; + + ALDevice = alcOpenDevice(providers[index].id); + ASSERT(ALDevice != NULL); + + ALContext = alcCreateContext(ALDevice, attr); + ASSERT(ALContext != NULL); + + alcMakeContextCurrent(ALContext); + + const char* ext=(const char*)alGetString(AL_EXTENSIONS); + ASSERT(strstr(ext,"AL_SOFT_loop_points")!=NULL); + if ( strstr(ext,"AL_SOFT_loop_points")==NULL ) + { + Terminate(); + return FALSE; + } + + alListenerf (AL_GAIN, 1.0f); + alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f); + alListener3f(AL_VELOCITY, 0.0f, 0.0f, 0.0f); + ALfloat orientation[6] = { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; + alListenerfv(AL_ORIENTATION, orientation); + + alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); + + if ( alcIsExtensionPresent(ALDevice, (ALCchar*)ALC_EXT_EFX_NAME) ) + { + _effectsSupported = providers[index].bSupportsFx; + alGenAuxiliaryEffectSlots(1, &ALEffectSlot); + alGenEffects(1, &ALEffect); + } + + alGenSources(MAX_STREAMS*2, ALStreamSources[0]); + for ( int32 i = 0; i < MAX_STREAMS; i++ ) + { + alGenBuffers(NUM_STREAMBUFFERS, ALStreamBuffers[i]); + alSourcei(ALStreamSources[i][0], AL_SOURCE_RELATIVE, AL_TRUE); + alSource3f(ALStreamSources[i][0], AL_POSITION, 0.0f, 0.0f, 0.0f); + alSourcef(ALStreamSources[i][0], AL_GAIN, 1.0f); + alSourcei(ALStreamSources[i][1], AL_SOURCE_RELATIVE, AL_TRUE); + alSource3f(ALStreamSources[i][1], AL_POSITION, 0.0f, 0.0f, 0.0f); + alSourcef(ALStreamSources[i][1], AL_GAIN, 1.0f); + } + + CChannel::InitChannels(); + + for ( int32 i = 0; i < MAXCHANNELS; i++ ) + aChannel[i].Init(i); + for ( int32 i = 0; i < MAX2DCHANNELS; i++ ) + aChannel[MAXCHANNELS+i].Init(MAXCHANNELS+i, true); + + if ( IsFXSupported() ) + { + /**/ + alAuxiliaryEffectSloti(ALEffectSlot, AL_EFFECTSLOT_EFFECT, ALEffect); + /**/ + + for ( int32 i = 0; i < MAXCHANNELS; i++ ) + aChannel[i].SetReverbMix(ALEffectSlot, 0.0f); + } + } { for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ ) nStreamLength[i] = 0; } - - add_providers(); #ifdef AUDIO_CACHE FILE *cacheFile = fcaseopen("audio\\sound.cache", "rb"); @@ -1002,7 +913,7 @@ cSampleManager::Initialise(void) if ( !InitialiseSampleBanks() ) { Terminate(); - return false; + return FALSE; } nSampleBankMemoryStartAddress[SFX_BANK_0] = (uintptr)malloc(nSampleBankSize[SFX_BANK_0]); @@ -1011,7 +922,7 @@ cSampleManager::Initialise(void) if ( nSampleBankMemoryStartAddress[SFX_BANK_0] == 0 ) { Terminate(); - return false; + return FALSE; } nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] = (uintptr)malloc(PED_BLOCKSIZE*MAX_PEDSFX); @@ -1030,7 +941,7 @@ cSampleManager::Initialise(void) } { - _bSampmanInitialised = true; + _bSampmanInitialised = TRUE; if ( defaultProvider >= 0 && defaultProvider < m_nNumberOfProviders ) { @@ -1039,7 +950,7 @@ cSampleManager::Initialise(void) else { Terminate(); - return false; + return FALSE; } } @@ -1062,13 +973,13 @@ cSampleManager::Initialise(void) time_t t = time(NULL); tm *localtm; - bool bUseRandomTable; + bool8 bUseRandomTable; if ( t == -1 ) - bUseRandomTable = true; + bUseRandomTable = TRUE; else { - bUseRandomTable = false; + bUseRandomTable = FALSE; localtm = localtime(&t); } @@ -1100,10 +1011,10 @@ cSampleManager::Initialise(void) else _CurMP3Pos = 0; - _bIsMp3Active = false; + _bIsMp3Active = FALSE; } - return true; + return TRUE; } void @@ -1118,8 +1029,51 @@ cSampleManager::Terminate(void) aStream[i] = NULL; } } - - release_existing(); + + for ( int32 i = 0; i < NUM_CHANNELS; i++ ) + aChannel[i].Term(); + + if ( IsFXSupported() ) + { + if ( alIsEffect(ALEffect) ) + { + alEffecti(ALEffect, AL_EFFECT_TYPE, AL_EFFECT_NULL); + alDeleteEffects(1, &ALEffect); + ALEffect = AL_EFFECT_NULL; + } + + if (alIsAuxiliaryEffectSlot(ALEffectSlot)) + { + alAuxiliaryEffectSloti(ALEffectSlot, AL_EFFECTSLOT_EFFECT, AL_EFFECT_NULL); + + alDeleteAuxiliaryEffectSlots(1, &ALEffectSlot); + ALEffectSlot = AL_EFFECTSLOT_NULL; + } + } + + for ( int32 i = 0; i < MAX_STREAMS; i++ ) + { + alDeleteBuffers(NUM_STREAMBUFFERS, ALStreamBuffers[i]); + } + alDeleteSources(MAX_STREAMS*2, ALStreamSources[0]); + + CChannel::DestroyChannels(); + + if ( ALContext ) + { + alcMakeContextCurrent(NULL); + alcSuspendContext(ALContext); + alcDestroyContext(ALContext); + } + if ( ALDevice ) + alcCloseDevice(ALDevice); + + ALDevice = NULL; + ALContext = NULL; + + _fPrevEaxRatioDestination = 0.0f; + _usingEFX = false; + _fEffectsLevel = 0.0f; _DeleteMP3Entries(); @@ -1137,12 +1091,12 @@ cSampleManager::Terminate(void) nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] = 0; } - _bSampmanInitialised = false; + _bSampmanInitialised = FALSE; } -bool cSampleManager::CheckForAnAudioFileOnCD(void) +bool8 cSampleManager::CheckForAnAudioFileOnCD(void) { - return true; + return TRUE; } char cSampleManager::GetCDAudioDriveLetter(void) @@ -1155,7 +1109,7 @@ cSampleManager::UpdateEffectsVolume(void) { if ( _bSampmanInitialised ) { - for ( int32 i = 0; i < MAXCHANNELS+MAX2DCHANNELS; i++ ) + for ( int32 i = 0; i < NUM_CHANNELS; i++ ) { if ( GetChannelUsedFlag(i) ) { @@ -1198,19 +1152,19 @@ cSampleManager::SetMonoMode(uint8 nMode) m_nMonoMode = nMode; } -bool +bool8 cSampleManager::LoadSampleBank(uint8 nBank) { ASSERT( nBank < MAX_SFX_BANKS); if ( CTimer::GetIsCodePaused() ) - return false; + return FALSE; if ( MusicManager.IsInitialised() && MusicManager.GetMusicMode() == MUSICMODE_CUTSCENE && nBank != SFX_BANK_0 ) { - return false; + return FALSE; } #ifdef OPUS_SFX @@ -1229,14 +1183,14 @@ cSampleManager::LoadSampleBank(uint8 nBank) } #else if ( fseek(fpSampleDataHandle, nSampleBankDiscStartOffset[nBank], SEEK_SET) != 0 ) - return false; + return FALSE; if ( fread((void *)nSampleBankMemoryStartAddress[nBank], 1, nSampleBankSize[nBank], fpSampleDataHandle) != nSampleBankSize[nBank] ) - return false; + return FALSE; #endif - bSampleBankLoaded[nBank] = true; + bSampleBankLoaded[nBank] = TRUE; - return true; + return TRUE; } void @@ -1244,10 +1198,10 @@ cSampleManager::UnloadSampleBank(uint8 nBank) { ASSERT( nBank < MAX_SFX_BANKS); - bSampleBankLoaded[nBank] = false; + bSampleBankLoaded[nBank] = FALSE; } -bool +bool8 cSampleManager::IsSampleBankLoaded(uint8 nBank) { ASSERT( nBank < MAX_SFX_BANKS); @@ -1255,39 +1209,39 @@ cSampleManager::IsSampleBankLoaded(uint8 nBank) return bSampleBankLoaded[nBank]; } -bool +bool8 cSampleManager::IsPedCommentLoaded(uint32 nComment) { ASSERT( nComment < TOTAL_AUDIO_SAMPLES ); - int8 slot; - for ( int32 i = 0; i < _TODOCONST(3); i++ ) { - slot = nCurrentPedSlot - i - 1; #ifdef FIX_BUGS + int8 slot = (int8)nCurrentPedSlot - i - 1; if (slot < 0) slot += ARRAY_SIZE(nPedSlotSfx); +#else + uint8 slot = nCurrentPedSlot - i - 1; #endif if ( nComment == nPedSlotSfx[slot] ) - return true; + return TRUE; } - return false; + return FALSE; } int32 cSampleManager::_GetPedCommentSlot(uint32 nComment) { - int8 slot; - for (int32 i = 0; i < _TODOCONST(3); i++) { - slot = nCurrentPedSlot - i - 1; #ifdef FIX_BUGS + int8 slot = (int8)nCurrentPedSlot - i - 1; if (slot < 0) slot += ARRAY_SIZE(nPedSlotSfx); +#else + uint8 slot = nCurrentPedSlot - i - 1; #endif if (nComment == nPedSlotSfx[slot]) return slot; @@ -1296,13 +1250,13 @@ cSampleManager::_GetPedCommentSlot(uint32 nComment) return -1; } -bool +bool8 cSampleManager::LoadPedComment(uint32 nComment) { ASSERT( nComment < TOTAL_AUDIO_SAMPLES ); if ( CTimer::GetIsCodePaused() ) - return false; + return FALSE; // no talking peds during cutsenes or the game end if ( MusicManager.IsInitialised() ) @@ -1311,7 +1265,7 @@ cSampleManager::LoadPedComment(uint32 nComment) { case MUSICMODE_CUTSCENE: { - return false; + return FALSE; break; } @@ -1319,7 +1273,7 @@ cSampleManager::LoadPedComment(uint32 nComment) case MUSICMODE_FRONTEND: { if ( MusicManager.GetNextTrack() == STREAMED_SOUND_GAME_COMPLETED ) - return false; + return FALSE; break; } @@ -1334,17 +1288,17 @@ cSampleManager::LoadPedComment(uint32 nComment) int size = op_read(fpSampleDataHandle, (opus_int16 *)(nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE * nCurrentPedSlot + samplesRead), samplesSize, NULL); if (size <= 0) { - return false; + return FALSE; } samplesRead += size * 2; samplesSize -= size; } #else if ( fseek(fpSampleDataHandle, m_aSamples[nComment].nOffset, SEEK_SET) != 0 ) - return false; + return FALSE; if ( fread((void *)(nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE*nCurrentPedSlot), 1, m_aSamples[nComment].nSize, fpSampleDataHandle) != m_aSamples[nComment].nSize ) - return false; + return FALSE; #endif nPedSlotSfx[nCurrentPedSlot] = nComment; @@ -1352,7 +1306,7 @@ cSampleManager::LoadPedComment(uint32 nComment) if ( ++nCurrentPedSlot >= MAX_PEDSFX ) nCurrentPedSlot = 0; - return true; + return TRUE; } int32 @@ -1395,13 +1349,13 @@ cSampleManager::GetSampleLength(uint32 nSample) return m_aSamples[nSample].nSize / sizeof(uint16); } -bool cSampleManager::UpdateReverb(void) +bool8 cSampleManager::UpdateReverb(void) { if ( !usingEAX && !_usingEFX ) - return false; + return FALSE; if ( AudioManager.GetFrameCounter() & 15 ) - return false; + return FALSE; float y = AudioManager.GetReflectionsDistance(REFLECTION_TOP) + AudioManager.GetReflectionsDistance(REFLECTION_BOTTOM); float x = AudioManager.GetReflectionsDistance(REFLECTION_LEFT) + AudioManager.GetReflectionsDistance(REFLECTION_RIGHT); @@ -1417,12 +1371,12 @@ bool cSampleManager::UpdateReverb(void) float fRatio = CALCRATIO(normx, normy, normz, 0.3f, 0.5f, (normy+normx+normz)/3.0f); #undef CALCRATIO - #undef ZE + #undef ZR - fRatio = clamp(fRatio, usingEAX3==1 ? 0.0f : 0.30f, 1.0f); + fRatio = Clamp(fRatio, usingEAX3==1 ? 0.0f : 0.30f, 1.0f); if ( fRatio == _fPrevEaxRatioDestination ) - return false; + return FALSE; #ifdef JUICY_OAL if ( usingEAX3 || _usingEFX ) @@ -1457,13 +1411,13 @@ bool cSampleManager::UpdateReverb(void) _fPrevEaxRatioDestination = fRatio; - return true; + return TRUE; } void -cSampleManager::SetChannelReverbFlag(uint32 nChannel, uint8 nReverbFlag) +cSampleManager::SetChannelReverbFlag(uint32 nChannel, bool8 nReverbFlag) { - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); if ( usingEAX || _usingEFX ) { @@ -1471,7 +1425,7 @@ cSampleManager::SetChannelReverbFlag(uint32 nChannel, uint8 nReverbFlag) { alAuxiliaryEffectSloti(ALEffectSlot, AL_EFFECTSLOT_EFFECT, ALEffect); - if ( nReverbFlag != 0 ) + if ( nReverbFlag != FALSE ) aChannel[nChannel].SetReverbMix(ALEffectSlot, _fEffectsLevel); else aChannel[nChannel].SetReverbMix(ALEffectSlot, 0.0f); @@ -1479,24 +1433,24 @@ cSampleManager::SetChannelReverbFlag(uint32 nChannel, uint8 nReverbFlag) } } -bool +bool8 cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank) { - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); uintptr addr; if ( nSfx < SAMPLEBANK_MAX ) { if ( !IsSampleBankLoaded(nBank) ) - return false; + return FALSE; addr = nSampleBankMemoryStartAddress[nBank] + m_aSamples[nSfx].nOffset - m_aSamples[BankStartOffset[nBank]].nOffset; } else { if ( !IsPedCommentLoaded(nSfx) ) - return false; + return FALSE; int32 slot = _GetPedCommentSlot(nSfx); addr = (nSampleBankMemoryStartAddress[SFX_BANK_PED_COMMENTS] + PED_BLOCKSIZE * slot); @@ -1514,17 +1468,16 @@ cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank) aChannel[nChannel].SetSampleData ((void*)addr, m_aSamples[nSfx].nSize, m_aSamples[nSfx].nFrequency); aChannel[nChannel].SetLoopPoints (0, -1); aChannel[nChannel].SetPitch (1.0f); - return true; + return TRUE; } - return false; + return FALSE; } void cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume) { - ASSERT( nChannel != CHANNEL2D ); - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < MAXCHANNELS ); uint32 vol = nVolume; if ( vol > MAX_VOLUME ) vol = MAX_VOLUME; @@ -1546,8 +1499,7 @@ cSampleManager::SetChannelEmittingVolume(uint32 nChannel, uint32 nVolume) void cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float fZ) { - ASSERT( nChannel != CHANNEL2D ); - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < MAXCHANNELS ); aChannel[nChannel].SetPosition(-fX, fY, fZ); } @@ -1555,18 +1507,17 @@ cSampleManager::SetChannel3DPosition(uint32 nChannel, float fX, float fY, float void cSampleManager::SetChannel3DDistances(uint32 nChannel, float fMax, float fMin) { - ASSERT( nChannel != CHANNEL2D ); - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < MAXCHANNELS ); aChannel[nChannel].SetDistances(fMax, fMin); } void cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume) { - ASSERT( nChannel == CHANNEL2D ); - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel >= MAXCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); - if ( nChannel == CHANNEL2D ) + if ( nChannel == CHANNEL_POLICE_RADIO ) { uint32 vol = nVolume; if ( vol > MAX_VOLUME ) vol = MAX_VOLUME; @@ -1588,10 +1539,10 @@ cSampleManager::SetChannelVolume(uint32 nChannel, uint32 nVolume) void cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan) { - ASSERT(nChannel == CHANNEL2D); - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel >= MAXCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); - if ( nChannel == CHANNEL2D ) + if ( nChannel == CHANNEL_POLICE_RADIO ) { aChannel[nChannel].SetPan(nPan); } @@ -1600,7 +1551,7 @@ cSampleManager::SetChannelPan(uint32 nChannel, uint32 nPan) void cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq) { - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); aChannel[nChannel].SetCurrentFreq(nFreq); } @@ -1608,7 +1559,7 @@ cSampleManager::SetChannelFrequency(uint32 nChannel, uint32 nFreq) void cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 nLoopEnd) { - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); aChannel[nChannel].SetLoopPoints(nLoopStart / (DIGITALBITS / 8), nLoopEnd / (DIGITALBITS / 8)); } @@ -1616,15 +1567,15 @@ cSampleManager::SetChannelLoopPoints(uint32 nChannel, uint32 nLoopStart, int32 n void cSampleManager::SetChannelLoopCount(uint32 nChannel, uint32 nLoopCount) { - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); aChannel[nChannel].SetLoopCount(nLoopCount); } -bool +bool8 cSampleManager::GetChannelUsedFlag(uint32 nChannel) { - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); return aChannel[nChannel].IsUsed(); } @@ -1632,7 +1583,7 @@ cSampleManager::GetChannelUsedFlag(uint32 nChannel) void cSampleManager::StartChannel(uint32 nChannel) { - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); aChannel[nChannel].Start(); } @@ -1640,7 +1591,7 @@ cSampleManager::StartChannel(uint32 nChannel) void cSampleManager::StopChannel(uint32 nChannel) { - ASSERT( nChannel < MAXCHANNELS+MAX2DCHANNELS ); + ASSERT( nChannel < NUM_CHANNELS ); aChannel[nChannel].Stop(); } @@ -1675,7 +1626,7 @@ cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream) } void -cSampleManager::PauseStream(uint8 nPauseFlag, uint8 nStream) +cSampleManager::PauseStream(bool8 nPauseFlag, uint8 nStream) { ASSERT( nStream < MAX_STREAMS ); @@ -1683,7 +1634,7 @@ cSampleManager::PauseStream(uint8 nPauseFlag, uint8 nStream) if ( stream ) { - stream->SetPause(nPauseFlag != 0); + stream->SetPause(nPauseFlag != FALSE); } } @@ -1703,94 +1654,94 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream) } } -bool +bool8 cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) { + int i = 0; uint32 position = nPos; - char filename[256]; - - ASSERT( nStream < MAX_STREAMS ); - - if ( nFile < TOTAL_STREAMED_SOUNDS ) - { - if ( aStream[nStream] ) - { - delete aStream[nStream]; - aStream[nStream] = NULL; - } - - if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER ) - { - uint32 i = 0; - do { - if(i != 0 || _bIsMp3Active) { - if(++_CurMP3Index >= nNumMP3s) _CurMP3Index = 0; - - _CurMP3Pos = 0; - - tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index); + char filename[MAX_PATH]; - if(mp3) { - mp3 = _pMP3List; - if(mp3 == NULL) { - _bIsMp3Active = false; - nFile = 0; - strcat(filename, StreamedNameTable[nFile]); + if ( nFile >= TOTAL_STREAMED_SOUNDS ) + return FALSE; - CStream* stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); - ASSERT(stream != NULL); + if ( aStream[nStream] ) + { + delete aStream[nStream]; + aStream[nStream] = NULL; + } + if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER ) + { + do + { + // Switched to MP3 player just now + if ( !_bIsMp3Active && i == 0 ) + { + if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] ) + position = 0; + tMP3Entry *e = _pMP3List; - aStream[nStream] = stream; + // Try to continue from previous song, if already started + if(!_GetMP3PosFromStreamPos(&position, &e) && !e) { + nFile = 0; + strcpy(filename, StreamedNameTable[nFile]); + + CStream* stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); - if (stream->Setup()) { - if (position != 0) - stream->SetPosMS(position); + aStream[nStream] = stream; - stream->Start(); + if (stream->Setup()) { + if (position != 0) + stream->SetPosMS(position); - return true; - } else { - delete stream; - aStream[nStream] = NULL; - } + stream->Start(); - return false; - } + return TRUE; + } else { + delete stream; + aStream[nStream] = NULL; } + return FALSE; - if (mp3->pLinkPath != NULL) - aStream[nStream] = new CStream(mp3->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); + } else { + if ( e->pLinkPath != NULL ) + aStream[nStream] = new CStream(e->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); else { strcpy(filename, _mp3DirectoryPath); - strcat(filename, mp3->aFilename); - - aStream[nStream] = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); + strcat(filename, e->aFilename); + + aStream[nStream] = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]); } - + if (aStream[nStream]->Setup()) { + if (position != 0) + aStream[nStream]->SetPosMS(position); + aStream[nStream]->Start(); - return true; + _bIsMp3Active = TRUE; + return TRUE; } else { delete aStream[nStream]; aStream[nStream] = NULL; } - - _bIsMp3Active = false; - continue; + // fall through, start playing from another song } - if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] ) - position = 0; - - tMP3Entry *e; - if ( !_GetMP3PosFromStreamPos(&position, &e) ) + } else { + if(++_CurMP3Index >= nNumMP3s) _CurMP3Index = 0; + + _CurMP3Pos = 0; + + tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index); + if ( !mp3 ) { - if ( e == NULL ) + mp3 = _pMP3List; + if ( !_pMP3List ) { nFile = 0; - strcat(filename, StreamedNameTable[nFile]); + _bIsMp3Active = 0; + strcpy(filename, StreamedNameTable[nFile]); + CStream* stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); - ASSERT(stream != NULL); aStream[nStream] = stream; @@ -1800,67 +1751,59 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) stream->Start(); - return true; + return TRUE; } else { delete stream; aStream[nStream] = NULL; } - - return false; + return FALSE; } } - - if (e->pLinkPath != NULL) - aStream[nStream] = new CStream(e->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); + if(mp3->pLinkPath != NULL) + aStream[nStream] = new CStream(mp3->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); else { strcpy(filename, _mp3DirectoryPath); - strcat(filename, e->aFilename); + strcat(filename, mp3->aFilename); aStream[nStream] = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]); } if (aStream[nStream]->Setup()) { - if (position != 0) - aStream[nStream]->SetPosMS(position); - aStream[nStream]->Start(); - - _bIsMp3Active = true; - return true; +#ifdef FIX_BUGS + _bIsMp3Active = TRUE; +#endif + return TRUE; } else { delete aStream[nStream]; aStream[nStream] = NULL; } - - _bIsMp3Active = false; - - } while(++i < nNumMP3s); - position = 0; - nFile = 0; + } + _bIsMp3Active = 0; } + while ( ++i < nNumMP3s ); + position = 0; + nFile = 0; + } + strcpy(filename, StreamedNameTable[nFile]); + + CStream *stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); - strcpy(filename, StreamedNameTable[nFile]); - - CStream *stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000); - ASSERT(stream != NULL); + aStream[nStream] = stream; + + if ( stream->Setup() ) { + if (position != 0) + stream->SetPosMS(position); - aStream[nStream] = stream; + stream->Start(); - if ( stream->Setup() ) { - if (position != 0) - stream->SetPosMS(position); - - stream->Start(); - - return true; - } else { - delete stream; - aStream[nStream] = NULL; - } + return TRUE; + } else { + delete stream; + aStream[nStream] = NULL; } - - return false; + return FALSE; } void @@ -1876,7 +1819,7 @@ cSampleManager::StopStreamedFile(uint8 nStream) aStream[nStream] = NULL; if ( nStream == 0 ) - _bIsMp3Active = false; + _bIsMp3Active = FALSE; } } @@ -1944,7 +1887,7 @@ cSampleManager::GetStreamedFileLength(uint8 nStream) return nStreamLength[nStream]; } -bool +bool8 cSampleManager::IsStreamPlaying(uint8 nStream) { ASSERT( nStream < MAX_STREAMS ); @@ -1954,10 +1897,10 @@ cSampleManager::IsStreamPlaying(uint8 nStream) if ( stream ) { if ( stream->IsPlaying() ) - return true; + return TRUE; } - return false; + return FALSE; } void @@ -1971,21 +1914,21 @@ cSampleManager::Service(void) stream->Update(); } int refCount = CChannel::channelsThatNeedService; - for ( int32 i = 0; refCount && i < MAXCHANNELS+MAX2DCHANNELS; i++ ) + for ( int32 i = 0; refCount && i < NUM_CHANNELS; i++ ) { if ( aChannel[i].Update() ) refCount--; } } -bool +bool8 cSampleManager::InitialiseSampleBanks(void) { int32 nBank = SFX_BANK_0; fpSampleDescHandle = fcaseopen(SampleBankDescFilename, "rb"); if ( fpSampleDescHandle == NULL ) - return false; + return FALSE; #ifndef OPUS_SFX fpSampleDataHandle = fcaseopen(SampleBankDataFilename, "rb"); if ( fpSampleDataHandle == NULL ) @@ -1993,7 +1936,7 @@ cSampleManager::InitialiseSampleBanks(void) fclose(fpSampleDescHandle); fpSampleDescHandle = NULL; - return false; + return FALSE; } fseek(fpSampleDataHandle, 0, SEEK_END); @@ -2025,6 +1968,6 @@ cSampleManager::InitialiseSampleBanks(void) nSampleBankSize[SFX_BANK_0] = nSampleBankDiscStartOffset[SFX_BANK_PED_COMMENTS] - nSampleBankDiscStartOffset[SFX_BANK_0]; nSampleBankSize[SFX_BANK_PED_COMMENTS] = _nSampleDataEndOffset - nSampleBankDiscStartOffset[SFX_BANK_PED_COMMENTS]; - return true; + return TRUE; } #endif diff --git a/src/buildings/Building.cpp b/src/buildings/Building.cpp index 00bbb21e..e4475ae6 100644 --- a/src/buildings/Building.cpp +++ b/src/buildings/Building.cpp @@ -4,8 +4,8 @@ #include "Streaming.h" #include "Pools.h" -void *CBuilding::operator new(size_t sz) { return CPools::GetBuildingPool()->New(); } -void CBuilding::operator delete(void *p, size_t sz) { CPools::GetBuildingPool()->Delete((CBuilding*)p); } +void *CBuilding::operator new(size_t sz) throw() { return CPools::GetBuildingPool()->New(); } +void CBuilding::operator delete(void *p, size_t sz) throw() { CPools::GetBuildingPool()->Delete((CBuilding*)p); } void CBuilding::ReplaceWithNewModel(int32 id) diff --git a/src/buildings/Building.h b/src/buildings/Building.h index 3586a8dc..94e66c89 100644 --- a/src/buildings/Building.h +++ b/src/buildings/Building.h @@ -9,8 +9,8 @@ public: m_type = ENTITY_TYPE_BUILDING; bUsesCollision = true; } - static void *operator new(size_t); - static void operator delete(void*, size_t); + static void *operator new(size_t) throw(); + static void operator delete(void*, size_t) throw(); void ReplaceWithNewModel(int32 id); diff --git a/src/buildings/Treadable.cpp b/src/buildings/Treadable.cpp index 00abbe13..d84603a6 100644 --- a/src/buildings/Treadable.cpp +++ b/src/buildings/Treadable.cpp @@ -4,5 +4,5 @@ #include "Treadable.h" #include "Pools.h" -void *CTreadable::operator new(size_t sz) { return CPools::GetTreadablePool()->New(); } -void CTreadable::operator delete(void *p, size_t sz) { CPools::GetTreadablePool()->Delete((CTreadable*)p); } +void *CTreadable::operator new(size_t sz) throw() { return CPools::GetTreadablePool()->New(); } +void CTreadable::operator delete(void *p, size_t sz) throw() { CPools::GetTreadablePool()->Delete((CTreadable*)p); } diff --git a/src/buildings/Treadable.h b/src/buildings/Treadable.h index c3160f47..9e895969 100644 --- a/src/buildings/Treadable.h +++ b/src/buildings/Treadable.h @@ -5,8 +5,8 @@ class CTreadable : public CBuilding { public: - static void *operator new(size_t); - static void operator delete(void*, size_t); + static void *operator new(size_t) throw(); + static void operator delete(void*, size_t) throw(); int16 m_nodeIndices[2][12]; // first car, then ped diff --git a/src/control/AutoPilot.cpp b/src/control/AutoPilot.cpp index 77cbd0b4..22a73179 100644 --- a/src/control/AutoPilot.cpp +++ b/src/control/AutoPilot.cpp @@ -5,6 +5,7 @@ #include "CarCtrl.h" #include "Curves.h" #include "PathFind.h" +#include "SaveBuf.h" void CAutoPilot::ModifySpeed(float speed) { @@ -88,39 +89,40 @@ void CAutoPilot::Save(uint8*& buf) void CAutoPilot::Load(uint8*& buf) { - m_nCurrentRouteNode = ReadSaveBuf<int32>(buf); - m_nNextRouteNode = ReadSaveBuf<int32>(buf); - m_nPrevRouteNode = ReadSaveBuf<int32>(buf); - m_nTimeEnteredCurve = ReadSaveBuf<int32>(buf); - m_nTimeToSpendOnCurrentCurve = ReadSaveBuf<int32>(buf); - m_nCurrentPathNodeInfo = ReadSaveBuf<uint32>(buf); - m_nNextPathNodeInfo = ReadSaveBuf<uint32>(buf); - m_nPreviousPathNodeInfo = ReadSaveBuf<uint32>(buf); - m_nAntiReverseTimer = ReadSaveBuf<uint32>(buf); - m_nTimeToStartMission = ReadSaveBuf<uint32>(buf); - m_nPreviousDirection = ReadSaveBuf<int8>(buf); - m_nCurrentDirection = ReadSaveBuf<int8>(buf); - m_nNextDirection = ReadSaveBuf<int8>(buf); - m_nCurrentLane = ReadSaveBuf<int8>(buf); - m_nNextLane = ReadSaveBuf<int8>(buf); - m_nDrivingStyle = ReadSaveBuf<uint8>(buf); - m_nCarMission = ReadSaveBuf<uint8>(buf); - m_nTempAction = ReadSaveBuf<uint8>(buf); - m_nTimeTempAction = ReadSaveBuf<uint32>(buf); - m_fMaxTrafficSpeed = ReadSaveBuf<float>(buf); - m_nCruiseSpeed = ReadSaveBuf<uint8>(buf); - uint8 flags = ReadSaveBuf<uint8>(buf); + ReadSaveBuf(&m_nCurrentRouteNode, buf); + ReadSaveBuf(&m_nNextRouteNode, buf); + ReadSaveBuf(&m_nPrevRouteNode, buf); + ReadSaveBuf(&m_nTimeEnteredCurve, buf); + ReadSaveBuf(&m_nTimeToSpendOnCurrentCurve, buf); + ReadSaveBuf(&m_nCurrentPathNodeInfo, buf); + ReadSaveBuf(&m_nNextPathNodeInfo, buf); + ReadSaveBuf(&m_nPreviousPathNodeInfo, buf); + ReadSaveBuf(&m_nAntiReverseTimer, buf); + ReadSaveBuf(&m_nTimeToStartMission, buf); + ReadSaveBuf(&m_nPreviousDirection, buf); + ReadSaveBuf(&m_nCurrentDirection, buf); + ReadSaveBuf(&m_nNextDirection, buf); + ReadSaveBuf(&m_nCurrentLane, buf); + ReadSaveBuf(&m_nNextLane, buf); + ReadSaveBuf(&m_nDrivingStyle, buf); + ReadSaveBuf(&m_nCarMission, buf); + ReadSaveBuf(&m_nTempAction, buf); + ReadSaveBuf(&m_nTimeTempAction, buf); + ReadSaveBuf(&m_fMaxTrafficSpeed, buf); + ReadSaveBuf(&m_nCruiseSpeed, buf); + uint8 flags; + ReadSaveBuf(&flags, buf); m_bSlowedDownBecauseOfCars = !!(flags & BIT(0)); m_bSlowedDownBecauseOfPeds = !!(flags & BIT(1)); m_bStayInCurrentLevel = !!(flags & BIT(2)); m_bStayInFastLane = !!(flags & BIT(3)); m_bIgnorePathfinding = !!(flags & BIT(4)); SkipSaveBuf(buf, 2); - m_vecDestinationCoors.x = ReadSaveBuf<float>(buf); - m_vecDestinationCoors.y = ReadSaveBuf<float>(buf); - m_vecDestinationCoors.z = ReadSaveBuf<float>(buf); + ReadSaveBuf(&m_vecDestinationCoors.x, buf); + ReadSaveBuf(&m_vecDestinationCoors.y, buf); + ReadSaveBuf(&m_vecDestinationCoors.z, buf); SkipSaveBuf(buf, 32); - m_nPathFindNodesCount = ReadSaveBuf<int16>(buf); + ReadSaveBuf(&m_nPathFindNodesCount, buf); SkipSaveBuf(buf, 6); } #endif
\ No newline at end of file diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 25ced498..0516e214 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -1330,8 +1330,8 @@ void CCarCtrl::WeaveForOtherCar(CEntity* pOtherEntity, CVehicle* pVehicle, float forward.NormaliseSafe(); float forwardAngle = CGeneral::GetATanOfXY(forward.x, forward.y); float angleDiff = angleBetweenVehicles - forwardAngle; - float lenProjection = ABS(pOtherCar->GetColModel()->boundingBox.max.y * sin(angleDiff)); - float widthProjection = ABS(pOtherCar->GetColModel()->boundingBox.max.x * cos(angleDiff)); + float lenProjection = ABS(pOtherCar->GetColModel()->boundingBox.max.y * Sin(angleDiff)); + float widthProjection = ABS(pOtherCar->GetColModel()->boundingBox.max.x * Cos(angleDiff)); float lengthToEvade = (2 * (lenProjection + widthProjection) + WIDTH_COEF_TO_WEAVE_SAFELY * 2 * pVehicle->GetColModel()->boundingBox.max.x) / distance; float diffToLeftAngle = LimitRadianAngle(angleBetweenVehicles - *pAngleToWeaveLeft); diffToLeftAngle = ABS(diffToLeftAngle); @@ -2718,7 +2718,7 @@ bool CCarCtrl::GenerateOneEmergencyServicesCar(uint32 mi, CVector vecPos) attempts += 1; } if (attempts >= 5) - return nil; + return false; CAutomobile* pVehicle = new CAutomobile(mi, RANDOM_VEHICLE); pVehicle->AutoPilot.m_vecDestinationCoors = vecPos; pVehicle->SetPosition(spawnPos); diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index d6e36875..3410c881 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -24,6 +24,7 @@ #include "Vehicle.h" #include "Wanted.h" #include "World.h" +#include "SaveBuf.h" #define CRUSHER_GARAGE_X1 (1135.5f) #define CRUSHER_GARAGE_Y1 (57.0f) @@ -160,7 +161,7 @@ void CGarages::Init(void) aCarsInSafeHouse3[i].Init(); hGarages = DMAudio.CreateEntity(AUDIOTYPE_GARAGE, (void*)1); if (hGarages >= 0) - DMAudio.SetEntityStatus(hGarages, true); + DMAudio.SetEntityStatus(hGarages, TRUE); AddOne( CVector(CRUSHER_GARAGE_X1, CRUSHER_GARAGE_Y1, CRUSHER_GARAGE_Z1), CVector(CRUSHER_GARAGE_X2, CRUSHER_GARAGE_Y2, CRUSHER_GARAGE_Z2), @@ -2361,22 +2362,25 @@ void CGarages::Load(uint8* buf, uint32 size) assert(size == 5484); #endif CloseHideOutGaragesBeforeSave(); - NumGarages = ReadSaveBuf<uint32>(buf); - BombsAreFree = ReadSaveBuf<uint32>(buf); - RespraysAreFree = ReadSaveBuf<uint32>(buf); - CarsCollected = ReadSaveBuf<int32>(buf); - BankVansCollected = ReadSaveBuf<int32>(buf); - PoliceCarsCollected = ReadSaveBuf<int32>(buf); + ReadSaveBuf(&NumGarages, buf); + int32 tempInt; + ReadSaveBuf(&tempInt, buf); + BombsAreFree = tempInt ? true : false; + ReadSaveBuf(&tempInt, buf); + RespraysAreFree = tempInt ? true : false; + ReadSaveBuf(&CarsCollected, buf); + ReadSaveBuf(&BankVansCollected, buf); + ReadSaveBuf(&PoliceCarsCollected, buf); for (int i = 0; i < TOTAL_COLLECTCARS_GARAGES; i++) - CarTypesCollected[i] = ReadSaveBuf<uint32>(buf); - LastTimeHelpMessage = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&CarTypesCollected[i], buf); + ReadSaveBuf(&LastTimeHelpMessage, buf); for (int i = 0; i < NUM_GARAGE_STORED_CARS; i++) { - aCarsInSafeHouse1[i] = ReadSaveBuf<CStoredCar>(buf); - aCarsInSafeHouse2[i] = ReadSaveBuf<CStoredCar>(buf); - aCarsInSafeHouse3[i] = ReadSaveBuf<CStoredCar>(buf); + ReadSaveBuf(&aCarsInSafeHouse1[i], buf); + ReadSaveBuf(&aCarsInSafeHouse2[i], buf); + ReadSaveBuf(&aCarsInSafeHouse3[i], buf); } for (int i = 0; i < NUM_GARAGES; i++) { - aGarages[i] = ReadSaveBuf<CGarage>(buf); + ReadSaveBuf(&aGarages[i], buf); aGarages[i].m_pDoor1 = nil; aGarages[i].m_pDoor2 = nil; aGarages[i].m_pTarget = nil; diff --git a/src/control/OnscreenTimer.cpp b/src/control/OnscreenTimer.cpp index d128efeb..08c68cb5 100644 --- a/src/control/OnscreenTimer.cpp +++ b/src/control/OnscreenTimer.cpp @@ -8,112 +8,111 @@ #include "Script.h" #include "OnscreenTimer.h" -void COnscreenTimer::Init() { +void +COnscreenTimer::Init() +{ m_bDisabled = false; for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { m_sEntries[i].m_nTimerOffset = 0; m_sEntries[i].m_nCounterOffset = 0; for(uint32 j = 0; j < 10; j++) { - m_sEntries[i].m_aTimerText[j] = 0; - m_sEntries[i].m_aCounterText[j] = 0; + m_sEntries[i].m_aTimerText[j] = '\0'; + m_sEntries[i].m_aCounterText[j] = '\0'; } m_sEntries[i].m_nType = COUNTER_DISPLAY_NUMBER; - m_sEntries[i].m_bTimerProcessed = 0; - m_sEntries[i].m_bCounterProcessed = 0; + m_sEntries[i].m_bTimerProcessed = false; + m_sEntries[i].m_bCounterProcessed = false; } } -void COnscreenTimer::Process() { - if(!CReplay::IsPlayingBack() && !m_bDisabled) { - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { +void +COnscreenTimer::Process() +{ + if(!CReplay::IsPlayingBack() && !m_bDisabled) + for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) m_sEntries[i].Process(); - } - } } -void COnscreenTimer::ProcessForDisplay() { +void +COnscreenTimer::ProcessForDisplay() +{ if(CHud::m_Wants_To_Draw_Hud) { m_bProcessed = false; - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { - if(m_sEntries[i].ProcessForDisplay()) { + for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) + if(m_sEntries[i].ProcessForDisplay()) m_bProcessed = true; - } - } } } -void COnscreenTimer::ClearCounter(uint32 offset) { +void +COnscreenTimer::ClearCounter(uint32 offset) +{ for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { if(offset == m_sEntries[i].m_nCounterOffset) { m_sEntries[i].m_nCounterOffset = 0; - m_sEntries[i].m_aCounterText[0] = 0; + m_sEntries[i].m_aCounterText[0] = '\0'; m_sEntries[i].m_nType = COUNTER_DISPLAY_NUMBER; - m_sEntries[i].m_bCounterProcessed = 0; + m_sEntries[i].m_bCounterProcessed = false; } } } -void COnscreenTimer::ClearClock(uint32 offset) { - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { +void +COnscreenTimer::ClearClock(uint32 offset) +{ + for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) if(offset == m_sEntries[i].m_nTimerOffset) { m_sEntries[i].m_nTimerOffset = 0; - m_sEntries[i].m_aTimerText[0] = 0; - m_sEntries[i].m_bTimerProcessed = 0; + m_sEntries[i].m_aTimerText[0] = '\0'; + m_sEntries[i].m_bTimerProcessed = false; } - } } -void COnscreenTimer::AddCounter(uint32 offset, uint16 type, char* text) { - uint32 i = 0; - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { +void +COnscreenTimer::AddCounter(uint32 offset, uint16 type, char* text) +{ + for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) if(m_sEntries[i].m_nCounterOffset == 0) { + m_sEntries[i].m_nCounterOffset = offset; + if (text) + strncpy(m_sEntries[i].m_aCounterText, text, 10); + else + m_sEntries[i].m_aCounterText[0] = '\0'; + m_sEntries[i].m_nType = type; break; } - return; - } - - m_sEntries[i].m_nCounterOffset = offset; - if(text) { - strncpy(m_sEntries[i].m_aCounterText, text, 10); - } else { - m_sEntries[i].m_aCounterText[0] = 0; - } - - m_sEntries[i].m_nType = type; } -void COnscreenTimer::AddClock(uint32 offset, char* text) { - uint32 i = 0; - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { +void +COnscreenTimer::AddClock(uint32 offset, char* text) +{ + for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) if(m_sEntries[i].m_nTimerOffset == 0) { + m_sEntries[i].m_nTimerOffset = offset; + if (text) + strncpy(m_sEntries[i].m_aTimerText, text, 10); + else + m_sEntries[i].m_aTimerText[0] = '\0'; break; } - return; - } - - m_sEntries[i].m_nTimerOffset = offset; - if(text) { - strncpy(m_sEntries[i].m_aTimerText, text, 10); - } else { - m_sEntries[i].m_aTimerText[0] = 0; - } } -void COnscreenTimerEntry::Process() { - if(m_nTimerOffset == 0) { +void +COnscreenTimerEntry::Process() +{ + if(m_nTimerOffset == 0) return; - } int32* timerPtr = CTheScripts::GetPointerToScriptVariable(m_nTimerOffset); int32 oldTime = *timerPtr; - int32 newTime = oldTime - int32(CTimer::GetTimeStepInSeconds() * 1000); + int32 newTime = oldTime - int32(CTimer::GetTimeStepInMilliseconds()); if(newTime < 0) { *timerPtr = 0; - m_bTimerProcessed = 0; + m_bTimerProcessed = false; m_nTimerOffset = 0; - m_aTimerText[0] = 0; + m_aTimerText[0] = '\0'; } else { *timerPtr = newTime; int32 oldTimeSeconds = oldTime / 1000; @@ -123,13 +122,14 @@ void COnscreenTimerEntry::Process() { } } -bool COnscreenTimerEntry::ProcessForDisplay() { +bool +COnscreenTimerEntry::ProcessForDisplay() +{ m_bTimerProcessed = false; m_bCounterProcessed = false; - if(m_nTimerOffset == 0 && m_nCounterOffset == 0) { + if(m_nTimerOffset == 0 && m_nCounterOffset == 0) return false; - } if(m_nTimerOffset != 0) { m_bTimerProcessed = true; @@ -143,13 +143,17 @@ bool COnscreenTimerEntry::ProcessForDisplay() { return true; } -void COnscreenTimerEntry::ProcessForDisplayClock() { +void +COnscreenTimerEntry::ProcessForDisplayClock() +{ uint32 time = *CTheScripts::GetPointerToScriptVariable(m_nTimerOffset); sprintf(m_bTimerBuffer, "%02d:%02d", time / 1000 / 60, time / 1000 % 60); } -void COnscreenTimerEntry::ProcessForDisplayCounter() { +void +COnscreenTimerEntry::ProcessForDisplayCounter() +{ uint32 counter = *CTheScripts::GetPointerToScriptVariable(m_nCounterOffset); sprintf(m_bCounterBuffer, "%d", counter); } diff --git a/src/control/PathFind.cpp b/src/control/PathFind.cpp index 49e43c81..c6407820 100644 --- a/src/control/PathFind.cpp +++ b/src/control/PathFind.cpp @@ -201,8 +201,8 @@ CPedPath::AddBlockade(CEntity *pEntity, CPedPathNode(*pathNodes)[40], CVector *p const float fBoundMaxY = boundingBox.max.y + 0.3f; const float fBoundMinY = boundingBox.min.y - 0.3f; const float fBoundMaxX = boundingBox.max.x + 0.3f; - const float fDistanceX = pPosition->x - pEntity->m_matrix.GetPosition().x; - const float fDistanceY = pPosition->y - pEntity->m_matrix.GetPosition().y; + const float fDistanceX = pPosition->x - pEntity->GetMatrix().GetPosition().x; + const float fDistanceY = pPosition->y - pEntity->GetMatrix().GetPosition().y; const float fBoundRadius = pEntity->GetBoundRadius(); CVector vecBoundCentre; pEntity->GetBoundCentre(vecBoundCentre); @@ -216,8 +216,8 @@ CPedPath::AddBlockade(CEntity *pEntity, CPedPathNode(*pathNodes)[40], CVector *p if (!pathNodes[x][y].bBlockade) { const float pointY = y * 0.7f + fDistanceY; CVector2D point(pointX, pointY); - if (fBoundMaxX > Abs(DotProduct2D(point, pEntity->m_matrix.GetRight()))) { - float fDotProduct = DotProduct2D(point, pEntity->m_matrix.GetForward()); + if (fBoundMaxX > Abs(DotProduct2D(point, pEntity->GetMatrix().GetRight()))) { + float fDotProduct = DotProduct2D(point, pEntity->GetMatrix().GetForward()); if (fBoundMaxY > fDotProduct && fBoundMinY < fDotProduct) pathNodes[x][y].bBlockade = true; } diff --git a/src/control/Phones.cpp b/src/control/Phones.cpp index ef7ecead..f9cb1421 100644 --- a/src/control/Phones.cpp +++ b/src/control/Phones.cpp @@ -13,6 +13,7 @@ #include "RpAnimBlend.h" #include "AnimBlendAssociation.h" #include "soundlist.h" +#include "SaveBuf.h" #ifdef FIX_BUGS #include "Replay.h" #endif @@ -212,8 +213,9 @@ void CPhoneInfo::Load(uint8 *buf, uint32 size) { INITSAVEBUF - int max = ReadSaveBuf<int32>(buf); - int scriptPhonesMax = ReadSaveBuf<int32>(buf); + int32 max, scriptPhonesMax; + ReadSaveBuf(&max, buf); + ReadSaveBuf(&scriptPhonesMax, buf); #ifdef PEDS_REPORT_CRIMES_ON_PHONE m_nMax = Min(NUMPHONES, max); @@ -223,7 +225,8 @@ INITSAVEBUF // We can do it without touching saves. We'll only load script phones, others are already loaded in Initialise for (int i = 0; i < 50; i++) { - CPhone phoneToLoad = ReadSaveBuf<CPhone>(buf); + CPhone phoneToLoad; + ReadSaveBuf(&phoneToLoad, buf); if (ignoreOtherPhones) continue; @@ -249,7 +252,7 @@ INITSAVEBUF m_nScriptPhonesMax = scriptPhonesMax; for (int i = 0; i < NUMPHONES; i++) { - m_aPhones[i] = ReadSaveBuf<CPhone>(buf); + ReadSaveBuf(&m_aPhones[i], buf); // It's saved as building pool index in save file, convert it to true entity if (m_aPhones[i].m_pEntity) { m_aPhones[i].m_pEntity = CPools::GetBuildingPool()->GetSlot((uintptr)m_aPhones[i].m_pEntity - 1); diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index be9f734d..10175fba 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -23,6 +23,7 @@ #ifdef FIX_BUGS #include "Replay.h" #endif +#include "SaveBuf.h" #include "Script.h" #include "Shadows.h" #include "SpecialFX.h" @@ -689,8 +690,7 @@ CPickups::DoPickUpEffects(CEntity *entity) entity->bDoNotRender = CTheScripts::IsPlayerOnAMission() || CDarkel::FrenzyOnGoing() || !CGame::nastyGame; if (!entity->bDoNotRender) { - float s = Sin((float)((CTimer::GetTimeInMilliseconds() + (uintptr)entity) & 0x7FF) * DEGTORAD(360.0f / 0x800)); - float modifiedSin = 0.3f * (s + 1.0f); + float modifiedSin = 0.3f * (Sin((float)((CTimer::GetTimeInMilliseconds() + (uintptr)entity) & 0x7FF) * DEGTORAD(360.0f / 0x800)) + 1.0f); int16 colorId; @@ -749,7 +749,20 @@ CPickups::DoPickUpEffects(CEntity *entity) } } - entity->GetMatrix().SetRotateZOnlyScaled((float)(CTimer::GetTimeInMilliseconds() & 0x7FF) * DEGTORAD(360.0f / 0x800), aWeaponScale[colorId]); + float angle = (float)(CTimer::GetTimeInMilliseconds() & 0x7FF) * DEGTORAD(360.0f / 0x800); + float c = Cos(angle) * aWeaponScale[colorId]; + float s = Sin(angle) * aWeaponScale[colorId]; + + // we know from SA they were setting each field manually like this + entity->GetMatrix().rx = c; + entity->GetMatrix().ry = s; + entity->GetMatrix().rz = 0.0f; + entity->GetMatrix().fx = -s; + entity->GetMatrix().fy = c; + entity->GetMatrix().fz = 0.0f; + entity->GetMatrix().ux = 0.0f; + entity->GetMatrix().uy = 0.0f; + entity->GetMatrix().uz = aWeaponScale[colorId]; } } @@ -987,18 +1000,18 @@ CPickups::Load(uint8 *buf, uint32 size) INITSAVEBUF for (int32 i = 0; i < NUMPICKUPS; i++) { - aPickUps[i] = ReadSaveBuf<CPickup>(buf); + ReadSaveBuf(&aPickUps[i], buf); if (aPickUps[i].m_eType != PICKUP_NONE && aPickUps[i].m_pObject != nil) aPickUps[i].m_pObject = CPools::GetObjectPool()->GetSlot((uintptr)aPickUps[i].m_pObject - 1); } - CollectedPickUpIndex = ReadSaveBuf<uint16>(buf); - ReadSaveBuf<uint16>(buf); + ReadSaveBuf(&CollectedPickUpIndex, buf); + SkipSaveBuf(buf, 2); NumMessages = 0; for (uint16 i = 0; i < NUMCOLLECTEDPICKUPS; i++) - aPickUpsCollected[i] = ReadSaveBuf<int32>(buf); + ReadSaveBuf(&aPickUpsCollected[i], buf); VALIDATESAVEBUF(size) } diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index d8b15385..b9b5530c 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -404,8 +404,8 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* main = RpAnimBlendClumpGetMainAssociation((RpClump*)ped->m_rwObject, &second, &blend_amount); if (main){ state->animId = main->animId; - state->time = 255.0f / 4.0f * clamp(main->currentTime, 0.0f, 4.0f); - state->speed = 255.0f / 3.0f * clamp(main->speed, 0.0f, 3.0f); + state->time = 255.0f / 4.0f * Clamp(main->currentTime, 0.0f, 4.0f); + state->speed = 255.0f / 3.0f * Clamp(main->speed, 0.0f, 3.0f); }else{ state->animId = 3; state->time = 0; @@ -413,9 +413,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) } if (second) { state->secAnimId = second->animId; - state->secTime = 255.0f / 4.0f * clamp(second->currentTime, 0.0f, 4.0f); - state->secSpeed = 255.0f / 3.0f * clamp(second->speed, 0.0f, 3.0f); - state->blendAmount = 255.0f / 2.0f * clamp(blend_amount, 0.0f, 2.0f); + state->secTime = 255.0f / 4.0f * Clamp(second->currentTime, 0.0f, 4.0f); + state->secSpeed = 255.0f / 3.0f * Clamp(second->speed, 0.0f, 3.0f); + state->blendAmount = 255.0f / 2.0f * Clamp(blend_amount, 0.0f, 2.0f); }else{ state->secAnimId = 0; state->secTime = 0; @@ -425,9 +425,9 @@ void CReplay::StorePedAnimation(CPed *ped, CStoredAnimationState *state) CAnimBlendAssociation* partial = RpAnimBlendClumpGetMainPartialAssociation((RpClump*)ped->m_rwObject); if (partial) { state->partAnimId = partial->animId; - state->partAnimTime = 255.0f / 4.0f * clamp(partial->currentTime, 0.0f, 4.0f); - state->partAnimSpeed = 255.0f / 3.0f * clamp(partial->speed, 0.0f, 3.0f); - state->partBlendAmount = 255.0f / 2.0f * clamp(partial->blendAmount, 0.0f, 2.0f); + state->partAnimTime = 255.0f / 4.0f * Clamp(partial->currentTime, 0.0f, 4.0f); + state->partAnimSpeed = 255.0f / 3.0f * Clamp(partial->speed, 0.0f, 3.0f); + state->partBlendAmount = 255.0f / 2.0f * Clamp(partial->blendAmount, 0.0f, 2.0f); }else{ state->partAnimId = 0; state->partAnimTime = 0; @@ -442,11 +442,11 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc){ state->aAnimId[i] = assoc->animId; - state->aCurTime[i] = 255.0f / 4.0f * clamp(assoc->currentTime, 0.0f, 4.0f); - state->aSpeed[i] = 255.0f / 3.0f * clamp(assoc->speed, 0.0f, 3.0f); - state->aBlendAmount[i] = 255.0f / 2.0f * clamp(assoc->blendAmount, 0.0f, 2.0f); + state->aCurTime[i] = 255.0f / 4.0f * Clamp(assoc->currentTime, 0.0f, 4.0f); + state->aSpeed[i] = 255.0f / 3.0f * Clamp(assoc->speed, 0.0f, 3.0f); + state->aBlendAmount[i] = 255.0f / 2.0f * Clamp(assoc->blendAmount, 0.0f, 2.0f); #ifdef FIX_REPLAY_BUGS - state->aBlendDelta[i] = 127.0f / 32.0f * clamp(assoc->blendDelta, -16.0f, 16.0f); + state->aBlendDelta[i] = 127.0f / 32.0f * Clamp(assoc->blendDelta, -16.0f, 16.0f); #endif state->aFlags[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { @@ -468,11 +468,11 @@ void CReplay::StoreDetailedPedAnimation(CPed *ped, CStoredDetailedAnimationState CAnimBlendAssociation* assoc = RpAnimBlendClumpGetMainPartialAssociation_N((RpClump*)ped->m_rwObject, i); if (assoc) { state->aAnimId2[i] = assoc->animId; - state->aCurTime2[i] = 255.0f / 4.0f * clamp(assoc->currentTime, 0.0f, 4.0f); - state->aSpeed2[i] = 255.0f / 3.0f * clamp(assoc->speed, 0.0f, 3.0f); - state->aBlendAmount2[i] = 255.0f / 2.0f * clamp(assoc->blendAmount, 0.0f, 2.0f); + state->aCurTime2[i] = 255.0f / 4.0f * Clamp(assoc->currentTime, 0.0f, 4.0f); + state->aSpeed2[i] = 255.0f / 3.0f * Clamp(assoc->speed, 0.0f, 3.0f); + state->aBlendAmount2[i] = 255.0f / 2.0f * Clamp(assoc->blendAmount, 0.0f, 2.0f); #ifdef FIX_REPLAY_BUGS - state->aBlendDelta2[i] = 127.0f / 16.0f * clamp(assoc->blendDelta, -16.0f, 16.0f); + state->aBlendDelta2[i] = 127.0f / 16.0f * Clamp(assoc->blendDelta, -16.0f, 16.0f); #endif state->aFlags2[i] = assoc->flags; if (assoc->callbackType == CAnimBlendAssociation::CB_FINISH || assoc->callbackType == CAnimBlendAssociation::CB_DELETE) { @@ -1232,7 +1232,7 @@ void CReplay::RestoreStuffFromMem(void) ped->SetModelIndex(mi); ped->m_pVehicleAnim = nil; ped->m_audioEntityId = DMAudio.CreateEntity(AUDIOTYPE_PHYSICAL, ped); - DMAudio.SetEntityStatus(ped->m_audioEntityId, true); + DMAudio.SetEntityStatus(ped->m_audioEntityId, TRUE); CPopulation::UpdatePedCount((ePedType)ped->m_nPedType, false); if (ped->m_wepModelID >= 0) ped->AddWeaponModel(ped->m_wepModelID); @@ -1270,7 +1270,7 @@ void CReplay::RestoreStuffFromMem(void) car->SetDoorDamage(CAR_DOOR_RR, DOOR_REAR_RIGHT, true); } vehicle->m_audioEntityId = DMAudio.CreateEntity(AUDIOTYPE_PHYSICAL, vehicle); - DMAudio.SetEntityStatus(vehicle->m_audioEntityId, true); + DMAudio.SetEntityStatus(vehicle->m_audioEntityId, TRUE); CCarCtrl::UpdateCarCount(vehicle, false); if ((mi == MI_AIRTRAIN || mi == MI_DEADDODO) && vehicle->m_rwObject){ CVehicleModelInfo* info = (CVehicleModelInfo*)CModelInfo::GetModelInfo(mi); diff --git a/src/control/Restart.cpp b/src/control/Restart.cpp index 4ca18c3b..2f5e3d45 100644 --- a/src/control/Restart.cpp +++ b/src/control/Restart.cpp @@ -1,6 +1,7 @@ #include "common.h" #include "Restart.h" +#include "SaveBuf.h" #include "Zones.h" #include "PathFind.h" @@ -173,29 +174,28 @@ INITSAVEBUF CheckSaveHeader(buf, 'R','S','T','\0', size - SAVE_HEADER_SIZE); for (int i = 0; i < NUM_RESTART_POINTS; i++) { - HospitalRestartPoints[i] = ReadSaveBuf<CVector>(buf); - HospitalRestartHeadings[i] = ReadSaveBuf<float>(buf); + ReadSaveBuf(&HospitalRestartPoints[i], buf); + ReadSaveBuf(&HospitalRestartHeadings[i], buf); } for (int i = 0; i < NUM_RESTART_POINTS; i++) { - PoliceRestartPoints[i] = ReadSaveBuf<CVector>(buf); - PoliceRestartHeadings[i] = ReadSaveBuf<float>(buf); + ReadSaveBuf(&PoliceRestartPoints[i], buf); + ReadSaveBuf(&PoliceRestartHeadings[i], buf); } - NumberOfHospitalRestarts = ReadSaveBuf<uint16>(buf); - NumberOfPoliceRestarts = ReadSaveBuf<uint16>(buf); - bOverrideRestart = ReadSaveBuf<bool>(buf); + ReadSaveBuf(&NumberOfHospitalRestarts, buf); + ReadSaveBuf(&NumberOfPoliceRestarts, buf); + ReadSaveBuf(&bOverrideRestart, buf); // skip something unused - ReadSaveBuf<uint8>(buf); - ReadSaveBuf<uint16>(buf); - - OverridePosition = ReadSaveBuf<CVector>(buf); - OverrideHeading = ReadSaveBuf<float>(buf); - bFadeInAfterNextDeath = ReadSaveBuf<bool>(buf); - bFadeInAfterNextArrest = ReadSaveBuf<bool>(buf); - OverrideHospitalLevel = ReadSaveBuf<uint8>(buf); - OverridePoliceStationLevel = ReadSaveBuf<uint8>(buf); + SkipSaveBuf(buf, 3); + + ReadSaveBuf(&OverridePosition, buf); + ReadSaveBuf(&OverrideHeading, buf); + ReadSaveBuf(&bFadeInAfterNextDeath, buf); + ReadSaveBuf(&bFadeInAfterNextArrest, buf); + ReadSaveBuf(&OverrideHospitalLevel, buf); + ReadSaveBuf(&OverridePoliceStationLevel, buf); VALIDATESAVEBUF(size); } diff --git a/src/control/RoadBlocks.cpp b/src/control/RoadBlocks.cpp index 3ec34a57..c22bebaa 100644 --- a/src/control/RoadBlocks.cpp +++ b/src/control/RoadBlocks.cpp @@ -55,7 +55,7 @@ CRoadBlocks::GenerateRoadBlockCopsForCar(CVehicle* pVehicle, int32 roadBlockType float fRadius = pVehicle->GetBoundRadius() / pPoliceColModel->boundingSphere.radius; for (int32 i = 0; i < 2; i++) { const int32 roadBlockIndex = i + 2 * roadBlockType; - CVector posForZ = pVehicle->m_matrix * (fRadius * vecRoadBlockOffets[roadBlockIndex]); + CVector posForZ = pVehicle->GetMatrix() * (fRadius * vecRoadBlockOffets[roadBlockIndex]); int32 modelInfoId = MI_COP; eCopType copType = COP_STREET; switch (pVehicle->GetModelIndex()) @@ -80,9 +80,7 @@ CRoadBlocks::GenerateRoadBlockCopsForCar(CVehicle* pVehicle, int32 roadBlockType pCopPed->SetCurrentWeapon(WEAPONTYPE_COLT45); CPedPlacement::FindZCoorForPed(&posForZ); pCopPed->SetPosition(posForZ); - CVector vecSavedPos = pCopPed->GetPosition(); - pCopPed->m_matrix.SetRotate(0.0f, 0.0f, -HALFPI); - pCopPed->m_matrix.GetPosition() += vecSavedPos; + pCopPed->SetOrientation(0.0f, 0.0f, -HALFPI); pCopPed->m_bIsDisabledCop = true; pCopPed->SetIdle(); pCopPed->bKindaStayInSamePlace = true; @@ -153,7 +151,7 @@ CRoadBlocks::GenerateRoadBlocks(void) offsetMatrix.GetPosition() = CVector(0.0f, i * fModelRadius - fOffset, 0.6f); else offsetMatrix.GetPosition() = CVector(i * fModelRadius - fOffset, 0.0f, 0.6f); - CMatrix vehicleMatrix = mapObject->m_matrix * offsetMatrix; + CMatrix vehicleMatrix = mapObject->GetMatrix() * offsetMatrix; float fModelRadius = CModelInfo::GetModelInfo(vehicleId)->GetColModel()->boundingSphere.radius - 0.25f; int16 colliding = 0; CWorld::FindObjectsKindaColliding(vehicleMatrix.GetPosition(), fModelRadius, 0, &colliding, 2, nil, false, true, true, false, false); @@ -162,10 +160,10 @@ CRoadBlocks::GenerateRoadBlocks(void) pVehicle->SetStatus(STATUS_ABANDONED); // pVehicle->GetHeightAboveRoad(); // called but return value is ignored? vehicleMatrix.GetPosition().z += fModelRadius - 0.6f; - pVehicle->m_matrix = vehicleMatrix; + pVehicle->SetMatrix(vehicleMatrix); pVehicle->PlaceOnRoadProperly(); pVehicle->SetIsStatic(false); - pVehicle->m_matrix.UpdateRW(); + pVehicle->GetMatrix().UpdateRW(); pVehicle->m_nDoorLock = CARLOCK_UNLOCKED; CCarCtrl::JoinCarWithRoadSystem(pVehicle); pVehicle->bIsLocked = false; diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 5598f3c9..e06acdc3 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1769,20 +1769,16 @@ void CRunningScript::Init() #ifdef USE_DEBUG_SCRIPT_LOADER int scriptToLoad = 0; -#ifdef _WIN32 -#include <Windows.h> -#endif int open_script() { // glfwGetKey doesn't work because of CGame::Initialise is blocking -#ifdef _WIN32 - if (GetAsyncKeyState('G') & 0x8000) + CPad::UpdatePads(); + if (CPad::GetPad(0)->GetChar('G')) scriptToLoad = 0; - if (GetAsyncKeyState('R') & 0x8000) + if (CPad::GetPad(0)->GetChar('R')) scriptToLoad = 1; - if (GetAsyncKeyState('D') & 0x8000) + if (CPad::GetPad(0)->GetChar('D')) scriptToLoad = 2; -#endif switch (scriptToLoad) { case 0: return CFileMgr::OpenFile("main.scm", "rb"); case 1: return CFileMgr::OpenFile("main_freeroam.scm", "rb"); diff --git a/src/control/Script2.cpp b/src/control/Script2.cpp index 5c953011..d3ab2af7 100644 --- a/src/control/Script2.cpp +++ b/src/control/Script2.cpp @@ -437,8 +437,8 @@ int8 CRunningScript::ProcessCommands300To399(int32 command) float length = *(float*)&ScriptParams[5]; float x, y; if (angle != 0.0f){ - y = cos(angle) * length; - x = sin(angle) * length; + y = Cos(angle) * length; + x = Sin(angle) * length; }else{ y = length; x = 0.0f; diff --git a/src/control/Script4.cpp b/src/control/Script4.cpp index 93956ea2..4e798be3 100644 --- a/src/control/Script4.cpp +++ b/src/control/Script4.cpp @@ -735,7 +735,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) CollectParameters(&m_nIp, 2); CPlayerPed* pPlayerPed = CWorld::Players[ScriptParams[0]].m_pPed; script_assert(pPlayerPed); - pPlayerPed->m_fArmour = clamp(pPlayerPed->m_fArmour + ScriptParams[1], 0.0f, 100.0f); + pPlayerPed->m_fArmour = Clamp(pPlayerPed->m_fArmour + ScriptParams[1], 0.0f, 100.0f); return 0; } case COMMAND_ADD_ARMOUR_TO_CHAR: @@ -743,7 +743,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) CollectParameters(&m_nIp, 2); CPed* pPed = CPools::GetPedPool()->GetAt(ScriptParams[0]); script_assert(pPed); - pPed->m_fArmour = clamp(pPed->m_fArmour + ScriptParams[1], 0.0f, 100.0f); + pPed->m_fArmour = Clamp(pPed->m_fArmour + ScriptParams[1], 0.0f, 100.0f); return 0; } case COMMAND_OPEN_GARAGE: @@ -1327,7 +1327,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command) { CollectParameters(&m_nIp, 1); DMAudio.ChangeMusicMode(MUSICMODE_FRONTEND); - DMAudio.PlayFrontEndTrack(ScriptParams[0] + STREAMED_SOUND_MISSION_COMPLETED - 1, 0); + DMAudio.PlayFrontEndTrack(ScriptParams[0] + STREAMED_SOUND_MISSION_COMPLETED - 1, FALSE); return 0; } case COMMAND_CLEAR_AREA: diff --git a/src/control/Script5.cpp b/src/control/Script5.cpp index 464a77d8..a9aec18e 100644 --- a/src/control/Script5.cpp +++ b/src/control/Script5.cpp @@ -12,6 +12,7 @@ #include "Pools.h" #include "Population.h" #include "RpAnimBlend.h" +#include "SaveBuf.h" #include "Shadows.h" #include "SpecialFX.h" #include "World.h" @@ -948,10 +949,10 @@ void CRunningScript::PlayerInAngledAreaCheckCommand(int32 command, uint32* pIp) initAngle -= TWOPI; // it looks like the idea is to use a rectangle using the diagonal of the rectangle as // the side of new rectangle, with "length" being the length of second side - float rotatedSupX = supX + side2length * sin(initAngle); - float rotatedSupY = supY - side2length * cos(initAngle); - float rotatedInfX = infX + side2length * sin(initAngle); - float rotatedInfY = infY - side2length * cos(initAngle); + float rotatedSupX = supX + side2length * Sin(initAngle); + float rotatedSupY = supY - side2length * Cos(initAngle); + float rotatedInfX = infX + side2length * Sin(initAngle); + float rotatedInfY = infY - side2length * Cos(initAngle); float side1X = supX - infX; float side1Y = supY - infY; float side1Length = CVector2D(side1X, side1Y).Magnitude(); @@ -2002,21 +2003,25 @@ void CTheScripts::LoadAllScripts(uint8* buf, uint32 size) Init(); INITSAVEBUF CheckSaveHeader(buf, 'S', 'C', 'R', '\0', size - SAVE_HEADER_SIZE); - uint32 varSpace = ReadSaveBuf<uint32>(buf); + uint32 varSpace, type, handle; + uint32 tmp; + + ReadSaveBuf(&varSpace, buf); for (uint32 i = 0; i < varSpace; i++) - ScriptSpace[i] = ReadSaveBuf<uint8>(buf); - script_assert(ReadSaveBuf<uint32>(buf) == SCRIPT_DATA_SIZE); - OnAMissionFlag = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&ScriptSpace[i], buf); + ReadSaveBuf(&tmp, buf); + script_assert(tmp == SCRIPT_DATA_SIZE); + ReadSaveBuf(&OnAMissionFlag, buf); for (uint32 i = 0; i < MAX_NUM_CONTACTS; i++) { - OnAMissionForContactFlag[i] = ReadSaveBuf<uint32>(buf); - BaseBriefIdForContact[i] = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&OnAMissionForContactFlag[i], buf); + ReadSaveBuf(&BaseBriefIdForContact[i], buf); } for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++) - CollectiveArray[i] = ReadSaveBuf<tCollectiveData>(buf); - NextFreeCollectiveIndex = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&CollectiveArray[i], buf); + ReadSaveBuf(&NextFreeCollectiveIndex, buf); for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) { - uint32 type = ReadSaveBuf<uint32>(buf); - uint32 handle = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&type, buf); + ReadSaveBuf(&handle, buf); switch (type) { case 0: BuildingSwapArray[i].m_pBuilding = nil; @@ -2030,14 +2035,14 @@ INITSAVEBUF default: script_assert(false); } - BuildingSwapArray[i].m_nNewModel = ReadSaveBuf<uint32>(buf); - BuildingSwapArray[i].m_nOldModel = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&BuildingSwapArray[i].m_nNewModel, buf); + ReadSaveBuf(&BuildingSwapArray[i].m_nOldModel, buf); if (BuildingSwapArray[i].m_pBuilding) BuildingSwapArray[i].m_pBuilding->ReplaceWithNewModel(BuildingSwapArray[i].m_nNewModel); } for (uint32 i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++) { - uint32 type = ReadSaveBuf<uint32>(buf); - uint32 handle = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&type, buf); + ReadSaveBuf(&handle, buf); switch (type) { case 0: InvisibilitySettingArray[i] = nil; @@ -2060,14 +2065,20 @@ INITSAVEBUF if (InvisibilitySettingArray[i]) InvisibilitySettingArray[i]->bIsVisible = false; } - script_assert(ReadSaveBuf<bool>(buf) == bUsingAMultiScriptFile); - ReadSaveBuf<uint8>(buf); - ReadSaveBuf<uint16>(buf); - script_assert(ReadSaveBuf<uint32>(buf) == MainScriptSize); - script_assert(ReadSaveBuf<uint32>(buf) == LargestMissionScriptSize); - script_assert(ReadSaveBuf<uint16>(buf) == NumberOfMissionScripts); - ReadSaveBuf<uint16>(buf); - uint32 runningScripts = ReadSaveBuf<uint32>(buf); + bool tmpBool; + ReadSaveBuf(&tmpBool, buf); + script_assert(tmpBool == bUsingAMultiScriptFile); + SkipSaveBuf(buf, 3); + ReadSaveBuf(&tmp, buf); + script_assert(tmp == MainScriptSize); + ReadSaveBuf(&tmp, buf); + script_assert(tmp == LargestMissionScriptSize); + uint16 tmp16; + ReadSaveBuf(&tmp16, buf); + script_assert(tmp16 == NumberOfMissionScripts); + SkipSaveBuf(buf, 2); + uint32 runningScripts; + ReadSaveBuf(&runningScripts, buf); for (uint32 i = 0; i < runningScripts; i++) StartNewScript(0)->Load(buf); VALIDATESAVEBUF(size) @@ -2115,35 +2126,35 @@ void CRunningScript::Load(uint8*& buf) #ifdef COMPATIBLE_SAVES SkipSaveBuf(buf, 8); for (int i = 0; i < 8; i++) - m_abScriptName[i] = ReadSaveBuf<char>(buf); - m_nIp = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&m_abScriptName[i], buf); + ReadSaveBuf(&m_nIp, buf); #ifdef CHECK_STRUCT_SIZES static_assert(MAX_STACK_DEPTH == 6, "Compatibility loss: MAX_STACK_DEPTH != 6"); #endif for (int i = 0; i < MAX_STACK_DEPTH; i++) - m_anStack[i] = ReadSaveBuf<uint32>(buf); - m_nStackPointer = ReadSaveBuf<uint16>(buf); + ReadSaveBuf(&m_anStack[i], buf); + ReadSaveBuf(&m_nStackPointer, buf); SkipSaveBuf(buf, 2); #ifdef CHECK_STRUCT_SIZES static_assert(NUM_LOCAL_VARS + NUM_TIMERS == 18, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 18"); #endif for (int i = 0; i < NUM_LOCAL_VARS + NUM_TIMERS; i++) - m_anLocalVariables[i] = ReadSaveBuf<int32>(buf); - m_bCondResult = ReadSaveBuf<bool>(buf); - m_bIsMissionScript = ReadSaveBuf<bool>(buf); - m_bSkipWakeTime = ReadSaveBuf<bool>(buf); + ReadSaveBuf(&m_anLocalVariables[i], buf); + ReadSaveBuf(&m_bCondResult, buf); + ReadSaveBuf(&m_bIsMissionScript, buf); + ReadSaveBuf(&m_bSkipWakeTime, buf); SkipSaveBuf(buf, 1); - m_nWakeTime = ReadSaveBuf<uint32>(buf); - m_nAndOrState = ReadSaveBuf<uint16>(buf); - m_bNotFlag = ReadSaveBuf<bool>(buf); - m_bDeatharrestEnabled = ReadSaveBuf<bool>(buf); - m_bDeatharrestExecuted = ReadSaveBuf<bool>(buf); - m_bMissionFlag = ReadSaveBuf<bool>(buf); + ReadSaveBuf(&m_nWakeTime, buf); + ReadSaveBuf(&m_nAndOrState, buf); + ReadSaveBuf(&m_bNotFlag, buf); + ReadSaveBuf(&m_bDeatharrestEnabled, buf); + ReadSaveBuf(&m_bDeatharrestExecuted, buf); + ReadSaveBuf(&m_bMissionFlag, buf); SkipSaveBuf(buf, 2); #else CRunningScript* n = next; CRunningScript* p = prev; - *this = ReadSaveBuf<CRunningScript>(buf); + ReadSaveBuf(this, buf); next = n; prev = p; #endif diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index e0497fe2..ecfade74 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -3482,7 +3482,7 @@ FindSplinePathPositionFloat(float *out, float *spline, uint32 time, uint32 &mark } } float a = ((float)time - (float)MS(spline[marker-4])) / (float)MS(spline[marker] - spline[marker-4]); - a = clamp(a, 0.0f, 1.0f); + a = Clamp(a, 0.0f, 1.0f); float b = 1.0f - a; *out = b*b*b * spline[marker-3] + 3.0f*a*b*b * spline[marker-1] + @@ -3520,7 +3520,7 @@ FindSplinePathPositionVector(CVector *out, float *spline, uint32 time, uint32 &m } float a = ((float)time - (float)MS(spline[marker-10])) / (float)MS(spline[marker] - spline[marker-10]); - a = clamp(a, 0.0f, 1.0f); + a = Clamp(a, 0.0f, 1.0f); float b = 1.0f - a; out->x = b*b*b * spline[marker-9] + @@ -4899,7 +4899,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, // 0.98f: CAR_FOV_FADE_MULT FOV = Pow(0.98f, CTimer::GetTimeStep()) * (FOV - DefaultFOV) + DefaultFOV; - FOV = clamp(FOV, DefaultFOV, DefaultFOV + 30.0f); + FOV = Clamp(FOV, DefaultFOV, DefaultFOV + 30.0f); } // WORKAROUND: I still don't know how looking behind works (m_bCamDirectlyInFront is unused in III, they seem to use m_bUseTransitionBeta) @@ -4933,9 +4933,9 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, AlphaSpeed = 0.0; Distance = 1000.0; - Front.x = -(cos(Beta) * cos(Alpha)); - Front.y = -(sin(Beta) * cos(Alpha)); - Front.z = sin(Alpha); + Front.x = -(Cos(Beta) * Cos(Alpha)); + Front.y = -(Sin(Beta) * Cos(Alpha)); + Front.z = Sin(Alpha); m_aTargetHistoryPosOne = TargetCoors - nextDistance * Front; @@ -5021,7 +5021,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, } } - float targetAlpha = Asin(clamp(Front.z, -1.0f, 1.0f)) - zoomModeAlphaOffset; + float targetAlpha = Asin(Clamp(Front.z, -1.0f, 1.0f)) - zoomModeAlphaOffset; if (targetAlpha <= maxAlphaAllowed) { if (targetAlpha < -CARCAM_SET[camSetArrPos][14]) targetAlpha = -CARCAM_SET[camSetArrPos][14]; @@ -5210,9 +5210,9 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, lastBeta = Beta; - Front.x = -(cos(Beta) * cos(Alpha)); - Front.y = -(sin(Beta) * cos(Alpha)); - Front.z = sin(Alpha); + Front.x = -(Cos(Beta) * Cos(Alpha)); + Front.y = -(Sin(Beta) * Cos(Alpha)); + Front.z = Sin(Alpha); GetVectorsReadyForRW(); TheCamera.m_bCamDirectlyBehind = false; TheCamera.m_bCamDirectlyInFront = false; @@ -5222,9 +5222,9 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, m_cvecTargetCoorsForFudgeInter = TargetCoors; m_aTargetHistoryPosThree = m_aTargetHistoryPosOne; float nextAlpha = alphaWithSpeedAccounted + zoomModeAlphaOffset; - float nextFrontX = -(cos(Beta) * cos(nextAlpha)); - float nextFrontY = -(sin(Beta) * cos(nextAlpha)); - float nextFrontZ = sin(nextAlpha); + float nextFrontX = -(Cos(Beta) * Cos(nextAlpha)); + float nextFrontY = -(Sin(Beta) * Cos(nextAlpha)); + float nextFrontZ = Sin(nextAlpha); m_aTargetHistoryPosOne.x = TargetCoors.x - nextFrontX * nextDistance; m_aTargetHistoryPosOne.y = TargetCoors.y - nextFrontY * nextDistance; diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 2ce4e754..f3b41655 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -213,7 +213,7 @@ CCamera::Init(void) m_iModeToGoTo = CCam::MODE_FOLLOWPED; m_bJust_Switched = false; m_bUseTransitionBeta = false; - m_matrix.SetScale(1.0f); + GetMatrix().SetScale(1.0f); m_bTargetJustBeenOnTrain = false; m_bInitialNoNodeStaticsSet = false; m_uiLongestTimeInMill = 5000; @@ -661,7 +661,7 @@ CCamera::Process(void) // Process Shake float shakeStrength = m_fCamShakeForce - 0.28f*(CTimer::GetTimeInMilliseconds()-m_uiCamShakeStart)/1000.0f; - shakeStrength = clamp(shakeStrength, 0.0f, 2.0f); + shakeStrength = Clamp(shakeStrength, 0.0f, 2.0f); int shakeRand = CGeneral::GetRandomNumber(); float shakeOffset = shakeStrength*0.1f; GetMatrix().GetPosition().x += shakeOffset * ((shakeRand & 0xF) - 7); @@ -1877,7 +1877,7 @@ CCamera::CamShake(float strength, float x, float y, float z) float curForce = mult*(m_fCamShakeForce - (CTimer::GetTimeInMilliseconds() - m_uiCamShakeStart)/1000.0f); strength = mult*strength; - if(clamp(curForce, 0.0f, 2.0f) < strength){ + if(Clamp(curForce, 0.0f, 2.0f) < strength){ m_fCamShakeForce = strength; m_uiCamShakeStart = CTimer::GetTimeInMilliseconds(); } @@ -1888,7 +1888,7 @@ void CamShakeNoPos(CCamera *cam, float strength) { float curForce = cam->m_fCamShakeForce - (CTimer::GetTimeInMilliseconds() - cam->m_uiCamShakeStart)/1000.0f; - if(clamp(curForce, 0.0f, 2.0f) < strength){ + if(Clamp(curForce, 0.0f, 2.0f) < strength){ cam->m_fCamShakeForce = strength; cam->m_uiCamShakeStart = CTimer::GetTimeInMilliseconds(); } @@ -3572,7 +3572,7 @@ CCamera::Find3rdPersonCamTargetVector(float dist, CVector pos, CVector &source, float CCamera::Find3rdPersonQuickAimPitch(void) { - float clampedFrontZ = clamp(Cams[ActiveCam].Front.z, -1.0f, 1.0f); + float clampedFrontZ = Clamp(Cams[ActiveCam].Front.z, -1.0f, 1.0f); float rot = Asin(clampedFrontZ); @@ -3592,7 +3592,7 @@ CCamera::SetRwCamera(RwCamera *cam) void CCamera::CalculateDerivedValues(void) { - m_cameraMatrix = Invert(m_matrix); + m_cameraMatrix = Invert(GetMatrix()); float hfov = DEGTORAD(CDraw::GetScaledFOV()/2.0f); float c = Cos(hfov); @@ -3650,7 +3650,7 @@ CCamera::IsPointVisible(const CVector ¢er, const CMatrix *mat) } bool -CCamera::IsSphereVisible(const CVector ¢er, float radius, const CMatrix *mat) +CCamera::IsSphereVisible(const CVector ¢er, float radius, Const CMatrix *mat) { #ifdef GTA_PS2 CVuVector c; @@ -3675,16 +3675,18 @@ CCamera::IsSphereVisible(const CVector ¢er, float radius, const CMatrix *mat bool CCamera::IsSphereVisible(const CVector ¢er, float radius) { - CMatrix mat = m_cameraMatrix; +#if GTA_VERSION < GTA3_PC_10 // not sure this condition is the right one + // Maybe this was a copy of the other function with m_cameraMatrix + return IsSphereVisible(center, radius, &m_cameraMatrix); +#else + // ...and on PC they decided to call the other one with a default matrix. + CMatrix mat(GetCameraMatrix()); // this matrix construction is stupid and gone in VC return IsSphereVisible(center, radius, &mat); +#endif } bool -#ifdef GTA_PS2 -CCamera::IsBoxVisible(CVuVector *box, const CMatrix *mat) -#else -CCamera::IsBoxVisible(CVector *box, const CMatrix *mat) -#endif +CCamera::IsBoxVisible(CVUVECTOR *box, const CMatrix *mat) { int i; int frustumTests[6] = { 0 }; diff --git a/src/core/Camera.h b/src/core/Camera.h index d7293e20..07a05cb4 100644 --- a/src/core/Camera.h +++ b/src/core/Camera.h @@ -639,13 +639,9 @@ public: CVector &GetGameCamPosition(void) { return m_vecGameCamPos; } void CalculateDerivedValues(void); bool IsPointVisible(const CVector ¢er, const CMatrix *mat); - bool IsSphereVisible(const CVector ¢er, float radius, const CMatrix *mat); + bool IsSphereVisible(const CVector ¢er, float radius, Const CMatrix *mat); bool IsSphereVisible(const CVector ¢er, float radius); -#ifdef GTA_PS2 - bool IsBoxVisible(CVuVector *box, const CMatrix *mat); -#else - bool IsBoxVisible(CVector *box, const CMatrix *mat); -#endif + bool IsBoxVisible(CVUVECTOR *box, const CMatrix *mat); }; VALIDATE_SIZE(CCamera, 0xE9D8); diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index 30fe06a0..bc9129eb 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -13,6 +13,7 @@ #include <fcntl.h> #include <sys/resource.h> #include <stdarg.h> +#include <limits.h> #ifdef __linux__ #include <sys/syscall.h> diff --git a/src/core/Crime.h b/src/core/Crime.h index 8dfae5b8..05829040 100644 --- a/src/core/Crime.h +++ b/src/core/Crime.h @@ -25,7 +25,7 @@ class CCrimeBeingQd { public: eCrimeType m_nType; - uint32 m_nId; + int32 m_nId; uint32 m_nTime; CVector m_vecPosn; bool m_bReported; diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index 22e0159c..cc2b402b 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -670,6 +670,7 @@ char *DoubleSidedNames[] = { "sbwy_tunl_cstm3", "sbwy_tunl_cstm2", "sbwy_tunl_cstm1", + "tenmnt6ad", "" }; @@ -1462,7 +1463,7 @@ CFileLoader::Load2dEffect(const char *line) &probability); effect->attractor.type = flags; #ifdef FIX_BUGS - effect->attractor.probability = clamp(probability, 0, 255); + effect->attractor.probability = Clamp(probability, 0, 255); #else effect->attractor.probability = probability; #endif diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 7d378e7f..7ff80697 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -899,29 +899,29 @@ CMenuManager::CheckSliderMovement(int value) switch (aScreens[m_nCurrScreen].m_aEntries[m_nCurrOption].m_Action) { case MENUACTION_BRIGHTNESS: m_PrefsBrightness += value * (512/16); - m_PrefsBrightness = clamp(m_PrefsBrightness, 0, 511); + m_PrefsBrightness = Clamp(m_PrefsBrightness, 0, 511); break; case MENUACTION_DRAWDIST: if(value > 0) m_PrefsLOD += ((1.8f - 0.8f) / 16.0f); else m_PrefsLOD -= ((1.8f - 0.8f) / 16.0f); - m_PrefsLOD = clamp(m_PrefsLOD, 0.8f, 1.8f); + m_PrefsLOD = Clamp(m_PrefsLOD, 0.8f, 1.8f); CRenderer::ms_lodDistScale = m_PrefsLOD; break; case MENUACTION_MUSICVOLUME: m_PrefsMusicVolume += value * (128/16); - m_PrefsMusicVolume = clamp(m_PrefsMusicVolume, 0, 127); + m_PrefsMusicVolume = Clamp(m_PrefsMusicVolume, 0, 127); DMAudio.SetMusicMasterVolume(m_PrefsMusicVolume); break; case MENUACTION_SFXVOLUME: m_PrefsSfxVolume += value * (128/16); - m_PrefsSfxVolume = clamp(m_PrefsSfxVolume, 0, 127); + m_PrefsSfxVolume = Clamp(m_PrefsSfxVolume, 0, 127); DMAudio.SetEffectsMasterVolume(m_PrefsSfxVolume); break; case MENUACTION_MOUSESENS: TheCamera.m_fMouseAccelHorzntl += value * 1.0f/200.0f/15.0f; // ??? - TheCamera.m_fMouseAccelHorzntl = clamp(TheCamera.m_fMouseAccelHorzntl, 1.0f/3200.0f, 1.0f/200.0f); + TheCamera.m_fMouseAccelHorzntl = Clamp(TheCamera.m_fMouseAccelHorzntl, 1.0f/3200.0f, 1.0f/200.0f); #ifdef FIX_BUGS TheCamera.m_fMouseAccelVertical = TheCamera.m_fMouseAccelHorzntl + 0.0005f; #else @@ -950,12 +950,7 @@ CMenuManager::DisplayHelperText() m_nHelperTextAlpha -= 2; } #else - static float fadeAlpha = 0.0f; // To keep it precisely - if (m_nHelperTextAlpha >= 255 && fadeAlpha < 250) fadeAlpha = m_nHelperTextAlpha; - - // -2 per every 33 ms (1000.f/30.f - original frame limiter fps) - fadeAlpha -= (frameTime / 33.0f) * 2.0f; - m_nHelperTextAlpha = fadeAlpha; + m_nHelperTextAlpha -= 2 * CTimer::GetLogicalFramesPassed(); #endif if (m_nHelperTextAlpha < 1) ResetHelperText(); @@ -2686,11 +2681,7 @@ CMenuManager::DrawFrontEndNormal() static float fadeAlpha = 0.0f; if (m_nMenuFadeAlpha < 255) { - if (m_nMenuFadeAlpha == 0 && fadeAlpha > 1.0f) fadeAlpha = 0.0f; - - // +20 per every 33 ms (1000.f/30.f - original frame limiter fps) - fadeAlpha += (frameTime) * 20.f / 33.f; - m_nMenuFadeAlpha = fadeAlpha; + m_nMenuFadeAlpha += 20 * CTimer::GetLogicalFramesPassed(); } else { // TODO: what is this? waiting mouse? if(field_518 == 4){ @@ -2950,12 +2941,7 @@ CMenuManager::DrawFrontEndNormal() // Famous transparent menu bug #ifdef FIX_BUGS - static float fadeAlpha = 0.0f; - if (m_nMenuFadeAlpha == 0 && fadeAlpha > 1.0f) fadeAlpha = 0.0f; - - // +20 per every 33 ms (1000.f/30.f - original frame limiter fps) - fadeAlpha += (frameTime) * 20.f / 33.f; - m_nMenuFadeAlpha = fadeAlpha; + m_nMenuFadeAlpha += 20 * CTimer::GetLogicalFramesPassed(); #else static uint32 LastFade = 0; @@ -2986,40 +2972,11 @@ CMenuManager::DrawFrontEndNormal() #ifdef RED_DELETE_BACKGROUND if (m_nCurrScreen == MENUPAGE_CHOOSE_DELETE_SLOT || m_nCurrScreen == MENUPAGE_DELETE_SLOT_CONFIRM) { - CSprite2d::Draw2DPolygon(SCREEN_STRETCH_X(18.0f), MENU_Y(8.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(20.0f), MENU_Y(8.0f), - SCREEN_STRETCH_X(12.0f), MENU_Y(11.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(14.0f), MENU_Y(11.0f), - CRGBA(150, 0, 0, 140)); - - CSprite2d::Draw2DPolygon(SCREEN_STRETCH_X(12.0f), MENU_Y(11.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(14.0f), MENU_Y(11.0f), - SCREEN_STRETCH_X(10.0f), MENU_Y(16.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(12.0f), MENU_Y(16.0f), - CRGBA(150, 0, 0, 140)); - - CSprite2d::Draw2DPolygon(SCREEN_STRETCH_X(10.0f), MENU_Y(16.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(12.0f), MENU_Y(16.0f), - SCREEN_STRETCH_X(10.0f), SCREEN_SCALE_Y(431.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(12.0f), SCREEN_SCALE_Y(431.0f), - CRGBA(150, 0, 0, 140)); - - CSprite2d::Draw2DPolygon(SCREEN_STRETCH_X(10.0f), SCREEN_SCALE_Y(431.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(12.0f), SCREEN_SCALE_Y(431.0f), - SCREEN_STRETCH_X(12.0f), SCREEN_SCALE_Y(435.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(14.0f), SCREEN_SCALE_Y(435.0f), - CRGBA(150, 0, 0, 140)); - - CSprite2d::Draw2DPolygon(SCREEN_STRETCH_X(12.0f), SCREEN_SCALE_Y(435.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(14.0f), SCREEN_SCALE_Y(435.0f), - SCREEN_STRETCH_X(18.0f), SCREEN_SCALE_Y(438.0f), - SCREEN_WIDTH - SCREEN_STRETCH_X(20.0f), SCREEN_SCALE_Y(438.0f), - CRGBA(150, 0, 0, 140)); - - // yellow bar - CSprite2d::DrawRect(CRect(MENU_X(13.0f), SCREEN_STRETCH_FROM_BOTTOM(96.0f), - SCREEN_STRETCH_FROM_RIGHT(11.0f), SCREEN_STRETCH_FROM_BOTTOM(59.0f)), - CRGBA(235, 170, 50, 255)); + CSprite2d::Draw2DPolygon(0.0f, 0.0f, + SCREEN_WIDTH, 0.0f, + 0.0f, SCREEN_HEIGHT, + SCREEN_WIDTH, SCREEN_HEIGHT, + CRGBA(150, 0, 0, 80)); } #endif @@ -3542,9 +3499,15 @@ CMenuManager::InitialiseChangedLanguageSettings() { if (m_bFrontEnd_ReloadObrTxtGxt) { m_bFrontEnd_ReloadObrTxtGxt = false; +#ifdef FIX_BUGS + if (gGameState > GS_INIT_ONCE) +#endif CTimer::Stop(); TheText.Unload(); TheText.Load(); +#ifdef FIX_BUGS + if (gGameState > GS_INIT_ONCE) +#endif CTimer::Update(); CGame::frenchGame = false; CGame::germanGame = false; @@ -3661,7 +3624,9 @@ CMenuManager::LoadAllTextures() #ifdef MENU_MAP static bool menuOptionAdded = false; for (int i = 0; i < ARRAY_SIZE(MapFilenames); i++) { - if (!menuOptionAdded && RwTextureRead(MapFilenames[i][0], MapFilenames[i][1])) { + RwTexture *firstTile; + if (!menuOptionAdded && (firstTile = RwTextureRead(MapFilenames[i][0], MapFilenames[i][1]))) { + RwTextureDestroy(firstTile); FrontendOptionSetCursor(MENUPAGE_PAUSE_MENU, 2, false); FrontendOptionAddBuiltinAction("FEG_MAP", MENUACTION_CHANGEMENU, MENUPAGE_MAP, SAVESLOT_NONE); menuOptionAdded = true; @@ -3825,11 +3790,10 @@ CMenuManager::LoadSettings() #ifdef LOAD_INI_SETTINGS if (LoadINISettings()) { LoadINIControllerSettings(); - } else { - // no re3.ini, create it - SaveINISettings(); - SaveINIControllerSettings(); } + // if no re3.ini, create it, or update it with new values + SaveINISettings(); + SaveINIControllerSettings(); #endif m_PrefsVsync = m_PrefsVsyncDisp; @@ -4326,29 +4290,16 @@ CMenuManager::ProcessButtonPresses(void) #ifdef USE_DEBUG_SCRIPT_LOADER if (m_nCurrScreen == MENUPAGE_START_MENU || m_nCurrScreen == MENUPAGE_NEW_GAME || m_nCurrScreen == MENUPAGE_NEW_GAME_RELOAD) { -#ifdef RW_GL3 - if (glfwGetKey(PSGLOBAL(window), GLFW_KEY_R) == GLFW_PRESS) { + if (CPad::GetPad(0)->GetChar('R')) { scriptToLoad = 1; DoSettingsBeforeStartingAGame(); return; } - if (glfwGetKey(PSGLOBAL(window), GLFW_KEY_D) == GLFW_PRESS) { + if (CPad::GetPad(0)->GetChar('D')) { scriptToLoad = 2; DoSettingsBeforeStartingAGame(); return; } -#elif defined _WIN32 - if (GetAsyncKeyState('R') & 0x8000) { - scriptToLoad = 1; - DoSettingsBeforeStartingAGame(); - return; - } - if (GetAsyncKeyState('D') & 0x8000) { - scriptToLoad = 2; - DoSettingsBeforeStartingAGame(); - return; - } -#endif } #endif @@ -4423,7 +4374,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = m_nHoverOption - HOVEROPTION_RADIO_0; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); } else if (m_nHoverOption == HOVEROPTION_RANDOM_ITEM && aScreens[m_nCurrScreen].m_aEntries[m_nCurrOption].m_Action != MENUACTION_RESUME) { @@ -4437,7 +4388,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = HEAD_RADIO; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RADIO_1: @@ -4445,7 +4396,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = DOUBLE_CLEF; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RADIO_2: @@ -4453,7 +4404,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = JAH_RADIO; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RADIO_3: @@ -4461,7 +4412,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = RISE_FM; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RADIO_4: @@ -4469,7 +4420,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = LIPS_106; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RADIO_5: @@ -4477,7 +4428,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = GAME_FM; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RADIO_6: @@ -4485,7 +4436,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = MSX_FM; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RADIO_7: @@ -4493,7 +4444,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = FLASHBACK; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RADIO_8: @@ -4501,7 +4452,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = CHATTERBOX; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RADIO_9: @@ -4509,7 +4460,7 @@ CMenuManager::ProcessButtonPresses(void) m_PrefsRadioStation = USERTRACK; SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; case HOVEROPTION_RANDOM_ITEM: @@ -4559,7 +4510,7 @@ CMenuManager::ProcessButtonPresses(void) break; case HOVEROPTION_INCREASE_MUSICVOLUME: m_PrefsMusicVolume = m_PrefsMusicVolume + 8; - m_PrefsMusicVolume = clamp(m_PrefsMusicVolume, 0, 127); + m_PrefsMusicVolume = Clamp(m_PrefsMusicVolume, 0, 127); DMAudio.SetMusicMasterVolume(uchar)(m_PrefsMusicVolume); SaveSettings(); break; @@ -4598,7 +4549,7 @@ CMenuManager::ProcessButtonPresses(void) break; case HOVEROPTION_INCREASE_MOUSESENS: TheCamera.m_fMouseAccelHorzntl += (1.0f / 3000); - TheCamera.m_fMouseAccelHorzntl = clamp(TheCamera.m_fMouseAccelHorzntl, 1.0f / 3200, 1.0f / 200); + TheCamera.m_fMouseAccelHorzntl = Clamp(TheCamera.m_fMouseAccelHorzntl, 1.0f / 3200, 1.0f / 200); #ifdef FIX_BUGS TheCamera.m_fMouseAccelVertical = TheCamera.m_fMouseAccelHorzntl + 0.0005f; #else @@ -4608,7 +4559,7 @@ CMenuManager::ProcessButtonPresses(void) break; case HOVEROPTION_DECREASE_MOUSESENS: TheCamera.m_fMouseAccelHorzntl -= (1.0f / 3000); - TheCamera.m_fMouseAccelHorzntl = clamp(TheCamera.m_fMouseAccelHorzntl, 1.0f / 3200, 1.0f / 200); + TheCamera.m_fMouseAccelHorzntl = Clamp(TheCamera.m_fMouseAccelHorzntl, 1.0f / 3200, 1.0f / 200); #ifdef FIX_BUGS TheCamera.m_fMouseAccelVertical = TheCamera.m_fMouseAccelHorzntl + 0.0005f; #else @@ -4732,7 +4683,7 @@ CMenuManager::ProcessButtonPresses(void) curBottomBarOption = hoveredBottomBarOption; ChangeScreen(bbNames[curBottomBarOption].screenId, 0, true, false); if (bbNames[curBottomBarOption].screenId == MENUPAGE_SOUND_SETTINGS) - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); return; } else if (bottomBarActive) { if (CPad::GetPad(0)->GetEnterJustDown() || CPad::GetPad(0)->GetCrossJustDown()) { @@ -4740,7 +4691,7 @@ CMenuManager::ProcessButtonPresses(void) bottomBarActive = false; if (bbNames[curBottomBarOption].screenId == MENUPAGE_SOUND_SETTINGS) - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); return; } else if (CPad::GetPad(0)->GetLeftJustDown() || CPad::GetPad(0)->GetAnaloguePadLeft() || CPad::GetPad(0)->GetDPadLeftJustDown() @@ -4891,7 +4842,7 @@ CMenuManager::ProcessButtonPresses(void) } SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); #endif break; @@ -5101,7 +5052,7 @@ CMenuManager::ProcessButtonPresses(void) DMAudio.SetMusicMasterVolume(102); DMAudio.SetEffectsMasterVolume(m_PrefsSfxVolume); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); SaveSettings(); } else if (m_nCurrScreen == MENUPAGE_DISPLAY_SETTINGS) { m_PrefsFrameLimiter = true; @@ -5187,7 +5138,7 @@ CMenuManager::ProcessButtonPresses(void) break; case MENUACTION_LOADRADIO: ChangeScreen(MENUPAGE_SOUND_SETTINGS, 0, true, true); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("STARTED PLAYING FRONTEND AUDIO TRACK"); break; #ifdef MISSION_REPLAY @@ -5382,7 +5333,7 @@ CMenuManager::ProcessButtonPresses(void) } SaveSettings(); DMAudio.SetRadioInCar(m_PrefsRadioStation); - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; #ifdef ASPECT_RATIO_SCALE @@ -5424,14 +5375,14 @@ CMenuManager::ProcessButtonPresses(void) case MENUACTION_AUDIOHW: if (m_nPrefsAudio3DProviderIndex != -1) { m_nPrefsAudio3DProviderIndex += changeValueBy; - m_nPrefsAudio3DProviderIndex = clamp(m_nPrefsAudio3DProviderIndex, 0, DMAudio.GetNum3DProvidersAvailable() - 1); + m_nPrefsAudio3DProviderIndex = Clamp(m_nPrefsAudio3DProviderIndex, 0, DMAudio.GetNum3DProvidersAvailable() - 1); } DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_NAVIGATION, 0); break; case MENUACTION_SPEAKERCONF: if (m_nPrefsAudio3DProviderIndex != -1) { m_PrefsSpeakers -= changeValueBy; - m_PrefsSpeakers = clamp(m_PrefsSpeakers, 0, 2); + m_PrefsSpeakers = Clamp(m_PrefsSpeakers, 0, 2); DMAudio.SetSpeakerConfig(m_PrefsSpeakers); SaveSettings(); DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SETTING_CHANGE, 0); diff --git a/src/core/FrontendTriggers.h b/src/core/FrontendTriggers.h index b2bde09c..44bae54f 100644 --- a/src/core/FrontendTriggers.h +++ b/src/core/FrontendTriggers.h @@ -779,7 +779,7 @@ TriggerAudio_RadioStation(CMenuMultiChoicePicturedTriggered *widget) if ( CMenuManager::m_PrefsRadioStation != widget->GetMenuSelection() ) { CMenuManager::m_PrefsRadioStation = widget->GetMenuSelection(); - DMAudio.PlayFrontEndTrack(CMenuManager::m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(CMenuManager::m_PrefsRadioStation, TRUE); DMAudio.SetRadioInCar(CMenuManager::m_PrefsRadioStation); } } @@ -792,12 +792,12 @@ TriggerAudio_StereoMono(CMenuMultiChoiceTriggered *widget) { if (widget->GetMenuSelection() == 1) { - DMAudio.SetMonoMode(true); + DMAudio.SetMonoMode(TRUE); DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MONO, 0); } else { - DMAudio.SetMonoMode(false); + DMAudio.SetMonoMode(FALSE); DMAudio.PlayFrontEndSound(SOUND_FRONTEND_STEREO, 0); } } diff --git a/src/core/Frontend_PS2.cpp b/src/core/Frontend_PS2.cpp index 1cb944d1..1da15fbb 100644 --- a/src/core/Frontend_PS2.cpp +++ b/src/core/Frontend_PS2.cpp @@ -1388,7 +1388,7 @@ CMenuManager::DrawFrontEndNormal(void) if ((m_nStartPauseTimer - CTimer::GetTimeInMillisecondsPauseMode()) <= 1600) alpha = float(m_nStartPauseTimer - CTimer::GetTimeInMillisecondsPauseMode()) / 400.0f; - m_someAlpha = 255 - clamp(alpha, 0.0f, 1.0f) * 255.0f; + m_someAlpha = 255 - Clamp(alpha, 0.0f, 1.0f) * 255.0f; switch ( m_nSlidingDir ) { @@ -1405,7 +1405,7 @@ CMenuManager::DrawFrontEndNormal(void) float slide = float(m_nEndPauseTimer - CTimer::GetTimeInMillisecondsPauseMode()) / 800.0f; float alpha = float((int32)(m_nEndPauseTimer - CTimer::GetTimeInMillisecondsPauseMode()) + -266) / 533.0f; - m_someAlpha = clamp(alpha, 0.0f, 1.0f) * 255.0f; + m_someAlpha = Clamp(alpha, 0.0f, 1.0f) * 255.0f; switch ( m_nSlidingDir ) { @@ -2871,7 +2871,7 @@ CMenuManager::ProcessDPadCrossJustDown(void) { if ( !gMusicPlaying ) { - DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); + DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, TRUE); gMusicPlaying = true; } } diff --git a/src/core/Game.cpp b/src/core/Game.cpp index 2a6afa97..f6156a4c 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -245,10 +245,16 @@ CGame::InitialiseRenderWare(void) #ifdef LIBRW #ifdef PS2_MATFX - rw::MatFX::modulateEnvMap = true; + rw::MatFX::envMapApplyLight = true; + rw::MatFX::envMapUseMatColor = true; + rw::MatFX::envMapFlipU = true; #else - rw::MatFX::modulateEnvMap = false; + rw::MatFX::envMapApplyLight = false; + rw::MatFX::envMapUseMatColor = false; + rw::MatFX::envMapFlipU = false; #endif + rw::RGBA envcol = { 128, 128, 128, 255 }; + rw::MatFX::envMapColor = envcol; #else #ifdef PS2_MATFX ReplaceMatFxCallback(); diff --git a/src/core/General.h b/src/core/General.h index 478ef027..d4b941dd 100644 --- a/src/core/General.h +++ b/src/core/General.h @@ -56,7 +56,7 @@ public: static float LimitRadianAngle(float angle) { - float result = clamp(angle, -25.0f, 25.0f); + float result = Clamp(angle, -25.0f, 25.0f); while (result >= PI) { result -= 2 * PI; diff --git a/src/core/Placeable.h b/src/core/Placeable.h index 1d51f306..2f246bc5 100644 --- a/src/core/Placeable.h +++ b/src/core/Placeable.h @@ -2,11 +2,12 @@ class CPlaceable { +protected: + CMatrix m_matrix; + public: // disable allocation - static void *operator new(size_t); - - CMatrix m_matrix; + static void *operator new(size_t) throw(); CPlaceable(void); virtual ~CPlaceable(void); @@ -21,6 +22,7 @@ public: CVector &GetForward(void) { return m_matrix.GetForward(); } CVector &GetUp(void) { return m_matrix.GetUp(); } CMatrix &GetMatrix(void) { return m_matrix; } + void SetMatrix(CMatrix &newMatrix) { m_matrix = newMatrix; } void SetTransform(RwMatrix *m) { m_matrix = CMatrix(m, false); } void SetHeading(float angle); void SetOrientation(float x, float y, float z){ diff --git a/src/core/PlayerInfo.cpp b/src/core/PlayerInfo.cpp index bd6feeed..91bd0691 100644 --- a/src/core/PlayerInfo.cpp +++ b/src/core/PlayerInfo.cpp @@ -121,7 +121,7 @@ CPlayerInfo::Process(void) m_fRoadDensity = ThePaths.CalcRoadDensity(playerPos.x, playerPos.y); } - m_fRoadDensity = clamp(m_fRoadDensity, 0.4f, 1.45f); + m_fRoadDensity = Clamp(m_fRoadDensity, 0.4f, 1.45f); // Because vehicle enter/exit use same key binding. bool enterOrExitVeh; diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp index 39cfb1d4..5cffe9e4 100644 --- a/src/core/Pools.cpp +++ b/src/core/Pools.cpp @@ -9,6 +9,7 @@ #endif #include "Population.h" #include "ProjectileInfo.h" +#include "SaveBuf.h" #include "Streaming.h" #include "Wanted.h" #include "World.h" @@ -130,14 +131,19 @@ CPools::MakeSureSlotInObjectPoolIsEmpty(int32 slot) void CPools::LoadVehiclePool(uint8* buf, uint32 size) { INITSAVEBUF - int nNumCars = ReadSaveBuf<int>(buf); - int nNumBoats = ReadSaveBuf<int>(buf); + int nNumCars, nNumBoats; + ReadSaveBuf(&nNumCars, buf); + ReadSaveBuf(&nNumBoats, buf); for (int i = 0; i < nNumCars + nNumBoats; i++) { - uint32 type = ReadSaveBuf<uint32>(buf); - int16 model = ReadSaveBuf<int16>(buf); + uint32 type; + int16 model; + int32 slot; + + ReadSaveBuf(&type, buf); + ReadSaveBuf(&model, buf); CStreaming::RequestModel(model, STREAMFLAGS_DEPENDENCY); CStreaming::LoadAllRequestedModels(false); - int32 slot = ReadSaveBuf<int32>(buf); + ReadSaveBuf(&slot, buf); CVehicle* pVehicle; #ifdef COMPATIBLE_SAVES if (type == VEHICLE_TYPE_BOAT) diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index 4fd7f1a5..77d6cc7f 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -16,6 +16,7 @@ #include "Script.h" #include "TxdStore.h" #include "World.h" +#include "SaveBuf.h" #include "Streaming.h" #include "SpecialFX.h" @@ -142,6 +143,79 @@ void GetTextureCorners(int32 x, int32 y, CVector2D *out) out[3].y = RADAR_TILE_SIZE * (y); } +uint8 CRadar::CalculateBlipAlpha(float dist) +{ +#ifdef MENU_MAP + if (CMenuManager::bMenuMapActive) + return 255; +#endif + if (dist <= 1.0f) + return 255; + + if (dist <= 5.0f) + return (128.0f * ((dist - 1.0f) / 4.0f)) + ((1.0f - (dist - 1.0f) / 4.0f) * 255.0f); + + return 128; +} + +void CRadar::ChangeBlipBrightness(int32 i, int32 bright) +{ + int index = GetActualBlipArrayIndex(i); + if (index != -1) + ms_RadarTrace[index].m_bDim = bright != 1; +} + +void CRadar::ChangeBlipColour(int32 i, int32 color) +{ + int index = GetActualBlipArrayIndex(i); + if (index != -1) + ms_RadarTrace[index].m_nColor = color; +} + +void CRadar::ChangeBlipDisplay(int32 i, eBlipDisplay display) +{ + int index = GetActualBlipArrayIndex(i); + if (index != -1) + ms_RadarTrace[index].m_eBlipDisplay = display; +} + +void CRadar::ChangeBlipScale(int32 i, int32 scale) +{ + int index = GetActualBlipArrayIndex(i); + if (index != -1) + ms_RadarTrace[index].m_wScale = scale; +} + +void CRadar::ClearBlip(int32 i) +{ + int index = GetActualBlipArrayIndex(i); + if (index != -1) { + SetRadarMarkerState(index, false); + ms_RadarTrace[index].m_bInUse = false; +#ifndef MENU_MAP + // Ssshhh + ms_RadarTrace[index].m_eBlipType = BLIP_NONE; + ms_RadarTrace[index].m_eBlipDisplay = BLIP_DISPLAY_NEITHER; + ms_RadarTrace[index].m_eRadarSprite = RADAR_SPRITE_NONE; +#endif + } +} + +void CRadar::ClearBlipForEntity(eBlipType type, int32 id) +{ + for (int i = 0; i < NUMRADARBLIPS; i++) { + if (type == ms_RadarTrace[i].m_eBlipType && id == ms_RadarTrace[i].m_nEntityHandle) { + SetRadarMarkerState(i, false); + ms_RadarTrace[i].m_bInUse = false; + ms_RadarTrace[i].m_eBlipType = BLIP_NONE; + ms_RadarTrace[i].m_eBlipDisplay = BLIP_DISPLAY_NEITHER; + ms_RadarTrace[i].m_eRadarSprite = RADAR_SPRITE_NONE; + } + }; +} + +// Why not a proper clipping algorithm? +#ifdef THIS_IS_STUPID bool IsPointInsideRadar(const CVector2D &point) { @@ -222,79 +296,6 @@ int LineRadarBoxCollision(CVector2D &out, const CVector2D &p1, const CVector2D & return edge; } - -uint8 CRadar::CalculateBlipAlpha(float dist) -{ -#ifdef MENU_MAP - if (CMenuManager::bMenuMapActive) - return 255; -#endif - if (dist <= 1.0f) - return 255; - - if (dist <= 5.0f) - return (128.0f * ((dist - 1.0f) / 4.0f)) + ((1.0f - (dist - 1.0f) / 4.0f) * 255.0f); - - return 128; -} - -void CRadar::ChangeBlipBrightness(int32 i, int32 bright) -{ - int index = GetActualBlipArrayIndex(i); - if (index != -1) - ms_RadarTrace[index].m_bDim = bright != 1; -} - -void CRadar::ChangeBlipColour(int32 i, int32 color) -{ - int index = GetActualBlipArrayIndex(i); - if (index != -1) - ms_RadarTrace[index].m_nColor = color; -} - -void CRadar::ChangeBlipDisplay(int32 i, eBlipDisplay display) -{ - int index = GetActualBlipArrayIndex(i); - if (index != -1) - ms_RadarTrace[index].m_eBlipDisplay = display; -} - -void CRadar::ChangeBlipScale(int32 i, int32 scale) -{ - int index = GetActualBlipArrayIndex(i); - if (index != -1) - ms_RadarTrace[index].m_wScale = scale; -} - -void CRadar::ClearBlip(int32 i) -{ - int index = GetActualBlipArrayIndex(i); - if (index != -1) { - SetRadarMarkerState(index, false); - ms_RadarTrace[index].m_bInUse = false; -#ifndef MENU_MAP - // Ssshhh - ms_RadarTrace[index].m_eBlipType = BLIP_NONE; - ms_RadarTrace[index].m_eBlipDisplay = BLIP_DISPLAY_NEITHER; - ms_RadarTrace[index].m_eRadarSprite = RADAR_SPRITE_NONE; -#endif - } -} - -void CRadar::ClearBlipForEntity(eBlipType type, int32 id) -{ - for (int i = 0; i < NUMRADARBLIPS; i++) { - if (type == ms_RadarTrace[i].m_eBlipType && id == ms_RadarTrace[i].m_nEntityHandle) { - SetRadarMarkerState(i, false); - ms_RadarTrace[i].m_bInUse = false; - ms_RadarTrace[i].m_eBlipType = BLIP_NONE; - ms_RadarTrace[i].m_eBlipDisplay = BLIP_DISPLAY_NEITHER; - ms_RadarTrace[i].m_eRadarSprite = RADAR_SPRITE_NONE; - } - }; -} - -// Why not a proper clipping algorithm? int CRadar::ClipRadarPoly(CVector2D *poly, const CVector2D *rect) { CVector2D corners[4] = { @@ -373,6 +374,50 @@ int CRadar::ClipRadarPoly(CVector2D *poly, const CVector2D *rect) return n; } +#else + +int +ClipPolyPlane(const CVector2D *in, int nin, CVector2D *out, CVector *plane) +{ + int j; + int nout; + int x1, x2; + float d1, d2, t; + + nout = 0; + for(j = 0; j < nin; j++){ + x1 = j; + x2 = (j+1) % nin; + + d1 = plane->x*in[x1].x + plane->y*in[x1].y + plane->z; + d2 = plane->x*in[x2].x + plane->y*in[x2].y + plane->z; + if(d1*d2 < 0.0f){ + t = d1/(d1 - d2); + out[nout++] = in[x1]*(1.0f-t) + in[x2]*t; + } + if(d2 >= 0.0f) + out[nout++] = in[x2]; + } + return nout; +} + +int CRadar::ClipRadarPoly(CVector2D *poly, const CVector2D *rect) +{ + CVector planes[4] = { + CVector(-1.0f, 0.0f, 1.0f), + CVector( 1.0f, 0.0f, 1.0f), + CVector(0.0f, -1.0f, 1.0f), + CVector(0.0f, 1.0f, 1.0f) + }; + CVector2D tmp[8]; + int n; + if(n = ClipPolyPlane(rect, 4, tmp, &planes[0]), n == 0) return 0; + if(n = ClipPolyPlane(tmp, n, poly, &planes[1]), n == 0) return 0; + if(n = ClipPolyPlane(poly, n, tmp, &planes[2]), n == 0) return 0; + if(n = ClipPolyPlane(tmp, n, poly, &planes[3]), n == 0) return 0; + return n; +} +#endif bool CRadar::DisplayThisBlip(int32 counter) { @@ -397,7 +442,7 @@ void CRadar::Draw3dMarkers() if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) { CVector pos = entity->GetPosition(); pos.z += 1.2f * CModelInfo::GetModelInfo(entity->GetModelIndex())->GetColModel()->boundingBox.max.z + 2.5f; - C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), 1, pos, 2.5f, 0, 128, 255, 255, 1024, 0.2f, 5); + C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), MARKERTYPE_ARROW, pos, 2.5f, 0, 128, 255, 255, 1024, 0.2f, 5); } break; } @@ -411,7 +456,7 @@ void CRadar::Draw3dMarkers() if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) { CVector pos = entity->GetPosition(); pos.z += 3.0f; - C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), 1, pos, 1.5f, 0, 128, 255, 255, 1024, 0.2f, 5); + C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), MARKERTYPE_ARROW, pos, 1.5f, 0, 128, 255, 255, 1024, 0.2f, 5); } break; } @@ -421,7 +466,7 @@ void CRadar::Draw3dMarkers() if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) { CVector pos = entity->GetPosition(); pos.z += CModelInfo::GetModelInfo(entity->GetModelIndex())->GetColModel()->boundingBox.max.z + 1.0f + 1.0f; - C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), 1, pos, 1.0f, 0, 128, 255, 255, 1024, 0.2f, 5); + C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), MARKERTYPE_ARROW, pos, 1.0f, 0, 128, 255, 255, 1024, 0.2f, 5); } break; } @@ -430,7 +475,7 @@ void CRadar::Draw3dMarkers() case BLIP_CONTACT_POINT: if (!CTheScripts::IsPlayerOnAMission()) { if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) - C3dMarkers::PlaceMarkerSet(i | (ms_RadarTrace[i].m_BlipIndex << 16), 4, ms_RadarTrace[i].m_vecPos, 2.0f, 0, 128, 255, 128, 2048, 0.2f, 0); + C3dMarkers::PlaceMarkerSet(i | (ms_RadarTrace[i].m_BlipIndex << 16), MARKERTYPE_CYLINDER, ms_RadarTrace[i].m_vecPos, 2.0f, 0, 128, 255, 128, 2048, 0.2f, 0); } break; } @@ -1011,7 +1056,7 @@ INITSAVEBUF CheckSaveHeader(buf, 'R', 'D', 'R', '\0', size - SAVE_HEADER_SIZE); for (int i = 0; i < NUMRADARBLIPS; i++) - ms_RadarTrace[i] = ReadSaveBuf<sRadarTrace>(buf); + ReadSaveBuf(&ms_RadarTrace[i], buf); VALIDATESAVEBUF(size); } diff --git a/src/core/References.cpp b/src/core/References.cpp index 6b0c868c..b7782099 100644 --- a/src/core/References.cpp +++ b/src/core/References.cpp @@ -39,9 +39,7 @@ CEntity::RegisterReference(CEntity **pent) ref->pentity = pent; ref->next = m_pFirstReference; m_pFirstReference = ref; - return; } - return; } // Clear all references to this entity diff --git a/src/core/Timer.cpp b/src/core/Timer.cpp index ed5580fd..e4f5b01e 100644 --- a/src/core/Timer.cpp +++ b/src/core/Timer.cpp @@ -16,6 +16,10 @@ float CTimer::ms_fTimeStep; float CTimer::ms_fTimeStepNonClipped; bool CTimer::m_UserPause; bool CTimer::m_CodePause; +#ifdef FIX_BUGS +uint32 CTimer::m_LogicalFrameCounter; +uint32 CTimer::m_LogicalFramesPassed; +#endif uint32 _nCyclesPerMS = 1; @@ -33,10 +37,6 @@ RsTimerType suspendPcTimer; uint32 suspendDepth; -#ifdef FIX_BUGS -double frameTime; -#endif - void CTimer::Initialise(void) { debug("Initialising CTimer...\n"); @@ -49,6 +49,10 @@ void CTimer::Initialise(void) m_snTimeInMillisecondsNonClipped = 0; m_snPreviousTimeInMilliseconds = 0; m_snTimeInMilliseconds = 1; +#ifdef FIX_BUGS + m_LogicalFrameCounter = 0; + m_LogicalFramesPassed = 0; +#endif #ifdef _WIN32 LARGE_INTEGER perfFreq; @@ -79,9 +83,15 @@ void CTimer::Shutdown(void) { ; } - +#ifdef FIX_BUGS void CTimer::Update(void) { + static double frameTimeLogical = 0.0; + static double frameTimeFraction = 0.0; + static double frameTimeFractionScaled = 0.0; + double frameTime; + double dblUpdInMs; + m_snPreviousTimeInMilliseconds = m_snTimeInMilliseconds; #ifdef _WIN32 @@ -93,15 +103,93 @@ void CTimer::Update(void) int32 updInCycles = (pc.LowPart - _oldPerfCounter.LowPart); // & 0x7FFFFFFF; pointless _oldPerfCounter = pc; + + // bugfix from VC + double updInCyclesScaled = GetIsPaused() ? updInCycles : updInCycles * ms_fTimeScale; + + frameTime = updInCyclesScaled / (double)_nCyclesPerMS; + + dblUpdInMs = (double)updInCycles / (double)_nCyclesPerMS; + } + else +#endif + { + RsTimerType timer = RsTimer(); - float updInCyclesScaled = updInCycles * ms_fTimeScale; + RsTimerType updInMs = timer - oldPcTimer; + + // bugfix from VC + frameTime = GetIsPaused() ? (double)updInMs : (double)updInMs * ms_fTimeScale; + + oldPcTimer = timer; + + dblUpdInMs = (double)updInMs; + } + + // count frames as if we're running at 30 fps + m_LogicalFramesPassed = 0; + frameTimeLogical += dblUpdInMs; + while(frameTimeLogical >= 1000.0 / 30.0) { + frameTimeLogical -= 1000.0 / 30.0; + m_LogicalFramesPassed++; + } + m_LogicalFrameCounter += m_LogicalFramesPassed; + + frameTimeFraction += dblUpdInMs; + frameTimeFractionScaled += frameTime; + + m_snTimeInMillisecondsPauseMode += uint32(frameTimeFraction); + + if ( GetIsPaused() ) + ms_fTimeStep = 0.0f; + else + { + m_snTimeInMilliseconds += uint32(frameTimeFractionScaled); + m_snTimeInMillisecondsNonClipped += uint32(frameTimeFractionScaled); + ms_fTimeStep = frameTime / 1000.0f * 50.0f; + } + frameTimeFraction -= uint32(frameTimeFraction); + frameTimeFractionScaled -= uint32(frameTimeFractionScaled); + + if ( ms_fTimeStep < 0.01f && !GetIsPaused() ) + ms_fTimeStep = 0.01f; + + ms_fTimeStepNonClipped = ms_fTimeStep; + + if ( !CRecordDataForGame::IsPlayingBack() ) + { + ms_fTimeStep = Min(3.0f, ms_fTimeStep); + + if ( (m_snTimeInMilliseconds - m_snPreviousTimeInMilliseconds) > 60 ) + m_snTimeInMilliseconds = m_snPreviousTimeInMilliseconds + 60; + } + + if ( CRecordDataForChase::IsRecording() ) + { + ms_fTimeStep = 1.0f; + m_snTimeInMilliseconds = m_snPreviousTimeInMilliseconds + 16; + } + + m_FrameCounter++; +} +#else +void CTimer::Update(void) +{ + m_snPreviousTimeInMilliseconds = m_snTimeInMilliseconds; + +#ifdef _WIN32 + if ( (double)_nCyclesPerMS != 0.0 ) + { + LARGE_INTEGER pc; + QueryPerformanceCounter(&pc); - // We need that real frame time to fix transparent menu bug. -#ifndef FIX_BUGS - double -#endif - frameTime = updInCyclesScaled / (double)_nCyclesPerMS; + int32 updInCycles = (pc.LowPart - _oldPerfCounter.LowPart); // & 0x7FFFFFFF; pointless + + _oldPerfCounter = pc; + + float updInCyclesScaled = updInCycles * ms_fTimeScale; + double frameTime = updInCyclesScaled / (double)_nCyclesPerMS; m_snTimeInMillisecondsPauseMode = m_snTimeInMillisecondsPauseMode + frameTime; if ( GetIsPaused() ) @@ -120,12 +208,8 @@ void CTimer::Update(void) RsTimerType updInMs = timer - oldPcTimer; - // We need that real frame time to fix transparent menu bug. -#ifndef FIX_BUGS - double -#endif - frameTime = (double)updInMs * ms_fTimeScale; - + double frameTime = (double)updInMs * ms_fTimeScale; + oldPcTimer = timer; m_snTimeInMillisecondsPauseMode = m_snTimeInMillisecondsPauseMode + frameTime; @@ -161,6 +245,7 @@ void CTimer::Update(void) m_FrameCounter++; } +#endif void CTimer::Suspend(void) { diff --git a/src/core/Timer.h b/src/core/Timer.h index 393242dd..819bd30c 100644 --- a/src/core/Timer.h +++ b/src/core/Timer.h @@ -11,6 +11,10 @@ class CTimer static float ms_fTimeScale; static float ms_fTimeStep; static float ms_fTimeStepNonClipped; +#ifdef FIX_BUGS + static uint32 m_LogicalFrameCounter; + static uint32 m_LogicalFramesPassed; +#endif public: static bool m_UserPause; static bool m_CodePause; @@ -61,9 +65,7 @@ public: #ifdef FIX_BUGS static float GetDefaultTimeStep(void) { return 50.0f / 30.0f; } static float GetTimeStepFix(void) { return GetTimeStep() / GetDefaultTimeStep(); } + static uint32 GetLogicalFrameCounter(void) { return m_LogicalFrameCounter; } + static uint32 GetLogicalFramesPassed(void) { return m_LogicalFramesPassed; } #endif }; - -#ifdef FIX_BUGS -extern double frameTime; -#endif diff --git a/src/core/World.cpp b/src/core/World.cpp index 90d73b09..6e8314f4 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -64,7 +64,7 @@ CWorld::Initialise() void CWorld::Add(CEntity *ent) { - if(ent->IsVehicle() || ent->IsPed()) DMAudio.SetEntityStatus(((CPhysical *)ent)->m_audioEntityId, true); + if(ent->IsVehicle() || ent->IsPed()) DMAudio.SetEntityStatus(((CPhysical *)ent)->m_audioEntityId, TRUE); if(ent->bIsBIGBuilding) ms_bigBuildingsList[ent->m_level].InsertItem(ent); @@ -79,7 +79,7 @@ CWorld::Add(CEntity *ent) void CWorld::Remove(CEntity *ent) { - if(ent->IsVehicle() || ent->IsPed()) DMAudio.SetEntityStatus(((CPhysical *)ent)->m_audioEntityId, false); + if(ent->IsVehicle() || ent->IsPed()) DMAudio.SetEntityStatus(((CPhysical *)ent)->m_audioEntityId, FALSE); if(ent->bIsBIGBuilding) ms_bigBuildingsList[ent->m_level].RemoveItem(ent); @@ -1445,7 +1445,7 @@ CWorld::CallOffChaseForAreaSectorListVehicles(CPtrList &list, float x1, float y1 CColModel *pColModel = pVehicle->GetColModel(); bool bInsideSphere = false; for(int32 i = 0; i < pColModel->numSpheres; i++) { - CVector pos = pVehicle->m_matrix * pColModel->spheres[i].center; + CVector pos = pVehicle->GetMatrix() * pColModel->spheres[i].center; float fRadius = pColModel->spheres[i].radius; if(pos.x + fRadius > x1 && pos.x - fRadius < x2 && pos.y + fRadius > y1 && pos.y - fRadius < y2) @@ -1763,7 +1763,7 @@ CWorld::RepositionOneObject(CEntity *pEntity) position.z = FindGroundZFor3DCoord(position.x, position.y, position.z + OBJECT_REPOSITION_OFFSET_Z, nil) - fBoundingBoxMinZ; - pEntity->m_matrix.UpdateRW(); + pEntity->GetMatrix().UpdateRW(); pEntity->UpdateRwFrame(); } else if(modelId == MI_BUOY) { float fWaterLevel = 0.0f; diff --git a/src/core/ZoneCull.cpp b/src/core/ZoneCull.cpp index 33586a4e..5a76e5ed 100644 --- a/src/core/ZoneCull.cpp +++ b/src/core/ZoneCull.cpp @@ -396,9 +396,9 @@ CCullZones::AddCullZone(CVector const &position, v = CVector(1061.7f, -613.0f, 19.0f); if((v-CVector(1029.48f, -495.757f, 21.98f)).Magnitude() < 1.0f) v = CVector(1061.4f, -506.0f, 18.5f); - cull->position.x = clamp(v.x, minx, maxx); - cull->position.y = clamp(v.y, miny, maxy); - cull->position.z = clamp(v.z, minz, maxz); + cull->position.x = Clamp(v.x, minx, maxx); + cull->position.y = Clamp(v.y, miny, maxy); + cull->position.z = Clamp(v.z, minz, maxz); cull->minx = minx; cull->maxx = maxx; cull->miny = miny; @@ -958,11 +958,11 @@ CCullZone::FindTestPoints() // indices of center int x = ElementsX * (position.x-minx)/(maxx-minx); - x = clamp(x, 0, ElementsX-1); + x = Clamp(x, 0, ElementsX-1); int y = ElementsY * (position.y-miny)/(maxy-miny); - y = clamp(y, 0, ElementsY-1); + y = Clamp(y, 0, ElementsY-1); int z = ElementsZ * (position.z-minz)/(maxz-minz); - z = clamp(z, 0, ElementsZ-1); + z = Clamp(z, 0, ElementsZ-1); // Mark which test points inside the zone are not occupied by buildings. // To do this, mark the start point as free and do a food fill. diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index cdae85e1..107b1db8 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -8,6 +8,7 @@ #include "Text.h" #include "World.h" #include "Timer.h" +#include "SaveBuf.h" eLevelName CTheZones::m_CurrLevel; CZone *CTheZones::m_pPlayersZone; @@ -696,17 +697,18 @@ void CTheZones::LoadAllZones(uint8 *buffer, uint32 size) { INITSAVEBUF - int i; + int32 i; CheckSaveHeader(buffer, 'Z', 'N', 'S', '\0', size - SAVE_HEADER_SIZE); - m_pPlayersZone = GetPointerForZoneIndex(ReadSaveBuf<int32>(buffer)); - m_CurrLevel = ReadSaveBuf<eLevelName>(buffer); - FindIndex = ReadSaveBuf<int16>(buffer); - ReadSaveBuf<int16>(buffer); + ReadSaveBuf(&i, buffer); + m_pPlayersZone = GetPointerForZoneIndex(i); + ReadSaveBuf(&m_CurrLevel, buffer); + ReadSaveBuf(&FindIndex, buffer); + SkipSaveBuf(buffer, 2); for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){ - ZoneArray[i] = ReadSaveBuf<CZone>(buffer); + ReadSaveBuf(&ZoneArray[i], buffer); ZoneArray[i].child = GetPointerForZoneIndex((uintptr)ZoneArray[i].child); ZoneArray[i].parent = GetPointerForZoneIndex((uintptr)ZoneArray[i].parent); @@ -714,13 +716,13 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) } for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) - ZoneInfoArray[i] = ReadSaveBuf<CZoneInfo>(buffer); + ReadSaveBuf(&ZoneInfoArray[i], buffer); - TotalNumberOfZones = ReadSaveBuf<int16>(buffer); - TotalNumberOfZoneInfos = ReadSaveBuf<int16>(buffer); + ReadSaveBuf(&TotalNumberOfZones, buffer); + ReadSaveBuf(&TotalNumberOfZoneInfos, buffer); for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){ - MapZoneArray[i] = ReadSaveBuf<CZone>(buffer); + ReadSaveBuf(&MapZoneArray[i], buffer); /* The call of GetPointerForZoneIndex is wrong, as it is @@ -736,10 +738,10 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) } for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++) - AudioZoneArray[i] = ReadSaveBuf<int16>(buffer); + ReadSaveBuf(&AudioZoneArray[i], buffer); - TotalNumberOfMapZones = ReadSaveBuf<uint16>(buffer); - NumberOfAudioZones = ReadSaveBuf<uint16>(buffer); + ReadSaveBuf(&TotalNumberOfMapZones, buffer); + ReadSaveBuf(&NumberOfAudioZones, buffer); VALIDATESAVEBUF(size) } diff --git a/src/core/common.h b/src/core/common.h index a8f19158..da162762 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -216,6 +216,12 @@ inline uint32 ldb(uint32 p, uint32 s, uint32 w) #include "maths.h" #include "Vector.h" +#ifdef GTA_PS2 +#include "VuVector.h" +#define CVUVECTOR CVuVector +#else +#define CVUVECTOR CVector +#endif #include "Vector2D.h" #include "Matrix.h" #include "Rect.h" @@ -284,7 +290,7 @@ extern int strcasecmp(const char *str1, const char *str2); extern wchar *AllocUnicode(const char*src); -#define clamp(v, low, high) ((v)<(low) ? (low) : (v)>(high) ? (high) : (v)) +#define Clamp(v, low, high) ((v)<(low) ? (low) : (v)>(high) ? (high) : (v)) inline float sq(float x) { return x*x; } #define SQR(x) ((x) * (x)) @@ -387,173 +393,3 @@ template<int s, int t> struct check_size { #define STR(x) STRINGIFY(x) #define CONCAT_(x,y) x##y #define CONCAT(x,y) CONCAT_(x,y) - -#ifdef DEBUGMENU -// Tweaking stuff for debugmenu -#define TWEAKPATH ___tw___TWEAKPATH -#define SETTWEAKPATH(path) static const char *___tw___TWEAKPATH = path; -#define TWEAKFUNC(v) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH); -#define TWEAKFUNCN(v, name) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH); -#define TWEAKBOOL(v) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH); -#define TWEAKBOOLN(v, name) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH); -#define TWEAKINT32(v, lower, upper, step) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKINT32N(v, lower, upper, step, name) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKUINT32(v, lower, upper, step) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKUINT32N(v, lower, upper, step, name) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKINT16(v, lower, upper, step) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKINT16N(v, lower, upper, step, name) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKUINT16(v, lower, upper, step) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKUINT16N(v, lower, upper, step, name) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKINT8(v, lower, upper, step) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKINT8N(v, lower, upper, step, name) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKUINT8(v, lower, upper, step) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKUINT8N(v, lower, upper, step, name) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKFLOAT(v, lower, upper, step) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKFLOATN(v, lower, upper, step, name) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKSWITCH(v, lower, upper, str, f) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, str, f, TWEAKPATH); -#define TWEAKSWITCHN(v, lower, upper, str, f, name) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, str, f, TWEAKPATH); - -// interface -class CTweakVar -{ -public: - virtual void AddDBG(const char *path) = 0; -}; - -class CTweakVars -{ -public: - static void Add(CTweakVar *var); - static void AddDBG(const char *path); -}; - -class CTweakFunc : public CTweakVar -{ - const char *m_pPath, *m_pVarName; - void (*m_pFunc)(); -public: - CTweakFunc(void (*pFunc)(), const char *strName, const char *strPath) : - m_pPath(strPath), m_pVarName(strName), m_pFunc(pFunc) - { - CTweakVars::Add(this); - } - - void AddDBG(const char *path); -}; - -class CTweakBool : public CTweakVar -{ - const char *m_pPath, *m_pVarName; - bool *m_pBoolVar; -public: - CTweakBool(bool *pBool, const char *strName, const char *strPath) : - m_pPath(strPath), m_pVarName(strName), m_pBoolVar(pBool) - { - CTweakVars::Add(this); - } - - void AddDBG(const char *path); -}; - -class CTweakSwitch : public CTweakVar -{ - const char *m_pPath, *m_pVarName; - void *m_pIntVar; - int32 m_nMin, m_nMax; - const char **m_aStr; - void (*m_pFunc)(); -public: - CTweakSwitch(void *pInt, const char *strName, int32 nMin, int32 nMax, const char **aStr, - void (*pFunc)(), const char *strPath) - : m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), m_nMin(nMin), m_nMax(nMax), - m_aStr(aStr) - { - CTweakVars::Add(this); - } - - void AddDBG(const char *path); -}; - -#define _TWEEKCLASS(name, type) \ - class name : public CTweakVar \ - { \ - public: \ - const char *m_pPath, *m_pVarName; \ - type *m_pIntVar, m_nLoawerBound, m_nUpperBound, m_nStep; \ - \ - name(type *pInt, const char *strName, type nLower, type nUpper, type nStep, \ - const char *strPath) \ - : m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), \ - m_nLoawerBound(nLower), m_nUpperBound(nUpper), m_nStep(nStep) \ - \ - { \ - CTweakVars::Add(this); \ - } \ - \ - void AddDBG(const char *path); \ - }; - -_TWEEKCLASS(CTweakInt8, int8); -_TWEEKCLASS(CTweakUInt8, uint8); -_TWEEKCLASS(CTweakInt16, int16); -_TWEEKCLASS(CTweakUInt16, uint16); -_TWEEKCLASS(CTweakInt32, int32); -_TWEEKCLASS(CTweakUInt32, uint32); -_TWEEKCLASS(CTweakFloat, float); - -#undef _TWEEKCLASS -#endif - -#ifdef VALIDATE_SAVE_SIZE -extern int32 _saveBufCount; -#define INITSAVEBUF _saveBufCount = 0; -#define VALIDATESAVEBUF(b) assert(_saveBufCount == b); -#else -#define INITSAVEBUF -#define VALIDATESAVEBUF(b) -#endif - -inline void SkipSaveBuf(uint8 *&buf, int32 skip) -{ - buf += skip; -#ifdef VALIDATE_SAVE_SIZE - _saveBufCount += skip; -#endif -} - -template<typename T> -inline const T ReadSaveBuf(uint8 *&buf) -{ - T &value = *(T*)buf; - SkipSaveBuf(buf, sizeof(T)); - return value; -} - -template<typename T> -inline T *WriteSaveBuf(uint8 *&buf, const T &value) -{ - T *p = (T*)buf; - *p = value; - SkipSaveBuf(buf, sizeof(T)); - return p; -} - - -#define SAVE_HEADER_SIZE (4*sizeof(char)+sizeof(uint32)) - -#define WriteSaveHeader(buf,a,b,c,d,size) \ - WriteSaveBuf(buf, a);\ - WriteSaveBuf(buf, b);\ - WriteSaveBuf(buf, c);\ - WriteSaveBuf(buf, d);\ - WriteSaveBuf<uint32>(buf, size); - -#define CheckSaveHeader(buf,a,b,c,d,size)\ - assert(ReadSaveBuf<char>(buf) == a);\ - assert(ReadSaveBuf<char>(buf) == b);\ - assert(ReadSaveBuf<char>(buf) == c);\ - assert(ReadSaveBuf<char>(buf) == d);\ - assert(ReadSaveBuf<uint32>(buf) == size); - - -void cprintf(char*, ...); diff --git a/src/core/config.h b/src/core/config.h index 6619be68..c9339b74 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -128,7 +128,6 @@ enum Config { NUM_PED_COMMENTS_SLOTS = 20, NUM_SOUNDS_SAMPLES_BANKS = 2, - NUM_SOUNDS_SAMPLES_SLOTS = 27, NUM_AUDIOENTITIES = 200, NUM_AUDIO_REFLECTIONS = 5, @@ -185,7 +184,8 @@ enum Config { #define DRAW_GAME_VERSION_TEXT #ifdef DRAW_GAME_VERSION_TEXT // unlike R* development builds, ours has runtime switch on debug menu & .ini, and disabled as default. - #define USE_OUR_VERSIONING // If you disable this then game will fetch version from peds.col, as R* did while in development + // If you disable this then game will fetch version from peds.col, as R* did while in development. + //#define USE_OUR_VERSIONING // enabled from buildfiles by default #endif //#define DRAW_MENU_VERSION_TEXT @@ -223,7 +223,6 @@ enum Config { // not in master builds #define VALIDATE_SAVE_SIZE - #define NO_MOVIES // disable intro videos #define DEBUGMENU #endif @@ -241,6 +240,8 @@ enum Config { #define COMPATIBLE_SAVES // this allows changing structs while keeping saves compatible #define LOAD_INI_SETTINGS // as the name suggests. fundamental for CUSTOM_FRONTEND_OPTIONS +#define NO_MOVIES // add option to disable intro videos + #if defined(__LP64__) || defined(_WIN64) #define FIX_BUGS_64 // Must have fixes to be able to run 64 bit build #endif @@ -379,12 +380,12 @@ enum Config { #define CAMERA_PICKUP // Peds -#define PED_SKIN // support for skinned geometry on peds +#define PED_SKIN // support for skinned geometry on peds, requires COMPATIBLE_SAVES #define ANIMATE_PED_COL_MODEL // #define VC_PED_PORTS // various ports from VC's CPed, mostly subtle // #define NEW_WALK_AROUND_ALGORITHM // to make walking around vehicles/objects less awkward #define CANCELLABLE_CAR_ENTER -//#define PEDS_REPORT_CRIMES_ON_PHONE +//#define PEDS_REPORT_CRIMES_ON_PHONE, requires COMPATIBLE_SAVES // Camera //#define PS2_CAM_TRANSITION // old way of transitioning between cam modes @@ -394,9 +395,11 @@ enum Config { // Audio #define RADIO_SCROLL_TO_PREV_STATION #define AUDIO_CACHE +#define PS2_AUDIO_CHANNELS // increases the maximum number of audio channels to PS2 value of 44 (PC has 28 originally) //#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_MPG123 // use mpg123 to support mp3 files +#define PAUSE_RADIO_IN_FRONTEND // pause radio when game is paused #ifdef AUDIO_OPUS #define AUDIO_OAL_USE_OPUS // enable support of opus files @@ -421,11 +424,18 @@ enum Config { #ifdef SQUEEZE_PERFORMANCE #undef PS2_ALPHA_TEST #undef NO_ISLAND_LOADING + #undef PS2_AUDIO_CHANNELS #define PC_PARTICLE #define VC_PED_PORTS // To not process collisions always. But should be tested if that's really beneficial #define VC_RAIN_NERF // Reduces number of rain particles #endif +// if these defines are enabled saves are not vanilla compatible without COMPATIBLE_SAVES +#ifndef COMPATIBLE_SAVES +#undef PED_SKIN +#undef PEDS_REPORT_CRIMES_ON_PHONE +#endif + // ------- #if defined __MWERKS__ || defined VANILLA_DEFINES @@ -466,6 +476,11 @@ enum Config { #undef ANISOTROPIC_FILTERING //#define USE_TEXTURE_POOL // not possible because R* used custom RW33 +#undef EXTENDED_COLOURFILTER +#undef EXTENDED_PIPELINES +#undef SCREEN_DROPLETS +#undef NEW_RENDERER + #undef FIX_SPRITES #define PC_PARTICLE @@ -513,4 +528,5 @@ enum Config { #undef FREE_CAM #undef RADIO_SCROLL_TO_PREV_STATION #undef BIG_IMG +#undef PS2_AUDIO_CHANNELS #endif diff --git a/src/core/main.cpp b/src/core/main.cpp index 5eccf759..2a0a77ca 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -92,7 +92,10 @@ bool gbModelViewer; bool gbShowTimebars; #endif #ifdef DRAW_GAME_VERSION_TEXT -bool gDrawVersionText; // Our addition, we think it was always enabled on !MASTER builds +bool gbDrawVersionText; // Our addition, we think it was always enabled on !MASTER builds +#endif +#ifdef NO_MOVIES +bool gbNoMovies; #endif volatile int32 frameCount; @@ -399,7 +402,7 @@ DoRWStuffEndOfFrame(void) } #else if (CPad::GetPad(1)->GetLeftShockJustDown() || CPad::GetPad(0)->GetFJustDown(11)) { - sprintf(s, "screen_%11lld.png", time(nil)); + sprintf(s, "screen_%011lld.png", time(nil)); RwGrabScreen(Scene.camera, s); } #endif @@ -1109,7 +1112,7 @@ DisplayGameDebugText() #ifdef DRAW_GAME_VERSION_TEXT wchar ver[200]; - if(gDrawVersionText) // This realtime switch is our thing + if(gbDrawVersionText) // This realtime switch is our thing { #ifdef USE_OUR_VERSIONING @@ -1174,10 +1177,13 @@ DisplayGameDebugText() FrameSamples++; #ifdef FIX_BUGS - FramesPerSecondCounter += frameTime / 1000.f; // convert to seconds + // this is inaccurate with over 1000 fps + static uint32 PreviousTimeInMillisecondsPauseMode = 0; + FramesPerSecondCounter += (CTimer::GetTimeInMillisecondsPauseMode() - PreviousTimeInMillisecondsPauseMode) / 1000.0f; // convert to seconds + PreviousTimeInMillisecondsPauseMode = CTimer::GetTimeInMillisecondsPauseMode(); FramesPerSecond = FrameSamples / FramesPerSecondCounter; #else - FramesPerSecondCounter += 1000.0f / (CTimer::GetTimeStepNonClippedInSeconds() * 1000.0f); + FramesPerSecondCounter += 1000.0f / CTimer::GetTimeStepNonClippedInMilliseconds(); FramesPerSecond = FramesPerSecondCounter / FrameSamples; #endif @@ -1330,11 +1336,13 @@ void RenderEffects_new(void) { PUSH_RENDERGROUP("RenderEffects_new"); +/* // stupid to do this before the whole world is drawn! CShadows::RenderStaticShadows(); // CRenderer::GenerateEnvironmentMap CShadows::RenderStoredShadows(); CSkidmarks::Render(); CRubbish::Render(); +*/ // these aren't really effects DefinedState(); @@ -1357,6 +1365,13 @@ if(gbRenderFadingInEntities) CRenderer::RenderFadingInEntities(); // actual effects here + + // from above + CShadows::RenderStaticShadows(); + CShadows::RenderStoredShadows(); + CSkidmarks::Render(); + CRubbish::Render(); + CGlass::Render(); // CMattRenderer::ResetRenderStates DefinedState(); diff --git a/src/core/main.h b/src/core/main.h index 311c0302..803afb14 100644 --- a/src/core/main.h +++ b/src/core/main.h @@ -66,3 +66,11 @@ void SaveINIControllerSettings(); extern bool gbNewRenderer; bool FredIsInFirstPersonCam(void); #endif + +#ifdef DRAW_GAME_VERSION_TEXT +extern bool gbDrawVersionText; +#endif + +#ifdef NO_MOVIES +extern bool gbNoMovies; +#endif diff --git a/src/core/re3.cpp b/src/core/re3.cpp index e0f9c5c2..fe0347d9 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -517,8 +517,10 @@ bool LoadINISettings() ReadIniIfExists("Draw", "FixSprites", &CDraw::ms_bFixSprites); #endif #ifdef DRAW_GAME_VERSION_TEXT - extern bool gDrawVersionText; - ReadIniIfExists("General", "DrawVersionText", &gDrawVersionText); + ReadIniIfExists("General", "DrawVersionText", &gbDrawVersionText); +#endif +#ifdef NO_MOVIES + ReadIniIfExists("General", "NoMovies", &gbNoMovies); #endif #ifdef CUSTOM_FRONTEND_OPTIONS @@ -608,8 +610,10 @@ void SaveINISettings() StoreIni("Draw", "FixSprites", CDraw::ms_bFixSprites); #endif #ifdef DRAW_GAME_VERSION_TEXT - extern bool gDrawVersionText; - StoreIni("General", "DrawVersionText", gDrawVersionText); + StoreIni("General", "DrawVersionText", gbDrawVersionText); +#endif +#ifdef NO_MOVIES + StoreIni("General", "NoMovies", gbNoMovies); #endif #ifdef CUSTOM_FRONTEND_OPTIONS for (int i = 0; i < MENUPAGES; i++) { @@ -960,6 +964,11 @@ extern bool gbRenderWorld2; DebugMenuAddVar("Render", "Intensity", &CPostFX::Intensity, nil, 0.05f, 0, 10.0f); DebugMenuAddVarBool8("Render", "Motion Blur", &CPostFX::MotionBlurOn, nil); #endif +#ifdef LIBRW + DebugMenuAddVarBool32("Render", "MatFX env map apply light", &rw::MatFX::envMapApplyLight, nil); + DebugMenuAddVarBool32("Render", "MatFX env map flip U", &rw::MatFX::envMapFlipU, nil); + DebugMenuAddVarBool32("Render", "MatFX env map use matcolor", &rw::MatFX::envMapUseMatColor, nil); +#endif #ifdef EXTENDED_PIPELINES static const char *vehpipenames[] = { "MatFX", "Neo" }; e = DebugMenuAddVar("Render", "Vehicle Pipeline", &CustomPipes::VehiclePipeSwitch, nil, @@ -990,14 +999,14 @@ extern bool gbRenderWorld2; #ifdef DRAW_GAME_VERSION_TEXT - extern bool gDrawVersionText; - DebugMenuAddVarBool8("Debug", "Version Text", &gDrawVersionText, nil); + DebugMenuAddVarBool8("Debug", "Version Text", &gbDrawVersionText, nil); #endif DebugMenuAddVarBool8("Debug", "Show DebugStuffInRelease", &gbDebugStuffInRelease, nil); #ifdef TIMEBARS DebugMenuAddVarBool8("Debug", "Show Timebars", &gbShowTimebars, nil); #endif #ifndef FINAL + DebugMenuAddVarBool8("Debug", "Use debug render groups", &bDebugRenderGroups, nil); DebugMenuAddVarBool8("Debug", "Print Memory Usage", &gbPrintMemoryUsage, nil); #ifdef USE_CUSTOM_ALLOCATOR DebugMenuAddCmd("Debug", "Parse Heap", ParseHeap); diff --git a/src/entities/Dummy.cpp b/src/entities/Dummy.cpp index 8a4bfd5f..d5fad3e4 100644 --- a/src/entities/Dummy.cpp +++ b/src/entities/Dummy.cpp @@ -4,8 +4,8 @@ #include "World.h" #include "Dummy.h" -void *CDummy::operator new(size_t sz) { return CPools::GetDummyPool()->New(); } -void CDummy::operator delete(void *p, size_t sz) { CPools::GetDummyPool()->Delete((CDummy*)p); } +void *CDummy::operator new(size_t sz) throw() { return CPools::GetDummyPool()->New(); } +void CDummy::operator delete(void *p, size_t sz) throw() { CPools::GetDummyPool()->Delete((CDummy*)p); } void CDummy::Add(void) diff --git a/src/entities/Dummy.h b/src/entities/Dummy.h index 3717a01c..6c3f12ea 100644 --- a/src/entities/Dummy.h +++ b/src/entities/Dummy.h @@ -12,8 +12,8 @@ public: void Add(void); void Remove(void); - static void *operator new(size_t); - static void operator delete(void*, size_t); + static void *operator new(size_t) throw(); + static void operator delete(void*, size_t) throw(); }; VALIDATE_SIZE(CDummy, 0x68); diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index 4885d631..a7f4bd45 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -22,6 +22,7 @@ #include "MemoryHeap.h" #include "Bones.h" #include "Debug.h" +#include "SaveBuf.h" int gBuildings; @@ -110,9 +111,9 @@ CEntity::CreateRwObject(void) if(IsBuilding()) gBuildings++; if(RwObjectGetType(m_rwObject) == rpATOMIC) - m_matrix.AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject)), false); + GetMatrix().AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic *)m_rwObject)), false); else if(RwObjectGetType(m_rwObject) == rpCLUMP) - m_matrix.AttachRW(RwFrameGetMatrix(RpClumpGetFrame((RpClump*)m_rwObject)), false); + GetMatrix().AttachRW(RwFrameGetMatrix(RpClumpGetFrame((RpClump *)m_rwObject)), false); mi->AddRef(); } } @@ -123,9 +124,9 @@ CEntity::AttachToRwObject(RwObject *obj) m_rwObject = obj; if(m_rwObject){ if(RwObjectGetType(m_rwObject) == rpATOMIC) - m_matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject)), false); + GetMatrix().Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic *)m_rwObject)), false); else if(RwObjectGetType(m_rwObject) == rpCLUMP) - m_matrix.Attach(RwFrameGetMatrix(RpClumpGetFrame((RpClump*)m_rwObject)), false); + GetMatrix().Attach(RwFrameGetMatrix(RpClumpGetFrame((RpClump *)m_rwObject)), false); CModelInfo::GetModelInfo(m_modelIndex)->AddRef(); } } @@ -136,7 +137,7 @@ CEntity::DetachFromRwObject(void) if(m_rwObject) CModelInfo::GetModelInfo(m_modelIndex)->RemoveRef(); m_rwObject = nil; - m_matrix.Detach(); + GetMatrix().Detach(); } #ifdef PED_SKIN @@ -166,7 +167,7 @@ CEntity::DeleteRwObject(void) { RwFrame *f; - m_matrix.Detach(); + GetMatrix().Detach(); if(m_rwObject){ if(RwObjectGetType(m_rwObject) == rpATOMIC){ f = RpAtomicGetFrame((RpAtomic*)m_rwObject); @@ -191,18 +192,18 @@ CEntity::GetBoundRect(void) { CRect rect; CVector v; - CColModel *col = CModelInfo::GetModelInfo(m_modelIndex)->GetColModel(); + CColModel *col = CModelInfo::GetColModel(m_modelIndex); - rect.ContainPoint(m_matrix * col->boundingBox.min); - rect.ContainPoint(m_matrix * col->boundingBox.max); + rect.ContainPoint(GetMatrix() * col->boundingBox.min); + rect.ContainPoint(GetMatrix() * col->boundingBox.max); v = col->boundingBox.min; v.x = col->boundingBox.max.x; - rect.ContainPoint(m_matrix * v); + rect.ContainPoint(GetMatrix() * v); v = col->boundingBox.max; v.x = col->boundingBox.min.x; - rect.ContainPoint(m_matrix * v); + rect.ContainPoint(GetMatrix() * v); return rect; } @@ -210,21 +211,27 @@ CEntity::GetBoundRect(void) CVector CEntity::GetBoundCentre(void) { - CVector v; - GetBoundCentre(v); - return v; + return GetMatrix() * CModelInfo::GetColModel(m_modelIndex)->boundingSphere.center; } +#ifdef GTA_PS2 +void +CEntity::GetBoundCentre(CVuVector &out) +{ + TransformPoint(out, GetMatrix(), CModelInfo::GetColModel(m_modelIndex)->boundingSphere.center); +} +#else void CEntity::GetBoundCentre(CVector &out) { - out = m_matrix * CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingSphere.center; + out = GetMatrix() * CModelInfo::GetColModel(m_modelIndex)->boundingSphere.center; } +#endif float CEntity::GetBoundRadius(void) { - return CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingSphere.radius; + return CModelInfo::GetColModel(m_modelIndex)->boundingSphere.radius; } void @@ -379,10 +386,13 @@ CEntity::Render(void) } } + bool -CEntity::GetIsTouching(CVector const ¢er, float radius) +CEntity::GetIsTouching(CVUVECTOR const ¢er, float radius) { - return sq(GetBoundRadius()+radius) > (GetBoundCentre()-center).MagnitudeSqr(); + CVUVECTOR boundCenter; + GetBoundCentre(boundCenter); + return sq(GetBoundRadius()+radius) > (boundCenter-center).MagnitudeSqr(); } bool @@ -400,8 +410,7 @@ CEntity::IsVisibleComplex(void) bool CEntity::GetIsOnScreen(void) { - return TheCamera.IsSphereVisible(GetBoundCentre(), GetBoundRadius(), - &TheCamera.GetCameraMatrix()); + return TheCamera.IsSphereVisible(GetBoundCentre(), GetBoundRadius()); } bool @@ -417,7 +426,7 @@ CEntity::GetIsOnScreenComplex(void) return true; CRect rect = GetBoundRect(); - CColModel *colmodel = CModelInfo::GetModelInfo(m_modelIndex)->GetColModel(); + CColModel *colmodel = CModelInfo::GetColModel(m_modelIndex); float z = GetPosition().z; float minz = z + colmodel->boundingBox.min.z; float maxz = z + colmodel->boundingBox.max.z; @@ -572,7 +581,7 @@ CEntity::Remove(void) float CEntity::GetDistanceFromCentreOfMassToBaseOfModel(void) { - return -CModelInfo::GetModelInfo(m_modelIndex)->GetColModel()->boundingBox.min.z; + return -CModelInfo::GetColModel(m_modelIndex)->boundingBox.min.z; } void @@ -745,7 +754,8 @@ CEntity::SaveEntityFlags(uint8*& buf) void CEntity::LoadEntityFlags(uint8*& buf) { - uint32 tmp = ReadSaveBuf<uint32>(buf); + uint32 tmp; + ReadSaveBuf(&tmp, buf); m_type = (tmp & ((BIT(3) - 1))); m_status = ((tmp >> 3) & (BIT(5) - 1)); @@ -776,7 +786,7 @@ CEntity::LoadEntityFlags(uint8*& buf) bZoneCulled = !!(tmp & BIT(30)); bZoneCulled2 = !!(tmp & BIT(31)); - tmp = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&tmp, buf); bRemoveFromWorld = !!(tmp & BIT(0)); bHasHitWall = !!(tmp & BIT(1)); diff --git a/src/entities/Entity.h b/src/entities/Entity.h index 7ee638d7..6174b61d 100644 --- a/src/entities/Entity.h +++ b/src/entities/Entity.h @@ -141,11 +141,11 @@ public: return (RpClump*)m_rwObject; } - void GetBoundCentre(CVector &out); + void GetBoundCentre(CVUVECTOR &out); CVector GetBoundCentre(void); float GetBoundRadius(void); float GetDistanceFromCentreOfMassToBaseOfModel(void); - bool GetIsTouching(CVector const ¢er, float r); + bool GetIsTouching(CVUVECTOR const ¢er, float r); bool GetIsOnScreen(void); bool GetIsOnScreenComplex(void); bool IsVisible(void); diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index ed01297e..182ff46b 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -216,7 +216,7 @@ CPhysical::RemoveAndAdd(void) CRect CPhysical::GetBoundRect(void) { - CVector center; + CVUVECTOR center; float radius; GetBoundCentre(center); radius = GetBoundRadius(); @@ -442,7 +442,7 @@ CPhysical::ApplyMoveForce(float jx, float jy, float jz) void CPhysical::ApplyTurnForce(float jx, float jy, float jz, float px, float py, float pz) { - CVector com = Multiply3x3(m_matrix, m_vecCentreOfMass); + CVector com = Multiply3x3(GetMatrix(), m_vecCentreOfMass); CVector turnimpulse = CrossProduct(CVector(px, py, pz)-com, CVector(jx, jy, jz)); m_vecTurnSpeed += turnimpulse*(1.0f/m_fTurnMass); } @@ -456,7 +456,7 @@ CPhysical::ApplyFrictionMoveForce(float jx, float jy, float jz) void CPhysical::ApplyFrictionTurnForce(float jx, float jy, float jz, float px, float py, float pz) { - CVector com = Multiply3x3(m_matrix, m_vecCentreOfMass); + CVector com = Multiply3x3(GetMatrix(), m_vecCentreOfMass); CVector turnimpulse = CrossProduct(CVector(px, py, pz)-com, CVector(jx, jy, jz)); m_vecTurnFriction += turnimpulse*(1.0f/m_fTurnMass); } @@ -853,7 +853,7 @@ CPhysical::ApplyCollisionAlt(CEntity *B, CColPoint &colpoint, float &impulse, CV moveSpeed += vImpulse * (1.0f/m_fMass); // ApplyTurnForce - CVector com = Multiply3x3(m_matrix, m_vecCentreOfMass); + CVector com = Multiply3x3(GetMatrix(), m_vecCentreOfMass); CVector turnimpulse = CrossProduct(pointpos-com, vImpulse); turnSpeed += turnimpulse*(1.0f/m_fTurnMass); @@ -1086,7 +1086,7 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists) CPhysical *A, *B; CObject *Bobj; bool canshift; - CVector center; + CVUVECTOR center; float radius; int numCollisions; @@ -1244,7 +1244,7 @@ CPhysical::ProcessCollisionSectorList_SimpleCar(CPtrList *lists) { static CColPoint aColPoints[MAX_COLLISION_POINTS]; float radius; - CVector center; + CVUVECTOR center; int listtype; CPhysical *A, *B; int numCollisions; @@ -1406,7 +1406,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists) { static CColPoint aColPoints[MAX_COLLISION_POINTS]; float radius; - CVector center; + CVUVECTOR center; CPtrList *list; CPhysical *A, *B; CObject *Aobj, *Bobj; diff --git a/src/extras/custompipes_d3d9.cpp b/src/extras/custompipes_d3d9.cpp index dad42b33..8b984448 100644 --- a/src/extras/custompipes_d3d9.cpp +++ b/src/extras/custompipes_d3d9.cpp @@ -568,6 +568,7 @@ struct BuildingInst { rw::RawMatrix combinedMat; rw::d3d9::InstanceDataHeader *instHeader; + uint32 cullMode; uint8 fadeAlpha; bool lighting; }; @@ -612,6 +613,7 @@ AtomicFirstPass(RpAtomic *atomic, int pass) assert(building->instHeader->platform == PLATFORM_D3D9); building->fadeAlpha = 255; building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT); + building->cullMode = rw::GetRenderState(rw::CULLMODE); rw::uint32 flags = atomic->geometry->flags; bool setupDone = false; @@ -630,6 +632,7 @@ AtomicFirstPass(RpAtomic *atomic, int pass) // alright we're rendering this atomic if(!setupDone){ + rw::SetRenderState(rw::CULLMODE, building->cullMode); setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride); setIndices(building->instHeader->indexBuffer); setVertexDeclaration(building->instHeader->vertexDeclaration); @@ -671,6 +674,7 @@ AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha) assert(building->instHeader->platform == PLATFORM_D3D9); building->fadeAlpha = fadeAlpha; building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT); + building->cullMode = rw::GetRenderState(rw::CULLMODE); SetMatrix(building, atomic->getFrame()->getLTM()); numBlendInsts[pass]++; } @@ -688,6 +692,7 @@ RenderBlendPass(int pass) for(i = 0; i < numBlendInsts[pass]; i++){ BuildingInst *building = &blendInsts[pass][i]; + rw::SetRenderState(rw::CULLMODE, building->cullMode); setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride); setIndices(building->instHeader->indexBuffer); setVertexDeclaration(building->instHeader->vertexDeclaration); diff --git a/src/extras/custompipes_gl.cpp b/src/extras/custompipes_gl.cpp index 040bf686..2b28cb52 100644 --- a/src/extras/custompipes_gl.cpp +++ b/src/extras/custompipes_gl.cpp @@ -154,7 +154,7 @@ CreateVehiclePipe(void) { #include "shaders/obj/neoVehicle_frag.inc" #include "shaders/obj/neoVehicle_vert.inc" - const char *vs[] = { shaderDecl, header_vert_src, neoVehicle_vert_src, nil }; + const char *vs[] = { shaderDecl, "#define DIRECTIONALS\n", header_vert_src, neoVehicle_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, neoVehicle_frag_src, nil }; neoVehicleShader = Shader::create(vs, fs); assert(neoVehicleShader); @@ -515,7 +515,7 @@ CreateRimLightPipes(void) { #include "shaders/obj/simple_frag.inc" #include "shaders/obj/neoRimSkin_vert.inc" - const char *vs[] = { shaderDecl, header_vert_src, neoRimSkin_vert_src, nil }; + const char *vs[] = { shaderDecl, "#define DIRECTIONALS\n", header_vert_src, neoRimSkin_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil }; neoRimSkinShader = Shader::create(vs, fs); assert(neoRimSkinShader); @@ -524,7 +524,7 @@ CreateRimLightPipes(void) { #include "shaders/obj/simple_frag.inc" #include "shaders/obj/neoRim_vert.inc" - const char *vs[] = { shaderDecl, header_vert_src, neoRim_vert_src, nil }; + const char *vs[] = { shaderDecl, "#define DIRECTIONALS\n", header_vert_src, neoRim_vert_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil }; neoRimShader = Shader::create(vs, fs); assert(neoRimShader); @@ -595,6 +595,7 @@ struct BuildingInst { rw::Matrix matrix; rw::gl3::InstanceDataHeader *instHeader; + uint32 cullMode; uint8 fadeAlpha; bool lighting; }; @@ -627,6 +628,7 @@ AtomicFirstPass(RpAtomic *atomic, int pass) assert(building->instHeader->platform == PLATFORM_GL3); building->fadeAlpha = 255; building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT); + building->cullMode = rw::GetRenderState(rw::CULLMODE); rw::uint32 flags = atomic->geometry->flags; WorldLights lights; @@ -654,6 +656,7 @@ AtomicFirstPass(RpAtomic *atomic, int pass) // alright we're rendering this atomic if(!setupDone){ + rw::SetRenderState(rw::CULLMODE, building->cullMode); defaultShader->use(); setWorldMatrix(&building->matrix); setupVertexInput(building->instHeader); @@ -686,6 +689,7 @@ AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha) assert(building->instHeader->platform == PLATFORM_GL3); building->fadeAlpha = fadeAlpha; building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT); + building->cullMode = rw::GetRenderState(rw::CULLMODE); building->matrix = *atomic->getFrame()->getLTM(); numBlendInsts[pass]++; } @@ -706,6 +710,7 @@ RenderBlendPass(int pass) for(i = 0; i < numBlendInsts[pass]; i++){ BuildingInst *building = &blendInsts[pass][i]; + rw::SetRenderState(rw::CULLMODE, building->cullMode); setupVertexInput(building->instHeader); setWorldMatrix(&building->matrix); if(building->lighting) diff --git a/src/extras/debugmenu.h b/src/extras/debugmenu.h index c2198aca..45b65d04 100644 --- a/src/extras/debugmenu.h +++ b/src/extras/debugmenu.h @@ -2,6 +2,120 @@ #ifdef DEBUGMENU +// Tweaking stuff for debugmenu +#define TWEAKPATH ___tw___TWEAKPATH +#define SETTWEAKPATH(path) static const char *___tw___TWEAKPATH = path; +#define TWEAKFUNC(v) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH); +#define TWEAKFUNCN(v, name) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH); +#define TWEAKBOOL(v) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH); +#define TWEAKBOOLN(v, name) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH); +#define TWEAKINT32(v, lower, upper, step) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); +#define TWEAKINT32N(v, lower, upper, step, name) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); +#define TWEAKUINT32(v, lower, upper, step) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); +#define TWEAKUINT32N(v, lower, upper, step, name) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); +#define TWEAKINT16(v, lower, upper, step) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); +#define TWEAKINT16N(v, lower, upper, step, name) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); +#define TWEAKUINT16(v, lower, upper, step) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); +#define TWEAKUINT16N(v, lower, upper, step, name) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); +#define TWEAKINT8(v, lower, upper, step) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); +#define TWEAKINT8N(v, lower, upper, step, name) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); +#define TWEAKUINT8(v, lower, upper, step) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); +#define TWEAKUINT8N(v, lower, upper, step, name) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); +#define TWEAKFLOAT(v, lower, upper, step) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); +#define TWEAKFLOATN(v, lower, upper, step, name) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); +#define TWEAKSWITCH(v, lower, upper, str, f) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, str, f, TWEAKPATH); +#define TWEAKSWITCHN(v, lower, upper, str, f, name) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, str, f, TWEAKPATH); + +// interface +class CTweakVar +{ +public: + virtual void AddDBG(const char* path) = 0; +}; + +class CTweakVars +{ +public: + static void Add(CTweakVar* var); + static void AddDBG(const char* path); +}; + +class CTweakFunc : public CTweakVar +{ + const char* m_pPath, * m_pVarName; + void (*m_pFunc)(); +public: + CTweakFunc(void (*pFunc)(), const char* strName, const char* strPath) : + m_pPath(strPath), m_pVarName(strName), m_pFunc(pFunc) + { + CTweakVars::Add(this); + } + + void AddDBG(const char* path); +}; + +class CTweakBool : public CTweakVar +{ + const char* m_pPath, * m_pVarName; + bool* m_pBoolVar; +public: + CTweakBool(bool* pBool, const char* strName, const char* strPath) : + m_pPath(strPath), m_pVarName(strName), m_pBoolVar(pBool) + { + CTweakVars::Add(this); + } + + void AddDBG(const char* path); +}; + +class CTweakSwitch : public CTweakVar +{ + const char* m_pPath, * m_pVarName; + void* m_pIntVar; + int32 m_nMin, m_nMax; + const char** m_aStr; + void (*m_pFunc)(); +public: + CTweakSwitch(void* pInt, const char* strName, int32 nMin, int32 nMax, const char** aStr, + void (*pFunc)(), const char* strPath) + : m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), m_nMin(nMin), m_nMax(nMax), + m_aStr(aStr) + { + CTweakVars::Add(this); + } + + void AddDBG(const char* path); +}; + +#define _TWEEKCLASS(name, type) \ + class name : public CTweakVar \ + { \ + public: \ + const char *m_pPath, *m_pVarName; \ + type *m_pIntVar, m_nLoawerBound, m_nUpperBound, m_nStep; \ + \ + name(type *pInt, const char *strName, type nLower, type nUpper, type nStep, \ + const char *strPath) \ + : m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), \ + m_nLoawerBound(nLower), m_nUpperBound(nUpper), m_nStep(nStep) \ + \ + { \ + CTweakVars::Add(this); \ + } \ + \ + void AddDBG(const char *path); \ + }; + +_TWEEKCLASS(CTweakInt8, int8); +_TWEEKCLASS(CTweakUInt8, uint8); +_TWEEKCLASS(CTweakInt16, int16); +_TWEEKCLASS(CTweakUInt16, uint16); +_TWEEKCLASS(CTweakInt32, int32); +_TWEEKCLASS(CTweakUInt32, uint32); +_TWEEKCLASS(CTweakFloat, float); + +#undef _TWEEKCLASS + typedef void (*TriggerFunc)(void); struct Menu; diff --git a/src/extras/postfx.cpp b/src/extras/postfx.cpp index 03d4833e..425a22d4 100644 --- a/src/extras/postfx.cpp +++ b/src/extras/postfx.cpp @@ -48,6 +48,9 @@ CPostFX::InitOnce(void) void CPostFX::Open(RwCamera *cam) { + if(pFrontBuffer) + Close(); + uint32 width = Pow(2.0f, int32(log2(RwRasterGetWidth (RwCameraGetRaster(cam))))+1); uint32 height = Pow(2.0f, int32(log2(RwRasterGetHeight(RwCameraGetRaster(cam))))+1); uint32 depth = RwRasterGetDepth(RwCameraGetRaster(cam)); diff --git a/src/extras/screendroplets.cpp b/src/extras/screendroplets.cpp index 1412141e..2485386b 100644 --- a/src/extras/screendroplets.cpp +++ b/src/extras/screendroplets.cpp @@ -423,7 +423,7 @@ ScreenDroplets::ProcessCameraMovement(void) ms_movingEnabled = !isTopDown && !isLookingInDirection; // 0 when looking stright up, 180 when looking up or down - ms_camUpAngle = RADTODEG(Acos(clamp(camUp.z, -1.0f, 1.0f))); + ms_camUpAngle = RADTODEG(Acos(Clamp(camUp.z, -1.0f, 1.0f))); } void diff --git a/src/math/Matrix.h b/src/math/Matrix.h index 9d50a4f6..6404b506 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -72,22 +72,6 @@ public: void SetRotateXOnly(float angle); void SetRotateYOnly(float angle); void SetRotateZOnly(float angle); - void SetRotateZOnlyScaled(float angle, float scale) { - float c = Cos(angle); - float s = Sin(angle); - - rx = c * scale; - ry = s * scale; - rz = 0.0f; - - fx = -s * scale; - fy = c * scale; - fz = 0.0f; - - ux = 0.0f; - uy = 0.0f; - uz = scale; - } void SetRotateX(float angle); void SetRotateY(float angle); void SetRotateZ(float angle); diff --git a/src/math/VuVector.h b/src/math/VuVector.h index 30d62cfc..41584095 100644 --- a/src/math/VuVector.h +++ b/src/math/VuVector.h @@ -22,6 +22,8 @@ public: x = 1.0f; } */ + + // TODO: operator- }; void TransformPoint(CVuVector &out, const CMatrix &mat, const CVuVector &in); diff --git a/src/math/maths.h b/src/math/maths.h index 8d68bf64..6a228036 100644 --- a/src/math/maths.h +++ b/src/math/maths.h @@ -10,7 +10,7 @@ inline float Acos(float x) { return acosf(x); } inline float Tan(float x) { return tanf(x); } inline float Atan(float x) { return atanf(x); } inline float Atan2(float y, float x) { return atan2f(y, x); } -inline float Abs(float x) { return fabs(x); } +inline float Abs(float x) { return fabsf(x); } inline float Sqrt(float x) { return sqrtf(x); } inline float RecipSqrt(float x, float y) { return x/Sqrt(y); } inline float RecipSqrt(float x) { return RecipSqrt(1.0f, x); } diff --git a/src/modelinfo/ModelInfo.h b/src/modelinfo/ModelInfo.h index 4fe1ebb0..4d24e78f 100644 --- a/src/modelinfo/ModelInfo.h +++ b/src/modelinfo/ModelInfo.h @@ -43,6 +43,9 @@ public: static CBaseModelInfo *GetModelInfo(int id){ return ms_modelInfoPtrs[id]; } + static CColModel *GetColModel(int id){ + return ms_modelInfoPtrs[id]->GetColModel(); + } static bool IsBoatModel(int32 id); static bool IsBikeModel(int32 id); diff --git a/src/modelinfo/PedModelInfo.cpp b/src/modelinfo/PedModelInfo.cpp index d0816467..2cce48f4 100644 --- a/src/modelinfo/PedModelInfo.cpp +++ b/src/modelinfo/PedModelInfo.cpp @@ -317,6 +317,10 @@ CPedModelInfo::CreateHitColModelSkinned(RpClump *clump) for(int i = 0; i < NUMPEDINFONODES; i++){ *mat = *invmat; + // From LCS. Otherwise gives FPE +#ifdef FIX_BUGS + spheres[i].center = CVector(0.0f, 0.0f, 0.0f); +#else int id = ConvertPedNode2BoneTag(m_pColNodeInfos[i].pedNode); // this is wrong, wtf R* ??? int idx = RpHAnimIDGetIndex(hier, id); @@ -326,6 +330,7 @@ CPedModelInfo::CreateHitColModelSkinned(RpClump *clump) RwV3dTransformPoints(&pos, &pos, 1, mat); spheres[i].center = pos + CVector(m_pColNodeInfos[i].x, 0.0f, m_pColNodeInfos[i].z); +#endif spheres[i].radius = m_pColNodeInfos[i].radius; spheres[i].surface = SURFACE_PED; spheres[i].piece = m_pColNodeInfos[i].pieceType; diff --git a/src/objects/CutsceneHead.cpp b/src/objects/CutsceneHead.cpp index 15611c29..19b3a592 100644 --- a/src/objects/CutsceneHead.cpp +++ b/src/objects/CutsceneHead.cpp @@ -85,7 +85,6 @@ CCutsceneHead::ProcessControl(void) { m_matrix.SetRotateY(PI/2); m_matrix = CMatrix(RwFrameGetLTM(m_pHeadNode)) * m_matrix; - UpdateRwFrame(); // android/xbox don't call this } assert(RwObjectGetType(m_rwObject) == rpCLUMP); @@ -95,7 +94,7 @@ CCutsceneHead::ProcessControl(void) // PS2 only plays anims in cutscene, PC always plays anims if(!lastLoadedSKA || CCutsceneMgr::IsRunning()) #endif - RpHAnimHierarchyAddAnimTime(hier, CTimer::GetTimeStepNonClipped()/50.0f); + RpHAnimHierarchyAddAnimTime(hier, CTimer::GetTimeStepNonClippedInSeconds()); } void diff --git a/src/objects/Object.cpp b/src/objects/Object.cpp index 411e245a..2a7de2c7 100644 --- a/src/objects/Object.cpp +++ b/src/objects/Object.cpp @@ -16,10 +16,32 @@ int16 CObject::nNoTempObjects; int16 CObject::nBodyCastHealth = 1000; -void *CObject::operator new(size_t sz) { return CPools::GetObjectPool()->New(); } -void *CObject::operator new(size_t sz, int handle) { return CPools::GetObjectPool()->New(handle);}; -void CObject::operator delete(void *p, size_t sz) { CPools::GetObjectPool()->Delete((CObject*)p); } -void CObject::operator delete(void *p, int handle) { CPools::GetObjectPool()->Delete((CObject*)p); } +// Object pools tends to be full sometimes, let's free a temp. object in this case. +#ifdef FIX_BUGS +void *CObject::operator new(size_t sz) throw() { + CObject *obj = CPools::GetObjectPool()->New(); + if (!obj) { + CObjectPool *objectPool = CPools::GetObjectPool(); + for (int32 i = 0; i < objectPool->GetSize(); i++) { + CObject *existing = objectPool->GetSlot(i); + if (existing && existing->ObjectCreatedBy == TEMP_OBJECT) { + int32 handle = objectPool->GetIndex(existing); + CWorld::Remove(existing); + delete existing; + obj = objectPool->New(handle); + break; + } + } + } + return obj; +} +#else +void *CObject::operator new(size_t sz) throw() { return CPools::GetObjectPool()->New(); } +#endif +void *CObject::operator new(size_t sz, int handle) throw() { return CPools::GetObjectPool()->New(handle); }; + +void CObject::operator delete(void *p, size_t sz) throw() { CPools::GetObjectPool()->Delete((CObject*)p); } +void CObject::operator delete(void *p, int handle) throw() { CPools::GetObjectPool()->Delete((CObject*)p); } CObject::CObject(void) { @@ -63,7 +85,7 @@ CObject::CObject(CDummyObject *dummy) if (dummy->m_rwObject) AttachToRwObject(dummy->m_rwObject); else - GetMatrix() = dummy->GetMatrix(); + SetMatrix(dummy->GetMatrix()); m_objectMatrix = dummy->GetMatrix(); dummy->DetachFromRwObject(); @@ -112,8 +134,8 @@ void CObject::Teleport(CVector vecPos) { CWorld::Remove(this); - m_matrix.GetPosition() = vecPos; - m_matrix.UpdateRW(); + GetMatrix().GetPosition() = vecPos; + GetMatrix().UpdateRW(); UpdateRwFrame(); CWorld::Add(this); } @@ -170,7 +192,7 @@ CObject::ObjectDamage(float amount) amount = 0.0f; } if ((amount * m_fCollisionDamageMultiplier > 150.0f || bBodyCastDamageEffect) && m_nCollisionDamageEffect) { - const CVector& vecPos = m_matrix.GetPosition(); + const CVector& vecPos = GetMatrix().GetPosition(); const float fDirectionZ = 0.0002f * amount; switch (m_nCollisionDamageEffect) { @@ -329,7 +351,7 @@ CObject::Init(void) m_pCollidingEntity = nil; CColPoint point; CEntity* outEntity = nil; - const CVector& vecPos = m_matrix.GetPosition(); + const CVector& vecPos = GetMatrix().GetPosition(); if (CWorld::ProcessVerticalLine(vecPos, vecPos.z - 10.0f, point, outEntity, true, false, false, false, false, false, nil)) m_pCurSurface = outEntity; else diff --git a/src/objects/Object.h b/src/objects/Object.h index c9a1bba8..114a1a9f 100644 --- a/src/objects/Object.h +++ b/src/objects/Object.h @@ -65,10 +65,10 @@ public: static int16 nNoTempObjects; static int16 nBodyCastHealth; - static void *operator new(size_t); - static void *operator new(size_t, int); - static void operator delete(void*, size_t); - static void operator delete(void*, int); + static void *operator new(size_t) throw(); + static void *operator new(size_t, int) throw(); + static void operator delete(void*, size_t) throw(); + static void operator delete(void*, int) throw(); CObject(void); CObject(int32, bool); diff --git a/src/objects/ParticleObject.cpp b/src/objects/ParticleObject.cpp index 71f223d7..211a568c 100644 --- a/src/objects/ParticleObject.cpp +++ b/src/objects/ParticleObject.cpp @@ -33,7 +33,7 @@ CAudioHydrant::Add(CParticleObject *particleobject) if ( AEHANDLE_IS_FAILED(List[i].AudioEntity) ) return false; - DMAudio.SetEntityStatus(List[i].AudioEntity, true); + DMAudio.SetEntityStatus(List[i].AudioEntity, TRUE); List[i].pParticleObject = particleobject; diff --git a/src/peds/Gangs.cpp b/src/peds/Gangs.cpp index 8859e61e..be29379c 100644 --- a/src/peds/Gangs.cpp +++ b/src/peds/Gangs.cpp @@ -3,6 +3,7 @@ #include "ModelIndices.h" #include "Gangs.h" #include "Weapon.h" +#include "SaveBuf.h" CGangInfo CGangs::Gang[NUM_GANGS]; @@ -72,6 +73,6 @@ INITSAVEBUF CheckSaveHeader(buf, 'G','N','G','\0', size - SAVE_HEADER_SIZE); for (int i = 0; i < NUM_GANGS; i++) - Gang[i] = ReadSaveBuf<CGangInfo>(buf); + ReadSaveBuf(&Gang[i], buf); VALIDATESAVEBUF(size); } diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 28a4e989..4d80cac2 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -32,6 +32,7 @@ #include "Floater.h" #include "Range2D.h" #include "Wanted.h" +#include "SaveBuf.h" CPed *gapTempPedList[50]; uint16 gnNumTempPedList; @@ -47,10 +48,10 @@ bool CPed::bPedCheat2; bool CPed::bPedCheat3; CVector2D CPed::ms_vec2DFleePosition; -void *CPed::operator new(size_t sz) { return CPools::GetPedPool()->New(); } -void *CPed::operator new(size_t sz, int handle) { return CPools::GetPedPool()->New(handle); } -void CPed::operator delete(void *p, size_t sz) { CPools::GetPedPool()->Delete((CPed*)p); } -void CPed::operator delete(void *p, int handle) { CPools::GetPedPool()->Delete((CPed*)p); } +void *CPed::operator new(size_t sz) throw() { return CPools::GetPedPool()->New(); } +void *CPed::operator new(size_t sz, int handle) throw() { return CPools::GetPedPool()->New(handle); } +void CPed::operator delete(void *p, size_t sz) throw() { CPools::GetPedPool()->Delete((CPed*)p); } +void CPed::operator delete(void *p, int handle) throw() { CPools::GetPedPool()->Delete((CPed*)p); } #ifdef DEBUGMENU bool CPed::bPopHeadsOnHeadshot = false; @@ -244,7 +245,7 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) bHasACamera = true; m_audioEntityId = DMAudio.CreateEntity(AUDIOTYPE_PHYSICAL, this); - DMAudio.SetEntityStatus(m_audioEntityId, true); + DMAudio.SetEntityStatus(m_audioEntityId, TRUE); m_fearFlags = CPedType::GetThreats(m_nPedType); m_threatEntity = nil; m_eventOrThreat = CVector2D(0.0f, 0.0f); @@ -307,6 +308,30 @@ CPed::~CPed(void) m_pFire->Extinguish(); CPopulation::UpdatePedCount((ePedType)m_nPedType, true); DMAudio.DestroyEntity(m_audioEntityId); + + // Because of the nature of ped lists in GTA, it can sometimes be outdated. + // Remove ourself from nearPeds list of the Peds in our nearPeds list. +#ifdef FIX_BUGS + for(int i = 0; i < m_numNearPeds; i++) { + CPed *nearPed = m_nearPeds[i]; + assert(nearPed != nil); + if (!nearPed->IsPointerValid()) + continue; + + for(int j = 0; j < nearPed->m_numNearPeds;) { + assert(j == ARRAY_SIZE(m_nearPeds) - 1 || nearPed->m_nearPeds[j] || !nearPed->m_nearPeds[j+1]); // ensure nil comes after nil + + if (nearPed->m_nearPeds[j] == this) { + for (int k = j; k < ARRAY_SIZE(m_nearPeds) - 1; k++) { + nearPed->m_nearPeds[k] = nearPed->m_nearPeds[k + 1]; + nearPed->m_nearPeds[k + 1] = nil; + } + nearPed->m_numNearPeds--; + } else + j++; + } + } +#endif } void @@ -397,13 +422,15 @@ CPed::BuildPedLists(void) } else removePed = true; } + + assert(i == ARRAY_SIZE(m_nearPeds) - 1 || m_nearPeds[i] || !m_nearPeds[i+1]); // ensure nil comes after nil + if (removePed) { // If we arrive here, the ped we're checking isn't "near", so we should remove it. for (int j = i; j < ARRAY_SIZE(m_nearPeds) - 1; j++) { m_nearPeds[j] = m_nearPeds[j + 1]; m_nearPeds[j + 1] = nil; } - // Above loop won't work on last slot, so we need to empty it. m_nearPeds[ARRAY_SIZE(m_nearPeds) - 1] = nil; m_numNearPeds--; } else @@ -2501,7 +2528,7 @@ CPed::ProcessControl(void) if (m_nPedState == PED_JUMP) { if (m_nWaitTimer <= 2000) { if (m_nWaitTimer < 1000) - m_nWaitTimer += CTimer::GetTimeStep() * 0.02f * 1000.0f; + m_nWaitTimer += CTimer::GetTimeStepInMilliseconds(); } else { m_nWaitTimer = 0; } @@ -2927,7 +2954,7 @@ CPed::ProcessControl(void) lDriveAssoc->blendAmount = 0.0f; if (rDriveAssoc) - rDriveAssoc->blendAmount = clamp(steerAngle * -100.0f / 61.0f, 0.0f, 1.0f); + rDriveAssoc->blendAmount = Clamp(steerAngle * -100.0f / 61.0f, 0.0f, 1.0f); else if (m_pMyVehicle->bLowVehicle) CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_STD_CAR_DRIVE_RIGHT_LO); else @@ -2938,7 +2965,7 @@ CPed::ProcessControl(void) rDriveAssoc->blendAmount = 0.0f; if (lDriveAssoc) - lDriveAssoc->blendAmount = clamp(steerAngle * 100.0f / 61.0f, 0.0f, 1.0f); + lDriveAssoc->blendAmount = Clamp(steerAngle * 100.0f / 61.0f, 0.0f, 1.0f); else if (m_pMyVehicle->bLowVehicle) CAnimManager::AddAnimation(GetClump(), ASSOCGRP_STD, ANIM_STD_CAR_DRIVE_LEFT_LO); else @@ -3022,7 +3049,7 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) CColModel *hisCol = CModelInfo::GetModelInfo(collidingEnt->GetModelIndex())->GetColModel(); if (!bUsesCollision) - return false; + return 0; if (collidingEnt->IsVehicle() && ((CVehicle*)collidingEnt)->IsBoat()) collidedWithBoat = true; @@ -6067,7 +6094,7 @@ CPed::FollowPath(void) } void -CPed::SetEvasiveStep(CEntity *reason, uint8 animType) +CPed::SetEvasiveStep(CPhysical *reason, uint8 animType) { AnimationId stepAnim; @@ -6085,22 +6112,23 @@ CPed::SetEvasiveStep(CEntity *reason, uint8 animType) if (neededTurn > PI) neededTurn = TWOPI - neededTurn; - CVehicle *veh = (CVehicle*)reason; - if (reason->IsVehicle() && veh->m_vehType == VEHICLE_TYPE_CAR) { + if (reason->IsVehicle() && ((CVehicle*)reason)->IsCar()) { + CVehicle *veh = (CVehicle*)reason; if (veh->m_nCarHornTimer != 0) { vehPressedHorn = true; if (!IsPlayer()) animType = 1; } } - if (neededTurn <= DEGTORAD(90.0f) || veh->GetModelIndex() == MI_RCBANDIT || vehPressedHorn || animType != 0) { - SetLookFlag(veh, true); - if ((CGeneral::GetRandomNumber() & 1) && veh->GetModelIndex() != MI_RCBANDIT && animType == 0) { + + if (neededTurn <= DEGTORAD(90.0f) || reason->GetModelIndex() == MI_RCBANDIT || vehPressedHorn || animType != 0) { + SetLookFlag(reason, true); + if ((CGeneral::GetRandomNumber() & 1) && reason->GetModelIndex() != MI_RCBANDIT && animType == 0) { stepAnim = ANIM_STD_HAILTAXI; } else { - float vehDirection = CGeneral::GetRadianAngleBetweenPoints( - veh->m_vecMoveSpeed.x, veh->m_vecMoveSpeed.y, + float dangerDirection = CGeneral::GetRadianAngleBetweenPoints( + reason->m_vecMoveSpeed.x, reason->m_vecMoveSpeed.y, 0.0f, 0.0f); // Let's turn our back to the "reason" @@ -6110,14 +6138,14 @@ CPed::SetEvasiveStep(CEntity *reason, uint8 animType) angleToFace -= TWOPI; // We don't want to run towards car's direction - float dangerZone = angleToFace - vehDirection; + float dangerZone = angleToFace - dangerDirection; dangerZone = CGeneral::LimitRadianAngle(dangerZone); // So, add or subtract 90deg (jump to left/right) according to that if (dangerZone > 0.0f) - angleToFace = vehDirection - HALFPI; + angleToFace = dangerDirection - HALFPI; else - angleToFace = vehDirection + HALFPI; + angleToFace = dangerDirection + HALFPI; stepAnim = ANIM_STD_NUM; if (animType == 0 || animType == 1) @@ -6983,14 +7011,21 @@ CPed::SetPedPositionInCar(void) } else { m_fRotationCur = m_pMyVehicle->GetForward().Heading(); } - GetMatrix() = newMat; + SetMatrix(newMat); } void CPed::LookForSexyPeds(void) { if ((!IsPedInControl() && m_nPedState != PED_DRIVING) - || m_lookTimer >= CTimer::GetTimeInMilliseconds() || m_nPedType != PEDTYPE_CIVMALE) + || m_lookTimer >= CTimer::GetTimeInMilliseconds() || +#ifdef FIX_BUGS + // gang members have these lines too + (!IsGangMember() && m_nPedType != PEDTYPE_CIVMALE) +#else + m_nPedType != PEDTYPE_CIVMALE +#endif + ) return; for (int i = 0; i < m_numNearPeds; i++) { @@ -6998,7 +7033,12 @@ CPed::LookForSexyPeds(void) if ((GetPosition() - m_nearPeds[i]->GetPosition()).Magnitude() < 10.0f) { CPed *nearPed = m_nearPeds[i]; if ((nearPed->m_pedStats->m_sexiness > m_pedStats->m_sexiness) +#ifdef FIX_BUGS + // react to prostitutes as well + && ((nearPed->m_nPedType == PEDTYPE_CIVFEMALE) || (nearPed->m_nPedType == PEDTYPE_PROSTITUTE))) { +#else && nearPed->m_nPedType == PEDTYPE_CIVFEMALE) { +#endif SetLookFlag(nearPed, true); m_lookTimer = CTimer::GetTimeInMilliseconds() + 4000; diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 0617a7bb..33839aa7 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -515,10 +515,10 @@ public: CVector m_vecSeekPosEx; // used for OBJECTIVE_GUARD_SPOT float m_distanceToCountSeekDoneEx; // used for OBJECTIVE_GUARD_SPOT - static void *operator new(size_t); - static void *operator new(size_t, int); - static void operator delete(void*, size_t); - static void operator delete(void*, int); + static void *operator new(size_t) throw(); + static void *operator new(size_t, int) throw(); + static void operator delete(void*, size_t) throw(); + static void operator delete(void*, int) throw(); CPed(uint32 pedType); ~CPed(void); @@ -625,7 +625,7 @@ public: void SetAimFlag(CEntity* to); void SetAimFlag(float angle); void SetAmmo(eWeaponType weaponType, uint32 ammo); - void SetEvasiveStep(CEntity*, uint8); + void SetEvasiveStep(CPhysical*, uint8); void GrantAmmo(eWeaponType, uint32); void SetEvasiveDive(CPhysical*, uint8); void SetAttack(CEntity*); diff --git a/src/peds/PedAI.cpp b/src/peds/PedAI.cpp index 7f7120af..f1c753ec 100644 --- a/src/peds/PedAI.cpp +++ b/src/peds/PedAI.cpp @@ -5362,7 +5362,7 @@ CPed::WarpPedToNearLeaderOffScreen(void) continue; appropriatePos.z = zCorrectedPos.z; - if (!TheCamera.IsSphereVisible(appropriatePos, 0.6f, &TheCamera.GetCameraMatrix()) + if (!TheCamera.IsSphereVisible(appropriatePos, 0.6f) && CWorld::GetIsLineOfSightClear(appropriatePos, warpToPos, true, true, false, true, false, false, false) && !CWorld::TestSphereAgainstWorld(appropriatePos, 0.6f, this, true, true, false, true, false, false)) { teleported = true; @@ -5396,7 +5396,7 @@ CPed::WarpPedToNearEntityOffScreen(CEntity *warpTo) continue; appropriatePos.z = zCorrectedPos.z; - if (!TheCamera.IsSphereVisible(appropriatePos, 0.6f, &TheCamera.GetCameraMatrix()) + if (!TheCamera.IsSphereVisible(appropriatePos, 0.6f) && CWorld::GetIsLineOfSightClear(appropriatePos, warpToPos, true, true, false, true, false, false, false) && !CWorld::TestSphereAgainstWorld(appropriatePos, 0.6f, this, true, true, false, true, false, false)) { teleported = true; diff --git a/src/peds/PedFight.cpp b/src/peds/PedFight.cpp index c03d492a..46ac369c 100644 --- a/src/peds/PedFight.cpp +++ b/src/peds/PedFight.cpp @@ -1044,7 +1044,7 @@ CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk) if (IsPlayer()) moveAssoc->speed = 1.3f; - m_takeAStepAfterAttack = 0; + m_takeAStepAfterAttack = false; m_fightButtonPressure = 0; } else if (IsPlayer() && m_currentWeapon != WEAPONTYPE_UNARMED) { CAnimBlendAssociation *moveAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, tFightMoves[m_curFightMove].animId, 4.0f); diff --git a/src/peds/PedIK.cpp b/src/peds/PedIK.cpp index 8bace9a0..8358a196 100644 --- a/src/peds/PedIK.cpp +++ b/src/peds/PedIK.cpp @@ -17,9 +17,9 @@ const RwV3d XaxisIK = { 1.0f, 0.0f, 0.0f}; const RwV3d YaxisIK = { 0.0f, 1.0f, 0.0f}; const RwV3d ZaxisIK = { 0.0f, 0.0f, 1.0f}; -CPedIK::CPedIK(CPed *ped) +CPedIK::CPedIK(CPed *ped) : m_ped(ped) { - m_ped = ped; + assert(ped != nil); m_flags = 0; m_headOrient.yaw = 0.0f; m_headOrient.pitch = 0.0f; @@ -194,7 +194,7 @@ CPedIK::MoveLimb(LimbOrientation &limb, float targetYaw, float targetPitch, Limb } if (limb.yaw > moveInfo.maxYaw || limb.yaw < moveInfo.minYaw) { - limb.yaw = clamp(limb.yaw, moveInfo.minYaw, moveInfo.maxYaw); + limb.yaw = Clamp(limb.yaw, moveInfo.minYaw, moveInfo.maxYaw); result = ANGLES_SET_TO_MAX; } @@ -212,7 +212,7 @@ CPedIK::MoveLimb(LimbOrientation &limb, float targetYaw, float targetPitch, Limb result = ONE_ANGLE_COULDNT_BE_SET_EXACTLY; if (limb.pitch > moveInfo.maxPitch || limb.pitch < moveInfo.minPitch) { - limb.pitch = clamp(limb.pitch, moveInfo.minPitch, moveInfo.maxPitch); + limb.pitch = Clamp(limb.pitch, moveInfo.minPitch, moveInfo.maxPitch); result = ANGLES_SET_TO_MAX; } return result; @@ -527,11 +527,11 @@ CPedIK::RestoreLookAt(void) void CPedIK::ExtractYawAndPitchWorld(RwMatrix *mat, float *yaw, float *pitch) { - float f = clamp(DotProduct(mat->up, CVector(0.0f, 1.0f, 0.0f)), -1.0f, 1.0f); + float f = Clamp(DotProduct(mat->up, CVector(0.0f, 1.0f, 0.0f)), -1.0f, 1.0f); *yaw = Acos(f); if (mat->up.x > 0.0f) *yaw = -*yaw; - f = clamp(DotProduct(mat->right, CVector(0.0f, 0.0f, 1.0f)), -1.0f, 1.0f); + f = Clamp(DotProduct(mat->right, CVector(0.0f, 0.0f, 1.0f)), -1.0f, 1.0f); *pitch = Acos(f); if (mat->up.z > 0.0f) *pitch = -*pitch; } @@ -539,11 +539,11 @@ CPedIK::ExtractYawAndPitchWorld(RwMatrix *mat, float *yaw, float *pitch) void CPedIK::ExtractYawAndPitchLocal(RwMatrix *mat, float *yaw, float *pitch) { - float f = clamp(DotProduct(mat->at, CVector(0.0f, 0.0f, 1.0f)), -1.0f, 1.0f); + float f = Clamp(DotProduct(mat->at, CVector(0.0f, 0.0f, 1.0f)), -1.0f, 1.0f); *yaw = Acos(f); if (mat->at.y > 0.0f) *yaw = -*yaw; - f = clamp(DotProduct(mat->right, CVector(1.0f, 0.0f, 0.0f)), -1.0f, 1.0f); + f = Clamp(DotProduct(mat->right, CVector(1.0f, 0.0f, 0.0f)), -1.0f, 1.0f); *pitch = Acos(f); if (mat->up.x > 0.0f) *pitch = -*pitch; } diff --git a/src/peds/PedIK.h b/src/peds/PedIK.h index 4eeef6f0..9077fbea 100644 --- a/src/peds/PedIK.h +++ b/src/peds/PedIK.h @@ -34,7 +34,7 @@ public: AIMS_WITH_ARM = 4, }; - CPed *m_ped; + CPed *Const m_ped; LimbOrientation m_headOrient; LimbOrientation m_torsoOrient; LimbOrientation m_upperArmOrient; diff --git a/src/peds/PedType.cpp b/src/peds/PedType.cpp index bacb1a78..dcd4c717 100644 --- a/src/peds/PedType.cpp +++ b/src/peds/PedType.cpp @@ -3,6 +3,7 @@ #include "General.h" #include "FileMgr.h" #include "PedType.h" +#include "SaveBuf.h" CPedType *CPedType::ms_apPedType[NUM_PEDTYPES]; CPedStats *CPedStats::ms_apPedStats[NUM_PEDSTATS]; @@ -201,7 +202,7 @@ INITSAVEBUF CheckSaveHeader(buf, 'P', 'T', 'P', '\0', size - SAVE_HEADER_SIZE); for(int i = 0; i < NUM_PEDTYPES; i++) - *ms_apPedType[i] = ReadSaveBuf<CPedType>(buf); + ReadSaveBuf(ms_apPedType[i], buf); VALIDATESAVEBUF(size) } diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index 53187d0b..93a403bd 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -16,6 +16,7 @@ #include "Pools.h" #include "Darkel.h" #include "CarCtrl.h" +#include "SaveBuf.h" #define PAD_MOVE_TO_GAME_WORLD_MOVE 60.0f @@ -681,8 +682,8 @@ CPlayerPed::PlayerControlFighter(CPad *padUsed) if (padMove > 0.0f) { m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(0.0f, 0.0f, -leftRight, upDown) - TheCamera.Orientation; - m_takeAStepAfterAttack = padMove > 2 * PAD_MOVE_TO_GAME_WORLD_MOVE; - if (padUsed->GetSprint() && padMove > 1 * PAD_MOVE_TO_GAME_WORLD_MOVE) + m_takeAStepAfterAttack = padMove > (2 * PAD_MOVE_TO_GAME_WORLD_MOVE); + if (padUsed->GetSprint() && padMove > (1 * PAD_MOVE_TO_GAME_WORLD_MOVE)) bIsAttacking = false; } @@ -714,7 +715,7 @@ CPlayerPed::PlayerControl1stPersonRunAround(CPad *padUsed) if (m_nPedState == PED_JUMP) { if (bIsInTheAir) { if (bUsesCollision && !bHitSteepSlope && (!bHitSomethingLastFrame || m_vecDamageNormal.z > 0.6f) - && m_fDistanceTravelled < CTimer::GetTimeStep() * 0.02 && m_vecMoveSpeed.MagnitudeSqr() < 0.01f) { + && m_fDistanceTravelled < CTimer::GetTimeStepInSeconds() && m_vecMoveSpeed.MagnitudeSqr() < 0.01f) { float angleSin = Sin(m_fRotationCur); // originally sin(DEGTORAD(RADTODEG(m_fRotationCur))) o_O float angleCos = Cos(m_fRotationCur); @@ -1205,7 +1206,7 @@ CPlayerPed::PlayerControlZelda(CPad *padUsed) if (m_nPedState == PED_JUMP) { if (bIsInTheAir) { if (bUsesCollision && !bHitSteepSlope && (!bHitSomethingLastFrame || m_vecDamageNormal.z > 0.6f) - && m_fDistanceTravelled < CTimer::GetTimeStep() * 0.02 && m_vecMoveSpeed.MagnitudeSqr() < 0.01f) { + && m_fDistanceTravelled < CTimer::GetTimeStepInSeconds() && m_vecMoveSpeed.MagnitudeSqr() < 0.01f) { float angleSin = Sin(m_fRotationCur); // originally sin(DEGTORAD(RADTODEG(m_fRotationCur))) o_O float angleCos = Cos(m_fRotationCur); diff --git a/src/peds/Population.cpp b/src/peds/Population.cpp index a0bf8be6..ace6d37c 100644 --- a/src/peds/Population.cpp +++ b/src/peds/Population.cpp @@ -484,7 +484,7 @@ CPopulation::PedCreationDistMultiplier() return 1.0f; float vehSpeed = veh->m_vecMoveSpeed.Magnitude2D(); - return clamp(vehSpeed - 0.1f + 1.0f, 1.0f, 1.5f); + return Clamp(vehSpeed - 0.1f + 1.0f, 1.0f, 1.5f); } CPed* @@ -706,8 +706,7 @@ CPopulation::AddToPopulation(float minDist, float maxDist, float minDistOffScree generatedCoors.z = Max(generatedCoors.z, groundZ); } bool farEnoughToAdd = true; - CMatrix mat(TheCamera.GetCameraMatrix()); - if (TheCamera.IsSphereVisible(generatedCoors, 2.0f, &mat)) { + if (TheCamera.IsSphereVisible(generatedCoors, 2.0f)) { if (PedCreationDistMultiplier() * MIN_CREATION_DIST > (generatedCoors - playerCentreOfWorld).Magnitude2D()) farEnoughToAdd = false; } @@ -945,10 +944,9 @@ CPopulation::MoveCarsAndPedsOutOfAbandonedZones() void CPopulation::ConvertAllObjectsToDummyObjects() { - int poolSize = CPools::GetObjectPool()->GetSize(); - for (int poolIndex = poolSize - 1; poolIndex >= 0; poolIndex--) { - - CObject *obj = CPools::GetObjectPool()->GetSlot(poolIndex); + uint32 i = CPools::GetObjectPool()->GetSize(); + while(i--) { + CObject *obj = CPools::GetObjectPool()->GetSlot(i); if (obj) { if (obj->CanBeDeleted()) ConvertToDummyObject(obj); @@ -1012,27 +1010,30 @@ CPopulation::TestSafeForRealObject(CDummyObject *dummy) { CPtrNode *ptrNode; CColModel *dummyCol = dummy->GetColModel(); - float colRadius = dummy->GetBoundRadius(); - CVector colCentre = dummy->GetBoundCentre(); - int minX = CWorld::GetSectorIndexX(dummy->GetPosition().x - colRadius); + float radius = dummyCol->boundingSphere.radius; + int minX = CWorld::GetSectorIndexX(dummy->GetPosition().x - radius); if (minX < 0) minX = 0; - int minY = CWorld::GetSectorIndexY(dummy->GetPosition().y - colRadius); + int minY = CWorld::GetSectorIndexY(dummy->GetPosition().y - radius); if (minY < 0) minY = 0; - int maxX = CWorld::GetSectorIndexX(dummy->GetPosition().x + colRadius); + int maxX = CWorld::GetSectorIndexX(dummy->GetPosition().x + radius); #ifdef FIX_BUGS if (maxX >= NUMSECTORS_X) maxX = NUMSECTORS_X - 1; #else if (maxX >= NUMSECTORS_X) maxX = NUMSECTORS_X; #endif - int maxY = CWorld::GetSectorIndexY(dummy->GetPosition().y + colRadius); + int maxY = CWorld::GetSectorIndexY(dummy->GetPosition().y + radius); #ifdef FIX_BUGS if (maxY >= NUMSECTORS_Y) maxY = NUMSECTORS_Y - 1; #else if (maxY >= NUMSECTORS_Y) maxY = NUMSECTORS_Y; #endif + float colRadius = dummy->GetBoundRadius(); + CVUVECTOR colCentre; + dummy->GetBoundCentre(colCentre); + static CColPoint aTempColPoints[MAX_COLLISION_POINTS]; for (int curY = minY; curY <= maxY; curY++) { diff --git a/src/render/Console.h b/src/render/Console.h index b4fa60c4..9f22236f 100644 --- a/src/render/Console.h +++ b/src/render/Console.h @@ -23,3 +23,5 @@ public: }; extern CConsole TheConsole; + +void cprintf(char*, ...);
\ No newline at end of file diff --git a/src/render/Coronas.cpp b/src/render/Coronas.cpp index 68e57b16..e9f9e662 100644 --- a/src/render/Coronas.cpp +++ b/src/render/Coronas.cpp @@ -481,7 +481,7 @@ CCoronas::RenderReflections(void) if(spriteCoors.z < drawDist){ float fadeDistance = drawDist / 2.0f; float distanceFade = spriteCoors.z < fadeDistance ? 1.0f : 1.0f - (spriteCoors.z - fadeDistance)/fadeDistance; - distanceFade = clamp(distanceFade, 0.0f, 1.0f); + distanceFade = Clamp(distanceFade, 0.0f, 1.0f); float recipz = 1.0f/RwCameraGetNearClipPlane(Scene.camera); float heightFade = (20.0f - aCoronas[i].heightAboveRoad)/20.0f; int intensity = distanceFade*heightFade * 230.0 * CWeather::WetRoads; diff --git a/src/render/Glass.cpp b/src/render/Glass.cpp index ede06ba1..cc45648c 100644 --- a/src/render/Glass.cpp +++ b/src/render/Glass.cpp @@ -139,9 +139,9 @@ CFallingGlassPane::Render(void) uint8 alpha = CGlass::CalcAlphaWithNormal(&fwdNorm); #ifdef FIX_BUGS - uint16 time = clamp(CTimer::GetTimeInMilliseconds() > m_nTimer ? CTimer::GetTimeInMilliseconds() - m_nTimer : 0u, 0u, 500u); + uint16 time = Clamp(CTimer::GetTimeInMilliseconds() > m_nTimer ? CTimer::GetTimeInMilliseconds() - m_nTimer : 0u, 0u, 500u); #else - uint16 time = clamp(CTimer::GetTimeInMilliseconds() - m_nTimer, 0, 500); + uint16 time = Clamp(CTimer::GetTimeInMilliseconds() - m_nTimer, 0, 500); #endif uint8 color = int32( float(alpha) * (float(time) / 500) ); diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 4991e024..bba8c525 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -75,6 +75,12 @@ #define SCALE_AND_CENTER_X_FIX(a) (a) #endif +#ifdef FIX_BUGS +#define FRAMECOUNTER CTimer::GetLogicalFrameCounter() +#else +#define FRAMECOUNTER CTimer::GetFrameCounter() +#endif + // Game has colors inlined in code. // For easier modification we collect them here: CRGBA MONEY_COLOR(89, 115, 150, 255); @@ -577,12 +583,12 @@ void CHud::Draw() CFont::SetPropOff(); CFont::SetFontStyle(FONT_HEADING); - if (m_ItemToFlash == ITEM_HEALTH && CTimer::GetFrameCounter() & 8 + if (m_ItemToFlash == ITEM_HEALTH && FRAMECOUNTER & 8 || m_ItemToFlash != ITEM_HEALTH || FindPlayerPed()->m_fHealth < 10 - && CTimer::GetFrameCounter() & 8) { + && FRAMECOUNTER & 8) { if (FindPlayerPed()->m_fHealth >= 10 - || FindPlayerPed()->m_fHealth < 10 && CTimer::GetFrameCounter() & 8) { + || FindPlayerPed()->m_fHealth < 10 && FRAMECOUNTER & 8) { AsciiToUnicode("{", sPrintIcon); #ifdef FIX_BUGS @@ -594,14 +600,14 @@ void CHud::Draw() CFont::SetColor(CRGBA(0, 0, 0, 255)); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(HEALTH_X) + SCREEN_SCALE_X_FIX(2.0f), SCREEN_SCALE_Y(65.0f) + SCREEN_SCALE_Y_FIX(2.0f), sPrint); - if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss + 2000 || CTimer::GetFrameCounter() & 4) + if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss + 2000 || FRAMECOUNTER & 4) CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(HEALTH_X) + SCREEN_SCALE_X_FIX(2.0f) - SCREEN_SCALE_X(56.0f) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(65.0f) + SCREEN_SCALE_Y_FIX(2.0f), sPrintIcon); CFont::SetColor(HEALTH_COLOR); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(HEALTH_X), SCREEN_SCALE_Y(65.0f), sPrint); - if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss + 2000 || CTimer::GetFrameCounter() & 4) + if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss + 2000 || FRAMECOUNTER & 4) CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(HEALTH_X) + SCREEN_SCALE_X_FIX(2.0f) - SCREEN_SCALE_X(56.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); } } @@ -609,7 +615,7 @@ void CHud::Draw() /* DrawArmour */ - if (m_ItemToFlash == ITEM_ARMOUR && CTimer::GetFrameCounter() & 8 || m_ItemToFlash != ITEM_ARMOUR) { + if (m_ItemToFlash == ITEM_ARMOUR && FRAMECOUNTER & 8 || m_ItemToFlash != ITEM_ARMOUR) { CFont::SetScale(SCREEN_SCALE_X(0.8f), SCREEN_SCALE_Y(1.35f)); if (FindPlayerPed()->m_fArmour > 1.0f) { AsciiToUnicode("[", sPrintIcon); @@ -623,14 +629,14 @@ void CHud::Draw() CFont::SetColor(CRGBA(0, 0, 0, 255)); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f) + SCREEN_SCALE_X_FIX(2.0f), SCREEN_SCALE_Y(65.0f) + SCREEN_SCALE_Y_FIX(2.0f), sPrint); - if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || CTimer::GetFrameCounter() & 4) + if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || FRAMECOUNTER & 4) CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f) + SCREEN_SCALE_X_FIX(2.0f) - SCREEN_SCALE_X(54.0f) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(65.0f) + SCREEN_SCALE_Y_FIX(2.0f), sPrintIcon); CFont::SetColor(ARMOUR_COLOR); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f), SCREEN_SCALE_Y(65.0f), sPrint); - if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || CTimer::GetFrameCounter() & 1) { + if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || FRAMECOUNTER & 1) { CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f) - SCREEN_SCALE_X(54.0f) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); } } @@ -657,7 +663,7 @@ void CHud::Draw() if (FindPlayerPed()->m_pWanted->GetWantedLevel() > i && (CTimer::GetTimeInMilliseconds() > FindPlayerPed()->m_pWanted->m_nLastWantedLevelChange - + 2000 || CTimer::GetFrameCounter() & 4)) { + + 2000 || FRAMECOUNTER & 4)) { CFont::SetColor(WANTED_COLOR); CFont::PrintString(fStarsX, SCREEN_SCALE_Y(87.0f), sPrintIcon); @@ -904,7 +910,7 @@ void CHud::Draw() TimerFlashTimer = 0; } - if (CTimer::GetFrameCounter() & 4 || !TimerFlashTimer) { + if (FRAMECOUNTER & 4 || !TimerFlashTimer) { AsciiToUnicode(CUserDisplay::OnscnTimer.m_sEntries[0].m_bTimerBuffer, sTimer); CFont::SetPropOn(); CFont::SetBackgroundOff(); @@ -941,7 +947,7 @@ void CHud::Draw() CounterFlashTimer = 0; } - if (CTimer::GetFrameCounter() & 4 || !CounterFlashTimer) { + if (FRAMECOUNTER & 4 || !CounterFlashTimer) { if (CUserDisplay::OnscnTimer.m_sEntries[0].m_nType == COUNTER_DISPLAY_NUMBER) { AsciiToUnicode(CUserDisplay::OnscnTimer.m_sEntries[0].m_bCounterBuffer, sTimer); CFont::SetPropOn(); @@ -1053,7 +1059,7 @@ void CHud::Draw() /* DrawRadar */ - if (m_ItemToFlash == ITEM_RADAR && CTimer::GetFrameCounter() & 8 || m_ItemToFlash != ITEM_RADAR) { + if (m_ItemToFlash == ITEM_RADAR && FRAMECOUNTER & 8 || m_ItemToFlash != ITEM_RADAR) { CRadar::DrawMap(); CRect rect(0.0f, 0.0f, SCREEN_SCALE_X(RADAR_WIDTH), SCREEN_SCALE_Y(RADAR_HEIGHT)); rect.Translate(SCREEN_SCALE_X_FIX(RADAR_LEFT), SCREEN_SCALE_FROM_BOTTOM(RADAR_BOTTOM + RADAR_HEIGHT)); diff --git a/src/render/Particle.cpp b/src/render/Particle.cpp index 07e80abe..76ddde50 100644 --- a/src/render/Particle.cpp +++ b/src/render/Particle.cpp @@ -14,6 +14,7 @@ #include "ParticleObject.h" #include "Particle.h" #include "soundlist.h" +#include "debugmenu.h" #define MAX_PARTICLES_ON_SCREEN (1000) @@ -879,15 +880,15 @@ CParticle *CParticle::AddParticle(tParticleType type, CVector const &vecPos, CVe int32 ColorVariation = CGeneral::GetRandomNumberInRange(-psystem->m_InitialColorVariation, psystem->m_InitialColorVariation); //Float ColorVariation = CGeneral::GetRandomNumberInRange((float)-psystem->m_InitialColorVariation, (float)psystem->m_InitialColorVariation); - pParticle->m_Color.red = clamp(pParticle->m_Color.red + + pParticle->m_Color.red = Clamp(pParticle->m_Color.red + PERCENT(pParticle->m_Color.red, ColorVariation), 0, 255); - pParticle->m_Color.green = clamp(pParticle->m_Color.green + + pParticle->m_Color.green = Clamp(pParticle->m_Color.green + PERCENT(pParticle->m_Color.green, ColorVariation), 0, 255); - pParticle->m_Color.blue = clamp(pParticle->m_Color.blue + + pParticle->m_Color.blue = Clamp(pParticle->m_Color.blue + PERCENT(pParticle->m_Color.blue, ColorVariation), 0, 255); } @@ -1082,15 +1083,15 @@ void CParticle::Update() { float colorMul = 1.0f - float(particle->m_nTimeWhenColorWillBeChanged - CTimer::GetTimeInMilliseconds()) / float(psystem->m_ColorFadeTime); - particle->m_Color.red = clamp( + particle->m_Color.red = Clamp( psystem->m_RenderColouring.red + int32(float(psystem->m_FadeDestinationColor.red - psystem->m_RenderColouring.red) * colorMul), 0, 255); - particle->m_Color.green = clamp( + particle->m_Color.green = Clamp( psystem->m_RenderColouring.green + int32(float(psystem->m_FadeDestinationColor.green - psystem->m_RenderColouring.green) * colorMul), 0, 255); - particle->m_Color.blue = clamp( + particle->m_Color.blue = Clamp( psystem->m_RenderColouring.blue + int32(float(psystem->m_FadeDestinationColor.blue - psystem->m_RenderColouring.blue) * colorMul), 0, 255); } @@ -1379,7 +1380,7 @@ void CParticle::Update() { particle->m_nFadeToBlackTimer = 0; - particle->m_nColorIntensity = clamp(particle->m_nColorIntensity - psystem->m_nFadeToBlackAmount, + particle->m_nColorIntensity = Clamp(particle->m_nColorIntensity - psystem->m_nFadeToBlackAmount, 0, 255); } else @@ -1392,7 +1393,7 @@ void CParticle::Update() { particle->m_nFadeAlphaTimer = 0; - particle->m_nAlpha = clamp(particle->m_nAlpha - psystem->m_nFadeAlphaAmount, + particle->m_nAlpha = Clamp(particle->m_nAlpha - psystem->m_nFadeAlphaAmount, 0, 255); #ifdef PC_PARTICLE if ( particle->m_nAlpha == 0 ) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 9e60fe22..1c0bd445 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -75,6 +75,8 @@ int32 CRenderer::ms_nNoOfVisibleVehicles; CEntity *CRenderer::ms_aVisibleVehiclePtrs[NUMVISIBLEENTITIES]; int32 CRenderer::ms_nNoOfVisibleBuildings; CEntity *CRenderer::ms_aVisibleBuildingPtrs[NUMVISIBLEENTITIES]; + +CLinkList<EntityInfo> gSortedBuildings; #endif CVector CRenderer::ms_vecCameraPosition; @@ -82,14 +84,6 @@ CVehicle *CRenderer::m_pFirstPersonVehicle; bool CRenderer::m_loadingPriority; float CRenderer::ms_lodDistScale = 1.2f; -#ifdef EXTRA_MODEL_FLAGS -#define BACKFACE_CULLING_ON SetCullMode(rwCULLMODECULLBACK) -#define BACKFACE_CULLING_OFF SetCullMode(rwCULLMODECULLNONE) -#else -#define BACKFACE_CULLING_ON -#define BACKFACE_CULLING_OFF -#endif - // unused BlockedRange CRenderer::aBlockedRanges[16]; BlockedRange *CRenderer::pFullBlockedRanges; @@ -100,12 +94,18 @@ CRenderer::Init(void) { gSortedVehiclesAndPeds.Init(40); SortBIGBuildings(); +#ifdef NEW_RENDERER + gSortedBuildings.Init(NUMVISIBLEENTITIES); +#endif } void CRenderer::Shutdown(void) { gSortedVehiclesAndPeds.Shutdown(); +#ifdef NEW_RENDERER + gSortedBuildings.Shutdown(); +#endif } void @@ -122,8 +122,12 @@ CRenderer::PreRender(void) for(i = 0; i < ms_nNoOfVisibleVehicles; i++) ms_aVisibleVehiclePtrs[i]->PreRender(); // How is this done with cWorldStream? - for(i = 0; i < ms_nNoOfVisibleBuildings; i++) - ms_aVisibleBuildingPtrs[i]->PreRender(); + //for(i = 0; i < ms_nNoOfVisibleBuildings; i++) + // ms_aVisibleBuildingPtrs[i]->PreRender(); + for(CLink<EntityInfo> *node = gSortedBuildings.head.next; + node != &gSortedBuildings.tail; + node = node->next) + ((CEntity*)node->item.ent)->PreRender(); for(node = CVisibilityPlugins::m_alphaBuildingList.head.next; node != &CVisibilityPlugins::m_alphaBuildingList.tail; node = node->next) @@ -442,6 +446,14 @@ CRenderer::RenderOneBuilding(CEntity *ent, float camdist) RpAtomic *atomic = (RpAtomic*)ent->m_rwObject; CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->GetModelIndex()); +#ifdef EXTRA_MODEL_FLAGS + bool resetCull = false; + if(!ent->IsBuilding() || mi->RenderDoubleSided()){ + resetCull = true; + BACKFACE_CULLING_OFF; + } +#endif + int pass = PASS_BLEND; if(mi->m_additive) // very questionable pass = PASS_ADD; @@ -471,6 +483,11 @@ CRenderer::RenderOneBuilding(CEntity *ent, float camdist) }else WorldRender::AtomicFirstPass(atomic, pass); +#ifdef EXTRA_MODEL_FLAGS + if(resetCull) + BACKFACE_CULLING_ON; +#endif + ent->bImBeingRendered = false; // TODO: this seems wrong, but do we even need it? } @@ -482,6 +499,7 @@ CRenderer::RenderWorld(int pass) CLink<CVisibilityPlugins::AlphaObjectInfo> *node; RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + BACKFACE_CULLING_ON; DeActivateDirectional(); SetAmbientColours(); @@ -491,11 +509,20 @@ CRenderer::RenderWorld(int pass) // Roads PUSH_RENDERGROUP("CRenderer::RenderWorld - Roads"); RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); +/* for(i = 0; i < ms_nNoOfVisibleBuildings; i++){ e = ms_aVisibleBuildingPtrs[i]; if(e->bIsBIGBuilding || IsRoad(e)) RenderOneBuilding(e); } +*/ + for(CLink<EntityInfo> *node = gSortedBuildings.tail.prev; + node != &gSortedBuildings.head; + node = node->prev){ + e = node->item.ent; + if(e->bIsBIGBuilding || IsRoad(e)) + RenderOneBuilding(e); + } for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev; node != &CVisibilityPlugins::m_alphaBuildingList.head; node = node->prev){ @@ -516,11 +543,20 @@ CRenderer::RenderWorld(int pass) // Opaque PUSH_RENDERGROUP("CRenderer::RenderWorld - Opaque"); RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); +/* for(i = 0; i < ms_nNoOfVisibleBuildings; i++){ e = ms_aVisibleBuildingPtrs[i]; if(!(e->bIsBIGBuilding || IsRoad(e))) RenderOneBuilding(e); } +*/ + for(CLink<EntityInfo> *node = gSortedBuildings.tail.prev; + node != &gSortedBuildings.head; + node = node->prev){ + e = node->item.ent; + if(!(e->bIsBIGBuilding || IsRoad(e))) + RenderOneBuilding(e); + } for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev; node != &CVisibilityPlugins::m_alphaBuildingList.head; node = node->prev){ @@ -634,6 +670,7 @@ CRenderer::ClearForFrame(void) ms_nNoOfVisibleBuildings = 0; ms_nNoOfInVisibleEntities = 0; gSortedVehiclesAndPeds.Clear(); + gSortedBuildings.Clear(); WorldRender::numBlendInsts[PASS_NOZ] = 0; WorldRender::numBlendInsts[PASS_ADD] = 0; @@ -1432,9 +1469,13 @@ CRenderer::InsertEntityIntoList(CEntity *ent) // TODO: there are more flags being checked here if(gbNewRenderer && (ent->IsVehicle() || ent->IsPed())) ms_aVisibleVehiclePtrs[ms_nNoOfVisibleVehicles++] = ent; - else if(gbNewRenderer && ent->IsBuilding()) - ms_aVisibleBuildingPtrs[ms_nNoOfVisibleBuildings++] = ent; - else + else if(gbNewRenderer && ent->IsBuilding()){ + EntityInfo info; + info.ent = ent; + info.sort = -(ent->GetPosition() - ms_vecCameraPosition).MagnitudeSqr(); + gSortedBuildings.InsertSorted(info); +// ms_aVisibleBuildingPtrs[ms_nNoOfVisibleBuildings++] = ent; + }else #endif ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent; } @@ -1451,7 +1492,7 @@ CRenderer::ScanBigBuildingList(CPtrList &list) // all missing from game actually TestedBigBuildings++; #endif - if(!ent->bZoneCulled){ + if(!ent->bZoneCulled || gbDisableZoneCull){ if(SetupBigBuildingVisibility(ent) == VIS_VISIBLE) InsertEntityIntoList(ent); #ifndef MASTER diff --git a/src/render/Renderer.h b/src/render/Renderer.h index 35b43a0b..0322939c 100644 --- a/src/render/Renderer.h +++ b/src/render/Renderer.h @@ -10,6 +10,14 @@ class CEntity; #define FADE_DISTANCE 20.0f #define STREAM_DISTANCE 30.0f +#ifdef EXTRA_MODEL_FLAGS +#define BACKFACE_CULLING_ON SetCullMode(rwCULLMODECULLBACK) +#define BACKFACE_CULLING_OFF SetCullMode(rwCULLMODECULLNONE) +#else +#define BACKFACE_CULLING_ON +#define BACKFACE_CULLING_OFF +#endif + extern bool gbShowPedRoadGroups; extern bool gbShowCarRoadGroups; extern bool gbShowCollisionPolys; diff --git a/src/render/Sprite.cpp b/src/render/Sprite.cpp index a441e08b..3fef0733 100644 --- a/src/render/Sprite.cpp +++ b/src/render/Sprite.cpp @@ -405,13 +405,13 @@ CSprite::RenderBufferedOneXLUSprite_Rotate_2Colours(float x, float y, float z, f // Colour factors, cx/y is the direction in which colours change from rgb1 to rgb2 cf[0] = (cx*(-c-s) + cy*(-c+s))*0.5f + 0.5f; - cf[0] = clamp(cf[0], 0.0f, 1.0f); + cf[0] = Clamp(cf[0], 0.0f, 1.0f); cf[1] = (cx*(-c+s) + cy*( c+s))*0.5f + 0.5f; - cf[1] = clamp(cf[1], 0.0f, 1.0f); + cf[1] = Clamp(cf[1], 0.0f, 1.0f); cf[2] = (cx*( c+s) + cy*( c-s))*0.5f + 0.5f; - cf[2] = clamp(cf[2], 0.0f, 1.0f); + cf[2] = Clamp(cf[2], 0.0f, 1.0f); cf[3] = (cx*( c-s) + cy*(-c-s))*0.5f + 0.5f; - cf[3] = clamp(cf[3], 0.0f, 1.0f); + cf[3] = Clamp(cf[3], 0.0f, 1.0f); float screenz = m_f2DNearScreenZ + (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / diff --git a/src/render/WaterLevel.cpp b/src/render/WaterLevel.cpp index bccaea39..7001c0cf 100644 --- a/src/render/WaterLevel.cpp +++ b/src/render/WaterLevel.cpp @@ -126,10 +126,10 @@ CWaterLevel::Initialise(Const char *pWaterDat) #ifdef FIX_BUGS // water.dat has rects that go out of bounds // which causes memory corruption - l = clamp(l, 0, MAX_SMALL_SECTORS - 1); - r = clamp(r, 0, MAX_SMALL_SECTORS - 1); - t = clamp(t, 0, MAX_SMALL_SECTORS - 1); - b = clamp(b, 0, MAX_SMALL_SECTORS - 1); + l = Clamp(l, 0, MAX_SMALL_SECTORS - 1); + r = Clamp(r, 0, MAX_SMALL_SECTORS - 1); + t = Clamp(t, 0, MAX_SMALL_SECTORS - 1); + b = Clamp(b, 0, MAX_SMALL_SECTORS - 1); #endif for (int32 x = l; x <= r; x++) @@ -432,14 +432,14 @@ CWaterLevel::TestVisibilityForFineWaterBlocks(const CVector &worldPos) if ((lineEnd.x > WORLD_MIN_X && lineEnd.x < WORLD_MAX_X) && (lineEnd.y > WORLD_MIN_Y && lineEnd.y < WORLD_MAX_Y)) { - if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false, nil)) + if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false)) { lineStart.x += 0.4f; lineStart.y += 0.4f; lineEnd.x += 0.4f; lineEnd.y += 0.4f; - if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false, nil)) + if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false)) { return false; } @@ -713,10 +713,10 @@ CWaterLevel::RenderWater() if ( bUseCamEndY ) nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y); - nStartX = clamp(nStartX, 0, MAX_HUGE_SECTORS - 1); - nEndX = clamp(nEndX, 0, MAX_HUGE_SECTORS - 1); - nStartY = clamp(nStartY, 0, MAX_HUGE_SECTORS - 1); - nEndY = clamp(nEndY, 0, MAX_HUGE_SECTORS - 1); + nStartX = Clamp(nStartX, 0, MAX_HUGE_SECTORS - 1); + nEndX = Clamp(nEndX, 0, MAX_HUGE_SECTORS - 1); + nStartY = Clamp(nStartY, 0, MAX_HUGE_SECTORS - 1); + nEndY = Clamp(nEndY, 0, MAX_HUGE_SECTORS - 1); for ( int32 x = nStartX; x <= nEndX; x++ ) { @@ -740,8 +740,7 @@ CWaterLevel::RenderWater() if ( fHugeSectorMaxRenderDistSqr > fHugeSectorDistToCamSqr ) { - if ( TheCamera.IsSphereVisible(CVector(vecHugeSectorCentre.x, vecHugeSectorCentre.y, 0.0f), SectorRadius(HUGE_SECTOR_SIZE), - &TheCamera.GetCameraMatrix()) ) + if ( TheCamera.IsSphereVisible(CVector(vecHugeSectorCentre.x, vecHugeSectorCentre.y, 0.0f), SectorRadius(HUGE_SECTOR_SIZE)) ) { if ( fHugeSectorDistToCamSqr >= SQR(500.0f) /*fHugeSectorNearDist*/ ) { @@ -782,8 +781,7 @@ CWaterLevel::RenderWater() if ( fLargeSectorDistToCamSqr < fHugeSectorMaxRenderDistSqr ) { - if ( TheCamera.IsSphereVisible(CVector(vecLargeSectorCentre.x, vecLargeSectorCentre.y, 0.0f), SectorRadius(LARGE_SECTOR_SIZE), //90.879997f, - &TheCamera.GetCameraMatrix()) ) + if ( TheCamera.IsSphereVisible(CVector(vecLargeSectorCentre.x, vecLargeSectorCentre.y, 0.0f), SectorRadius(LARGE_SECTOR_SIZE)) ) //90.879997f, { // Render four small(32x32) sectors, or one large(64x64). @@ -945,8 +943,7 @@ CWaterLevel::RenderWater() if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) { - if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE), - &TheCamera.GetCameraMatrix()) ) + if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) { RenderOneFlatExtraHugeWaterPoly( vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, @@ -979,8 +976,7 @@ CWaterLevel::RenderWater() if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) { - if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE), - &TheCamera.GetCameraMatrix()) ) + if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) { RenderOneFlatExtraHugeWaterPoly( vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, @@ -1003,8 +999,7 @@ CWaterLevel::RenderWater() if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) { - if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE), - &TheCamera.GetCameraMatrix()) ) + if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) { RenderOneFlatExtraHugeWaterPoly( vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, @@ -1411,10 +1406,10 @@ CWaterLevel::CalcDistanceToWater(float fX, float fY) int32 nStartY = WATER_TO_SMALL_SECTOR_Y(fY - fSectorMaxRenderDist) - 1; int32 nEndY = WATER_TO_SMALL_SECTOR_Y(fY + fSectorMaxRenderDist) + 1; - nStartX = clamp(nStartX, 0, MAX_SMALL_SECTORS - 1); - nEndX = clamp(nEndX, 0, MAX_SMALL_SECTORS - 1); - nStartY = clamp(nStartY, 0, MAX_SMALL_SECTORS - 1); - nEndY = clamp(nEndY, 0, MAX_SMALL_SECTORS - 1); + nStartX = Clamp(nStartX, 0, MAX_SMALL_SECTORS - 1); + nEndX = Clamp(nEndX, 0, MAX_SMALL_SECTORS - 1); + nStartY = Clamp(nStartY, 0, MAX_SMALL_SECTORS - 1); + nEndY = Clamp(nEndY, 0, MAX_SMALL_SECTORS - 1); float fDistSqr = 1.0e10f; @@ -1438,7 +1433,7 @@ CWaterLevel::CalcDistanceToWater(float fX, float fY) } } - return clamp(Sqrt(fDistSqr) - 23.0f, 0.0f, fSectorMaxRenderDist); + return Clamp(Sqrt(fDistSqr) - 23.0f, 0.0f, fSectorMaxRenderDist); } void diff --git a/src/render/Weather.cpp b/src/render/Weather.cpp index 771f85de..e57d57d6 100644 --- a/src/render/Weather.cpp +++ b/src/render/Weather.cpp @@ -114,7 +114,7 @@ void CWeather::Init(void) ForcedWeatherType = WEATHER_RANDOM; SoundHandle = DMAudio.CreateEntity(AUDIOTYPE_WEATHER, (void*)1); if (SoundHandle >= 0) - DMAudio.SetEntityStatus(SoundHandle, true); + DMAudio.SetEntityStatus(SoundHandle, TRUE); } void CWeather::Update(void) diff --git a/src/rw/MemoryMgr.cpp b/src/rw/MemoryMgr.cpp index 2379692c..b9cff043 100644 --- a/src/rw/MemoryMgr.cpp +++ b/src/rw/MemoryMgr.cpp @@ -28,10 +28,10 @@ RwMemoryFunctions memFuncs = { #ifdef USE_CUSTOM_ALLOCATOR // game seems to be using heap directly here, but this is nicer -void *operator new(size_t sz) { return MemoryMgrMalloc(sz); } -void *operator new[](size_t sz) { return MemoryMgrMalloc(sz); } -void operator delete(void *ptr) noexcept { MemoryMgrFree(ptr); } -void operator delete[](void *ptr) noexcept { MemoryMgrFree(ptr); } +void *operator new(size_t sz) throw() { return MemoryMgrMalloc(sz); } +void *operator new[](size_t sz) throw() { return MemoryMgrMalloc(sz); } +void operator delete(void *ptr) throw() { MemoryMgrFree(ptr); } +void operator delete[](void *ptr) throw() { MemoryMgrFree(ptr); } #endif void* diff --git a/src/rw/RwHelper.cpp b/src/rw/RwHelper.cpp index e98b58f6..35593722 100644 --- a/src/rw/RwHelper.cpp +++ b/src/rw/RwHelper.cpp @@ -6,11 +6,13 @@ #include "Timecycle.h" #include "skeleton.h" #include "Debug.h" +#include "MBlur.h" #if !defined(FINAL) || defined(DEBUGMENU) #include "rtcharse.h" #endif #ifndef FINAL RtCharset *debugCharset; +bool bDebugRenderGroups; #endif #ifdef PS2_ALPHA_TEST @@ -117,8 +119,11 @@ SetCullMode(uint32 mode) void PushRendergroup(const char *name) { + if(!bDebugRenderGroups) + return; #if defined(RW_OPENGL) - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, name); + if(GLAD_GL_KHR_debug) + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, name); #elif defined(RW_D3D9) static WCHAR tmp[256]; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, tmp, sizeof(tmp)); @@ -129,8 +134,11 @@ PushRendergroup(const char *name) void PopRendergroup(void) { + if(!bDebugRenderGroups) + return; #if defined(RW_OPENGL) - glPopDebugGroup(); + if(GLAD_GL_KHR_debug) + glPopDebugGroup(); #elif defined(RW_D3D9) D3DPERF_EndEvent(); #endif @@ -491,6 +499,12 @@ CameraSize(RwCamera * camera, RwRect * rect, raster->width = zRaster->width = rect->w; raster->height = zRaster->height = rect->h; #endif +#ifdef FIX_BUGS + if(CMBlur::BlurOn){ + CMBlur::MotionBlurClose(); + CMBlur::MotionBlurOpen(camera); + } +#endif } /* Figure out the view window */ diff --git a/src/rw/RwHelper.h b/src/rw/RwHelper.h index 1a5f64b1..0e04aece 100644 --- a/src/rw/RwHelper.h +++ b/src/rw/RwHelper.h @@ -1,5 +1,6 @@ #pragma once +extern bool bDebugRenderGroups; extern bool gPS2alphaTest; void OpenCharsetSafe(); diff --git a/src/rw/VisibilityPlugins.cpp b/src/rw/VisibilityPlugins.cpp index 9ea5b11c..7ff5c243 100644 --- a/src/rw/VisibilityPlugins.cpp +++ b/src/rw/VisibilityPlugins.cpp @@ -303,6 +303,8 @@ CVisibilityPlugins::RenderFadingEntities(void) #ifdef EXTRA_MODEL_FLAGS else if(mi->m_bIsTree) SetAlphaRef(128); + if(!e->IsBuilding() || mi->RenderDoubleSided()) + BACKFACE_CULLING_OFF; #endif if(e->bDistanceFade){ @@ -319,6 +321,7 @@ CVisibilityPlugins::RenderFadingEntities(void) #ifdef EXTRA_MODEL_FLAGS if(mi->m_bIsTree) SetAlphaRef(2); + BACKFACE_CULLING_ON; #endif #ifdef FIX_BUGS if(mi->GetModelType() == MITYPE_SIMPLE && mi->m_noZwrite) diff --git a/src/rw/VisibilityPlugins.h b/src/rw/VisibilityPlugins.h index f092de5a..5fb87765 100644 --- a/src/rw/VisibilityPlugins.h +++ b/src/rw/VisibilityPlugins.h @@ -117,7 +117,6 @@ public: int32 offset, int32 len); static int32 ms_framePluginOffset; - // Not actually used struct ClumpExt { ClumpVisibilityCB visibilityCB; diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index a7cafec8..23a8fd6a 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -220,6 +220,11 @@ GenericSave(int file) WriteSaveDataBlock(CStreaming::MemoryCardSave); WriteSaveDataBlock(CPedType::Save); + // sure just write garbage data repeatedly ... +#ifndef THIS_IS_STUPID + memset(work_buff, 0, sizeof(work_buff)); +#endif + // Write padding for (int i = 0; i < 4; i++) { size = align4bytes(SIZE_OF_ONE_GAME_IN_BYTES - totalSize - 4); @@ -487,7 +492,11 @@ GetNameOfSavedGame(int32 slot) bool CheckDataNotCorrupt(int32 slot, char *name) { +#ifdef FIX_BUGS + char filename[MAX_PATH]; +#else char filename[100]; +#endif int32 blocknum = 0; eLevelName level = LEVEL_GENERIC; diff --git a/src/save/PCSave.cpp b/src/save/PCSave.cpp index d8ede0d3..a9df00af 100644 --- a/src/save/PCSave.cpp +++ b/src/save/PCSave.cpp @@ -25,7 +25,11 @@ C_PcSave::SetSaveDirectory(const char *path) bool C_PcSave::DeleteSlot(int32 slot) { +#ifdef FIX_BUGS + char FileName[MAX_PATH]; +#else char FileName[200]; +#endif PcSaveHelper.nErrorCode = SAVESTATUS_SUCCESSFUL; sprintf(FileName, "%s%i.b", DefaultPCSaveFileName, slot + 1); diff --git a/src/save/SaveBuf.h b/src/save/SaveBuf.h new file mode 100644 index 00000000..98fe888b --- /dev/null +++ b/src/save/SaveBuf.h @@ -0,0 +1,64 @@ +#pragma once + +#ifdef VALIDATE_SAVE_SIZE +extern int32 _saveBufCount; +#define INITSAVEBUF _saveBufCount = 0; +#define VALIDATESAVEBUF(b) assert(_saveBufCount == b); +#else +#define INITSAVEBUF +#define VALIDATESAVEBUF(b) +#endif + +inline void +SkipSaveBuf(uint8 *&buf, int32 skip) +{ + buf += skip; +#ifdef VALIDATE_SAVE_SIZE + _saveBufCount += skip; +#endif +} + +template <typename T> +inline void +ReadSaveBuf(T* out, uint8 *&buf) +{ + *out = *(T *)buf; + SkipSaveBuf(buf, sizeof(T)); +} + +template <typename T> +inline T * +WriteSaveBuf(uint8 *&buf, const T &value) +{ + T *p = (T *)buf; + *p = value; + SkipSaveBuf(buf, sizeof(T)); + return p; +} + +#define SAVE_HEADER_SIZE (4 * sizeof(char) + sizeof(uint32)) + +#define WriteSaveHeader(buf, a, b, c, d, size) \ + WriteSaveBuf(buf, a); \ + WriteSaveBuf(buf, b); \ + WriteSaveBuf(buf, c); \ + WriteSaveBuf(buf, d); \ + WriteSaveBuf(buf, (uint32)(size)); + +#ifdef VALIDATE_SAVE_SIZE +#define CheckSaveHeader(buf, a, b, c, d, size) do { \ + char _c; uint32 _size;\ + ReadSaveBuf(&_c, buf);\ + assert(_c == a);\ + ReadSaveBuf(&_c, buf);\ + assert(_c == b);\ + ReadSaveBuf(&_c, buf);\ + assert(_c == c);\ + ReadSaveBuf(&_c, buf);\ + assert(_c == d);\ + ReadSaveBuf(&_size, buf);\ + assert(_size == size);\ + } while(0) +#else +#define CheckSaveHeader(buf, a, b, c, d, size) SkipSaveBuf(buf, 8); +#endif
\ No newline at end of file diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h index 710a7702..2dd9c162 100644 --- a/src/skel/crossplatform.h +++ b/src/skel/crossplatform.h @@ -1,4 +1,5 @@ #include <time.h> +#include <limits.h> // This is the common include for platform/renderer specific skeletons(glfw.cpp, win.cpp etc.) and using cross platform things (like Windows directories wrapper, platform specific global arrays etc.) // Functions that's different on glfw and win but have same signature, should be located on platform.h. @@ -143,7 +144,7 @@ typedef void* HANDLE; struct WIN32_FIND_DATA { char extension[32]; // for searching - char folder[32]; // for searching + char folder[MAX_PATH]; // for searching char cFileName[256]; // because tSkinInfo has it 256 time_t ftLastWriteTime; }; diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index baed9000..8d3fc7d7 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -50,17 +50,30 @@ long _dwOperatingSystemVersion; #include "Font.h" #include "MemoryMgr.h" -#define MAX_SUBSYSTEMS (16) +// We found out that GLFW's keyboard input handling is still pretty delayed/not stable, so now we fetch input from X11 directly on Linux. +#if !defined _WIN32 && !defined __APPLE__ && !defined __SWITCH__ // && !defined WAYLAND +#define GET_KEYBOARD_INPUT_FROM_X11 +#endif + +#ifdef GET_KEYBOARD_INPUT_FROM_X11 +#include <X11/Xlib.h> +#include <X11/XKBlib.h> +#define GLFW_EXPOSE_NATIVE_X11 +#include <GLFW/glfw3native.h> +#endif #ifdef _WIN32 #define GLFW_EXPOSE_NATIVE_WIN32 #include <GLFW/glfw3native.h> #endif +#define MAX_SUBSYSTEMS (16) rw::EngineOpenParams openParams; static RwBool ForegroundApp = TRUE; +static RwBool WindowIconified = FALSE; +static RwBool WindowFocused = TRUE; static RwBool RwInitialised = FALSE; @@ -322,7 +335,9 @@ psInitialize(void) RsGlobal.ps = &PsGlobal; PsGlobal.fullScreen = FALSE; - PsGlobal.cursorIsInWindow = TRUE; + PsGlobal.cursorIsInWindow = FALSE; + WindowFocused = TRUE; + WindowIconified = FALSE; PsGlobal.joy1id = -1; PsGlobal.joy2id = -1; @@ -838,11 +853,15 @@ psSelectDevice() return TRUE; } +#ifndef GET_KEYBOARD_INPUT_FROM_X11 void keypressCB(GLFWwindow* window, int key, int scancode, int action, int mods); +#endif void resizeCB(GLFWwindow* window, int width, int height); void scrollCB(GLFWwindow* window, double xoffset, double yoffset); void cursorCB(GLFWwindow* window, double xpos, double ypos); void cursorEnterCB(GLFWwindow* window, int entered); +void windowFocusCB(GLFWwindow* window, int focused); +void windowIconifyCB(GLFWwindow* window, int iconified); void joysChangeCB(int jid, int event); bool IsThisJoystickBlacklisted(int i) @@ -930,11 +949,15 @@ void psPostRWinit(void) RwVideoMode vm; RwEngineGetVideoModeInfo(&vm, GcurSelVM); +#ifndef GET_KEYBOARD_INPUT_FROM_X11 glfwSetKeyCallback(PSGLOBAL(window), keypressCB); +#endif glfwSetFramebufferSizeCallback(PSGLOBAL(window), resizeCB); glfwSetScrollCallback(PSGLOBAL(window), scrollCB); glfwSetCursorPosCallback(PSGLOBAL(window), cursorCB); glfwSetCursorEnterCallback(PSGLOBAL(window), cursorEnterCB); + glfwSetWindowIconifyCallback(PSGLOBAL(window), windowIconifyCB); + glfwSetWindowFocusCallback(PSGLOBAL(window), windowFocusCB); glfwSetJoystickCallback(joysChangeCB); _InputInitialiseJoys(); @@ -1286,6 +1309,10 @@ void scrollCB(GLFWwindow* window, double xoffset, double yoffset) { PSGLOBAL(mouseWheel) = yoffset; } +bool lshiftStatus = false; +bool rshiftStatus = false; + +#ifndef GET_KEYBOARD_INPUT_FROM_X11 int keymap[GLFW_KEY_LAST + 1]; static void @@ -1416,9 +1443,6 @@ initkeymap(void) keymap[GLFW_KEY_MENU] = rsNULL; } -bool lshiftStatus = false; -bool rshiftStatus = false; - void keypressCB(GLFWwindow* window, int key, int scancode, int action, int mods) { @@ -1436,6 +1460,266 @@ keypressCB(GLFWwindow* window, int key, int scancode, int action, int mods) } } +#else + +uint32 keymap[512]; // 256 ascii + 256 KeySyms between 0xff00 - 0xffff +bool keyStates[512]; +uint32 keyCodeToKeymapIndex[256]; // cache for physical keys + +#define KEY_MAP_OFFSET (0xff00 - 256) +static void +initkeymap(void) +{ + Display *display = glfwGetX11Display(); + int i; + + for (i = 0; i < ARRAY_SIZE(keymap); i++) + keymap[i] = rsNULL; + + // You can add new ASCII mappings to here freely (but beware that if right hand side of assignment isn't supported on CFont, it'll be blank/won't work on binding screen) + // Right hand side of assigments should always be uppercase counterpart of character + keymap[XK_space] = ' '; + keymap[XK_apostrophe] = '\''; + keymap[XK_ampersand] = '&'; + keymap[XK_percent] = '%'; + keymap[XK_dollar] = '$'; + keymap[XK_comma] = ','; + keymap[XK_minus] = '-'; + keymap[XK_period] = '.'; + keymap[XK_slash] = '/'; + keymap[XK_question] = '?'; + keymap[XK_exclam] = '!'; + keymap[XK_quotedbl] = '"'; + keymap[XK_colon] = ':'; + keymap[XK_semicolon] = ';'; + keymap[XK_equal] = '='; + keymap[XK_bracketleft] = '['; + keymap[XK_backslash] = '\\'; + keymap[XK_bracketright] = ']'; + keymap[XK_grave] = '`'; + keymap[XK_0] = '0'; + keymap[XK_1] = '1'; + keymap[XK_2] = '2'; + keymap[XK_3] = '3'; + keymap[XK_4] = '4'; + keymap[XK_5] = '5'; + keymap[XK_6] = '6'; + keymap[XK_7] = '7'; + keymap[XK_8] = '8'; + keymap[XK_9] = '9'; + keymap[XK_a] = 'A'; + keymap[XK_b] = 'B'; + keymap[XK_c] = 'C'; + keymap[XK_d] = 'D'; + keymap[XK_e] = 'E'; + keymap[XK_f] = 'F'; + keymap[XK_g] = 'G'; + keymap[XK_h] = 'H'; + keymap[XK_i] = 'I'; + keymap[XK_I] = 'I'; // Turkish I problem + keymap[XK_j] = 'J'; + keymap[XK_k] = 'K'; + keymap[XK_l] = 'L'; + keymap[XK_m] = 'M'; + keymap[XK_n] = 'N'; + keymap[XK_o] = 'O'; + keymap[XK_p] = 'P'; + keymap[XK_q] = 'Q'; + keymap[XK_r] = 'R'; + keymap[XK_s] = 'S'; + keymap[XK_t] = 'T'; + keymap[XK_u] = 'U'; + keymap[XK_v] = 'V'; + keymap[XK_w] = 'W'; + keymap[XK_x] = 'X'; + keymap[XK_y] = 'Y'; + keymap[XK_z] = 'Z'; + + // Some of regional but ASCII characters that GTA supports + keymap[XK_agrave] = 0x00c0; + keymap[XK_aacute] = 0x00c1; + keymap[XK_acircumflex] = 0x00c2; + keymap[XK_adiaeresis] = 0x00c4; + + keymap[XK_ae] = 0x00c6; + + keymap[XK_egrave] = 0x00c8; + keymap[XK_eacute] = 0x00c9; + keymap[XK_ecircumflex] = 0x00ca; + keymap[XK_ediaeresis] = 0x00cb; + + keymap[XK_igrave] = 0x00cc; + keymap[XK_iacute] = 0x00cd; + keymap[XK_icircumflex] = 0x00ce; + keymap[XK_idiaeresis] = 0x00cf; + + keymap[XK_ccedilla] = 0x00c7; + keymap[XK_odiaeresis] = 0x00d6; + keymap[XK_udiaeresis] = 0x00dc; + + // These are 0xff00 - 0xffff range of KeySym's, and subtracting KEY_MAP_OFFSET is needed + keymap[XK_Escape - KEY_MAP_OFFSET] = rsESC; + keymap[XK_Return - KEY_MAP_OFFSET] = rsENTER; + keymap[XK_Tab - KEY_MAP_OFFSET] = rsTAB; + keymap[XK_BackSpace - KEY_MAP_OFFSET] = rsBACKSP; + keymap[XK_Insert - KEY_MAP_OFFSET] = rsINS; + keymap[XK_Delete - KEY_MAP_OFFSET] = rsDEL; + keymap[XK_Right - KEY_MAP_OFFSET] = rsRIGHT; + keymap[XK_Left - KEY_MAP_OFFSET] = rsLEFT; + keymap[XK_Down - KEY_MAP_OFFSET] = rsDOWN; + keymap[XK_Up - KEY_MAP_OFFSET] = rsUP; + keymap[XK_Page_Up - KEY_MAP_OFFSET] = rsPGUP; + keymap[XK_Page_Down - KEY_MAP_OFFSET] = rsPGDN; + keymap[XK_Home - KEY_MAP_OFFSET] = rsHOME; + keymap[XK_End - KEY_MAP_OFFSET] = rsEND; + keymap[XK_Caps_Lock - KEY_MAP_OFFSET] = rsCAPSLK; + keymap[XK_Scroll_Lock - KEY_MAP_OFFSET] = rsSCROLL; + keymap[XK_Num_Lock - KEY_MAP_OFFSET] = rsNUMLOCK; + keymap[XK_Pause - KEY_MAP_OFFSET] = rsPAUSE; + + keymap[XK_F1 - KEY_MAP_OFFSET] = rsF1; + keymap[XK_F2 - KEY_MAP_OFFSET] = rsF2; + keymap[XK_F3 - KEY_MAP_OFFSET] = rsF3; + keymap[XK_F4 - KEY_MAP_OFFSET] = rsF4; + keymap[XK_F5 - KEY_MAP_OFFSET] = rsF5; + keymap[XK_F6 - KEY_MAP_OFFSET] = rsF6; + keymap[XK_F7 - KEY_MAP_OFFSET] = rsF7; + keymap[XK_F8 - KEY_MAP_OFFSET] = rsF8; + keymap[XK_F9 - KEY_MAP_OFFSET] = rsF9; + keymap[XK_F10 - KEY_MAP_OFFSET] = rsF10; + keymap[XK_F11 - KEY_MAP_OFFSET] = rsF11; + keymap[XK_F12 - KEY_MAP_OFFSET] = rsF12; + keymap[XK_F13 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F14 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F15 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F16 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F17 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F18 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F19 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F20 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F21 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F22 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F23 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F24 - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_F25 - KEY_MAP_OFFSET] = rsNULL; + + keymap[XK_KP_0 - KEY_MAP_OFFSET] = rsPADINS; + keymap[XK_KP_1 - KEY_MAP_OFFSET] = rsPADEND; + keymap[XK_KP_2 - KEY_MAP_OFFSET] = rsPADDOWN; + keymap[XK_KP_3 - KEY_MAP_OFFSET] = rsPADPGDN; + keymap[XK_KP_4 - KEY_MAP_OFFSET] = rsPADLEFT; + keymap[XK_KP_5 - KEY_MAP_OFFSET] = rsPAD5; + keymap[XK_KP_6 - KEY_MAP_OFFSET] = rsPADRIGHT; + keymap[XK_KP_7 - KEY_MAP_OFFSET] = rsPADHOME; + keymap[XK_KP_8 - KEY_MAP_OFFSET] = rsPADUP; + keymap[XK_KP_9 - KEY_MAP_OFFSET] = rsPADPGUP; + keymap[XK_KP_Insert - KEY_MAP_OFFSET] = rsPADINS; + keymap[XK_KP_End - KEY_MAP_OFFSET] = rsPADEND; + keymap[XK_KP_Down - KEY_MAP_OFFSET] = rsPADDOWN; + keymap[XK_KP_Page_Down - KEY_MAP_OFFSET] = rsPADPGDN; + keymap[XK_KP_Left - KEY_MAP_OFFSET] = rsPADLEFT; + keymap[XK_KP_Begin - KEY_MAP_OFFSET] = rsPAD5; + keymap[XK_KP_Right - KEY_MAP_OFFSET] = rsPADRIGHT; + keymap[XK_KP_Home - KEY_MAP_OFFSET] = rsPADHOME; + keymap[XK_KP_Up - KEY_MAP_OFFSET] = rsPADUP; + keymap[XK_KP_Page_Up - KEY_MAP_OFFSET] = rsPADPGUP; + + keymap[XK_KP_Decimal - KEY_MAP_OFFSET] = rsPADDEL; + keymap[XK_KP_Divide - KEY_MAP_OFFSET] = rsDIVIDE; + keymap[XK_KP_Multiply - KEY_MAP_OFFSET] = rsTIMES; + keymap[XK_KP_Subtract - KEY_MAP_OFFSET] = rsMINUS; + keymap[XK_KP_Add - KEY_MAP_OFFSET] = rsPLUS; + keymap[XK_KP_Enter - KEY_MAP_OFFSET] = rsPADENTER; + keymap[XK_KP_Equal - KEY_MAP_OFFSET] = rsNULL; + keymap[XK_Shift_L - KEY_MAP_OFFSET] = rsLSHIFT; + keymap[XK_Control_L - KEY_MAP_OFFSET] = rsLCTRL; + keymap[XK_Alt_L - KEY_MAP_OFFSET] = rsLALT; + keymap[XK_Super_L - KEY_MAP_OFFSET] = rsLWIN; + keymap[XK_Shift_R - KEY_MAP_OFFSET] = rsRSHIFT; + keymap[XK_Control_R - KEY_MAP_OFFSET] = rsRCTRL; + keymap[XK_Alt_R - KEY_MAP_OFFSET] = rsRALT; + keymap[XK_Super_R - KEY_MAP_OFFSET] = rsRWIN; + keymap[XK_Menu - KEY_MAP_OFFSET] = rsNULL; + + // Cache the key codes' key symbol equivelants, otherwise we will have to do it on each frame + // KeyCode is always in [0,255], and represents a physical key + + int min_keycode, max_keycode, keysyms_per_keycode; + KeySym *keymap, *origkeymap; + + char *keyboardLang = setlocale (LC_CTYPE, NULL); + setlocale(LC_CTYPE, ""); + + XDisplayKeycodes(display, &min_keycode, &max_keycode); + origkeymap = XGetKeyboardMapping(display, min_keycode, (max_keycode - min_keycode + 1), &keysyms_per_keycode); + keymap = origkeymap; + for (int i = min_keycode; i <= max_keycode; i++) { + int j, lastKeysym; + + lastKeysym = keysyms_per_keycode - 1; + while ((lastKeysym >= 0) && (keymap[lastKeysym] == NoSymbol)) + lastKeysym--; + + for (j = 0; j <= lastKeysym; j++) { + KeySym ks = keymap[j]; + + if (ks == NoSymbol) + continue; + + if (ks < 256) { + keyCodeToKeymapIndex[i] = ks; + break; + } else if (ks >= 0xff00 && ks < 0xffff) { + keyCodeToKeymapIndex[i] = ks - KEY_MAP_OFFSET; + break; + } + } + keymap += keysyms_per_keycode; + } + XFree(origkeymap); + + setlocale(LC_CTYPE, keyboardLang); +} +#undef KEY_MAP_OFFSET + +void checkKeyPresses() +{ + Display *display = glfwGetX11Display(); + char keys[32]; + XQueryKeymap(display, keys); + for (int i = 0; i < sizeof(keys); i++) { + for (int j = 0; j < 8; j++) { + KeyCode keycode = 8 * i + j; + uint32 keymapIndex = keyCodeToKeymapIndex[keycode]; + if (keymapIndex != 0) { + int rsCode = keymap[keymapIndex]; + if (rsCode == rsNULL) + continue; + + bool pressed = WindowFocused && !!(keys[i] & (1 << j)); + + // idk why R* does that + if (rsCode == rsLSHIFT) + lshiftStatus = pressed; + else if (rsCode == rsRSHIFT) + rshiftStatus = pressed; + + if (keyStates[keymapIndex] != pressed) { + if (pressed) { + RsKeyboardEventHandler(rsKEYDOWN, &rsCode); + } else { + RsKeyboardEventHandler(rsKEYUP, &rsCode); + } + } + + keyStates[keymapIndex] = pressed; + } + } + } + +} +#endif + // R* calls that in ControllerConfig, idk why void _InputTranslateShiftKeyUpDown(RsKeyCodes *rs) { @@ -1460,6 +1744,16 @@ cursorEnterCB(GLFWwindow* window, int entered) { PSGLOBAL(cursorIsInWindow) = !!entered; } +void +windowFocusCB(GLFWwindow* window, int focused) { + WindowFocused = !!focused; +} + +void +windowIconifyCB(GLFWwindow* window, int iconified) { + WindowIconified = !!iconified; +} + /* ***************************************************************************** */ @@ -1712,6 +2006,9 @@ main(int argc, char *argv[]) #endif { glfwPollEvents(); +#ifdef GET_KEYBOARD_INPUT_FROM_X11 + checkKeyPresses(); +#endif #ifndef MASTER if (gbModelViewer) { // This is TheModelViewerCore in LCS, but TheModelViewer on other state-machine III-VCs. @@ -1849,7 +2146,7 @@ main(int argc, char *argv[]) case GS_FRONTEND: { - if(!glfwGetWindowAttrib(PSGLOBAL(window), GLFW_ICONIFIED)) + if(!WindowIconified) RsEventHandler(rsFRONTENDIDLE, nil); #ifdef PS2_MENU diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index 86b0b214..01e56701 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -914,14 +914,14 @@ void WaitForState(FILTER_STATE State) */ void HandleGraphEvent(void) { - LONG evCode, evParam1, evParam2; + LONG evCode; + LONG_PTR evParam1, evParam2; HRESULT hr=S_OK; ASSERT(pME != nil); // Process all queued events - while (SUCCEEDED(pME->GetEvent(&evCode, (LONG_PTR *)&evParam1, - (LONG_PTR *)&evParam2, 0))) + while (SUCCEEDED(pME->GetEvent(&evCode, &evParam1, &evParam2, 0))) { // Free memory associated with callback, since we're not using it hr = pME->FreeEventParams(evCode, evParam1, evParam2); @@ -2275,7 +2275,7 @@ WinMain(HINSTANCE instance, case GS_START_UP: { #ifdef NO_MOVIES - gGameState = GS_INIT_ONCE; + gGameState = gbNoMovies ? GS_INIT_ONCE : GS_INIT_LOGO_MPEG; #else gGameState = GS_INIT_LOGO_MPEG; #endif @@ -2314,8 +2314,11 @@ WinMain(HINSTANCE instance, case GS_INIT_INTRO_MPEG: { -#ifndef NO_MOVIES +#ifdef NO_MOVIES + if (!gbNoMovies) +#endif CloseClip(); +#ifndef FIX_BUGS CoUninitialize(); #endif @@ -2351,8 +2354,11 @@ WinMain(HINSTANCE instance, case GS_INIT_ONCE: { -#ifndef NO_MOVIES +#ifdef NO_MOVIES + if (!gbNoMovies) +#endif CloseClip(); +#ifndef FIX_BUGS CoUninitialize(); #endif diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 4863b945..3de3e12b 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -45,6 +45,7 @@ #include "Object.h" #include "Automobile.h" #include "Wanted.h" +#include "SaveBuf.h" bool bAllCarCheat; // unused @@ -333,7 +334,11 @@ CAutomobile::ProcessControl(void) bool playerRemote = false; switch(GetStatus()){ case STATUS_PLAYER_REMOTE: - if(CPad::GetPad(0)->WeaponJustDown()){ +#ifdef FIX_BUGS + if (CPad::GetPad(0)->CarGunJustDown()) { +#else + if (CPad::GetPad(0)->WeaponJustDown()) { +#endif BlowUpCar(FindPlayerPed()); CRemote::TakeRemoteControlledCarFromPlayer(); } @@ -1660,7 +1665,7 @@ CAutomobile::PreRender(void) // 1.0 if directly behind car, -1.0 if in front // BUG on PC: Abs of DotProduct is taken float behindness = DotProduct(lookVector, GetForward()); - behindness = clamp(behindness, -1.0f, 1.0f); // shouldn't be necessary + behindness = Clamp(behindness, -1.0f, 1.0f); // shouldn't be necessary // 0.0 if behind car, PI if in front // Abs not necessary float angle = Abs(Acos(behindness)); @@ -2259,7 +2264,7 @@ CAutomobile::ProcessControlInputs(uint8 pad) 0.2f*CTimer::GetTimeStep(); nLastControlInput = 0; } - m_fSteerInput = clamp(m_fSteerInput, -1.0f, 1.0f); + m_fSteerInput = Clamp(m_fSteerInput, -1.0f, 1.0f); // Accelerate/Brake float acceleration = (CPad::GetPad(pad)->GetAccelerate() - CPad::GetPad(pad)->GetBrake())/255.0f; @@ -2372,7 +2377,11 @@ void CAutomobile::FireTruckControl(void) { if(this == FindPlayerVehicle()){ - if(!CPad::GetPad(0)->GetWeapon()) +#ifdef FIX_BUGS + if (!CPad::GetPad(0)->GetCarGunFired()) +#else + if (!CPad::GetPad(0)->GetWeapon()) +#endif // FIX_BUGS return; #ifdef FREE_CAM if (!CCamera::bFreeCam) @@ -2381,7 +2390,7 @@ CAutomobile::FireTruckControl(void) m_fCarGunLR += CPad::GetPad(0)->GetCarGunLeftRight() * 0.00025f * CTimer::GetTimeStep(); m_fCarGunUD += CPad::GetPad(0)->GetCarGunUpDown() * 0.0001f * CTimer::GetTimeStep(); } - m_fCarGunUD = clamp(m_fCarGunUD, 0.05f, 0.3f); + m_fCarGunUD = Clamp(m_fCarGunUD, 0.05f, 0.3f); CVector cannonPos(0.0f, 1.5f, 1.9f); @@ -2826,7 +2835,7 @@ CAutomobile::HydraulicControl(void) float limitDiff = extendedLowerLimit - normalLowerLimit; if(limitDiff != 0.0f && Abs(maxDelta/limitDiff) > 0.01f){ float f = (maxDelta + limitDiff)/2.0f/limitDiff; - f = clamp(f, 0.0f, 1.0f); + f = Clamp(f, 0.0f, 1.0f); DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_HYDRAULIC_3, f); if(f < 0.4f || f > 0.6f) setPrevRatio = true; @@ -3054,7 +3063,7 @@ CAutomobile::DoDriveByShootings(void) lookingLeft = true; if(TheCamera.Cams[TheCamera.ActiveCam].LookingRight) lookingRight = true; - } + } if(lookingLeft || lookingRight){ if(lookingLeft){ @@ -4042,7 +4051,7 @@ CAutomobile::GetHeightAboveRoad(void) void CAutomobile::PlayCarHorn(void) { - int r; + uint32 r; if(m_nCarHornTimer != 0) return; @@ -4716,7 +4725,7 @@ void CAutomobile::Load(uint8*& buf) { CVehicle::Load(buf); - Damage = ReadSaveBuf<CDamageManager>(buf); + ReadSaveBuf(&Damage, buf); SkipSaveBuf(buf, 800 - sizeof(CDamageManager)); SetupDamageAfterLoad(); } diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp index 4bbbadbd..88444e95 100644 --- a/src/vehicles/Boat.cpp +++ b/src/vehicles/Boat.cpp @@ -19,6 +19,7 @@ #include "Pools.h" #include "Pad.h" #include "Boat.h" +#include "SaveBuf.h" #define INVALID_ORIENTATION (-9999.99f) @@ -122,9 +123,9 @@ CBoat::ProcessControl(void) r = 114.75f*(CTimeCycle::GetAmbientRed() + 0.5f*CTimeCycle::GetDirectionalRed()); g = 114.75f*(CTimeCycle::GetAmbientGreen() + 0.5f*CTimeCycle::GetDirectionalGreen()); b = 114.75f*(CTimeCycle::GetAmbientBlue() + 0.5f*CTimeCycle::GetDirectionalBlue()); - r = clamp(r, 0, 255); - g = clamp(g, 0, 255); - b = clamp(b, 0, 255); + r = Clamp(r, 0, 255); + g = Clamp(g, 0, 255); + b = Clamp(b, 0, 255); splashColor.red = r; splashColor.green = g; splashColor.blue = b; @@ -133,9 +134,9 @@ CBoat::ProcessControl(void) r = 242.25f*(CTimeCycle::GetAmbientRed() + 0.5f*CTimeCycle::GetDirectionalRed()); g = 242.25f*(CTimeCycle::GetAmbientGreen() + 0.5f*CTimeCycle::GetDirectionalGreen()); b = 242.25f*(CTimeCycle::GetAmbientBlue() + 0.5f*CTimeCycle::GetDirectionalBlue()); - r = clamp(r, 0, 255); - g = clamp(g, 0, 255); - b = clamp(b, 0, 255); + r = Clamp(r, 0, 255); + g = Clamp(g, 0, 255); + b = Clamp(b, 0, 255); jetColor.red = r; jetColor.green = g; jetColor.blue = b; @@ -541,17 +542,17 @@ CBoat::ProcessControlInputs(uint8 pad) m_nPadID = 3; m_fBrake += (CPad::GetPad(pad)->GetBrake()/255.0f - m_fBrake)*0.1f; - m_fBrake = clamp(m_fBrake, 0.0f, 1.0f); + m_fBrake = Clamp(m_fBrake, 0.0f, 1.0f); if(m_fBrake < 0.05f){ m_fBrake = 0.0f; m_fAccelerate += (CPad::GetPad(pad)->GetAccelerate()/255.0f - m_fAccelerate)*0.1f; - m_fAccelerate = clamp(m_fAccelerate, 0.0f, 1.0f); + m_fAccelerate = Clamp(m_fAccelerate, 0.0f, 1.0f); }else m_fAccelerate = -m_fBrake*0.2f; m_fSteeringLeftRight += (-CPad::GetPad(pad)->GetSteeringLeftRight()/128.0f - m_fSteeringLeftRight)*0.2f; - m_fSteeringLeftRight = clamp(m_fSteeringLeftRight, -1.0f, 1.0f); + m_fSteeringLeftRight = Clamp(m_fSteeringLeftRight, -1.0f, 1.0f); float steeringSq = m_fSteeringLeftRight < 0.0f ? -SQR(m_fSteeringLeftRight) : SQR(m_fSteeringLeftRight); m_fSteerAngle = pHandling->fSteeringLock * DEGTORAD(steeringSq); diff --git a/src/vehicles/CarGen.cpp b/src/vehicles/CarGen.cpp index 7524444b..22b2fc60 100644 --- a/src/vehicles/CarGen.cpp +++ b/src/vehicles/CarGen.cpp @@ -13,6 +13,7 @@ #include "Timer.h" #include "Vehicle.h" #include "World.h" +#include "SaveBuf.h" uint8 CTheCarGenerators::ProcessCounter; uint32 CTheCarGenerators::NumOfCarGenerators; @@ -254,14 +255,17 @@ void CTheCarGenerators::LoadAllCarGenerators(uint8* buffer, uint32 size) Init(); INITSAVEBUF CheckSaveHeader(buffer, 'C','G','N','\0', size - SAVE_HEADER_SIZE); - assert(ReadSaveBuf<uint32>(buffer) == nGeneralDataSize); - NumOfCarGenerators = ReadSaveBuf<uint32>(buffer); - CurrentActiveCount = ReadSaveBuf<uint32>(buffer); - ProcessCounter = ReadSaveBuf<uint8>(buffer); - GenerateEvenIfPlayerIsCloseCounter = ReadSaveBuf<uint8>(buffer); - ReadSaveBuf<int16>(buffer); // alignment - assert(ReadSaveBuf<uint32>(buffer) == sizeof(CarGeneratorArray)); + uint32 tmp; + ReadSaveBuf(&tmp, buffer); + assert(tmp == nGeneralDataSize); + ReadSaveBuf(&NumOfCarGenerators, buffer); + ReadSaveBuf(&CurrentActiveCount, buffer); + ReadSaveBuf(&ProcessCounter, buffer); + ReadSaveBuf(&GenerateEvenIfPlayerIsCloseCounter, buffer); + SkipSaveBuf(buffer, 2); + ReadSaveBuf(&tmp, buffer); + assert(tmp == sizeof(CarGeneratorArray)); for (int i = 0; i < NUM_CARGENS; i++) - CarGeneratorArray[i] = ReadSaveBuf<CCarGenerator>(buffer); + ReadSaveBuf(&CarGeneratorArray[i], buffer); VALIDATESAVEBUF(size) } diff --git a/src/vehicles/Cranes.cpp b/src/vehicles/Cranes.cpp index 1191465a..0f1b8b4c 100644 --- a/src/vehicles/Cranes.cpp +++ b/src/vehicles/Cranes.cpp @@ -11,6 +11,7 @@ #include "Replay.h" #include "Object.h" #include "World.h" +#include "SaveBuf.h" #define MAX_DISTANCE_TO_FIND_CRANE (10.0f) #define CRANE_UPDATE_RADIUS (300.0f) @@ -85,7 +86,7 @@ void CCranes::AddThisOneCrane(CEntity* pEntity) pCrane->m_bWasMilitaryCrane = false; pCrane->m_nAudioEntity = DMAudio.CreateEntity(AUDIOTYPE_CRANE, &aCranes[NumCranes]); if (pCrane->m_nAudioEntity >= 0) - DMAudio.SetEntityStatus(pCrane->m_nAudioEntity, true); + DMAudio.SetEntityStatus(pCrane->m_nAudioEntity, TRUE); pCrane->m_bIsTop = (MODELID_CRANE_1 != pEntity->GetModelIndex()); // Is this used to avoid military crane? if (pCrane->m_bIsTop || pEntity->GetPosition().y > 0.0f) { @@ -653,10 +654,10 @@ void CCranes::Load(uint8* buf, uint32 size) { INITSAVEBUF - NumCranes = ReadSaveBuf<int32>(buf); - CarsCollectedMilitaryCrane = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&NumCranes, buf); + ReadSaveBuf(&CarsCollectedMilitaryCrane, buf); for (int i = 0; i < NUM_CRANES; i++) - aCranes[i] = ReadSaveBuf<CCrane>(buf); + ReadSaveBuf(&aCranes[i], buf); for (int i = 0; i < NUM_CRANES; i++) { CCrane *pCrane = &aCranes[i]; if (pCrane->m_pCraneEntity != nil) @@ -669,7 +670,7 @@ void CCranes::Load(uint8* buf, uint32 size) 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, true); + DMAudio.SetEntityStatus(aCranes[i].m_nAudioEntity, TRUE); } VALIDATESAVEBUF(size); diff --git a/src/vehicles/Door.cpp b/src/vehicles/Door.cpp index c80965aa..1b3f9e8f 100644 --- a/src/vehicles/Door.cpp +++ b/src/vehicles/Door.cpp @@ -52,11 +52,11 @@ CDoor::Process(CVehicle *vehicle) fSpeedDiff = vecSpeedDiff.y - vecSpeedDiff.x; break; } - fSpeedDiff = clamp(fSpeedDiff, -0.2f, 0.2f); + fSpeedDiff = Clamp(fSpeedDiff, -0.2f, 0.2f); if(Abs(fSpeedDiff) > 0.002f) m_fAngVel += fSpeedDiff; m_fAngVel *= 0.945f; - m_fAngVel = clamp(m_fAngVel, -0.3f, 0.3f); + m_fAngVel = Clamp(m_fAngVel, -0.3f, 0.3f); m_fAngle += m_fAngVel; m_nDoorState = DOORST_SWINGING; diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp index 98e1f5fa..6e302e01 100644 --- a/src/vehicles/Heli.cpp +++ b/src/vehicles/Heli.cpp @@ -250,7 +250,7 @@ CHeli::ProcessControl(void) // Move up if too low if(GetPosition().z - 2.0f < groundZ && m_heliStatus != HELI_STATUS_SHOT_DOWN) m_vecMoveSpeed.z += CTimer::GetTimeStep()*0.01f; - m_vecMoveSpeed.z = clamp(m_vecMoveSpeed.z, -0.3f, 0.3f); + m_vecMoveSpeed.z = Clamp(m_vecMoveSpeed.z, -0.3f, 0.3f); } float fTargetDist = vTargetDist.Magnitude(); diff --git a/src/vehicles/Plane.cpp b/src/vehicles/Plane.cpp index 532be938..8ea03bf7 100644 --- a/src/vehicles/Plane.cpp +++ b/src/vehicles/Plane.cpp @@ -106,7 +106,7 @@ void CPlane::DeleteRwObject(void) { if(m_rwObject && RwObjectGetType(m_rwObject) == rpATOMIC){ - m_matrix.Detach(); + GetMatrix().Detach(); if(RwObjectGetType(m_rwObject) == rpATOMIC){ // useless check RwFrame *f = RpAtomicGetFrame((RpAtomic*)m_rwObject); RpAtomicDestroy((RpAtomic*)m_rwObject); @@ -556,13 +556,13 @@ CPlane::ProcessControl(void) m_rwObject = CModelInfo::GetModelInfo(mi->m_planeLodId)->CreateInstance(); POP_MEMID(); if(m_rwObject) - m_matrix.AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject))); + GetMatrix().AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject))); } } }else if(CStreaming::HasModelLoaded(GetModelIndex())){ if(m_rwObject && RwObjectGetType(m_rwObject) == rpATOMIC){ // Get rid of LOD model - m_matrix.Detach(); + GetMatrix().Detach(); if(m_rwObject){ // useless check if(RwObjectGetType(m_rwObject) == rpATOMIC){ // useless check RwFrame *f = RpAtomicGetFrame((RpAtomic*)m_rwObject); diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index 6696f4a6..3d3ba8f2 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -18,6 +18,7 @@ #include "Radar.h" #include "Fire.h" #include "Darkel.h" +#include "SaveBuf.h" bool CVehicle::bWheelsOnlyCheat; bool CVehicle::bAllDodosCheat; @@ -29,10 +30,10 @@ bool CVehicle::bAltDodoCheat; #endif bool CVehicle::m_bDisableMouseSteering = true; -void *CVehicle::operator new(size_t sz) { return CPools::GetVehiclePool()->New(); } -void *CVehicle::operator new(size_t sz, int handle) { return CPools::GetVehiclePool()->New(handle); } -void CVehicle::operator delete(void *p, size_t sz) { CPools::GetVehiclePool()->Delete((CVehicle*)p); } -void CVehicle::operator delete(void *p, int handle) { CPools::GetVehiclePool()->Delete((CVehicle*)p); } +void *CVehicle::operator new(size_t sz) throw() { return CPools::GetVehiclePool()->New(); } +void *CVehicle::operator new(size_t sz, int handle) throw() { return CPools::GetVehiclePool()->New(handle); } +void CVehicle::operator delete(void *p, size_t sz) throw() { CPools::GetVehiclePool()->Delete((CVehicle*)p); } +void CVehicle::operator delete(void *p, int handle) throw() { CPools::GetVehiclePool()->Delete((CVehicle*)p); } #ifdef FIX_BUGS // I think they meant that @@ -108,7 +109,7 @@ CVehicle::CVehicle(uint8 CreatedBy) m_fMapObjectHeightAhead = m_fMapObjectHeightBehind = 0.0f; m_audioEntityId = DMAudio.CreateEntity(AUDIOTYPE_PHYSICAL, this); if(m_audioEntityId >= 0) - DMAudio.SetEntityStatus(m_audioEntityId, true); + DMAudio.SetEntityStatus(m_audioEntityId, TRUE); m_nRadioStation = CGeneral::GetRandomNumber() % USERTRACK; m_pCurGroundEntity = nil; m_bRainAudioCounter = 0; @@ -429,8 +430,8 @@ CVehicle::FlyingControl(eFlightModel flightModel) } if (CPad::GetPad(0)->GetHorn()) { fYaw = 0.0f; - fPitch = clamp(10.0f * DotProduct(m_vecMoveSpeed, GetForward()), -200.0f, 1.3f); - fRoll = clamp(10.0f * DotProduct(m_vecMoveSpeed, GetRight()), -200.0f, 1.3f); + fPitch = Clamp(10.0f * DotProduct(m_vecMoveSpeed, GetForward()), -200.0f, 1.3f); + fRoll = Clamp(10.0f * DotProduct(m_vecMoveSpeed, GetRight()), -200.0f, 1.3f); } ApplyTurnForce(fPitch * GetUp() * fPitchVar * m_fTurnMass * CTimer::GetTimeStep(), GetForward()); ApplyTurnForce(fRoll * GetUp() * fRollVar * m_fTurnMass * CTimer::GetTimeStep(), GetRight()); @@ -497,11 +498,12 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon if(contactSpeedRight != 0.0f){ // exert opposing force right = -contactSpeedRight/wheelsOnGround; -#ifdef FIX_BUGS + // BUG? // contactSpeedRight is independent of framerate but right has timestep as a factor // so we probably have to fix this - right *= CTimer::GetTimeStepFix(); -#endif + // fixing this causes jittery cars at 15fps, and causes the car to move backwards slowly at 18fps + // at 19fps, the effects are gone ... + //right *= CTimer::GetTimeStepFix(); if(wheelStatus == WHEEL_STATUS_BURST){ float fwdspeed = Min(contactSpeedFwd, fBurstSpeedMax); @@ -1323,43 +1325,44 @@ CVehicle::Load(uint8*& buf) { CMatrix tmp; SkipSaveBuf(buf, 4); - tmp.GetRight().x = ReadSaveBuf<float>(buf); - tmp.GetRight().y = ReadSaveBuf<float>(buf); - tmp.GetRight().z = ReadSaveBuf<float>(buf); + ReadSaveBuf(&tmp.GetRight().x, buf); + ReadSaveBuf(&tmp.GetRight().y, buf); + ReadSaveBuf(&tmp.GetRight().z, buf); SkipSaveBuf(buf, 4); - tmp.GetForward().x = ReadSaveBuf<float>(buf); - tmp.GetForward().y = ReadSaveBuf<float>(buf); - tmp.GetForward().z = ReadSaveBuf<float>(buf); + ReadSaveBuf(&tmp.GetForward().x, buf); + ReadSaveBuf(&tmp.GetForward().y, buf); + ReadSaveBuf(&tmp.GetForward().z, buf); SkipSaveBuf(buf, 4); - tmp.GetUp().x = ReadSaveBuf<float>(buf); - tmp.GetUp().y = ReadSaveBuf<float>(buf); - tmp.GetUp().z = ReadSaveBuf<float>(buf); + ReadSaveBuf(&tmp.GetUp().x, buf); + ReadSaveBuf(&tmp.GetUp().y, buf); + ReadSaveBuf(&tmp.GetUp().z, buf); SkipSaveBuf(buf, 4); - tmp.GetPosition().x = ReadSaveBuf<float>(buf); - tmp.GetPosition().y = ReadSaveBuf<float>(buf); - tmp.GetPosition().z = ReadSaveBuf<float>(buf); + ReadSaveBuf(&tmp.GetPosition().x, buf); + ReadSaveBuf(&tmp.GetPosition().y, buf); + ReadSaveBuf(&tmp.GetPosition().z, buf); m_matrix = tmp; SkipSaveBuf(buf, 16); LoadEntityFlags(buf); SkipSaveBuf(buf, 212); AutoPilot.Load(buf); - m_currentColour1 = ReadSaveBuf<int8>(buf); - m_currentColour2 = ReadSaveBuf<int8>(buf); + ReadSaveBuf(&m_currentColour1, buf); + ReadSaveBuf(&m_currentColour2, buf); SkipSaveBuf(buf, 2); - m_nAlarmState = ReadSaveBuf<int16>(buf); + ReadSaveBuf(&m_nAlarmState, buf); SkipSaveBuf(buf, 43); - m_nNumMaxPassengers = ReadSaveBuf<int8>(buf); + ReadSaveBuf(&m_nNumMaxPassengers, buf); SkipSaveBuf(buf, 2); - field_1D0[0] = ReadSaveBuf<float>(buf); - field_1D0[1] = ReadSaveBuf<float>(buf); - field_1D0[2] = ReadSaveBuf<float>(buf); - field_1D0[3] = ReadSaveBuf<float>(buf); + ReadSaveBuf(&field_1D0[0], buf); + ReadSaveBuf(&field_1D0[1], buf); + ReadSaveBuf(&field_1D0[2], buf); + ReadSaveBuf(&field_1D0[3], buf); SkipSaveBuf(buf, 8); - m_fSteerAngle = ReadSaveBuf<float>(buf); - m_fGasPedal = ReadSaveBuf<float>(buf); - m_fBrakePedal = ReadSaveBuf<float>(buf); - VehicleCreatedBy = ReadSaveBuf<uint8>(buf); - uint8 flags = ReadSaveBuf<uint8>(buf); + ReadSaveBuf(&m_fSteerAngle, buf); + ReadSaveBuf(&m_fGasPedal, buf); + ReadSaveBuf(&m_fBrakePedal, buf); + ReadSaveBuf(&VehicleCreatedBy, buf); + uint8 flags; + ReadSaveBuf(&flags, buf); bIsLawEnforcer = !!(flags & BIT(0)); bIsLocked = !!(flags & BIT(3)); bEngineOn = !!(flags & BIT(4)); @@ -1367,16 +1370,17 @@ CVehicle::Load(uint8*& buf) bLightsOn = !!(flags & BIT(6)); bFreebies = !!(flags & BIT(7)); SkipSaveBuf(buf, 10); - m_fHealth = ReadSaveBuf<float>(buf); - m_nCurrentGear = ReadSaveBuf<uint8>(buf); + ReadSaveBuf(&m_fHealth, buf); + ReadSaveBuf(&m_nCurrentGear, buf); SkipSaveBuf(buf, 3); - m_fChangeGearTime = ReadSaveBuf<float>(buf); + ReadSaveBuf(&m_fChangeGearTime, buf); SkipSaveBuf(buf, 4); - m_nTimeOfDeath = ReadSaveBuf<uint32>(buf); + ReadSaveBuf(&m_nTimeOfDeath, buf); SkipSaveBuf(buf, 2); - m_nBombTimer = ReadSaveBuf<int16>(buf); + ReadSaveBuf(&m_nBombTimer, buf); SkipSaveBuf(buf, 12); - m_nDoorLock = (eCarLock)ReadSaveBuf<int8>(buf); + ReadSaveBuf(&flags, buf); + m_nDoorLock = (eCarLock)flags; SkipSaveBuf(buf, 99); } #endif diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h index fcfa3401..e7ad5c13 100644 --- a/src/vehicles/Vehicle.h +++ b/src/vehicles/Vehicle.h @@ -193,10 +193,10 @@ public: float m_fSteerInput; eVehicleType m_vehType; - static void *operator new(size_t); - static void *operator new(size_t sz, int slot); - static void operator delete(void*, size_t); - static void operator delete(void*, int); + static void *operator new(size_t) throw(); + static void *operator new(size_t sz, int slot) throw(); + static void operator delete(void*, size_t) throw(); + static void operator delete(void*, int) throw(); CVehicle(void) {} // FAKE CVehicle(uint8 CreatedBy); diff --git a/src/weapons/Explosion.cpp b/src/weapons/Explosion.cpp index 8ab81748..f79c0278 100644 --- a/src/weapons/Explosion.cpp +++ b/src/weapons/Explosion.cpp @@ -46,7 +46,7 @@ CExplosion::Initialise() } AudioHandle = DMAudio.CreateEntity(AUDIOTYPE_EXPLOSION, (void*)1); if (AudioHandle >= 0) - DMAudio.SetEntityStatus(AudioHandle, true); + DMAudio.SetEntityStatus(AudioHandle, TRUE); debug("CExplosion ready\n"); } diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp index dab510be..43a85db8 100644 --- a/src/weapons/Weapon.cpp +++ b/src/weapons/Weapon.cpp @@ -30,6 +30,7 @@ #include "WaterLevel.h" #include "WeaponInfo.h" #include "World.h" +#include "SaveBuf.h" uint16 gReloadSampleTime[WEAPONTYPE_LAST_WEAPONTYPE] = { @@ -202,7 +203,7 @@ CWeapon::Fire(CEntity *shooter, CVector *fireSource) else if ( shooter->IsPed() && ((CPed*)shooter)->m_pSeekTarget != nil ) { float distToTarget = (shooter->GetPosition() - ((CPed*)shooter)->m_pSeekTarget->GetPosition()).Magnitude(); - float power = clamp((distToTarget-10.0f)*0.02f, 0.2f, 1.0f); + float power = Clamp((distToTarget-10.0f)*0.02f, 0.2f, 1.0f); fired = FireProjectile(shooter, source, power); } @@ -578,12 +579,29 @@ CWeapon::FireInstantHit(CEntity *shooter, CVector *fireSource) ProcessLineOfSight(*fireSource, target, point, victim, m_eWeaponType, shooter, true, true, true, true, true, true, false); } +#ifdef FIX_BUGS + // fix muzzleflash rotation + heading = CGeneral::GetAngleBetweenPoints(fireSource->x, fireSource->y, target.x, target.y); + angle = DEGTORAD(heading); + + ahead = CVector2D(-Sin(angle), Cos(angle)); + ahead.Normalise(); +#endif } else if ( shooter == FindPlayerPed() && TheCamera.Cams[0].Using3rdPersonMouseCam() ) { CVector src, trgt; TheCamera.Find3rdPersonCamTargetVector(info->m_fRange, *fireSource, src, trgt); +#ifdef FIX_BUGS + // fix muzzleflash rotation + heading = CGeneral::GetAngleBetweenPoints(src.x, src.y, trgt.x, trgt.y); + angle = DEGTORAD(heading); + + ahead = CVector2D(-Sin(angle), Cos(angle)); + ahead.Normalise(); +#endif + CWorld::bIncludeDeadPeds = true; ProcessLineOfSight(src, trgt,point, victim, m_eWeaponType, shooter, true, true, true, true, true, true, false); CWorld::bIncludeDeadPeds = false; @@ -2248,7 +2266,11 @@ CWeapon::HitsGround(CEntity *holder, CVector *fireSource, CEntity *aimingTo) void CWeapon::BlowUpExplosiveThings(CEntity *thing) { +#ifdef FIX_BUGS + if ( thing && thing->IsObject() ) +#else if ( thing ) +#endif { CObject *object = (CObject*)thing; int32 mi = object->GetModelIndex(); |