From 5f4d049a2b07d7cf009f023c64d253b0b0ee09f9 Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 20 Dec 2016 04:14:57 +0100 Subject: [PATCH] some explenations --- src/Affection.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Affection.hs b/src/Affection.hs index 4cfc9cb..9ff09b9 100644 --- a/src/Affection.hs +++ b/src/Affection.hs @@ -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 () )