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
This commit is contained in:
helixhorned 2014-09-07 18:10:14 +00:00
parent 3dc5c9e144
commit 2713bc3d75
8 changed files with 56 additions and 62 deletions

View file

@ -80,6 +80,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define MAXLEVELS 64 #define MAXLEVELS 64
#define MAXGAMETYPES 16 #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 ////////// ////////// TIMING CONSTANTS //////////
// The number of 'totalclock' increments per second: // The number of 'totalclock' increments per second:
#define TICRATE 120 #define TICRATE 120

View file

@ -8764,7 +8764,7 @@ void G_HandleLocalKeys(void)
{ {
if (i == 5 && g_player[myconnectindex].ps->fta > 0 && g_player[myconnectindex].ps->ftq == QUOTE_MUSIC) 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 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) // -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) 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); Bassert(ID != NULL);
if (!Bstrcmp(ID,"intro")) if (!Bstrcmp(ID,"intro"))
{ {
ID = EnvMusicFilename[0]; // nothing
} }
else if (!Bstrcmp(ID,"briefing")) else if (!Bstrcmp(ID,"briefing"))
{ {
sel++; sel++;
ID = EnvMusicFilename[1];
} }
else if (!Bstrcmp(ID,"loading")) else if (!Bstrcmp(ID,"loading"))
{ {
sel += 2; sel += 2;
ID = EnvMusicFilename[2];
} }
else else
{ {
sel = G_GetMusicIdx(ID); sel = G_GetMusicIdx(ID);
if (sel < 0) if (sel < 0)
return -1; return -1;
ID = MapInfo[sel].musicfn;
} }
ID = MapInfo[sel].musicfn;
{ {
map_t *map = &MapInfo[sel]; 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); map->alt_musicfn = S_OggifyFilename(map->alt_musicfn, name, ID);
@ -10416,8 +10414,8 @@ static void G_DisplayLogo(void)
if (logoflags & LOGO_PLAYMUSIC) if (logoflags & LOGO_PLAYMUSIC)
{ {
g_musicIndex = -1; // hack g_musicIndex = MUS_INTRO;
S_PlayMusic(EnvMusicFilename[0], MAXVOLUMES*MAXLEVELS); S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex);
} }
if (!NAM) if (!NAM)

View file

@ -2156,25 +2156,15 @@ void G_DoGameStartup(const int32_t *params)
void C_DefineMusic(int32_t vol, int32_t lev, const char *fn) 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); Bfree(map->musicfn);
check_filename_case(EnvMusicFilename[lev]); map->musicfn = dup_filename(fn);
} check_filename_case(map->musicfn);
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);
}
} }
} }
@ -2959,15 +2949,18 @@ static int32_t C_ParseCommand(int32_t loop)
C_GetNextValue(LABEL_DEFINE); // Volume Number (0/4) C_GetNextValue(LABEL_DEFINE); // Volume Number (0/4)
g_scriptPtr--; 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; i = 0;
// get the file name... // get the file name...
while (C_GetKeyword() == -1) while (C_GetKeyword() == -1)
{ {
C_SkipComments(); C_SkipComments();
j = 0; j = 0;
tempbuf[j] = '/'; tempbuf[j] = '/';
while (isaltok(*(textptr+j))) while (isaltok(*(textptr+j)))
@ -2980,32 +2973,20 @@ static int32_t C_ParseCommand(int32_t loop)
C_DefineMusic(k, i, tempbuf); C_DefineMusic(k, i, tempbuf);
textptr += j; textptr += j;
if (i > MAXLEVELS-1) break;
if (i >= MAXLEVELS)
break;
i++; i++;
} }
} }
else if (k == -1) else
{ {
i = 0; g_numCompilerErrors++;
while (C_GetKeyword() == -1) C_ReportError(-1);
{ initprintf("%s:%d: error: volume number must be between 0 and MAXVOLUMES+1=%d.\n",
C_SkipComments(); g_szScriptFileName, g_lineNumber, MAXVOLUMES+1);
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++;
}
} }
} }
continue; continue;

View file

