From 938db6d35d3d04a7cf984171cc8fef5bf41c40ab Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 16 Dec 2019 08:19:57 +0100 Subject: [PATCH] - sounds in the menu are working now. Since the in-game sound is paused in the menu these sounds need the CHAN_UI flag to play. --- source/common/gamecontrol.cpp | 1 + source/duke3d/src/actors.cpp | 3 ++- source/duke3d/src/anim.cpp | 6 +++--- source/duke3d/src/d_menu.cpp | 6 +++--- source/duke3d/src/game.cpp | 8 +++----- source/duke3d/src/gameexec.cpp | 2 +- source/duke3d/src/sounds.cpp | 18 +++++++++--------- source/duke3d/src/sounds.h | 7 ++++--- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index fabfc7e81..97096face 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -479,6 +479,7 @@ int RunGame() M_Init(); SetDefaultStrings(); if (g_gameType & GAMEFLAG_RR) InitRREndMap(); // this needs to be done better later + C_DoCommand("stat sounddebug"); return gi->app_main(); } diff --git a/source/duke3d/src/actors.cpp b/source/duke3d/src/actors.cpp index 04af80cb0..12674006a 100644 --- a/source/duke3d/src/actors.cpp +++ b/source/duke3d/src/actors.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define actors_c_ #include "duke3d.h" +#include "sounds.h" BEGIN_DUKE_NS @@ -1527,7 +1528,7 @@ ACTOR_STATIC void G_MoveFX(void) goto next_sprite; } #endif - A_PlaySound(pSprite->lotag,spriteNum, true); + A_PlaySound(pSprite->lotag,spriteNum, CHAN_LOOP); T1(spriteNum) = 1; // AMBIENT_SFX_PLAYING } else if (playerDist >= spriteHitag && T1(spriteNum) == 1) diff --git a/source/duke3d/src/anim.cpp b/source/duke3d/src/anim.cpp index 081f85777..f92bae3f6 100644 --- a/source/duke3d/src/anim.cpp +++ b/source/duke3d/src/anim.cpp @@ -364,7 +364,7 @@ int32_t Anim_Play(const char *fn) if (sound == -1) FX_StopAllSounds(); else - S_PlaySound(sound); + S_PlaySound(sound, CHAN_UI); soundidx++; } @@ -378,7 +378,7 @@ int32_t Anim_Play(const char *fn) if (sound == -1) FX_StopAllSounds(); else - S_PlaySound(sound); + S_PlaySound(sound, CHAN_UI); soundidx++; } @@ -536,7 +536,7 @@ int32_t Anim_Play(const char *fn) if (sound == -1) FX_StopAllSounds(); else - S_PlaySound(sound); + S_PlaySound(sound, CHAN_UI); soundidx++; } diff --git a/source/duke3d/src/d_menu.cpp b/source/duke3d/src/d_menu.cpp index feedd7e02..497db18f1 100644 --- a/source/duke3d/src/d_menu.cpp +++ b/source/duke3d/src/d_menu.cpp @@ -481,15 +481,15 @@ void GameInterface::MenuSound(EMenuSounds snd) switch (snd) { case CursorSound: - S_PlaySound(KICK_HIT); + S_PlaySound(KICK_HIT, CHAN_UI); break; case AdvanceSound: - S_PlaySound(PISTOL_BODYHIT); + S_PlaySound(PISTOL_BODYHIT, CHAN_UI); break; case CloseSound: - S_PlaySound(EXITMENUSOUND); + S_PlaySound(EXITMENUSOUND, CHAN_UI); break; default: diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 77f4d0e66..d1de8d1ab 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -172,8 +172,7 @@ enum gametokens static void gameTimerHandler(void) { - MUSIC_Update(); - + S_Update(); G_HandleSpecialKeys(); } @@ -4492,7 +4491,7 @@ void G_HandleLocalKeys(void) { if (G_ChangeHudLayout(1)) { - S_PlaySound(THUD); + S_PlaySound(THUD, CHAN_UI); } } else @@ -4511,7 +4510,7 @@ void G_HandleLocalKeys(void) { if (G_ChangeHudLayout(-1)) { - S_PlaySound(THUD); + S_PlaySound(THUD, CHAN_UI); } } else @@ -6159,7 +6158,6 @@ MAIN_LOOP_RESTART: && (myplayer.gm & MODE_GAME)) { G_MoveLoop(); - S_Update(); } if (totalclock - moveClock >= (TICSPERFRAME>>1)) diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index 4c0df3108..3a4c49080 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -4125,7 +4125,7 @@ badindex: if (S_CheckSoundPlaying(soundNum)) S_StopSound((int16_t)soundNum); dispatch(); - case CON_SCREENSOUND: S_PlaySound(soundNum); dispatch(); + case CON_SCREENSOUND: S_PlaySound(soundNum, CHAN_UI); dispatch(); } } dispatch(); diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index 8a2bf3529..654f69989 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -386,7 +386,7 @@ void S_Update(void) // //========================================================================== -int S_PlaySound3D(int num, int spriteNum, const vec3_t* pos, bool looped) +int S_PlaySound3D(int num, int spriteNum, const vec3_t* pos, int flags) { int32_t j = VM_OnEventWithReturn(EVENT_SOUND, spriteNum, screenpeek, num); @@ -470,8 +470,8 @@ int S_PlaySound3D(int num, int spriteNum, const vec3_t* pos, bool looped) // Now float attenuation = (userflags & (SF_GLOBAL | SF_DTAG)) == SF_GLOBAL ? ATTN_NONE : ATTN_NORM; - auto chflg = ((userflags & SF_LOOP) || looped) ? CHAN_AUTO | CHAN_LOOP : CHAN_AUTO; - auto chan = soundEngine->StartSound(SOURCE_Actor, &sprite[spriteNum], &sndpos, chflg, sndnum+1, 1.f, attenuation, nullptr, S_ConvertPitch(pitch)); + if (userflags & SF_LOOP) flags |= CHAN_LOOP; + auto chan = soundEngine->StartSound(SOURCE_Actor, &sprite[spriteNum], &sndpos, flags, sndnum+1, 1.f, attenuation, nullptr, S_ConvertPitch(pitch)); if (!chan) return -1; return 0; } @@ -482,7 +482,7 @@ int S_PlaySound3D(int num, int spriteNum, const vec3_t* pos, bool looped) // //========================================================================== -int S_PlaySound(int num, bool looped) +int S_PlaySound(int num, int flags) { int sndnum = VM_OnEventWithReturn(EVENT_SOUND, g_player[screenpeek].ps->i, screenpeek, num); @@ -494,8 +494,8 @@ int S_PlaySound(int num, bool looped) int const pitch = S_GetPitch(sndnum); - auto chflg = ((userflags & SF_LOOP) || looped) ? CHAN_AUTO | CHAN_LOOP : CHAN_AUTO; - soundEngine->StartSound(SOURCE_None, nullptr, nullptr, chflg, sndnum + 1, 1.f, ATTN_NONE, nullptr, S_ConvertPitch(pitch)); + if (userflags & SF_LOOP) flags |= CHAN_LOOP; + soundEngine->StartSound(SOURCE_None, nullptr, nullptr, flags, sndnum + 1, 1.f, ATTN_NONE, nullptr, S_ConvertPitch(pitch)); /* for reference. May still be needed for balancing later. : FX_Play3D(snd.ptr, snd.siz, FX_ONESHOT, pitch, 0, 255 - LOUDESTVOLUME, snd.pr, snd.volume, (num * MAXSOUNDINSTANCES) + sndnum); @@ -509,10 +509,10 @@ int S_PlaySound(int num, bool looped) // //========================================================================== -int A_PlaySound(int soundNum, int spriteNum, bool looped) +int A_PlaySound(int soundNum, int spriteNum, int flags) { - return (unsigned)spriteNum >= MAXSPRITES ? S_PlaySound(soundNum, looped) : - S_PlaySound3D(soundNum, spriteNum, &sprite[spriteNum].pos, looped); + return (unsigned)spriteNum >= MAXSPRITES ? S_PlaySound(soundNum, flags) : + S_PlaySound3D(soundNum, spriteNum, &sprite[spriteNum].pos, flags); } void S_StopEnvSound(int sndNum, int sprNum) diff --git a/source/duke3d/src/sounds.h b/source/duke3d/src/sounds.h index d30c9576c..a625ae1cc 100644 --- a/source/duke3d/src/sounds.h +++ b/source/duke3d/src/sounds.h @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define sounds_public_h_ #include "sounds_common.h" +#include "sound/s_soundinternal.h" #include "z_music.h" BEGIN_DUKE_NS @@ -45,7 +46,7 @@ typedef struct } sound_t; int A_CheckSoundPlaying(int spriteNum,int soundNum); -int A_PlaySound(int soundNum, int spriteNum, bool looped = false); +int A_PlaySound(int soundNum, int spriteNum, int flags = 0); void S_Callback(intptr_t num); int A_CheckAnySoundPlaying(int spriteNum); int S_CheckSoundPlaying(int soundNum); @@ -58,8 +59,8 @@ void S_PlayLevelMusicOrNothing(unsigned int); int S_TryPlaySpecialMusic(unsigned int); void S_PlaySpecialMusicOrNothing(unsigned int); void S_ContinueLevelMusic(void); -int S_PlaySound(int num, bool looped = false); -int S_PlaySound3D(int num, int spriteNum, const vec3_t *pos, bool looped = false); +int S_PlaySound(int num, int flags = 0); +int S_PlaySound3D(int num, int spriteNum, const vec3_t *pos, int flags = 0); void S_StopEnvSound(int sndNum,int sprNum); void S_StopAllSounds(void); void S_Update(void);