From a1fbf37b4a5cf66bfb6e302e2dd8b7a82d627509 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sun, 22 Dec 2024 09:21:07 -0800 Subject: Fix use of ddt. --- Spear/App.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Spear/App.hs b/Spear/App.hs index 93837c2..7f23359 100644 --- a/Spear/App.hs +++ b/Spear/App.hs @@ -32,7 +32,7 @@ data AppOptions = AppOptions } defaultAppOptions = AppOptions - { maxFPS = 60 -- If non-zero, cap frame rate to this value. + { maxFPS = 0 -- If non-zero, cap frame rate to this value. , animationFPS = 60 -- If non-zero, use fixed time step animation. , enableProfiling = False } @@ -69,13 +69,13 @@ loop app window = do loop' :: Window -> - TimeDelta -> -- Desired frame time delta. + TimeDelta -> -- Desired render time delta. TimeDelta -> -- Desired animation time delta. TimePoint -> -- Time point of last animation update. Timer -> App s -> Game s () -loop' window ddt animationDdt lastAnimationTime inputTimer app = do +loop' window renderDdt animationDdt lastAnimationTime inputTimer app = do timer <- gameIO $ tick inputTimer windowEvents <- gameIO $ pollWindowEvents window close <- gameIO $ shouldWindowClose window @@ -91,6 +91,7 @@ loop' window ddt animationDdt lastAnimationTime inputTimer app = do _ -> do -- Fixed time step animation. + let ddt = animationDdt {- let elapsed = runningTime timer let dt = timeDeltaToSec ddt let timeBudgetThisFrame = timeBudget + deltaTime timer @@ -119,11 +120,13 @@ loop' window ddt animationDdt lastAnimationTime inputTimer app = do gameIO $ swapBuffers window -- Limit frame rate if so requested by the application. + -- This currently makes the rendering stutter and is not very desirable. when ((maxFPS . options $ app) > 0) $ do frameEnd <- gameIO now + let ddt = renderDdt let frameTime = timeDiff (lastTick timer) frameEnd when (frameTime < ddt) $ do gameIO $ Timer.sleep (ddt - frameTime) when (continue && not close) $ do - loop' window ddt animationDdt lastAnimationTimeNextFrame timer app + loop' window renderDdt animationDdt lastAnimationTimeNextFrame timer app -- cgit v1.2.3