now using built-in timing facilities

This commit is contained in:
nek0 2016-11-04 19:05:43 +01:00
parent e11312fb5d
commit 211cbd85ad

View file

@ -32,7 +32,10 @@ main = do
}
withAffection conf
type UserData = M.Map String G.GeglNode
data UserData = UserData
{ nodeGraph :: M.Map String G.GeglNode
, elapsedTime :: Double
}
load :: SDL.Surface -> IO UserData
load _ = do
@ -49,12 +52,16 @@ load _ = do
, ("checkerboard", checkerboard)
]
traceM "loading complete"
return myMap
return $ UserData
{ nodeGraph = myMap
, elapsedTime = 0
}
draw :: AffectionState (AffectionData UserData) IO ()
draw = do
traceM "drawing"
AffectionData{..} <- get
let UserData{..} = userState
liftIO $ SDL.lockSurface drawSurface
pixels <- liftIO $ SDL.surfacePixels drawSurface
let SDL.Surface rawSurfacePtr _ = drawSurface
@ -64,7 +71,7 @@ draw = do
SDL.V2 (CInt rw) (CInt rh) <- SDL.surfaceDimensions drawSurface
let (w, h) = (fromIntegral rw, fromIntegral rh)
liftIO $ G.gegl_node_blit
(userState M.! "checkerboard" :: G.GeglNode)
(nodeGraph M.! "checkerboard" :: G.GeglNode)
1
(G.GeglRectangle 0 0 w h)
format
@ -77,9 +84,18 @@ draw = do
update :: Double -> AffectionState (AffectionData UserData) IO ()
update sec = do
traceM "updating"
-- traceM $ show sec
liftIO $ delaySec 5
ud@AffectionData{..} <- get
put $ ud
-- liftIO $ delaySec 5
ad@AffectionData{..} <- get
let ud@UserData{..} = userState
traceM $ show elapsedTime
if elapsedTime < 5
then
put $ ad
{ userState = ud
{ elapsedTime = elapsedTime + sec
}
}
else
put $ ad
{ quitEvent = True
}