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

View File

@ -91,6 +91,7 @@ data AffectionData us = AffectionData
, drawCPP :: Int -- ^ Number of components per pixel
, elapsedTime :: Double -- ^ Elapsed time in seconds
, 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