aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeanne-Kamikaze <jeannekamikaze@gmail.com>2013-02-22 15:11:51 +0100
committerJeanne-Kamikaze <jeannekamikaze@gmail.com>2013-02-22 15:11:51 +0100
commit8ed4094013e769d2b57002b5f2bdecbcf8200f57 (patch)
tree083257f58458fd5c2ce5ed02975f78c62ba7d55b
parent594e76d1df5a2148387fced2730f3ec2d89a7814 (diff)
run -> loop
-rw-r--r--Spear/App/Application.hs30
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
83type Update s = Float -> Game s (Bool) 83type Update s = Float -> Game s (Bool)
84 84
85-- | Run the application's main loop. 85-- | Run the application's main loop.
86run :: Update s -> Game s () 86loop :: Update s -> Game s ()
87run update = do 87loop update = do
88 timer <- gameIO $ start newTimer 88 timer <- gameIO $ start newTimer
89 run' timer update 89 run timer update
90 90
91run' :: Timer -> Update s -> Game s () 91run :: Timer -> Update s -> Game s ()
92run' timer update = do 92run 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.
101runCapped :: Int -> Update s -> Game s () 101loopCapped :: Int -> Update s -> Game s ()
102runCapped maxFPS update = do 102loopCapped 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
107runCapped' :: Float -> Timer -> Update s -> Game s () 107runCapped :: Float -> Timer -> Update s -> Game s ()
108runCapped' ddt timer update = do 108runCapped 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
120onResize :: WindowSizeCallback -> Size -> IO () 120onResize :: WindowSizeCallback -> Size -> IO ()
121onResize callback s@(Size w h) = do 121onResize callback s@(Size w h) = do