[Scummvm-git-logs] scummvm master -> 3d81248e025203baa1c02c95ed445d77e7bbd447

mduggan noreply at scummvm.org
Sun Jan 26 07:40:41 UTC 2025


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
fa6e3caa96 DGDS: Sync volume state from menu properly with music player
3b240cc470 DGDS: Fix crash if Dragon countdown overlaps hour
3d81248e02 DGDS: Clear sounds, drag item, and mouse cursor on game load


Commit: fa6e3caa969bf8f5b311284c63b1a370c473af53
    https://github.com/scummvm/scummvm/commit/fa6e3caa969bf8f5b311284c63b1a370c473af53
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2025-01-26T17:22:30+11:00

Commit Message:
DGDS: Sync volume state from menu properly with music player

Pause the music if it's turned off.

Also update midi driver loops to C++11 style for cleaner code.

Changed paths:
    engines/dgds/menu.cpp
    engines/dgds/sound.cpp
    engines/dgds/sound.h
    engines/dgds/sound/music.cpp
    engines/dgds/sound/music.h


diff --git a/engines/dgds/menu.cpp b/engines/dgds/menu.cpp
index ffb4bc76bdc..f1bc3a26354 100644
--- a/engines/dgds/menu.cpp
+++ b/engines/dgds/menu.cpp
@@ -504,16 +504,10 @@ static void _toggleSoundType(Audio::Mixer::SoundType soundType) {
 	const char *typeStr = (soundType == Audio::Mixer::kMusicSoundType) ? "music" : "sfx";
 	if (!mixer->isSoundTypeMuted(soundType)) {
 		mixer->muteSoundType(soundType, true);
-		warning("TODO: Sync volume and pause %s", typeStr);
-		//midiPlayer->syncVolume();
-		//if (soundType == Audio::Mixer::kMusicSoundType)
-		//	engine->_soundPlayer->pauseMusic();
+		engine->_soundPlayer->muteSoundType(soundType);
 	} else {
 		mixer->muteSoundType(soundType, false);
-		warning("TODO: Sync volume and resume %s", typeStr);
-		//midiPlayer->syncVolume();
-		//if (soundType == Audio::Mixer::kMusicSoundType)
-		//	engine->_soundPlayer->resumeMusic();
+		engine->_soundPlayer->unmuteSoundType(soundType);
 	}
 }
 
