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
|
-- 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,8 +91,12 @@ withAffection AffectionConfig{..} = do
|
||||||
, sysTime = execTime
|
, sysTime = execTime
|
||||||
, pausedTime = False
|
, pausedTime = False
|
||||||
}
|
}
|
||||||
(_, nState) <- runStateT ( A.runState $ do
|
-- initialize and run state
|
||||||
|
(_, nState) <- runStateT
|
||||||
|
(A.runState
|
||||||
|
(do
|
||||||
liftIO $ logIO Debug "Starting Loop"
|
liftIO $ logIO Debug "Starting Loop"
|
||||||
|
-- run preLoop function from Affectionate
|
||||||
preLoop gameData
|
preLoop gameData
|
||||||
whileM_ (hasNextStep gameData)
|
whileM_ (hasNextStep gameData)
|
||||||
(do
|
(do
|
||||||
|
@ -103,6 +109,7 @@ withAffection AffectionConfig{..} = do
|
||||||
let !dt = fromIntegral
|
let !dt = fromIntegral
|
||||||
(toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ (9 :: Int))
|
(toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ (9 :: Int))
|
||||||
!ne = elapsedTime ad + dt
|
!ne = elapsedTime ad + dt
|
||||||
|
-- update state data object with new time values
|
||||||
put $ ad
|
put $ ad
|
||||||
{ elapsedTime = ne
|
{ elapsedTime = ne
|
||||||
, deltaTime = dt
|
, deltaTime = dt
|
||||||
|
@ -113,18 +120,19 @@ withAffection AffectionConfig{..} = do
|
||||||
handleEvents gameData evs
|
handleEvents gameData evs
|
||||||
-- execute user defined update loop
|
-- execute user defined update loop
|
||||||
unless (pausedTime ad) (update gameData dt)
|
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]
|
liftIO $ GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer]
|
||||||
draw gameData
|
draw gameData
|
||||||
liftIO GL.flush
|
liftIO GL.flush
|
||||||
-- actual displaying of newly drawn frame
|
-- actual displaying of newly drawn frame
|
||||||
mapM_ (SDL.glSwapWindow . (\(_,y,_) -> y)) windows
|
mapM_ (SDL.glSwapWindow . (\(_,y,_) -> y)) windows
|
||||||
-- save new time
|
-- -- save new time
|
||||||
ad3 <- get
|
-- ad3 <- get
|
||||||
when (sysTime ad == sysTime ad3) (
|
-- when (sysTime ad == sysTime ad3) (
|
||||||
put ad3
|
-- put ad3
|
||||||
{ sysTime = now
|
-- { sysTime = now
|
||||||
}
|
-- }
|
||||||
|
-- )
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) initContainer
|
) initContainer
|
||||||
|
|
Loading…
Reference in a new issue