From c75778c08d671de4688b8d0f77e79a819f7f08bb Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 5 Aug 2021 14:48:32 +1000 Subject: [PATCH] - Blood: Re-time menu's blood dripping based on reworked timer and QAV struct code. --- source/games/blood/src/d_menu.cpp | 37 +++++++++---------------------- source/games/blood/src/qav.cpp | 18 +++++++++++++++ source/games/blood/src/qav.h | 3 ++- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/source/games/blood/src/d_menu.cpp b/source/games/blood/src/d_menu.cpp index be4292249..b747adeaf 100644 --- a/source/games/blood/src/d_menu.cpp +++ b/source/games/blood/src/d_menu.cpp @@ -41,8 +41,7 @@ BEGIN_BLD_NS class CGameMenuItemQAV { public: - int m_nX, m_nY; - TArray raw; + QAV* data; int duration; int lastTick; bool bWideScreen; @@ -54,25 +53,20 @@ public: CGameMenuItemQAV::CGameMenuItemQAV(int a3, int a4, const char* name, bool widescreen, bool clearbackground) { - m_nY = a4; - m_nX = a3; bWideScreen = widescreen; bClearBackground = clearbackground; filename = name; if (name) { - // NBlood read this directly from the file system cache, but let's better store the data locally for robustness. - raw = fileSystem.LoadFile(name, 0); - if (raw.Size() != 0) + data = getQAV(fileSystem.GetResourceId(fileSystem.FindFile(name))); + if (data) { - auto data = (QAV*)raw.Data(); data->nSprite = -1; - data->x = m_nX; - data->y = m_nY; - //data->Preload(); + data->x = a3; + data->y = a4; duration = data->duration; - lastTick = I_GetTime(); + lastTick = I_GetTime(data->ticrate); } } } @@ -82,29 +76,18 @@ void CGameMenuItemQAV::Draw(void) if (bClearBackground) twod->ClearScreen(); - if (raw.Size() > 0) + if (data) { - auto data = (QAV*)raw.Data(); - - auto thisTick = I_GetTime(); - if (!lastTick) - { - lastTick = thisTick; - } - if (lastTick < thisTick) - { - lastTick = thisTick; - duration -= 4; - } + qavProcessTicker(data, &duration, &lastTick); if (duration <= 0 || duration > data->duration) { duration = data->duration; } auto currentDuration = data->duration - duration; - auto smoothratio = I_GetTimeFrac() * MaxSmoothRatio; + auto smoothratio = I_GetTimeFrac(data->ticrate) * MaxSmoothRatio; - data->Play(currentDuration - 4, currentDuration, -1, NULL); + data->Play(currentDuration - data->ticksPerFrame, currentDuration, -1, NULL); if (bWideScreen) { diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index dbebc6ec3..ef985fc9e 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -221,6 +221,21 @@ void QAV::Precache(int palette) } } +void qavProcessTicker(QAV* const pQAV, int* duration, int* lastTick) +{ + if (*duration > 0) + { + auto thisTick = I_GetTime(pQAV->ticrate); + auto numTicks = thisTick - (*lastTick); + if (numTicks) + { + *lastTick = thisTick; + *duration -= pQAV->ticksPerFrame * numTicks; + } + } + *duration = ClipLow(*duration, 0); +} + // This is to eliminate a huge design issue in NBlood that was apparently copied verbatim from the DOS-Version. // Sequences were cached in the resource and directly returned from there in writable form, with byte swapping directly performed in the cache on Big Endian systems. @@ -279,6 +294,9 @@ QAV* getQAV(int res_id) } } + // Write out additions. + qavdata->ticrate = 120. / qavdata->ticksPerFrame; + qavcache.Insert(res_id, qavdata); return qavdata; } diff --git a/source/games/blood/src/qav.h b/source/games/blood/src/qav.h index 798d0c03e..805fd3582 100644 --- a/source/games/blood/src/qav.h +++ b/source/games/blood/src/qav.h @@ -67,7 +67,7 @@ struct FRAMEINFO struct QAV { - char pad1[8]; // 0 + double ticrate; // 0 int nFrames; // 8 int ticksPerFrame; // C int duration; // 10 @@ -85,5 +85,6 @@ struct QAV }; QAV* getQAV(int res_id); +void qavProcessTicker(QAV* const pQAV, int* duration, int* lastTick); END_BLD_NS