From 5597f3faab602b367ed90e5e2b8205c539f43c81 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 7 Sep 2014 18:10:09 +0000 Subject: [PATCH] Some cleanup around S_PlayMusic() and related functionality. git-svn-id: https://svn.eduke32.com/eduke32@4585 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 56 +++++++++++++++---------------- polymer/eduke32/source/menus.c | 17 ++-------- polymer/eduke32/source/osdcmds.c | 9 +---- polymer/eduke32/source/premap.c | 4 +-- polymer/eduke32/source/savegame.c | 2 +- polymer/eduke32/source/sounds.c | 18 +++++++--- polymer/eduke32/source/sounds.h | 1 + 7 files changed, 48 insertions(+), 59 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 706a416a8..354566985 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -8750,22 +8750,22 @@ void G_HandleLocalKeys(void) { if (i == 5 && g_player[myconnectindex].ps->fta > 0 && g_player[myconnectindex].ps->ftq == QUOTE_MUSIC) { - i = (VOLUMEALL?MAXVOLUMES*MAXLEVELS:6); - g_musicIndex = (g_musicIndex+1)%i; - while (MapInfo[g_musicIndex].musicfn == NULL) + i = VOLUMEALL ? MAXVOLUMES*MAXLEVELS : 6; + + do { g_musicIndex++; if (g_musicIndex >= i) g_musicIndex = 0; } - if (MapInfo[g_musicIndex].musicfn != NULL) - { - if (S_PlayMusic(&MapInfo[g_musicIndex].musicfn[0],g_musicIndex)) - Bsprintf(ScriptQuotes[QUOTE_MUSIC],"Playing %s",&MapInfo[g_musicIndex].alt_musicfn[0]); - else - Bsprintf(ScriptQuotes[QUOTE_MUSIC],"Playing %s",&MapInfo[g_musicIndex].musicfn[0]); - P_DoQuote(QUOTE_MUSIC,g_player[myconnectindex].ps); - } + while (MapInfo[g_musicIndex].musicfn == NULL); + + if (S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex)) + Bsprintf(ScriptQuotes[QUOTE_MUSIC],"Playing %s", MapInfo[g_musicIndex].alt_musicfn); + else + Bsprintf(ScriptQuotes[QUOTE_MUSIC],"Playing %s", MapInfo[g_musicIndex].musicfn); + P_DoQuote(QUOTE_MUSIC,g_player[myconnectindex].ps); + return; } @@ -9175,7 +9175,7 @@ static void G_ShowDebugHelp(void) #endif } -static char *S_OggifyFilename(char *outputname, char *newname, const char *origname) +static char *S_OggifyFilename(char *outputname, const char *newname, const char *origname) { if (!origname) return outputname; @@ -9192,34 +9192,27 @@ static char *S_OggifyFilename(char *outputname, char *newname, const char *orign Bstrcat(outputname, origname); } -#if 0 - // XXX: I don't see why we were previously clobbering the extension regardless of what it is. - if ((newname = Bstrchr(outputname, '.'))) - Bstrcpy(newname, ".ogg"); - else Bstrcat(outputname, ".ogg"); -#endif - if (Bstrchr(outputname, '.') == NULL) Bstrcat(outputname, ".ogg"); return outputname; } -static int32_t S_DefineSound(int32_t ID,char *name) +static int32_t S_DefineSound(int32_t ID, const char *name) { - if (ID >= MAXSOUNDS) + if ((unsigned)ID >= MAXSOUNDS) return 1; - g_sounds[ID].filename1 = S_OggifyFilename(g_sounds[ID].filename1,name,g_sounds[ID].filename); + + g_sounds[ID].filename1 = S_OggifyFilename(g_sounds[ID].filename1, name, g_sounds[ID].filename); // initprintf("(%s)(%s)(%s)\n",g_sounds[ID].filename1,name,g_sounds[ID].filename); // S_LoadSound(ID); + return 0; } -static int32_t S_DefineMusic(char *ID,char *name) +static int32_t S_DefineMusic(const char *ID, const char *name) { - int32_t lev, ep; int32_t sel = MAXVOLUMES * MAXLEVELS; - char b1, b2; if (!ID) return 1; @@ -9240,19 +9233,24 @@ static int32_t S_DefineMusic(char *ID,char *name) } else { - sscanf(ID,"%c%d%c%d",&b1,&ep,&b2,&lev); + int32_t lev, ep; + char b1, b2; - if (Btoupper(b1) != 'E' || Btoupper(b2) != 'L' || --lev >= MAXLEVELS || --ep >= MAXVOLUMES) + int32_t matches = sscanf(ID,"%c%d%c%d",&b1,&ep,&b2,&lev); + + if (matches != 4 || Btoupper(b1) != 'E' || Btoupper(b2) != 'L' || + (unsigned)--lev >= MAXLEVELS || (unsigned)--ep >= MAXVOLUMES) return 1; sel = (ep * MAXLEVELS) + lev; ID = MapInfo[sel].musicfn; } - MapInfo[sel].alt_musicfn = S_OggifyFilename(MapInfo[sel].alt_musicfn,name,ID); + MapInfo[sel].alt_musicfn = S_OggifyFilename(MapInfo[sel].alt_musicfn, name, ID); // initprintf("%-15s | ",ID); // initprintf("%3d %2d %2d | %s\n",sel,ep,lev,MapInfo[sel].alt_musicfn); // S_PlayMusic(ID,sel); + return 0; } @@ -10384,7 +10382,7 @@ static void G_DisplayLogo(void) if (logoflags & LOGO_PLAYMUSIC) { g_musicIndex = -1; // hack - S_PlayMusic(&EnvMusicFilename[0][0],MAXVOLUMES*MAXLEVELS); + S_PlayMusic(EnvMusicFilename[0], MAXVOLUMES*MAXLEVELS); } if (!NAM) diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 2c89e7ffa..adbc9e12a 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -2440,14 +2440,7 @@ static void M_MenuEntryLinkActivate(MenuGroup_t *group, MenuEntry_t *entry) S_ClearSoundLocks(); if (ud.config.MusicToggle == 1) - { - if (ud.recstat != 2 && g_player[myconnectindex].ps->gm&MODE_GAME) - { - if (MapInfo[g_musicIndex].musicfn != NULL) - S_PlayMusic(&MapInfo[g_musicIndex].musicfn[0],g_musicIndex); - } - else S_PlayMusic(&EnvMusicFilename[0][0],MAXVOLUMES*MAXLEVELS); - } + S_RestartMusic(); } else if (entry == &ME_COLCORR_RESET) { @@ -2562,13 +2555,7 @@ static int32_t M_MenuEntryOptionModify(MenuGroup_t* group, MenuEntry_t *entry, i S_PauseMusic(1); else { - if (ud.recstat != 2 && g_player[myconnectindex].ps->gm&MODE_GAME) - { - if (MapInfo[g_musicIndex].musicfn != NULL) - S_PlayMusic(&MapInfo[g_musicIndex].musicfn[0], g_musicIndex); - } - else S_PlayMusic(&EnvMusicFilename[0][0], MAXVOLUMES*MAXLEVELS); - + S_RestartMusic(); S_PauseMusic(0); } } diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index 4f6d69144..1ddc187b8 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -379,14 +379,7 @@ static int32_t osdcmd_restartsound(const osdfuncparm_t *parm) S_ClearSoundLocks(); if (ud.config.MusicToggle == 1) - { - if (ud.recstat != 2 && g_player[myconnectindex].ps->gm&MODE_GAME) - { - if (MapInfo[g_musicIndex].musicfn != NULL) - S_PlayMusic(&MapInfo[g_musicIndex].musicfn[0],g_musicIndex); - } - else S_PlayMusic(&EnvMusicFilename[0][0],MAXVOLUMES*MAXLEVELS); - } + S_RestartMusic(); return OSDCMD_OK; } diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 4855eca26..eeed38c48 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -439,7 +439,7 @@ void G_CacheMapData(void) if (MapInfo[MAXVOLUMES*MAXLEVELS+2].alt_musicfn) { S_StopMusic(); - S_PlayMusic(&EnvMusicFilename[2][0],MAXVOLUMES*MAXLEVELS+2); // loadmus + S_PlayMusic(EnvMusicFilename[2], MAXVOLUMES*MAXLEVELS+2); // loadmus } starttime = getticks(); @@ -1382,7 +1382,7 @@ void G_NewGame(int32_t vn, int32_t ln, int32_t sk) if (ln == 0 && vn == 3 && (!g_netServer && ud.multimode < 2) && ud.lockout == 0 && (G_GetLogoFlags() & LOGO_NOE4CUTSCENE)==0) { - S_PlayMusic(&EnvMusicFilename[1][0],MAXVOLUMES*MAXLEVELS+1); + S_PlayMusic(EnvMusicFilename[1], MAXVOLUMES*MAXLEVELS+1); flushperms(); setview(0,0,xdim-1,ydim-1); diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 5f95f504f..408637a38 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -1957,7 +1957,7 @@ static void postloadplayer(int32_t savegamep) (i != g_musicIndex || MapInfo[MAXVOLUMES*MAXLEVELS+2].alt_musicfn)) { S_StopMusic(); - S_PlayMusic(&MapInfo[g_musicIndex].musicfn[0], g_musicIndex); + S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex); } S_PauseMusic(0); diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index 949269870..33f35c7a2 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -166,6 +166,16 @@ void S_MusicVolume(int32_t volume) MUSIC_SetVolume(volume); } +void S_RestartMusic(void) +{ + if (ud.recstat != 2 && g_player[myconnectindex].ps->gm&MODE_GAME) + { + if (MapInfo[g_musicIndex].musicfn != NULL) + S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex); + } + else S_PlayMusic(EnvMusicFilename[0], MAXVOLUMES*MAXLEVELS); +} + void S_MenuSound(void) { static int32_t SoundNum=0; @@ -195,7 +205,8 @@ void S_MenuSound(void) int32_t S_PlayMusic(const char *fn, const int32_t sel) { - char *ofn = (char *)fn, *testfn, *extension; + const char *const ofn = fn; + char *testfn, *extension; int32_t fp, MusicLen; const char *alt = 0; @@ -216,15 +227,14 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel) // we've been asked to load a .mid file, but first let's see // if there's a flac or an ogg with the same base name lying around strcpy(extension, ".flac"); - extension[5] = '\0'; fp = kopen4loadfrommod(testfn, 0); if (fp >= 0) { Bfree(testfn); break; } + strcpy(extension, ".ogg"); - extension[4] = '\0'; fp = kopen4loadfrommod(testfn, 0); if (fp >= 0) { @@ -236,7 +246,7 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel) Bfree(testfn); // just use what we've been given - fp = kopen4loadfrommod((char *)fn, 0); + fp = kopen4loadfrommod(fn, 0); if (alt && fp < 0) fp = kopen4loadfrommod(ofn, 0); diff --git a/polymer/eduke32/source/sounds.h b/polymer/eduke32/source/sounds.h index a6fe1dbae..8abb532a9 100644 --- a/polymer/eduke32/source/sounds.h +++ b/polymer/eduke32/source/sounds.h @@ -89,6 +89,7 @@ void S_MenuSound(void); void S_MusicShutdown(void); void S_MusicStartup(void); void S_MusicVolume(int32_t volume); +void S_RestartMusic(void); void S_PauseMusic(int32_t onf); int32_t S_PlayMusic(const char *fn,const int32_t sel); int32_t S_PlaySound(int32_t num);