From 2713bc3d756e88714900d881862d65129b8fdb3c Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 7 Sep 2014 18:10:14 +0000 Subject: [PATCH] Get rid of EnvMusicFilename[] and use MapInfo[].musicfn for that. The additional space was there all the time, so it's not understandable why another array was necessary. CON: for 'music', error if volume number is outside [0 .. MAXVOLUMES+1], and in LunaCON, additionally warn if it's MAXVOLUMES+1 (0 is preferred for that). git-svn-id: https://svn.eduke32.com/eduke32@4588 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/duke3d.h | 8 +++ polymer/eduke32/source/game.c | 18 +++---- polymer/eduke32/source/gamedef.c | 61 ++++++++-------------- polymer/eduke32/source/global.h | 3 +- polymer/eduke32/source/lunatic/lunacon.lua | 15 ++++-- polymer/eduke32/source/premap.c | 6 +-- polymer/eduke32/source/savegame.c | 2 +- polymer/eduke32/source/sounds.c | 5 +- 8 files changed, 56 insertions(+), 62 deletions(-) diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index a20019fa1..cb04dc1a8 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -80,6 +80,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define MAXLEVELS 64 #define MAXGAMETYPES 16 +enum { + MUS_FIRST_SPECIAL = MAXVOLUMES*MAXLEVELS, + + MUS_INTRO = MUS_FIRST_SPECIAL, + MUS_BRIEFING = MUS_FIRST_SPECIAL + 1, + MUS_LOADING = MUS_FIRST_SPECIAL + 2, +}; + ////////// TIMING CONSTANTS ////////// // The number of 'totalclock' increments per second: #define TICRATE 120 diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 4a53f8897..47a4713ab 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -8764,7 +8764,7 @@ void G_HandleLocalKeys(void) { if (i == 5 && g_player[myconnectindex].ps->fta > 0 && g_player[myconnectindex].ps->ftq == QUOTE_MUSIC) { - const int32_t maxi = VOLUMEALL ? MAXVOLUMES*MAXLEVELS : 6; + const int32_t maxi = VOLUMEALL ? MUS_FIRST_SPECIAL : 6; do { @@ -9230,36 +9230,34 @@ static int32_t S_DefineSound(int32_t ID, const char *name) // -2: map has no .musicfn (and hence will not be considered even if it has an .alt_musicfn) static int32_t S_DefineMusic(const char *ID, const char *name) { - int32_t sel = MAXVOLUMES * MAXLEVELS; + int32_t sel = MUS_FIRST_SPECIAL; Bassert(ID != NULL); if (!Bstrcmp(ID,"intro")) { - ID = EnvMusicFilename[0]; + // nothing } else if (!Bstrcmp(ID,"briefing")) { sel++; - ID = EnvMusicFilename[1]; } else if (!Bstrcmp(ID,"loading")) { sel += 2; - ID = EnvMusicFilename[2]; } else { sel = G_GetMusicIdx(ID); if (sel < 0) return -1; - - ID = MapInfo[sel].musicfn; } + ID = MapInfo[sel].musicfn; + { map_t *map = &MapInfo[sel]; - const int special = (sel >= MAXVOLUMES*MAXLEVELS); + const int special = (sel >= MUS_FIRST_SPECIAL); map->alt_musicfn = S_OggifyFilename(map->alt_musicfn, name, ID); @@ -10416,8 +10414,8 @@ static void G_DisplayLogo(void) if (logoflags & LOGO_PLAYMUSIC) { - g_musicIndex = -1; // hack - S_PlayMusic(EnvMusicFilename[0], MAXVOLUMES*MAXLEVELS); + g_musicIndex = MUS_INTRO; + S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex); } if (!NAM) diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 19860186c..7c4da0c29 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -2156,25 +2156,15 @@ void G_DoGameStartup(const int32_t *params) void C_DefineMusic(int32_t vol, int32_t lev, const char *fn) { - if (vol==-1) + Bassert((unsigned)vol < MAXVOLUMES+1); + Bassert((unsigned)lev < MAXLEVELS); + { - Bassert((unsigned)lev < MAXVOLUMES); + map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev]; - Bstrncpyz(EnvMusicFilename[lev], fn, BMAX_PATH); - check_filename_case(EnvMusicFilename[lev]); - } - else - { - Bassert((unsigned)vol < MAXVOLUMES+1); - Bassert((unsigned)lev < MAXLEVELS); - - { - map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev]; - - Bfree(map->musicfn); - map->musicfn = dup_filename(fn); - check_filename_case(map->musicfn); - } + Bfree(map->musicfn); + map->musicfn = dup_filename(fn); + check_filename_case(map->musicfn); } } @@ -2959,15 +2949,18 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextValue(LABEL_DEFINE); // Volume Number (0/4) g_scriptPtr--; - k = *g_scriptPtr-1; + k = *g_scriptPtr-1; // 0-based volume number. -1 or MAXVOLUMES: "special" + if (k == -1) + k = MAXVOLUMES; - if (k >= 0 && k < MAXVOLUMES) // if it's background music + if (k >= 0 && k < MAXVOLUMES+1) // if it's background or special music { i = 0; // get the file name... while (C_GetKeyword() == -1) { C_SkipComments(); + j = 0; tempbuf[j] = '/'; while (isaltok(*(textptr+j))) @@ -2980,32 +2973,20 @@ static int32_t C_ParseCommand(int32_t loop) C_DefineMusic(k, i, tempbuf); textptr += j; - if (i > MAXLEVELS-1) break; + + if (i >= MAXLEVELS) + break; i++; } } - else if (k == -1) + else { - i = 0; - while (C_GetKeyword() == -1) - { - C_SkipComments(); - j = 0; - - while (isaltok(*(textptr+j))) - { - EnvMusicFilename[i][j] = textptr[j]; - j++; - } - EnvMusicFilename[i][j] = '\0'; - - check_filename_case(EnvMusicFilename[i]); - - textptr += j; - if (i > MAXVOLUMES-1) break; - i++; - } + g_numCompilerErrors++; + C_ReportError(-1); + initprintf("%s:%d: error: volume number must be between 0 and MAXVOLUMES+1=%d.\n", + g_szScriptFileName, g_lineNumber, MAXVOLUMES+1); } + } continue; diff --git a/polymer/eduke32/source/global.h b/polymer/eduke32/source/global.h index d6abfa725..94ead06a8 100644 --- a/polymer/eduke32/source/global.h +++ b/polymer/eduke32/source/global.h @@ -57,7 +57,6 @@ G_EXTERN tiledata_t g_tile[MAXTILES]; G_EXTERN animwalltype animwall[MAXANIMWALLS]; G_EXTERN char *ScriptQuotes[MAXQUOTES],*ScriptQuoteRedefinitions[MAXQUOTES]; G_EXTERN char *label; -G_EXTERN char EnvMusicFilename[MAXVOLUMES+1][BMAX_PATH]; G_EXTERN int32_t g_musicIndex; G_EXTERN char g_loadFromGroupOnly; G_EXTERN char g_numSkills; @@ -109,7 +108,7 @@ G_EXTERN intptr_t *g_parsingActorPtr; G_EXTERN intptr_t *g_scriptPtr,*insptr; G_EXTERN int32_t *labelcode,*labeltype; G_EXTERN intptr_t *script; -G_EXTERN map_t MapInfo[(MAXVOLUMES+1)*MAXLEVELS]; // +1 volume for "intro", "briefing" music +G_EXTERN map_t MapInfo[(MAXVOLUMES+1)*MAXLEVELS]; // +1 volume for "intro", "briefing" and "loading" music #pragma pack(push,1) G_EXTERN playerdata_t g_player[MAXPLAYERS]; G_EXTERN playerspawn_t g_playerSpawnPoints[MAXPLAYERS]; diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 028987681..a2370a40a 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -1403,16 +1403,21 @@ function Cmd.definesound(sndlabel, fn, ...) end function Cmd.music(volnum, ...) - local envmusicp = (volnum==0) - if (not (volnum >= 0 and volnum <= conl.MAXVOLUMES+1)) then - -- NOTE: Also allow MAXVOLUMES+1. - errprintf("volume number must be between 0 and MAXVOLUMES=%d", conl.MAXVOLUMES) + -- The passed volume number is 1-based. + -- Both 0 and MAXVOLUMES+1 means "special music" + errprintf("volume number must be between 0 and MAXVOLUMES+1=%d", conl.MAXVOLUMES+1) return + elseif (volnum == conl.MAXVOLUMES+1) then + warnprintf("volume number MAXVOLUMES+1 is discouraged, use 0 instead") + end + + if (volnum == 0) then + volnum = conl.MAXVOLUMES+1 -- special music end local filenames = {...} - local MAXFNS = envmusicp and conl.MAXVOLUMES or conl.MAXLEVELS + local MAXFNS = conl.MAXLEVELS if (#filenames > MAXFNS) then warnprintf("ignoring extraneous %d music file names", #filenames-MAXFNS) diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 3a03e5705..ba4d3e659 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -436,10 +436,10 @@ void G_CacheMapData(void) return; S_PauseMusic(1); - if (MapInfo[MAXVOLUMES*MAXLEVELS+2].alt_musicfn) + if (MapInfo[MUS_LOADING].musicfn) { S_StopMusic(); - S_PlayMusic(EnvMusicFilename[2], MAXVOLUMES*MAXLEVELS+2); // loadmus + S_PlayMusic(MapInfo[MUS_LOADING].musicfn, MUS_LOADING); } 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], MAXVOLUMES*MAXLEVELS+1); + S_PlayMusic(MapInfo[MUS_BRIEFING].musicfn, MUS_BRIEFING); flushperms(); setview(0,0,xdim-1,ydim-1); diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 408637a38..ab0d5f9b4 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -1954,7 +1954,7 @@ static void postloadplayer(int32_t savegamep) if (ud.config.MusicToggle) { if (MapInfo[g_musicIndex].musicfn != NULL && - (i != g_musicIndex || MapInfo[MAXVOLUMES*MAXLEVELS+2].alt_musicfn)) + (i != g_musicIndex /* || MapInfo[MUS_LOADING].musicfn */)) { S_StopMusic(); S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex); diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index 33f35c7a2..f9b5963c7 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -173,7 +173,10 @@ void S_RestartMusic(void) if (MapInfo[g_musicIndex].musicfn != NULL) S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex); } - else S_PlayMusic(EnvMusicFilename[0], MAXVOLUMES*MAXLEVELS); + else if (MapInfo[MUS_INTRO].musicfn != 0) + { + S_PlayMusic(MapInfo[MUS_INTRO].musicfn, MUS_INTRO); + } } void S_MenuSound(void)