- Blood: Perform interpolation of menu's blood dripping.

* All supporting code is here, is tested and works, need to determine best how to flag the menu as "Animated" to uncap the frame-rate.
This commit is contained in:
Mitchell Richters 2021-07-31 10:05:18 +10:00
parent a67c126129
commit 9884d5f396
3 changed files with 71 additions and 43 deletions

View file

@ -47,6 +47,7 @@ public:
int lastTick;
bool bWideScreen;
bool bClearBackground;
const char* filename;
CGameMenuItemQAV(int, int, const char*, bool widescreen = false, bool clearbackground = false);
void Draw(void);
};
@ -57,6 +58,7 @@ CGameMenuItemQAV::CGameMenuItemQAV(int a3, int a4, const char* name, bool widesc
m_nX = a3;
bWideScreen = widescreen;
bClearBackground = clearbackground;
filename = name;
if (name)
{
@ -70,7 +72,7 @@ CGameMenuItemQAV::CGameMenuItemQAV(int a3, int a4, const char* name, bool widesc
data->y = m_nY;
//data->Preload();
duration = data->duration;
lastTick = I_GetBuildTime();
lastTick = I_GetTime();
}
}
}
@ -83,17 +85,26 @@ void CGameMenuItemQAV::Draw(void)
if (raw.Size() > 0)
{
auto data = (QAV*)raw.Data();
int backFC = PlayClock;
int currentclock = I_GetBuildTime();
PlayClock = currentclock;
int nTicks = currentclock - lastTick;
lastTick = currentclock;
duration -= nTicks;
auto thisTick = I_GetTime();
if (!lastTick)
{
lastTick = thisTick;
}
if (lastTick < thisTick)
{
lastTick = thisTick;
duration -= 4;
}
if (duration <= 0 || duration > data->duration)
{
duration = data->duration;
}
data->Play(data->duration - duration - nTicks, data->duration - duration, -1, NULL);
auto currentDuration = data->duration - duration;
auto smoothratio = I_GetTimeFrac() * MaxSmoothRatio;
data->Play(currentDuration - 4, currentDuration, -1, NULL);
if (bWideScreen)
{
@ -102,15 +113,13 @@ void CGameMenuItemQAV::Draw(void)
int backX = data->x;
for (int i = 0; i < nCount; i++)
{
data->Draw(data->duration - duration, 10 + kQavOrientationLeft, 0, 0, false);
data->Draw(currentDuration, 10 + kQavOrientationLeft, 0, 0, false, smoothratio, filename == "BDRIP.QAV");
data->x += 320;
}
data->x = backX;
}
else
data->Draw(data->duration - duration, 10, 0, 0, false);
PlayClock = backFC;
data->Draw(currentDuration, 10, 0, 0, false, smoothratio, filename == "BDRIP.QAV");
}
}

View file

@ -72,7 +72,7 @@ void DrawFrame(double x, double y, double z, double a, TILE_FRAME *pTile, int st
}
}
void QAV::Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool to3dview, double const smoothratio)
void QAV::Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool to3dview, double const smoothratio, bool const menudrip)
{
assert(ticksPerFrame > 0);
@ -93,45 +93,64 @@ void QAV::Draw(double x, double y, int ticks, int stat, int shade, int palnum, b
assert(oFrame >= 0 && oFrame < nFrames);
FRAMEINFO *prevFrame = &frames[oFrame];
auto drawTile = [&](TILE_FRAME *thisTile, TILE_FRAME *prevTile, bool const interpolate = true)
{
double tileX = x;
double tileY = y;
double tileZ;
double tileA;
if (prevTile && cl_hudinterpolation && (nFrames > 1) && (nFrame != oFrame) && (smoothratio != MaxSmoothRatio) && interpolate)
{
tileX += interpolatedvaluef(prevTile->x, thisTile->x, smoothratio);
tileY += interpolatedvaluef(prevTile->y, thisTile->y, smoothratio);
tileZ = interpolatedvaluef(prevTile->z, thisTile->z, smoothratio);
tileA = interpolatedangle(buildang(prevTile->angle), buildang(thisTile->angle), smoothratio).asbuildf();
}
else
{
tileX += thisTile->x;
tileY += thisTile->y;
tileZ = thisTile->z;
tileA = thisTile->angle;
}
DrawFrame(tileX, tileY, tileZ, tileA, thisTile, stat, shade, palnum, to3dview);
};
for (int i = 0; i < 8; i++)
{
auto* thisTile = &thisFrame->tiles[i];
TILE_FRAME *thisTile = &thisFrame->tiles[i];
TILE_FRAME *prevTile = nullptr;
if (thisTile->picnum > 0)
{
TILE_FRAME *prevTile = nullptr;
if (thisTile->picnum == prevFrame->tiles[i].picnum)
// Menu's blood drip requires special treatment.
if (menudrip)
{
prevTile = &prevFrame->tiles[i];
}
else for (int j = 0; j < 8; j++) if (thisTile->picnum == prevFrame->tiles[j].picnum)
{
prevTile = &prevFrame->tiles[j];
break;
}
if (i != 0)
{
// Find previous frame by iterating all previous frame's tiles and match on the consistent x coordinate.
// Tile indices can change between frames for no reason, we need to accomodate that.
for (int j = 0; j < 8; j++) if (thisTile->x == prevFrame->tiles[j].x)
{
prevTile = &prevFrame->tiles[j];
break;
}
double tileX = x;
double tileY = y;
double tileZ;
double tileA;
if ((nFrames > 1) && (nFrame != oFrame) && (prevTile && (thisTile->picnum == prevTile->picnum)) && (smoothratio != MaxSmoothRatio))
{
tileX += interpolatedvaluef(prevTile->x, thisTile->x, smoothratio);
tileY += interpolatedvaluef(prevTile->y, thisTile->y, smoothratio);
tileZ = interpolatedvaluef(prevTile->z, thisTile->z, smoothratio);
tileA = interpolatedangle(buildang(prevTile->angle), buildang(thisTile->angle), smoothratio).asbuildf();
drawTile(thisTile, prevTile, true);
}
else
{
// First index is always the dripping bar at the top.
drawTile(thisTile, prevTile, false);
}
}
else
{
tileX += thisTile->x;
tileY += thisTile->y;
tileZ = thisTile->z;
tileA = thisTile->angle;
prevTile = &prevFrame->tiles[i];
drawTile(thisTile, prevTile, thisTile->picnum == prevTile->picnum);
}
DrawFrame(tileX, tileY, tileZ, tileA, thisTile, stat, shade, palnum, to3dview);
}
}
}

View file

@ -80,8 +80,8 @@ struct QAV
char pad3[3]; // 20
char lastframetic;
FRAMEINFO frames[1]; // 24
void Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool to3dview, double const smoothratio = 65536);
void Draw(int ticks, int stat, int shade, int palnum, bool to3dview, double const smoothratio = 65536) { Draw(x, y, ticks, stat, shade, palnum, to3dview, smoothratio); }
void Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool to3dview, double const smoothratio = 65536, bool const menudrip = false);
void Draw(int ticks, int stat, int shade, int palnum, bool to3dview, double const smoothratio = 65536, bool const menudrip = false) { Draw(x, y, ticks, stat, shade, palnum, to3dview, smoothratio, menudrip); }
void Play(int, int, int, void *);
void Precache(int palette = 0);
};