diff --git a/source/duke3d/src/d_menu.cpp b/source/duke3d/src/d_menu.cpp index 38e3822bf..feedd7e02 100644 --- a/source/duke3d/src/d_menu.cpp +++ b/source/duke3d/src/d_menu.cpp @@ -568,7 +568,11 @@ void GameInterface::StartGame(FGameStartup& gs) } ud.m_player_skill = gs.Skill + 1; - if (menu_sounds) ud.skill_voice = S_PlaySound(skillsound); + if (menu_sounds) + { + ud.skill_voice = skillsound; + S_PlaySound(skillsound); + } ud.m_respawn_monsters = (gs.Skill == 3); ud.m_monsters_off = ud.monsters_off = 0; ud.m_respawn_items = 0; diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index a48db358e..16be9253a 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "menu/menu.h" #include "mapinfo.h" #include "cmdlib.h" + BEGIN_DUKE_NS static uint8_t precachehightile[2][(MAXTILES+7)>>3]; @@ -1321,9 +1322,10 @@ void G_NewGame(int volumeNum, int levelNum, int skillNum) if (ud.skill_voice > 0 && SoundEnabled()) { - while (FX_SoundActive(ud.skill_voice)) + while (S_CheckSoundPlaying(ud.skill_voice)) gameHandleEvents(); } + ud.skill_voice = 0; ready2send = 0; diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index 48949bdee..591a46a00 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -118,70 +118,6 @@ void S_PauseSounds(bool paused) } } -void S_MenuSound(void) -{ - static int SoundNum; - int const menusnds[] = { - LASERTRIP_EXPLODE, DUKE_GRUNT, DUKE_LAND_HURT, CHAINGUN_FIRE, SQUISHED, KICK_HIT, - PISTOL_RICOCHET, PISTOL_BODYHIT, PISTOL_FIRE, SHOTGUN_FIRE, BOS1_WALK, RPG_EXPLODE, - PIPEBOMB_BOUNCE, PIPEBOMB_EXPLODE, NITEVISION_ONOFF, RPG_SHOOT, SELECT_WEAPON, - }; - int s = VM_OnEventWithReturn(EVENT_OPENMENUSOUND, g_player[screenpeek].ps->i, screenpeek, FURY ? -1 : menusnds[SoundNum++ % ARRAY_SIZE(menusnds)]); - if (s != -1) - S_PlaySound(s); -} - - -static void S_SetMusicIndex(unsigned int m) -{ - ud.music_episode = m / MAXLEVELS; - ud.music_level = m % MAXLEVELS; -} - -void S_PlayLevelMusicOrNothing(unsigned int m) -{ - ud.returnvar[0] = m / MAXLEVELS; - ud.returnvar[1] = m % MAXLEVELS; - - int retval = VM_OnEvent(EVENT_PLAYLEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex); - - if (retval >= 0) - { - // Thanks to scripting that stupid slot hijack cannot be refactored - but we'll store the real data elsewhere anyway! - auto &mr = m == USERMAPMUSICFAKESLOT ? userMapRecord : mapList[m]; - Mus_Play(mr.labelName, mr.music, true); - S_SetMusicIndex(m); - } -} - -int S_TryPlaySpecialMusic(unsigned int m) -{ - auto &musicfn = mapList[m].music; - if (musicfn.IsNotEmpty()) - { - if (!Mus_Play(nullptr, musicfn, true)) - { - S_SetMusicIndex(m); - return 0; - } - } - - return 1; -} - -void S_PlaySpecialMusicOrNothing(unsigned int m) -{ - if (S_TryPlaySpecialMusic(m)) - { - S_SetMusicIndex(m); - } -} - -void S_ContinueLevelMusic(void) -{ - VM_OnEvent(EVENT_CONTINUELEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex); -} - void S_Cleanup(void) { static uint32_t ldnum = 0; @@ -717,4 +653,76 @@ int S_CheckSoundPlaying(int soundNum) if (EDUKE32_PREDICT_FALSE((unsigned)soundNum > (unsigned)g_highestSoundIdx)) return false; return (g_sounds[soundNum].num != 0); } + +//========================================================================== +// +// +// +//========================================================================== + +void S_MenuSound(void) +{ + static int SoundNum; + int const menusnds[] = { + LASERTRIP_EXPLODE, DUKE_GRUNT, DUKE_LAND_HURT, CHAINGUN_FIRE, SQUISHED, KICK_HIT, + PISTOL_RICOCHET, PISTOL_BODYHIT, PISTOL_FIRE, SHOTGUN_FIRE, BOS1_WALK, RPG_EXPLODE, + PIPEBOMB_BOUNCE, PIPEBOMB_EXPLODE, NITEVISION_ONOFF, RPG_SHOOT, SELECT_WEAPON, + }; + int s = VM_OnEventWithReturn(EVENT_OPENMENUSOUND, g_player[screenpeek].ps->i, screenpeek, FURY ? -1 : menusnds[SoundNum++ % ARRAY_SIZE(menusnds)]); + if (s != -1) + S_PlaySound(s); +} + + +static void S_SetMusicIndex(unsigned int m) +{ + ud.music_episode = m / MAXLEVELS; + ud.music_level = m % MAXLEVELS; +} + +void S_PlayLevelMusicOrNothing(unsigned int m) +{ + ud.returnvar[0] = m / MAXLEVELS; + ud.returnvar[1] = m % MAXLEVELS; + + int retval = VM_OnEvent(EVENT_PLAYLEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex); + + if (retval >= 0) + { + // Thanks to scripting that stupid slot hijack cannot be refactored - but we'll store the real data elsewhere anyway! + auto& mr = m == USERMAPMUSICFAKESLOT ? userMapRecord : mapList[m]; + Mus_Play(mr.labelName, mr.music, true); + S_SetMusicIndex(m); + } +} + +int S_TryPlaySpecialMusic(unsigned int m) +{ + auto& musicfn = mapList[m].music; + if (musicfn.IsNotEmpty()) + { + if (!Mus_Play(nullptr, musicfn, true)) + { + S_SetMusicIndex(m); + return 0; + } + } + + return 1; +} + +void S_PlaySpecialMusicOrNothing(unsigned int m) +{ + if (S_TryPlaySpecialMusic(m)) + { + S_SetMusicIndex(m); + } +} + +void S_ContinueLevelMusic(void) +{ + VM_OnEvent(EVENT_CONTINUELEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex); +} + + END_DUKE_NS