@ -57,7 +57,6 @@ G_EXTERN tiledata_t g_tile[MAXTILES];
G_EXTERN animwalltype animwall[MAXANIMWALLS]; G_EXTERN animwalltype animwall[MAXANIMWALLS];
G_EXTERN char *ScriptQuotes[MAXQUOTES],*ScriptQuoteRedefinitions[MAXQUOTES]; G_EXTERN char *ScriptQuotes[MAXQUOTES],*ScriptQuoteRedefinitions[MAXQUOTES];
G_EXTERN char *label; G_EXTERN char *label;
G_EXTERN char EnvMusicFilename[MAXVOLUMES+1][BMAX_PATH];
G_EXTERN int32_t g_musicIndex; G_EXTERN int32_t g_musicIndex;
G_EXTERN char g_loadFromGroupOnly; G_EXTERN char g_loadFromGroupOnly;
G_EXTERN char g_numSkills; G_EXTERN char g_numSkills;
@ -109,7 +108,7 @@ G_EXTERN intptr_t *g_parsingActorPtr;
G_EXTERN intptr_t *g_scriptPtr,*insptr; G_EXTERN intptr_t *g_scriptPtr,*insptr;
G_EXTERN int32_t *labelcode,*labeltype; G_EXTERN int32_t *labelcode,*labeltype;
G_EXTERN intptr_t *script; 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) #pragma pack(push,1)
G_EXTERN playerdata_t g_player[MAXPLAYERS]; G_EXTERN playerdata_t g_player[MAXPLAYERS];
G_EXTERN playerspawn_t g_playerSpawnPoints[MAXPLAYERS]; G_EXTERN playerspawn_t g_playerSpawnPoints[MAXPLAYERS];

View file

@ -1403,16 +1403,21 @@ function Cmd.definesound(sndlabel, fn, ...)
end end
function Cmd.music(volnum, ...) function Cmd.music(volnum, ...)
local envmusicp = (volnum==0)
if (not (volnum >= 0 and volnum <= conl.MAXVOLUMES+1)) then if (not (volnum >= 0 and volnum <= conl.MAXVOLUMES+1)) then
-- NOTE: Also allow MAXVOLUMES+1. -- The passed volume number is 1-based.
errprintf("volume number must be between 0 and MAXVOLUMES=%d", conl.MAXVOLUMES) -- Both 0 and MAXVOLUMES+1 means "special music"
errprintf("volume number must be between 0 and MAXVOLUMES+1=%d", conl.MAXVOLUMES+1)
return 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 end
local filenames = {...} local filenames = {...}
local MAXFNS = envmusicp and conl.MAXVOLUMES or conl.MAXLEVELS local MAXFNS = conl.MAXLEVELS
if (#filenames > MAXFNS) then if (#filenames > MAXFNS) then
warnprintf("ignoring extraneous %d music file names", #filenames-MAXFNS) warnprintf("ignoring extraneous %d music file names", #filenames-MAXFNS)

View file

@ -436,10 +436,10 @@ void G_CacheMapData(void)
return; return;
S_PauseMusic(1); S_PauseMusic(1);
if (MapInfo[MAXVOLUMES*MAXLEVELS+2].alt_musicfn) if (MapInfo[MUS_LOADING].musicfn)
{ {
S_StopMusic(); S_StopMusic();
S_PlayMusic(EnvMusicFilename[2], MAXVOLUMES*MAXLEVELS+2); // loadmus S_PlayMusic(MapInfo[MUS_LOADING].musicfn, MUS_LOADING);
} }
starttime = getticks(); 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 if (ln == 0 && vn == 3 && (!g_netServer && ud.multimode < 2) && ud.lockout == 0
&& (G_GetLogoFlags() & LOGO_NOE4CUTSCENE)==0) && (G_GetLogoFlags() & LOGO_NOE4CUTSCENE)==0)
{ {
S_PlayMusic(EnvMusicFilename[1], MAXVOLUMES*MAXLEVELS+1); S_PlayMusic(MapInfo[MUS_BRIEFING].musicfn, MUS_BRIEFING);
flushperms(); flushperms();
setview(0,0,xdim-1,ydim-1); setview(0,0,xdim-1,ydim-1);

View file

@ -1954,7 +1954,7 @@ static void postloadplayer(int32_t savegamep)
if (ud.config.MusicToggle) if (ud.config.MusicToggle)
{ {
if (MapInfo[g_musicIndex].musicfn != NULL && 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_StopMusic();
S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex); S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex);

View file

@ -173,7 +173,10 @@ void S_RestartMusic(void)
if (MapInfo[g_musicIndex].musicfn != NULL) if (MapInfo[g_musicIndex].musicfn != NULL)
S_PlayMusic(MapInfo[g_musicIndex].musicfn, g_musicIndex); 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) void S_MenuSound(void)