rework music looping a little so that eg 'cd play' does not loop, like vanilla

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5658 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2020-03-27 00:49:13 +00:00
parent 73af4c8bf1
commit 2d1699985f
2 changed files with 29 additions and 22 deletions

View file

@ -178,15 +178,7 @@ sfx_t *Media_NextTrack(int musicchannelnum, float *starttime)
sfx_t *s = NULL;
if (bgmvolume.value <= 0 || mastervolume.value <= 0)
return NULL;
if (media_fadeout)
{
if (S_Music_Playing(musicchannelnum))
return NULL; //can't pick a new track until they've all stopped.
//okay, it has actually stopped everywhere.
}
media_fadeout = false; //it has actually ended now
media_fadeout = false; //it has actually ended now, at least on one device. don't fade the new track too...
Q_strncpyz(media_currenttrack, "", sizeof(media_currenttrack));
#ifdef HAVE_JUKEBOX
@ -254,9 +246,15 @@ sfx_t *Media_NextTrack(int musicchannelnum, float *starttime)
return NULL;
}
#endif
if (*media_playtrack)
if (*media_playtrack || *media_loopingtrack)
{
Q_strncpyz(media_currenttrack, media_playtrack, sizeof(media_currenttrack));
if (*media_playtrack)
{
Q_strncpyz(media_currenttrack, media_playtrack, sizeof(media_currenttrack));
*media_playtrack = 0;
}
else
Q_strncpyz(media_currenttrack, media_loopingtrack, sizeof(media_currenttrack));
#ifdef HAVE_JUKEBOX
Q_strncpyz(media_friendlyname, "", sizeof(media_friendlyname));
media_playlistcurrent = MEDIA_GAMEMUSIC;
@ -290,7 +288,7 @@ static qboolean Media_Changed (unsigned int mediatype)
return true;
}
//returns the new volume the sample should be at, to support crossfading.
//returns the new volume the sample should be at, to support fading.
//if we return < 0, the mixer will know to kill whatever is currently playing, ready for a new track.
//this is on the main thread with the mixer locked, its safe to do stuff, but try not to block
float Media_CrossFade(int musicchanel, float vol, float time)

View file

@ -3442,18 +3442,27 @@ void S_UpdateAmbientSounds (soundcardinfo_t *sc)
if (!chan->sfx)
{
float time = 0;
sfx_t *newmusic = Media_NextTrack(i-MUSIC_FIRST, &time);
if (newmusic && newmusic->loadstate != SLS_FAILED)
sfx_t *newmusic;
if (!S_Music_Playing(i-MUSIC_FIRST))
{
chan->sfx = newmusic;
chan->rate = 1<<PITCHSHIFT;
chan->pos = (int)(time * sc->sn.speed) * chan->rate;
changed = CUR_EVERYTHING;
newmusic = Media_NextTrack(i-MUSIC_FIRST, &time);
if (newmusic && newmusic->loadstate != SLS_FAILED)
{ //okay, now we know which track we're meant to be playing, all devices can play it at once.
soundcardinfo_t *sc2;
for (sc2 = sndcardinfo; sc2; sc2=sc2->next)
{
channel_t *chan = &sc2->channel[i];
chan->sfx = newmusic;
chan->rate = 1<<PITCHSHIFT;
chan->pos = (int)(time * sc->sn.speed) * chan->rate;
changed = CUR_EVERYTHING;
chan->master_vol = bound(0, 1, 255);
chan->vol[0] = chan->vol[1] = chan->vol[2] = chan->vol[3] = chan->vol[4] = chan->vol[5] = chan->master_vol;
if (sc->ChannelUpdate)
sc->ChannelUpdate(sc, chan, changed);
chan->master_vol = bound(0, 1, 255);
chan->vol[0] = chan->vol[1] = chan->vol[2] = chan->vol[3] = chan->vol[4] = chan->vol[5] = chan->master_vol;
if (sc->ChannelUpdate)
sc->ChannelUpdate(sc, chan, changed);
}
}
}
}
if (chan->sfx)