comments and formatting
This commit is contained in:
parent
786bfe1b21
commit
44ec3cc8e0
1 changed files with 46 additions and 38 deletions
|
@ -80,7 +80,9 @@ withAffection AffectionConfig{..} = do
|
|||
-- get current time
|
||||
execTime <- getTime Monotonic
|
||||
liftIO $ logIO Debug "Loading initial data container"
|
||||
-- construct game data object from provided Affectionate instance
|
||||
gameData <- loadState @us
|
||||
-- build state container
|
||||
let initContainer = AffectionData
|
||||
{ drawWindows = windows
|
||||
, glContext = contexts
|
||||
|
@ -89,8 +91,12 @@ withAffection AffectionConfig{..} = do
|
|||
, sysTime = execTime
|
||||
, pausedTime = False
|
||||
}
|
||||
(_, nState) <- runStateT ( A.runState $ do
|
||||
-- initialize and run state
|
||||
(_, nState) <- runStateT
|
||||
(A.runState
|
||||
(do
|
||||
liftIO $ logIO Debug "Starting Loop"
|
||||
-- run preLoop function from Affectionate
|
||||
preLoop gameData
|
||||
whileM_ (hasNextStep gameData)
|
||||
(do
|
||||
|
@ -103,6 +109,7 @@ withAffection AffectionConfig{..} = do
|
|||
let !dt = fromIntegral
|
||||
(toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ (9 :: Int))
|
||||
!ne = elapsedTime ad + dt
|
||||
-- update state data object with new time values
|
||||
put $ ad
|
||||
{ elapsedTime = ne
|
||||
, deltaTime = dt
|
||||
|
@ -113,18 +120,19 @@ withAffection AffectionConfig{..} = do
|
|||
handleEvents gameData evs
|
||||
-- execute user defined update loop
|
||||
unless (pausedTime ad) (update gameData dt)
|
||||
-- execute user defined draw loop
|
||||
-- clear GL buffer >> execute user defined draw loop >> flush GL buffer
|
||||
liftIO $ GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer]
|
||||
draw gameData
|
||||
liftIO GL.flush
|
||||
-- actual displaying of newly drawn frame
|
||||
mapM_ (SDL.glSwapWindow . (\(_,y,_) -> y)) windows
|
||||
-- save new time
|
||||
ad3 <- get
|
||||
when (sysTime ad == sysTime ad3) (
|
||||
put ad3
|
||||
{ sysTime = now
|
||||
}
|
||||
-- -- save new time
|
||||
-- ad3 <- get
|
||||
-- when (sysTime ad == sysTime ad3) (
|
||||
-- put ad3
|
||||
-- { sysTime = now
|
||||
-- }
|
||||
-- )
|
||||
)
|
||||
)
|
||||
) initContainer
|
||||
|
|
Loading…
Reference in a new issue