From 369a74c0d08ce826f0d57fe65f52591ef08f74c3 Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 23 Mar 2017 04:29:48 +0100 Subject: [PATCH] make update provide the time again --- examples/example00.hs | 6 +++--- examples/example01.hs | 6 +++--- examples/example02.1.hs | 6 +++--- examples/example02.hs | 6 +++--- examples/example03.hs | 4 ++-- src/Affection/Types.hs | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/example00.hs b/examples/example00.hs index ef595d1..def9f9e 100644 --- a/examples/example00.hs +++ b/examples/example00.hs @@ -100,13 +100,13 @@ draw = do handle :: SDL.EventPayload -> Affection UserData () handle = const $ return () -update :: Affection UserData () -update = do +update :: Double -> Affection UserData () +update sec = do traceM "updating" ad <- get ud@UserData{..} <- getAffection - sec <- getDelta + -- sec <- getDelta traceM $ (show $ 1 / sec) ++ " FPS" when (elapsedTime ad > 5) $ put $ ad diff --git a/examples/example01.hs b/examples/example01.hs index 87360e9..7619052 100644 --- a/examples/example01.hs +++ b/examples/example01.hs @@ -91,15 +91,15 @@ draw = do UserData{..} <- getAffection drawRect (nodeGraph M.! "nop") (G.RGB 1 0 0) Fill (G.GeglRectangle 10 10 500 500) foreground process $ nodeGraph M.! "sink" + render Nothing Nothing -update :: Affection UserData () -update = do +update :: Double -> Affection UserData () +update dt = do traceM "updating" ud <- getAffection -- let last = lastTick ud -- tick <- getTick -- putAffection $ ud { lastTick = tick } - dt <- getDelta traceM $ (show $ 1 / dt) ++ " FPS" elapsed <- getElapsedTime when (elapsed > 20) $ diff --git a/examples/example02.1.hs b/examples/example02.1.hs index 62d8c55..4859fec 100644 --- a/examples/example02.1.hs +++ b/examples/example02.1.hs @@ -134,16 +134,16 @@ draw = do traceM "loading complete" process (myMap M.! "sink") present (GeglRectangle 0 0 800 600) buffer True + render Nothing Nothing -update :: Affection UserData () -update = do +update :: Double -> Affection UserData () +update dt = do traceM "updating" tick <- getElapsedTime ud <- getAffection putAffection $ ud { lastTick = tick } - let dt = tick - lastTick ud return () traceM $ (show $ 1 / dt) ++ " FPS" diff --git a/examples/example02.hs b/examples/example02.hs index 151c16e..b600e6c 100644 --- a/examples/example02.hs +++ b/examples/example02.hs @@ -108,15 +108,15 @@ draw = do process (nodeGraph M.! "sink") present (GeglRectangle 0 0 800 600) foreground True -update :: Affection UserData () -update = do +update :: Double -> Affection UserData () +update dt = do traceM "updating" tick <- getElapsedTime ud <- getAffection putAffection $ ud { lastTick = tick } - let dt = tick - lastTick ud + -- let dt = tick - lastTick ud return () traceM $ show (1 / dt) ++ " FPS" diff --git a/examples/example03.hs b/examples/example03.hs index b6f2d2f..51124d1 100644 --- a/examples/example03.hs +++ b/examples/example03.hs @@ -100,8 +100,8 @@ draw = do foreground True -update :: Affection UserData () -update = do +update :: Double -> Affection UserData () +update dt = do traceM "updating" ad <- get ud <- getAffection diff --git a/src/Affection/Types.hs b/src/Affection/Types.hs index 018c64e..27ed78f 100644 --- a/src/Affection/Types.hs +++ b/src/Affection/Types.hs @@ -59,7 +59,7 @@ data AffectionConfig us = AffectionConfig -- ^ Actions to be performed, before loop starts , eventLoop :: SDL.EventPayload -> Affection us () -- ^ Main update function. Takes fractions of a second as input. - , updateLoop :: Affection us () + , updateLoop :: Double -> Affection us () -- ^ Main update function. Takes fractions of a second as input. , drawLoop :: Affection us () -- ^ Function for updating graphics.