diff options
-rw-r--r-- | Spear/App.hs | 11 |
1 files 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 | |||
32 | } | 32 | } |
33 | 33 | ||
34 | defaultAppOptions = AppOptions | 34 | defaultAppOptions = AppOptions |
35 | { maxFPS = 60 -- If non-zero, cap frame rate to this value. | 35 | { maxFPS = 0 -- If non-zero, cap frame rate to this value. |
36 | , animationFPS = 60 -- If non-zero, use fixed time step animation. | 36 | , animationFPS = 60 -- If non-zero, use fixed time step animation. |
37 | , enableProfiling = False | 37 | , enableProfiling = False |
38 | } | 38 | } |
@@ -69,13 +69,13 @@ loop app window = do | |||
69 | 69 | ||
70 | loop' :: | 70 | loop' :: |
71 | Window -> | 71 | Window -> |
72 | TimeDelta -> -- Desired frame time delta. | 72 | TimeDelta -> -- Desired render time delta. |
73 | TimeDelta -> -- Desired animation time delta. | 73 | TimeDelta -> -- Desired animation time delta. |
74 | TimePoint -> -- Time point of last animation update. | 74 | TimePoint -> -- Time point of last animation update. |
75 | Timer -> | 75 | Timer -> |
76 | App s -> | 76 | App s -> |
77 | Game s () | 77 | Game s () |
78 | loop' window ddt animationDdt lastAnimationTime inputTimer app = do | 78 | loop' window renderDdt animationDdt lastAnimationTime inputTimer app = do |
79 | timer <- gameIO $ tick inputTimer | 79 | timer <- gameIO $ tick inputTimer |
80 | windowEvents <- gameIO $ pollWindowEvents window | 80 | windowEvents <- gameIO $ pollWindowEvents window |
81 | close <- gameIO $ shouldWindowClose window | 81 | close <- gameIO $ shouldWindowClose window |
@@ -91,6 +91,7 @@ loop' window ddt animationDdt lastAnimationTime inputTimer app = do | |||
91 | 91 | ||
92 | _ -> do | 92 | _ -> do |
93 | -- Fixed time step animation. | 93 | -- Fixed time step animation. |
94 | let ddt = animationDdt | ||
94 | {- let elapsed = runningTime timer | 95 | {- let elapsed = runningTime timer |
95 | let dt = timeDeltaToSec ddt | 96 | let dt = timeDeltaToSec ddt |
96 | let timeBudgetThisFrame = timeBudget + deltaTime timer | 97 | let timeBudgetThisFrame = timeBudget + deltaTime timer |
@@ -119,11 +120,13 @@ loop' window ddt animationDdt lastAnimationTime inputTimer app = do | |||
119 | gameIO $ swapBuffers window | 120 | gameIO $ swapBuffers window |
120 | 121 | ||
121 | -- Limit frame rate if so requested by the application. | 122 | -- Limit frame rate if so requested by the application. |
123 | -- This currently makes the rendering stutter and is not very desirable. | ||
122 | when ((maxFPS . options $ app) > 0) $ do | 124 | when ((maxFPS . options $ app) > 0) $ do |
123 | frameEnd <- gameIO now | 125 | frameEnd <- gameIO now |
126 | let ddt = renderDdt | ||
124 | let frameTime = timeDiff (lastTick timer) frameEnd | 127 | let frameTime = timeDiff (lastTick timer) frameEnd |
125 | when (frameTime < ddt) $ do | 128 | when (frameTime < ddt) $ do |
126 | gameIO $ Timer.sleep (ddt - frameTime) | 129 | gameIO $ Timer.sleep (ddt - frameTime) |
127 | 130 | ||
128 | when (continue && not close) $ do | 131 | when (continue && not close) $ do |
129 | loop' window ddt animationDdt lastAnimationTimeNextFrame timer app | 132 | loop' window renderDdt animationDdt lastAnimationTimeNextFrame timer app |