changing time management

This commit is contained in:
nek0 2017-07-29 02:40:41 +02:00
parent 9d9833d88a
commit 61a36984ae
2 changed files with 13 additions and 9 deletions

View file

@ -96,15 +96,15 @@ withAffection AffectionConfig{..} = do
cpp = B.babl_components_per_pixel bablFormat cpp = B.babl_components_per_pixel bablFormat
!stride = cpp * w !stride = cpp * w
format <- B.babl_format bablFormat format <- B.babl_format bablFormat
-- get current time
execTime <- getTime Monotonic
initContainer <- (\x -> AffectionData initContainer <- (\x -> AffectionData
{ quitEvent = False { quitEvent = False
, userState = x , userState = x
, drawWindow = window , drawWindow = window
, windowRenderer = renderer , windowRenderer = renderer
-- , drawSurface = surface
, drawTexture = texture , drawTexture = texture
, drawFormat = format , drawFormat = format
-- , drawPixels = pixels
, drawDimensions = case canvasSize of , drawDimensions = case canvasSize of
Just (cw, ch) -> (cw, ch) Just (cw, ch) -> (cw, ch)
Nothing -> (w, h) Nothing -> (w, h)
@ -113,9 +113,9 @@ withAffection AffectionConfig{..} = do
, drawStack = [] , drawStack = []
, elapsedTime = 0 , elapsedTime = 0
, deltaTime = 0 , deltaTime = 0
, sysTime = execTime
, pausedTime = False
}) <$> loadState }) <$> loadState
-- get current time
execTime <- newIORef =<< getTime Monotonic
(_, nState) <- runStateT ( A.runState $ do (_, nState) <- runStateT ( A.runState $ do
preLoop preLoop
whileM_ (do whileM_ (do
@ -123,11 +123,11 @@ withAffection AffectionConfig{..} = do
return $ not $ A.quitEvent current return $ not $ A.quitEvent current
) )
(do (do
-- Measure time difference form last run
now <- liftIO $ getTime Monotonic
lastTime <- liftIO $ readIORef execTime
-- get state -- get state
ad <- get ad <- get
-- Measure time difference form last run
now <- liftIO $ getTime Monotonic
lastTime <- sysTime ad
-- clean draw requests from last run -- clean draw requests from last run
MP.mapM_ (invalidateDrawRequest (drawStride ad) (drawCPP ad)) (drawStack ad) MP.mapM_ (invalidateDrawRequest (drawStride ad) (drawCPP ad)) (drawStack ad)
-- clean the renderer form last time -- clean the renderer form last time
@ -144,7 +144,7 @@ withAffection AffectionConfig{..} = do
evs <- preHandleEvents =<< liftIO SDL.pollEvents evs <- preHandleEvents =<< liftIO SDL.pollEvents
mapM_ eventLoop evs mapM_ eventLoop evs
-- execute user defined update loop -- execute user defined update loop
updateLoop dt unless pausedTime (updateLoop dt)
-- execute user defined draw loop -- execute user defined draw loop
drawLoop drawLoop
-- handle all new draw requests -- handle all new draw requests
@ -157,7 +157,10 @@ withAffection AffectionConfig{..} = do
-- actual drawing -- actual drawing
SDL.present (windowRenderer ad2) SDL.present (windowRenderer ad2)
-- save new time -- save new time
liftIO $ writeIORef execTime now ad3 <- get
put ad3
{ sysTime = now
}
) )
) initContainer ) initContainer
G.gegl_exit G.gegl_exit

View file

@ -91,6 +91,7 @@ data AffectionData us = AffectionData
, drawCPP :: Int -- ^ Number of components per pixel , drawCPP :: Int -- ^ Number of components per pixel
, elapsedTime :: Double -- ^ Elapsed time in seconds , elapsedTime :: Double -- ^ Elapsed time in seconds
, deltaTime :: Double -- ^ Elapsed time in seconds since last tick , deltaTime :: Double -- ^ Elapsed time in seconds since last tick
, pausedTime :: Bool -- ^ Should the update loop be executed?
} }
-- | This datatype stores information about areas of a 'G.GeglBuffer' to be updated -- | This datatype stores information about areas of a 'G.GeglBuffer' to be updated