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