some explenations

This commit is contained in:
nek0 2016-12-20 04:14:57 +01:00
parent 5a44486477
commit 5f4d049a2b

View file

@ -67,25 +67,35 @@ withAffection AffectionConfig{..} = do
}) =<< loadState surface
(_, nState) <- runStateT ( A.runState $ do
preLoop
liftIO $ SDL.surfaceBlit surface Nothing oldSurf Nothing
whileM_ (do
current <- get
return $ not $ A.quitEvent current
)
(do
-- Measure time difference form last run
now <- liftIO $ getTime Monotonic
lastTime <- liftIO $ fromMaybe now <$> tryReadMVar execTime
-- get state
ad <- get
-- clean draw requests from last run
mapM_ (invalidateDrawRequest pixels format stride cpp) $ drawStack ad
put $ ad
{ drawStack = [] }
-- execute user defined draw loop
drawLoop
-- execute user defined update loop
updateLoop $ (fromIntegral $ toNanoSecs $ diffTimeSpec lastTime now) /
(fromIntegral 10 ^ 9)
ad <- get
clear <- return . catMaybes =<< mapM (handleDrawRequest pixels format stride cpp) (drawStack ad)
-- handle all new draw requests
clear <- catMaybes <$> mapM (handleDrawRequest pixels format stride cpp) (drawStack ad)
-- save all draw requests to clear in next run
put $ ad
{ drawStack = clear }
-- blit surface and update window
liftIO $ SDL.surfaceBlit surface Nothing oldSurf Nothing
liftIO $ SDL.updateWindowSurface $ drawWindow ad
-- save new time
_ <- liftIO $ swapMVar execTime $ now
return ()
)