From 9627f00f32040cfd29a2ca9929e052398b301167 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 1 Oct 2022 12:59:43 +0200 Subject: [PATCH] - Duke: added emulation for a sound system bug that prevents certain duplicate sounds from playing. Since our sound system does not reject this case, the calling code must check for the relevant condition. --- source/games/duke/src/actors.cpp | 4 ++-- source/games/duke/src/sectors.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index b874dfe7c..a41f16408 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -2603,7 +2603,7 @@ void handle_se00(DDukeActor* actor) { actor->tempang += 4; if (actor->tempang >= 256) - callsound(actor->sector(), actor); + callsound(actor->sector(), actor, true); if (actor->spr.clipdist) l = 1; else l = -1; } @@ -2631,7 +2631,7 @@ void handle_se00(DDukeActor* actor) { actor->tempang -= 4; if (actor->tempang <= 0) - callsound(actor->sector(), actor); + callsound(actor->sector(), actor, true); if (actor->spr.clipdist) l = -1; else l = 1; } diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 725386397..97a3ffbe2 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -95,9 +95,16 @@ int callsound(sectortype* sn, DDukeActor* whatsprite, bool endstate) } else if (act->spr.hitag < 1000) { + // The original code performed these two actions in reverse order which in case of a looped sound being stopped + // being the same as the sound about to be started, the newly started sound would fall through some cracks in the sound system and be rejected. + // Here this case needs to be simulated. + bool stopped = false; if ((flags & SF_LOOP) || (act->spr.hitag && act->spr.hitag != act->spr.lotag)) + { S_StopSound(act->spr.lotag, act->temp_actor); - if (act->spr.hitag) S_PlayActorSound(act->spr.hitag, whatsprite); + if (act->spr.hitag == act->spr.lotag) stopped = true; + } + if (act->spr.hitag && !stopped) S_PlayActorSound(act->spr.hitag, whatsprite); act->temp_data[0] = 0; act->temp_actor = whatsprite; }