diff options
| -rw-r--r-- | Spear/App/Application.hs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/Spear/App/Application.hs b/Spear/App/Application.hs index 82bfde0..1a2a616 100644 --- a/Spear/App/Application.hs +++ b/Spear/App/Application.hs | |||
| @@ -13,8 +13,8 @@ module Spear.App.Application | |||
| 13 | , setup | 13 | , setup |
| 14 | , quit | 14 | , quit |
| 15 | -- * Main loop | 15 | -- * Main loop |
| 16 | , run | 16 | , loop |
| 17 | , runCapped | 17 | , loopCapped |
| 18 | -- * Helpers | 18 | -- * Helpers |
| 19 | , swapBuffers | 19 | , swapBuffers |
| 20 | , getParam | 20 | , getParam |
| @@ -83,29 +83,29 @@ quit = GLFW.terminate | |||
| 83 | type Update s = Float -> Game s (Bool) | 83 | type Update s = Float -> Game s (Bool) |
| 84 | 84 | ||
| 85 | -- | Run the application's main loop. | 85 | -- | Run the application's main loop. |
| 86 | run :: Update s -> Game s () | 86 | loop :: Update s -> Game s () |
| 87 | run update = do | 87 | loop update = do |
| 88 | timer <- gameIO $ start newTimer | 88 | timer <- gameIO $ start newTimer |
| 89 | run' timer update | 89 | run timer update |
| 90 | 90 | ||
| 91 | run' :: Timer -> Update s -> Game s () | 91 | run :: Timer -> Update s -> Game s () |
| 92 | run' timer update = do | 92 | run timer update = do |
| 93 | timer' <- gameIO $ tick timer | 93 | timer' <- gameIO $ tick timer |
| 94 | continue <- update $ getDelta timer' | 94 | continue <- update $ getDelta timer' |
| 95 | opened <- gameIO $ getParam Opened | 95 | opened <- gameIO $ getParam Opened |
| 96 | case continue && opened of | 96 | case continue && opened of |
| 97 | False -> return () | 97 | False -> return () |
| 98 | True -> run' timer' update | 98 | True -> run timer' update |
| 99 | 99 | ||
| 100 | -- | Run the application's main loop, with a limit on the frame rate. | 100 | -- | Run the application's main loop, with a limit on the frame rate. |
| 101 | runCapped :: Int -> Update s -> Game s () | 101 | loopCapped :: Int -> Update s -> Game s () |
| 102 | runCapped maxFPS update = do | 102 | loopCapped maxFPS update = do |
| 103 | let ddt = 1.0 / (fromIntegral maxFPS) | 103 | let ddt = 1.0 / (fromIntegral maxFPS) |
| 104 | timer <- gameIO $ start newTimer | 104 | timer <- gameIO $ start newTimer |
| 105 | runCapped' ddt timer update | 105 | runCapped ddt timer update |
| 106 | 106 | ||
| 107 | runCapped' :: Float -> Timer -> Update s -> Game s () | 107 | runCapped :: Float -> Timer -> Update s -> Game s () |
| 108 | runCapped' ddt timer update = do | 108 | runCapped ddt timer update = do |
| 109 | timer' <- gameIO $ tick timer | 109 | timer' <- gameIO $ tick timer |
| 110 | continue <- update $ getDelta timer' | 110 | continue <- update $ getDelta timer' |
| 111 | opened <- gameIO $ getParam Opened | 111 | opened <- gameIO $ getParam Opened |
| @@ -115,7 +115,7 @@ runCapped' ddt timer update = do | |||
| 115 | t'' <- gameIO $ tick timer' | 115 | t'' <- gameIO $ tick timer' |
| 116 | let dt = getDelta t'' | 116 | let dt = getDelta t'' |
| 117 | when (dt < ddt) $ gameIO $ Timer.sleep (ddt - dt) | 117 | when (dt < ddt) $ gameIO $ Timer.sleep (ddt - dt) |
| 118 | runCapped' ddt timer' update | 118 | runCapped ddt timer' update |
| 119 | 119 | ||
| 120 | onResize :: WindowSizeCallback -> Size -> IO () | 120 | onResize :: WindowSizeCallback -> Size -> IO () |
| 121 | onResize callback s@(Size w h) = do | 121 | onResize callback s@(Size w h) = do |
