diff options
author | 3gg <3gg@shellblade.net> | 2024-11-17 09:48:34 -0800 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-11-17 09:48:34 -0800 |
commit | 0c3aec903c2fa0fbb9db5c04a29f7e1f8529ae77 (patch) | |
tree | cfc0a08b6e0ea3ac9328f3d3740e1c6b369e5435 | |
parent | aaebd48a0334b0252786716d806e4388ce443833 (diff) |
Smoother resizing.
-rw-r--r-- | Spear/App.hs | 35 | ||||
-rw-r--r-- | Spear/Render/Core/State.hs | 1 |
2 files changed, 15 insertions, 21 deletions
diff --git a/Spear/App.hs b/Spear/App.hs index b0c7141..96d45f1 100644 --- a/Spear/App.hs +++ b/Spear/App.hs | |||
@@ -55,9 +55,10 @@ loop' :: | |||
55 | App s -> | 55 | App s -> |
56 | Game s () | 56 | Game s () |
57 | loop' window ddt inputTimer elapsed timeBudget app = do | 57 | loop' window ddt inputTimer elapsed timeBudget app = do |
58 | timer <- gameIO $ tick inputTimer | 58 | timer <- gameIO $ tick inputTimer |
59 | 59 | inputEvents <- gameIO $ pollInputEvents window | |
60 | inputEvents <- gameIO $ pollInputEvents window | 60 | windowEvents <- gameIO $ pollWindowEvents window |
61 | close <- gameIO $ shouldWindowClose window | ||
61 | 62 | ||
62 | let timeBudgetThisFrame = timeBudget + deltaTime timer | 63 | let timeBudgetThisFrame = timeBudget + deltaTime timer |
63 | let steps = timeBudgetThisFrame `div` ddt | 64 | let steps = timeBudgetThisFrame `div` ddt |
@@ -69,27 +70,21 @@ loop' window ddt inputTimer elapsed timeBudget app = do | |||
69 | let dt = timeDeltaToSec ddt | 70 | let dt = timeDeltaToSec ddt |
70 | stepApp app t dt inputEvents) | 71 | stepApp app t dt inputEvents) |
71 | 72 | ||
72 | let elapsed' = elapsed + steps * ddt | 73 | let elapsedNextFrame = elapsed + steps * ddt |
73 | let timeBudget' = timeBudgetThisFrame `mod` ddt | 74 | let timeBudgetNextFrame = timeBudgetThisFrame `mod` ddt |
75 | |||
76 | when (continue && not close) $ do | ||
77 | resized <- or <$> forM windowEvents (\event -> case event of | ||
78 | ResizeEvent {} -> resizeApp app event >> return True) | ||
74 | 79 | ||
75 | when continue $ do | 80 | -- For smoother resizing, render only while not resizing. |
76 | windowEvents <- gameIO $ pollWindowEvents window | 81 | unless resized $ do |
77 | forM_ windowEvents $ \event -> case event of | 82 | renderApp app |
78 | ResizeEvent {} -> resizeApp app event | 83 | gameIO $ swapBuffers window |
79 | renderApp app | ||
80 | gameIO $ swapBuffers window | ||
81 | 84 | ||
82 | frameEnd <- gameIO now | 85 | frameEnd <- gameIO now |
83 | let frameTime = timeDiff (lastTick timer) frameEnd | 86 | let frameTime = timeDiff (lastTick timer) frameEnd |
84 | when (frameTime < ddt) $ do | 87 | when (frameTime < ddt) $ do |
85 | gameIO $ Timer.sleep (ddt - frameTime) | 88 | gameIO $ Timer.sleep (ddt - frameTime) |
86 | 89 | ||
87 | close <- gameIO $ shouldWindowClose window | 90 | loop' window ddt timer elapsedNextFrame timeBudgetNextFrame app |
88 | when (continue && not close) $ | ||
89 | loop' | ||
90 | window | ||
91 | ddt | ||
92 | timer | ||
93 | elapsed' | ||
94 | timeBudget' | ||
95 | app | ||
diff --git a/Spear/Render/Core/State.hs b/Spear/Render/Core/State.hs index f7e5627..dac7b9a 100644 --- a/Spear/Render/Core/State.hs +++ b/Spear/Render/Core/State.hs | |||
@@ -123,7 +123,6 @@ type ShaderHash = Int | |||
123 | type ShaderProgramHash = Int | 123 | type ShaderProgramHash = Int |
124 | 124 | ||
125 | 125 | ||
126 | |||
127 | instance ResourceClass Buffer where | 126 | instance ResourceClass Buffer where |
128 | getResource = bufferResource | 127 | getResource = bufferResource |
129 | 128 | ||