Skip to content
Browse files

Now we have reliable frame timing. Woot.

  • Loading branch information...
1 parent 859d352 commit dd5708e6308ec38eda226439ce6ec6464f4aa3e2 @sixohsix committed Mar 10, 2012
Showing with 12 additions and 9 deletions.
  1. +12 −9 HsSdlTest.hs
  2. BIN sprites.png
View
21 HsSdlTest.hs
@@ -2,16 +2,16 @@
module HsSdlTest where
+import Control.Monad (when)
+
import Foreign.C
import Foreign
import Graphics.UI.SDL as SDL
import Graphics.UI.SDL.Image as SDLi
---import Prelude (printLn)
-
background = "background.bmp"
-tick = 100
+tick = 30
foreign export ccall my_main :: IO ()
@@ -26,22 +26,25 @@ my_main = SDL.withInit [InitEverything] $ do
blitSurface back Nothing screen Nothing
blitTile guyTile screen 64 64
SDL.flip screen
- now <- getTicks
- eventLoop $ now + tick
+ eventLoop 0
-eventLoop nextTick = SDL.waitEvent >>= checkEvent
+eventLoop :: Word32 -> IO ()
+eventLoop nextTick = SDL.pollEvent >>= checkEvent
where checkEvent (KeyUp _) = return ()
checkEvent _ = do updateGame
waitUntil nextTick
eventLoop $ nextTick + tick
+updateGame :: IO ()
updateGame = return ()
+waitUntil :: Word32 -> IO ()
waitUntil ticks = do
now <- getTicks
- wait <- return $ ticks - now
- putStrLn ("Waiting " ++ (show wait))
- delay wait
+ when (now < ticks) $ do
+ w <- return (ticks - now)
+ putStrLn ("Waiting " ++ (show w))
+ delay w
data TileMap = TileMap {
View
BIN sprites.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd5708e

Please sign in to comment.
Something went wrong with that request. Please try again.