Updated captions to:

* be more efficient
* fade away early if they stop playing
* make their current max stick-around time longer
* make the fade time/etc easier to modify
This commit is contained in:
toasterbabe 2017-04-29 12:58:40 +01:00
parent bdaa0aea9b
commit 94add11fab
3 changed files with 17 additions and 14 deletions

View File

@ -586,7 +586,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)
closedcaptions[set].c = &channels[cnum];
closedcaptions[set].s = sfx;
closedcaptions[set].t = TICRATE+2;
closedcaptions[set].t = MAXCAPTIONTICS+2;
}
// Assigns the handle to one of the channels in the
@ -694,7 +694,7 @@ dontplay:
closedcaptions[set].c = &channels[cnum];
closedcaptions[set].s = sfx;
closedcaptions[set].t = TICRATE+2;
closedcaptions[set].t = MAXCAPTIONTICS+2;
}
// Assigns the handle to one of the channels in the
@ -973,21 +973,22 @@ notinlevel:
for (i = 0; i < NUMCAPTIONS; i++) // update captions
{
boolean cond = (closedcaptions[i].c && I_SoundIsPlaying(closedcaptions[i].c->handle));
if (!closedcaptions[i].s)
continue;
if (closedcaptions[i].t <= TICRATE)
if (closedcaptions[i].t <= MAXCAPTIONTICS)
closedcaptions[i].t--;
if (cond || (closedcaptions[i].s && closedcaptions[i].t))
{
if (!cond)
closedcaptions[i].c = NULL;
}
if (!closedcaptions[i].t)
{
closedcaptions[i].c = NULL;
closedcaptions[i].s = NULL;
closedcaptions[i].t = 0;
}
else if (closedcaptions[i].c && !I_SoundIsPlaying(closedcaptions[i].c->handle))
{
closedcaptions[i].c = NULL;
if (closedcaptions[i].t > CAPTIONFADETICS)
closedcaptions[i].t = CAPTIONFADETICS;
}
}
}

View File

@ -86,6 +86,8 @@ typedef struct {
} caption_t;
#define NUMCAPTIONS 8
#define MAXCAPTIONTICS (2*TICRATE)
#define CAPTIONFADETICS 20
extern caption_t closedcaptions[NUMCAPTIONS];

View File

@ -449,10 +449,10 @@ void SCR_ClosedCaptions(void)
INT32 flags = V_NOSCALESTART|V_ALLOWLOWERCASE;
INT32 y = vid.height-((i + 2)*10*vid.dupy);
char dir = ' ';
if (closedcaptions[i].t < 20)
flags |= (((20-closedcaptions[i].t)/2)*V_10TRANS);
else if (closedcaptions[i].t > TICRATE)
y -= (closedcaptions[i].t-- - TICRATE)*vid.dupy;
if (closedcaptions[i].t < CAPTIONFADETICS)
flags |= (((CAPTIONFADETICS-closedcaptions[i].t)/2)*V_10TRANS);
else if (closedcaptions[i].t > MAXCAPTIONTICS)
y -= (closedcaptions[i].t-- - MAXCAPTIONTICS)*vid.dupy;
if (closedcaptions[i].c && closedcaptions[i].c->origin)
dir = '\x1E';
V_DrawRightAlignedString(vid.width-(20*vid.dupx), y,