From f76d13920776ca5be95f1fe1c59420011b804dc5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 2 Feb 2020 09:51:44 +0100 Subject: [PATCH] - fixed SW's interpolation math. --- source/build/include/clockticks.hpp | 4 ++++ source/sw/src/draw.cpp | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/source/build/include/clockticks.hpp b/source/build/include/clockticks.hpp index c4de5584d..d4a6948dd 100644 --- a/source/build/include/clockticks.hpp +++ b/source/build/include/clockticks.hpp @@ -44,6 +44,10 @@ public: { return ticksS32 >> 16; } + double toScale16F() const + { + return ticksS32 * (1/(65536.*65536.)); + } ClockTicks& setFromScale16(int64_t const ticksScale16) { ticksS32 = ticksScale16 << 16; diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index dc1ed5609..0f3d7a2da 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1994,6 +1994,19 @@ SWBOOL PicInView(short, SWBOOL); void DoPlayerDiveMeter(PLAYERp pp); void MoveScrollMode2D(PLAYERp pp); + +static inline int32_t calc_smoothratio_demo(ClockTicks totalclk, ClockTicks ototalclk) +{ + const int TICRATE = 120; + const int REALGAMETICSPERSEC = TICRATE / synctics; + + int32_t rfreq = (refreshfreq != -1 ? refreshfreq : 60); + double elapsedTime = (totalclk - ototalclk).toScale16F(); + double elapsedFrames = elapsedTime * rfreq * (1. / TICRATE); + double ratio = (elapsedFrames * REALGAMETICSPERSEC) / rfreq; + return clamp(xs_RoundToInt(ratio * 65536), 0, 65536); +} + void drawscreen(PLAYERp pp) { @@ -2063,7 +2076,7 @@ drawscreen(PLAYERp pp) PreUpdatePanel(); - smoothratio = min(max(((int32_t) totalclock - ototalclock) * (65536 / synctics),0),65536); + smoothratio = calc_smoothratio_demo(totalclock, ototalclock); if (!ScreenSavePic) {