More music-related cleanup.

git-svn-id: https://svn.eduke32.com/eduke32@4586 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2014-09-07 18:10:12 +00:00
parent 5597f3faab
commit 73a252a73e
3 changed files with 54 additions and 55 deletions

View file

@ -8750,20 +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;
const int32_t maxi = VOLUMEALL ? MAXVOLUMES*MAXLEVELS : 6;
int32_t res;
do
{
g_musicIndex++;
if (g_musicIndex >= i)
if (g_musicIndex >= maxi)
g_musicIndex = 0;
}
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);
i = g_musicIndex;
res = S_PlayMusic(MapInfo[i].musicfn, i);
Bsnprintf(ScriptQuotes[QUOTE_MUSIC], MAXQUOTELEN, "Playing %s",
res ? MapInfo[i].alt_musicfn : MapInfo[i].musicfn);
P_DoQuote(QUOTE_MUSIC, g_player[myconnectindex].ps);
return;
@ -8970,15 +8972,19 @@ FAKE_F3:
if (KB_UnBoundKeyPressed(sc_F5) && ud.config.MusicDevice >= 0)
{
map_t *map = &MapInfo[g_musicIndex];
char *const qmusic = ScriptQuotes[QUOTE_MUSIC];
KB_ClearKeyDown(sc_F5);
if (MapInfo[g_musicIndex].alt_musicfn != NULL)
Bstrcpy(ScriptQuotes[QUOTE_MUSIC],MapInfo[g_musicIndex].alt_musicfn);
else if (MapInfo[g_musicIndex].musicfn != NULL)
{
Bstrcpy(ScriptQuotes[QUOTE_MUSIC],MapInfo[g_musicIndex].musicfn);
Bstrcat(ScriptQuotes[QUOTE_MUSIC],". Use SHIFT-F5 to change.");
}
else ScriptQuotes[QUOTE_MUSIC][0] = '\0';
if (map->alt_musicfn != NULL)
Bstrncpyz(qmusic, map->alt_musicfn, MAXQUOTELEN);
else if (map->musicfn != NULL)
Bsnprintf(qmusic, MAXQUOTELEN, "%s. Use SHIFT-F5 to change.",
map->musicfn);
else
qmusic[0] = '\0';
P_DoQuote(QUOTE_MUSIC, g_player[myconnectindex].ps);
}

View file

@ -2154,6 +2154,30 @@ void G_DoGameStartup(const int32_t *params)
}
}
void C_DefineMusic(int32_t vol, int32_t lev, const char *fn)
{
if (vol==-1)
{
Bassert((unsigned)lev < MAXVOLUMES);
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);
}
}
}
#ifdef LUNATIC
void C_DefineSound(int32_t sndidx, const char *fn, int32_t args[5])
{
@ -2179,30 +2203,6 @@ void C_DefineSound(int32_t sndidx, const char *fn, int32_t args[5])
}
}
void C_DefineMusic(int32_t vol, int32_t lev, const char *fn)
{
if (vol==-1)
{
Bassert((unsigned)lev < MAXVOLUMES);
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);
}
}
}
void C_DefineQuote(int32_t qnum, const char *qstr)
{
C_AllocQuote(qnum);
@ -2961,7 +2961,7 @@ static int32_t C_ParseCommand(int32_t loop)
k = *g_scriptPtr-1;
if (k >= 0) // if it's background music
if (k >= 0 && k < MAXVOLUMES) // if it's background music
{
i = 0;
// get the file name...
@ -2977,21 +2977,14 @@ static int32_t C_ParseCommand(int32_t loop)
}
tempbuf[j+1] = '\0';
if (MapInfo[(k*MAXLEVELS)+i].musicfn == NULL)
MapInfo[(k*MAXLEVELS)+i].musicfn = (char *)Xcalloc(Bstrlen(tempbuf)+1,sizeof(uint8_t));
else if ((Bstrlen(tempbuf)+1) > sizeof(MapInfo[(k*MAXLEVELS)+i].musicfn))
MapInfo[(k*MAXLEVELS)+i].musicfn = (char *)Xrealloc(MapInfo[(k*MAXLEVELS)+i].musicfn,(Bstrlen(tempbuf)+1));
Bstrcpy(MapInfo[(k*MAXLEVELS)+i].musicfn,tempbuf);
check_filename_case(tempbuf);
C_DefineMusic(k, i, tempbuf);
textptr += j;
if (i > MAXLEVELS-1) break;
i++;
}
}
else
else if (k == -1)
{
i = 0;
while (C_GetKeyword() == -1)

View file

@ -1726,13 +1726,13 @@ static void G_LoadMapHack(char *outbuf, const char *filename)
initprintf("Loaded map hack file \"%s\"\n",outbuf);
}
static void realloc_and_copy_musicfn(int32_t level_number, const char *levnamebuf, int32_t altp)
static void G_ReallocCopyMusicName(int32_t level_number, const char *levnamebuf, int32_t altp)
{
char **musicfn = altp ? &MapInfo[level_number].alt_musicfn : &MapInfo[level_number].musicfn;
char **musfn = altp ? &MapInfo[level_number].alt_musicfn : &MapInfo[level_number].musicfn;
int32_t dastrlen = Bstrlen(levnamebuf);
*musicfn = (char *)Xrealloc(*musicfn, dastrlen+1);
Bstrcpy(*musicfn, levnamebuf);
*musfn = (char *)Xrealloc(*musfn, dastrlen+1);
Bstrcpy(*musfn, levnamebuf);
}
// levnamebuf should have at least size BMAX_PATH
@ -1761,7 +1761,7 @@ void G_SetupFilenameBasedMusic(char *levnamebuf, const char *boardfilename, int3
{
kclose(fil);
realloc_and_copy_musicfn(level_number, levnamebuf, 1);
G_ReallocCopyMusicName(level_number, levnamebuf, 1);
}
else if (MapInfo[level_number].alt_musicfn != NULL)
{
@ -1778,7 +1778,7 @@ void G_SetupFilenameBasedMusic(char *levnamebuf, const char *boardfilename, int3
Bstrcpy(levnamebuf, "dethtoll.mid");
else kclose(fil);
realloc_and_copy_musicfn(level_number, levnamebuf, 0);
G_ReallocCopyMusicName(level_number, levnamebuf, 0);
}
static int G_HaveUserMap(void)