Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(milesaudio): one music track at a time
Olcay Seygand8a5a373c96e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex de91bfb63..b5dd71a93 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1714,6 +1714,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- A sound on the right of the screen comes out of the right speaker. Since the game went 64-bit its sound library worked left and right out the wrong way round, so a tank firing off to the right was heard on the left. Only a sound well off to one side swings far enough to notice, which is why it seemed to come and go.- Your units answer you over the battle. A reply plays at whichever of the effects and voice sliders is higher, lifted again on top of that, so "Moving out" is heard in the middle of an artillery duel. Nothing else is turned down to make room for it. EVA and briefings stay where the voice slider puts them.- Leaving the score screen no longer plays its music over the main menu theme. The score music was told to fade out over two seconds, but a fade only moves while the game updates its sound, and the menu's background battle was loading in that time with no sound update at all. The music came out of the load at full volume and faded on top of the menu's own track. It stops the moment you click now.+- Two music tracks no longer play on top of each other. A track change told the old track to stop, and the stop went to the first track it found; when two changes landed between two sound updates, a mission script and the skirmish music on the same frame or a burst of frames catching up, the second stop found the old track a second time and the first new one played on under the second for the rest of the match. A stop now reaches every track, and a track that starts silences any other that is not already fading out.- Movies follow the voice volume slider. The volume was handed to the video before it was ready to take it, so every movie played at full level, and moving the slider while one was playing changed nothing.- A sound at the edge of its range can fade out instead of stopping dead. The volume curve neveractually reaches zero, so a sound you are walking away from was cut off mid-note at the maximumdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cppindex a1129e10b..dae84a94b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp@@ -846,6 +846,17 @@ void MilesAudioManager::playAudioEvent( AudioEventRTS *event, Bool requestStop )}}+ // One track at a time. Whatever music is still on the list and not fading out is stopped,+ // so a track started without a stop in front of it cannot play over another.+ if (info->m_soundType == AT_Music && (!handleToKill || foundSoundToReplace)) {+ for (it = m_playingStreams.begin(); it != m_playingStreams.end(); ++it) {+ playing = (*it);+ if (playing && !playing->m_fade && audioIsType(playing->m_audioEventRTS, AT_Music)) {+ stopPlayingAudio(playing);+ }+ }+ }+HSTREAM stream;if (!handleToKill || foundSoundToReplace) {stream = AIL_open_stream(m_digitalHandle, fileToPlay.str(), 0);@@ -1046,7 +1057,10 @@ void MilesAudioManager::stopAudioEvent( AudioHandle handle )std::list<PlayingAudio *>::iterator it;if ( handle == AHSV_StopTheMusic || handle == AHSV_StopTheMusicFade ) {- // for music, just find the currently playing music stream and kill it.+ // Every music stream, not the first one found. A stream that was already told to stop or fade+ // stays on this list until the end of the update, so two track changes inside one update (two+ // logic frames, or two scripts on one frame) used to find the old track a second time and leave+ // the first new one playing under the second.for ( it = m_playingStreams.begin(); it != m_playingStreams.end(); ++it ) {PlayingAudio *audio = (*it);if (!audio) {@@ -1063,7 +1077,6 @@ void MilesAudioManager::stopAudioEvent( AudioHandle handle ){stopPlayingAudio( audio );}- break;}}}diff --git a/GeneralsMD/Code/Tests/test_milesaudiomanager.cpp b/GeneralsMD/Code/Tests/test_milesaudiomanager.cppindex c16c9f553..b09738de7 100644--- a/GeneralsMD/Code/Tests/test_milesaudiomanager.cpp+++ b/GeneralsMD/Code/Tests/test_milesaudiomanager.cpp@@ -52,6 +52,7 @@#include "Common/AudioAffect.h"#include "Common/AudioEventInfo.h"#include "Common/AudioEventRTS.h"+#include "Common/AudioHandleSpecialValues.h"#include "Common/AudioSettings.h"#include "Common/FileSystem.h"#include "Common/GameAudio.h"@@ -167,6 +168,16 @@ public:processPlayingList();processFadingList();}+ // Music streams still on the playing list at full voice: neither stopping nor fading out+ int musicPlaying( void ) const+ {+ int n = 0;+ for (std::list<PlayingAudio *>::const_iterator it = m_playingStreams.begin(); it != m_playingStreams.end(); ++it)+ if (*it && !(*it)->m_fade && (*it)->m_status == PS_Playing+ && (*it)->m_audioEventRTS->getAudioEventInfo()->m_soundType == AT_Music)+ ++n;+ return n;+ }void runFor( int ms, bool ticking = true ){for (int t = 0; t < ms; t += 10)@@ -495,6 +506,33 @@ TEST(music_plays_and_a_stop_brings_silence)CHECK( after < during * 0.05 );}+TEST(two_track_changes_in_one_update_leave_one_track_playing)+{+ TestAudio *audio = theAudio();+ const Pick pick = pickEvent( AT_Music, 0, 0, 10.0 );+ CHECK( !pick.name.isEmpty() );+ if (pick.name.isEmpty())+ return;+ play( pick );+ audio->runFor( 200 );+ CHECK_EQ( audio->musicPlaying(), 1 );+ // doMusicTrackChange twice before the next update: the second stop used to find the faded track again+ for (int i = 0; i < 2; ++i)+ {+ TheAudio->removeAudioEvent( AHSV_StopTheMusicFade );+ play( pick );+ }+ audio->tick();+ CHECK_EQ( audio->musicPlaying(), 1 );+ // a track started with no stop in front of it replaces the one playing+ play( pick );+ audio->tick();+ CHECK_EQ( audio->musicPlaying(), 1 );+ TheAudio->removeAudioEvent( AHSV_StopTheMusic );+ audio->runFor( 100 );+ CHECK_EQ( audio->musicPlaying(), 0 );+}+TEST(with_sound_switched_off_nothing_is_heard){TestAudio *audio = theAudio();