Interpolate captions

This commit is contained in:
Zwip-Zwap Zapony 2023-02-02 15:50:40 +01:00
parent c2aa6d4c74
commit 8cf6e8252c
2 changed files with 12 additions and 6 deletions

View file

@ -513,7 +513,7 @@ void S_StartCaption(sfxenum_t sfx_id, INT32 cnum, UINT16 lifespan)
closedcaptions[set].c = ((cnum == -1) ? NULL : &channels[cnum]); closedcaptions[set].c = ((cnum == -1) ? NULL : &channels[cnum]);
closedcaptions[set].s = sfx; closedcaptions[set].s = sfx;
closedcaptions[set].t = lifespan; closedcaptions[set].t = lifespan;
closedcaptions[set].b = 2; // bob closedcaptions[set].b = 3; // bob
} }
void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)

View file

@ -572,7 +572,8 @@ void SCR_ClosedCaptions(void)
for (i = 0; i < NUMCAPTIONS; i++) for (i = 0; i < NUMCAPTIONS; i++)
{ {
INT32 flags, y; INT32 flags;
fixed_t y;
char dot; char dot;
boolean music; boolean music;
@ -585,14 +586,19 @@ void SCR_ClosedCaptions(void)
continue; continue;
flags = V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_ALLOWLOWERCASE; flags = V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_ALLOWLOWERCASE;
y = basey-(i*10); y = (basey-(i*10)) * FRACUNIT;
if (closedcaptions[i].b) if (closedcaptions[i].b)
{ {
y -= closedcaptions[i].b * 4;
if (renderisnewtic) if (renderisnewtic)
{
closedcaptions[i].b--; closedcaptions[i].b--;
if (closedcaptions[i].b) // If the caption hasn't reached its final destination...
{
y -= closedcaptions[i].b * 4 * FRACUNIT; // ...move it per tic...
y += (rendertimefrac % FRACUNIT) * 4; // ...and interpolate it per frame
// We have to modulo it by FRACUNIT, so that it won't be a tic ahead with interpolation disabled
// Unlike everything else, captions are (intentionally) interpolated from T to T+1 instead of T-1 to T
} }
} }
@ -606,7 +612,7 @@ void SCR_ClosedCaptions(void)
else else
dot = ' '; dot = ' ';
V_DrawRightAlignedString(BASEVIDWIDTH - 20, y, flags, V_DrawRightAlignedStringAtFixed((BASEVIDWIDTH-20) * FRACUNIT, y, flags,
va("%c [%s]", dot, (closedcaptions[i].s->caption[0] ? closedcaptions[i].s->caption : closedcaptions[i].s->name))); va("%c [%s]", dot, (closedcaptions[i].s->caption[0] ? closedcaptions[i].s->caption : closedcaptions[i].s->name)));
} }
} }