From e7cbf0b1a964be5d02966a4dd64d29398e650de2 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 29 Jan 2018 11:14:08 +0000 Subject: [PATCH] New events EVENT_PLAYLEVELMUSICSLOT and EVENT_CONTINUELEVELMUSICSLOT. Called when a music track will be started from the beginning, and when the current track is continued after loading a save, etc. The requested track is passed into PLAYLEVELMUSICSLOT via ud.m_volume_number and ud.m_level_number. git-svn-id: https://svn.eduke32.com/eduke32@6624 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/events_defs.h | 2 ++ source/duke3d/src/gamedef.cpp | 2 ++ source/duke3d/src/premap.cpp | 4 ++++ source/duke3d/src/savegame.cpp | 2 ++ source/duke3d/src/sounds.cpp | 16 ++++++++++++++++ source/duke3d/src/sounds.h | 1 + 6 files changed, 27 insertions(+) diff --git a/source/duke3d/src/events_defs.h b/source/duke3d/src/events_defs.h index e7ba44f72..98bb89fb4 100644 --- a/source/duke3d/src/events_defs.h +++ b/source/duke3d/src/events_defs.h @@ -146,6 +146,8 @@ enum GameEvent_t { EVENT_MENUCURSORRIGHT, EVENT_MENUCURSORSHADE, EVENT_MENUSHADESELECTED, + EVENT_PLAYLEVELMUSICSLOT, + EVENT_CONTINUELEVELMUSICSLOT, #ifdef LUNATIC EVENT_ANIMATEALLSPRITES, #endif diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index 69c365407..bf289de52 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -748,6 +748,8 @@ const char *EventNames[MAXEVENTS] = "EVENT_MENUCURSORRIGHT", "EVENT_MENUCURSORSHADE", "EVENT_MENUSHADESELECTED", + "EVENT_PLAYLEVELMUSICSLOT", + "EVENT_CONTINUELEVELMUSICSLOT", #ifdef LUNATIC "EVENT_ANIMATEALLSPRITES", #endif diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index 6d21ef30e..62dc4a2f1 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -1942,6 +1942,10 @@ int G_EnterLevel(int gameMode) { S_PlayLevelMusicOrNothing(mii); } + else + { + S_ContinueLevelMusic(); + } } if (gameMode & (MODE_GAME|MODE_EOL)) diff --git a/source/duke3d/src/savegame.cpp b/source/duke3d/src/savegame.cpp index 7f9b304aa..161a1bb03 100644 --- a/source/duke3d/src/savegame.cpp +++ b/source/duke3d/src/savegame.cpp @@ -2161,6 +2161,8 @@ static void postloadplayer(int32_t savegamep) ud.music_level = g_musicIndex % MAXLEVELS; S_PlayLevelMusicOrNothing(musicIdx); } + else + S_ContinueLevelMusic(); if (ud.config.MusicToggle) S_PauseMusic(0); diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index 94e3857d3..5a03560ca 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -277,6 +277,17 @@ static void S_SetMusicIndex(unsigned int m) int S_TryPlayLevelMusic(unsigned int m) { + auto m_volume_number = ud.m_volume_number; + auto m_level_number = ud.m_level_number; + ud.m_volume_number = m / MAXLEVELS; + ud.m_level_number = m % MAXLEVELS; + int retval = VM_OnEvent(EVENT_PLAYLEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex); + ud.m_volume_number = m_volume_number; + ud.m_level_number = m_level_number; + + if (retval < 0) + return 0; + char const * musicfn = g_mapInfo[m].musicfn; if (musicfn != NULL) { @@ -323,6 +334,11 @@ void S_PlaySpecialMusicOrNothing(unsigned int m) } } +void S_ContinueLevelMusic(void) +{ + VM_OnEvent(EVENT_CONTINUELEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex); +} + int32_t S_GetMusicPosition(void) { int32_t position = 0; diff --git a/source/duke3d/src/sounds.h b/source/duke3d/src/sounds.h index 8cd2e3f79..c57e9ec64 100644 --- a/source/duke3d/src/sounds.h +++ b/source/duke3d/src/sounds.h @@ -100,6 +100,7 @@ int S_TryPlayLevelMusic(unsigned int); void S_PlayLevelMusicOrNothing(unsigned int); int S_TryPlaySpecialMusic(unsigned int); void S_PlaySpecialMusicOrNothing(unsigned int); +void S_ContinueLevelMusic(void); int32_t S_PlaySound(int32_t num); int32_t S_PlaySound3D(int32_t num,int32_t i,const vec3_t *pos); void S_SoundShutdown(void);