diff --git a/engines/dgds/sound.cpp b/engines/dgds/sound.cpp
index 4940b483a7b..4c390240297 100644
--- a/engines/dgds/sound.cpp
+++ b/engines/dgds/sound.cpp
@@ -194,7 +194,8 @@ static byte _loadSndTrack(uint32 track, const byte** trackPtr, uint16* trackSiz,
 
 
 Sound::Sound(Audio::Mixer *mixer, ResourceManager *resource, Decompressor *decompressor) :
-	_mixer(mixer), _resource(resource), _decompressor(decompressor), _music(nullptr) {
+	_mixer(mixer), _resource(resource), _decompressor(decompressor), _music(nullptr),
+	_isMusicMuted(false), _isSfxMuted(false) {
 	ARRAYCLEAR(_channels);
 	_music = new SciMusic(true);
 	_music->init();
@@ -616,8 +617,19 @@ void Sound::playPCSound(int num, const Common::Array<SoundData> &dataArray, Audi
 			playPCM(data._data, data._size);
 		} else {
 			int idOffset = soundType == Audio::Mixer::kSFXSoundType ? SND_RESOURCE_OFFSET : MUSIC_RESOURCE_OFFSET;
+
+			// Only play one music at a time, don't play sfx if sfx muted.
+			if (soundType == Audio::Mixer::kMusicSoundType)
+				stopMusic();
+			else if (soundType == Audio::Mixer::kSFXSoundType && _isSfxMuted)
+				return;
+
 			processInitSound(num + idOffset, data, soundType);
 			processPlaySound(num + idOffset, false, false, data);
+
+			// Immediately pause new music if muted
+			if (_isMusicMuted && soundType == Audio::Mixer::kMusicSoundType)
+				_music->pauseMusic();
 		}
 	} else {
 		warning("Sound: Requested to play %d but only have %d tracks", num, dataArray.size());
@@ -629,6 +641,29 @@ void Sound::stopMusic() {
 	_music->stopMusic();
 }
 
+void Sound::muteSoundType(Audio::Mixer::SoundType soundType) {
+	if (soundType == Audio::Mixer::kMusicSoundType) {
+		_isMusicMuted = true;
+		_music->pauseMusic();
+	} else if (soundType == Audio::Mixer::kSFXSoundType) {
+		_isSfxMuted = true;
+		stopAllSfx();
+	} else {
+		error("Sound: Can only mute music or sfx, not sound type %d", soundType);
+	}
+}
+
+void Sound::unmuteSoundType(Audio::Mixer::SoundType soundType) {
+	if (soundType == Audio::Mixer::kMusicSoundType) {
+		_isMusicMuted = false;
+		_music->resumeMusic();
+	} else if (soundType == Audio::Mixer::kSFXSoundType) {
+		_isSfxMuted = false;
+	} else {
+		error("Sound: Can only unmute music or sfx, not sound type %d", soundType);
+	}
+}
+
 void Sound::unloadMusic() {
 	stopMusic();
 	for (auto &data: _musicData)
diff --git a/engines/dgds/sound.h b/engines/dgds/sound.h
index df65eb039c8..f8e1d95904d 100644
--- a/engines/dgds/sound.h
+++ b/engines/dgds/sound.h
@@ -72,6 +72,9 @@ public:
 
 	bool playPCM(const byte *data, uint32 size);
 
+	void muteSoundType(Audio::Mixer::SoundType soundType);
+	void unmuteSoundType(Audio::Mixer::SoundType soundType);
+
 private:
 	void loadSNGSoundData(const Common::String &filename, Common::Array<SoundData> &dataArray);
 	bool loadSXSoundData(const Common::String &filename, Common::Array<SoundData> &dataArray, Common::HashMap<uint16, uint16> &idMap);
@@ -102,6 +105,9 @@ private:
 	Audio::Mixer *_mixer;
 	ResourceManager *_resource;
 	Decompressor *_decompressor;
+
+	bool _isMusicMuted;
+	bool _isSfxMuted;
 };
 
 enum {
diff --git a/engines/dgds/sound/music.cpp b/engines/dgds/sound/music.cpp
index 420046343be..af7d8d7ca1c 100644
--- a/engines/dgds/sound/music.cpp
+++ b/engines/dgds/sound/music.cpp
@@ -255,17 +255,15 @@ void SciMusic::resetGlobalPauseCounter() {
 }
 
 void SciMusic::stopAll() {
-	const MusicList::iterator end = _playList.end();
-	for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
-		soundStop(*i);
+	for (auto &sound: _playList) {
+		soundStop(sound);
 	}
 }
 
 void SciMusic::stopAllSamples() {
-	const MusicList::iterator end = _playList.end();
-	for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
-		if ((*i)->isSample) {
-			soundStop(*i);
+	for (auto &sound: _playList) {
+		if (sound->isSample) {
+			soundStop(sound);
 		}
 	}
 }
@@ -286,34 +284,47 @@ uint16 SciMusic::soundGetVoices() {
 MusicEntry *SciMusic::getSlot(uint32 obj) {
 	Common::StackLock lock(_mutex);
 
-	const MusicList::iterator end = _playList.end();
-	for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
-		if ((*i)->soundObj == obj)
-			return *i;
+	for (auto &sound: _playList) {
+		if (sound->soundObj == obj)
+			return sound;
 	}
 
 	return nullptr;
 }
 
 MusicEntry *SciMusic::getFirstSlotWithStatus(SoundStatus status) {
-	for (MusicList::iterator i = _playList.begin(); i != _playList.end(); ++i) {
-		if ((*i)->status == status)
-			return *i;
+	for (auto &sound: _playList) {
+		if (sound->status == status)
+			return sound;
 	}
 	return nullptr;
 }
 
 void SciMusic::stopMusic() {
-	for (MusicList::iterator i = _playList.begin(); i != _playList.end(); ++i) {
-		if ((*i)->soundType == Audio::Mixer::kMusicSoundType)
-			soundStop(*i);
+	for (auto &sound: _playList) {
+		if (sound->soundType == Audio::Mixer::kMusicSoundType)
+			soundStop(sound);
+	}
+}
+
+void SciMusic::pauseMusic() {
+	for (auto &sound: _playList) {
+		if (sound->soundType == Audio::Mixer::kMusicSoundType)
+			soundPause(sound);
+	}
+}
+
+void SciMusic::resumeMusic() {
+	for (auto &sound: _playList) {
+		if (sound->soundType == Audio::Mixer::kMusicSoundType)
+			soundResume(sound);
 	}
 }
 
 void SciMusic::stopSFX() {
-	for (MusicList::iterator i = _playList.begin(); i != _playList.end(); ++i) {
-		if ((*i)->soundType == Audio::Mixer::kSFXSoundType)
-			soundStop(*i);
+	for (auto &sound: _playList) {
+		if (sound->soundType == Audio::Mixer::kSFXSoundType)
+			soundStop(sound);
 	}
 }
 
@@ -325,20 +336,18 @@ void SciMusic::setGlobalReverb(int8 reverb) {
 		_globalReverb = reverb;
 
 		// Check the reverb of the active song...
-		const MusicList::iterator end = _playList.end();
-		for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
-			if ((*i)->status == kSoundPlaying) {
-				if ((*i)->reverb == 127)			// Active song has no reverb
+		for (const auto &sound: _playList) {
+			if (sound->status == kSoundPlaying) {
+				if (sound->reverb == 127)			// Active song has no reverb
 					_pMidiDrv->setReverb(reverb);	// Set the global reverb
 				break;
 			}
 		}
 	} else {
 		// Set reverb of the active song
-		const MusicList::iterator end = _playList.end();
-		for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
-			if ((*i)->status == kSoundPlaying) {
-				_pMidiDrv->setReverb((*i)->reverb);	// Set the song's reverb
+		for (const auto &sound: _playList) {
+			if (sound->status == kSoundPlaying) {
+				_pMidiDrv->setReverb(sound->reverb);	// Set the song's reverb
 				break;
 			}
 		}
@@ -783,10 +792,9 @@ void SciMusic::soundSetMasterVolume(uint16 vol) {
 
 	Common::StackLock lock(_mutex);
 
-	const MusicList::iterator end = _playList.end();
-	for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
-		if ((*i)->pMidiParser)
-			(*i)->pMidiParser->setMasterVolume(vol);
+	for (auto &sound : _playList) {
+		if (sound->pMidiParser)
+			sound->pMidiParser->setMasterVolume(vol);
 	}
 }
 
diff --git a/engines/dgds/sound/music.h b/engines/dgds/sound/music.h
index 1c0e5ffd2d7..32dfaa46da0 100644
--- a/engines/dgds/sound/music.h
+++ b/engines/dgds/sound/music.h
@@ -200,6 +200,8 @@ public:
 	void stopAll();
 	void stopAllSamples();
 	void stopMusic();
+	void pauseMusic();
+	void resumeMusic();
 	void stopSFX();
 
 	// sound and midi functions


Commit: 3b240cc470c0e50c17241396f2f23293b267945e
    https://github.com/scummvm/scummvm/commit/3b240cc470c0e50c17241396f2f23293b267945e
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2025-01-26T17:26:55+11:00

Commit Message:
DGDS: Fix crash if Dragon countdown overlaps hour

Changed paths:
    engines/dgds/dragon_native.cpp


diff --git a/engines/dgds/dragon_native.cpp b/engines/dgds/dragon_native.cpp
index ff294fd5949..420a713b6e2 100644
--- a/engines/dgds/dragon_native.cpp
+++ b/engines/dgds/dragon_native.cpp
@@ -33,7 +33,10 @@ void DragonNative::drawCountdown(FontManager::FontType fontType, int16 x, int16
 	int16 countdownEnd = engine->getGameGlobals()->getGlobal(0x22);
 	int16 currentMins = engine->getClock().getMins();
 	const DgdsFont *fnt = engine->getFontMan()->getFont(fontType);
-	Common::String str = Common::String::format("%d", countdownEnd - currentMins);
+	int16 minsLeft = countdownEnd - currentMins;
+	if (minsLeft < 0)
+		minsLeft += 60;
+	Common::String str = Common::String::format("%2d", minsLeft);
 	fnt->drawString(&engine->_compositionBuffer, str, x, y, SCREEN_WIDTH - x, 10);
 }
 


Commit: 3d81248e025203baa1c02c95ed445d77e7bbd447
    https://github.com/scummvm/scummvm/commit/3d81248e025203baa1c02c95ed445d77e7bbd447
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2025-01-26T18:10:13+11:00

Commit Message:
DGDS: Clear sounds, drag item, and mouse cursor on game load

Changed paths:
    engines/dgds/dgds.cpp


diff --git a/engines/dgds/dgds.cpp b/engines/dgds/dgds.cpp
index d384aa671c2..1b453d9d378 100644
--- a/engines/dgds/dgds.cpp
+++ b/engines/dgds/dgds.cpp
@@ -923,14 +923,23 @@ Common::Error DgdsEngine::syncGame(Common::Serializer &s) {
 		if (!_resource->hasResource(sceneFile))
 			error("Game references non-existent scene %d", sceneNum);
 
+		// Reset scene and music etc.
+		setMouseCursor(kDgdsMouseGameDefault);
 		_soundPlayer->stopAllSfx();
+		_soundPlayer->stopMusic();
 		_scene->unload();
+		_scene->setDragItem(nullptr);
 		_adsInterp->unload();
 
 		// Clear arcade state completely.
 		if (getGameId() == GID_DRAGON) {
 			delete _dragonArcade;
 			_dragonArcade = new DragonArcade();
+		} else if (getGameId() == GID_HOC) {
+			delete _chinaTank;
+			delete _chinaTrain;
+			_chinaTank = new ChinaTank();
+			_chinaTrain = new ChinaTrain();
 		}
 
 		_scene->load(sceneFile, _resource, _decompressor);




More information about the Scummvm-git-logs mailing list