comments and formatting

This commit is contained in:
nek0 2020-05-04 05:26:49 +02:00
parent 786bfe1b21
commit 44ec3cc8e0

View file

@ -80,7 +80,9 @@ withAffection AffectionConfig{..} = do
-- get current time -- get current time
execTime <- getTime Monotonic execTime <- getTime Monotonic
liftIO $ logIO Debug "Loading initial data container" liftIO $ logIO Debug "Loading initial data container"
-- construct game data object from provided Affectionate instance
gameData <- loadState @us gameData <- loadState @us
-- build state container
let initContainer = AffectionData let initContainer = AffectionData
{ drawWindows = windows { drawWindows = windows
, glContext = contexts , glContext = contexts
@ -89,45 +91,51 @@ withAffection AffectionConfig{..} = do
, sysTime = execTime , sysTime = execTime
, pausedTime = False , pausedTime = False
} }
(_, nState) <- runStateT ( A.runState $ do -- initialize and run state
liftIO $ logIO Debug "Starting Loop" (_, nState) <- runStateT
preLoop gameData (A.runState
whileM_ (hasNextStep gameData)
(do (do
-- get state liftIO $ logIO Debug "Starting Loop"
ad <- get -- run preLoop function from Affectionate
-- Measure time difference form last run preLoop gameData
now <- liftIO $ getTime Monotonic whileM_ (hasNextStep gameData)
let lastTime = sysTime ad (do
-- compute dt and update elapsedTime -- get state
let !dt = fromIntegral ad <- get
(toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ (9 :: Int)) -- Measure time difference form last run
!ne = elapsedTime ad + dt now <- liftIO $ getTime Monotonic
put $ ad let lastTime = sysTime ad
{ elapsedTime = ne -- compute dt and update elapsedTime
, deltaTime = dt let !dt = fromIntegral
} (toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ (9 :: Int))
-- poll events !ne = elapsedTime ad + dt
evs <- preHandleEvents =<< liftIO SDL.pollEvents -- update state data object with new time values
-- handle events put $ ad
handleEvents gameData evs { elapsedTime = ne
-- execute user defined update loop , deltaTime = dt
unless (pausedTime ad) (update gameData dt) }
-- execute user defined draw loop -- poll events
liftIO $ GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer] evs <- preHandleEvents =<< liftIO SDL.pollEvents
draw gameData -- handle events
liftIO GL.flush handleEvents gameData evs
-- actual displaying of newly drawn frame -- execute user defined update loop
mapM_ (SDL.glSwapWindow . (\(_,y,_) -> y)) windows unless (pausedTime ad) (update gameData dt)
-- save new time -- clear GL buffer >> execute user defined draw loop >> flush GL buffer
ad3 <- get liftIO $ GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer]
when (sysTime ad == sysTime ad3) ( draw gameData
put ad3 liftIO GL.flush
{ sysTime = now -- actual displaying of newly drawn frame
} mapM_ (SDL.glSwapWindow . (\(_,y,_) -> y)) windows
) -- -- save new time
) -- ad3 <- get
) initContainer -- when (sysTime ad == sysTime ad3) (
-- put ad3
-- { sysTime = now
-- }
-- )
)
)
) initContainer
liftIO $ logIO Debug "Loop ended. Cleaning" liftIO $ logIO Debug "Loop ended. Cleaning"
cleanUp gameData cleanUp gameData
liftIO $ logIO Debug "Destroying Window" liftIO $ logIO Debug "Destroying Window"