some explenations
This commit is contained in:
parent
5a44486477
commit
5f4d049a2b
1 changed files with 12 additions and 2 deletions
|
@ -67,25 +67,35 @@ withAffection AffectionConfig{..} = do
|
||||||
}) =<< loadState surface
|
}) =<< loadState surface
|
||||||
(_, nState) <- runStateT ( A.runState $ do
|
(_, nState) <- runStateT ( A.runState $ do
|
||||||
preLoop
|
preLoop
|
||||||
|
liftIO $ SDL.surfaceBlit surface Nothing oldSurf Nothing
|
||||||
whileM_ (do
|
whileM_ (do
|
||||||
current <- get
|
current <- get
|
||||||
return $ not $ A.quitEvent current
|
return $ not $ A.quitEvent current
|
||||||
)
|
)
|
||||||
(do
|
(do
|
||||||
|
-- Measure time difference form last run
|
||||||
now <- liftIO $ getTime Monotonic
|
now <- liftIO $ getTime Monotonic
|
||||||
lastTime <- liftIO $ fromMaybe now <$> tryReadMVar execTime
|
lastTime <- liftIO $ fromMaybe now <$> tryReadMVar execTime
|
||||||
|
-- get state
|
||||||
ad <- get
|
ad <- get
|
||||||
|
-- clean draw requests from last run
|
||||||
mapM_ (invalidateDrawRequest pixels format stride cpp) $ drawStack ad
|
mapM_ (invalidateDrawRequest pixels format stride cpp) $ drawStack ad
|
||||||
put $ ad
|
put $ ad
|
||||||
{ drawStack = [] }
|
{ drawStack = [] }
|
||||||
|
-- execute user defined draw loop
|
||||||
drawLoop
|
drawLoop
|
||||||
|
-- execute user defined update loop
|
||||||
updateLoop $ (fromIntegral $ toNanoSecs $ diffTimeSpec lastTime now) /
|
updateLoop $ (fromIntegral $ toNanoSecs $ diffTimeSpec lastTime now) /
|
||||||
(fromIntegral 10 ^ 9)
|
(fromIntegral 10 ^ 9)
|
||||||
ad <- get
|
-- handle all new draw requests
|
||||||
clear <- return . catMaybes =<< mapM (handleDrawRequest pixels format stride cpp) (drawStack ad)
|
clear <- catMaybes <$> mapM (handleDrawRequest pixels format stride cpp) (drawStack ad)
|
||||||
|
-- save all draw requests to clear in next run
|
||||||
put $ ad
|
put $ ad
|
||||||
{ drawStack = clear }
|
{ drawStack = clear }
|
||||||
|
-- blit surface and update window
|
||||||
liftIO $ SDL.surfaceBlit surface Nothing oldSurf Nothing
|
liftIO $ SDL.surfaceBlit surface Nothing oldSurf Nothing
|
||||||
|
liftIO $ SDL.updateWindowSurface $ drawWindow ad
|
||||||
|
-- save new time
|
||||||
_ <- liftIO $ swapMVar execTime $ now
|
_ <- liftIO $ swapMVar execTime $ now
|
||||||
return ()
|
return ()
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue