Include tick counting code

This commit is contained in:
2021-02-27 02:09:04 +01:00
parent 4fc6917741
commit 3b4b387943
9 changed files with 64 additions and 116 deletions
+9 -12
View File
@@ -14,7 +14,7 @@ import Geometry
import Preload
import Control.Lens ((.~),(&))
import Control.Lens ((.~),(&),(+~))
winConfig x y = defaultWindow
{ windowGraphicsContext
@@ -80,6 +80,7 @@ doLoop setup window startWorld
GL.clear [GL.ColorBuffer,GL.DepthBuffer]
newParams <- worldSideEffects (setup & currentTime .~ startLoopTicks) startWorld
glSwapWindow window
endSideTicks <- ticks
--worldSideEffects setup updatedWorld
events <- pollEvents
--let-- maybeUpdatedWorld :: Maybe (WorldView world0)
@@ -91,12 +92,17 @@ doLoop setup window startWorld
--worldSideEffects setup updatedWorld
--glSwapWindow window
--GL.flush
endSimTicks <- ticks
performGC
endLoopTicks <- ticks -- it might be better to use System.Clock (monotonic)
let delay = max 0 (10 + fromIntegral startLoopTicks - fromIntegral endLoopTicks)
threadDelay (delay * 1000)
doLoop newParams window updatedWorld worldSideEffects eventFn worldUpdate
Nothing -> return ()
endTime <- ticks
let newNewParams = newParams & idleTime +~ (endTime - endLoopTicks)
& gcTime +~ (endLoopTicks - endSimTicks)
& simTime +~ (endSimTicks - endSideTicks)
doLoop newNewParams window updatedWorld worldSideEffects eventFn worldUpdate
Nothing -> showTiming setup
applyEvents :: (world0 -> Event -> Maybe world0)
-> world0
@@ -115,15 +121,6 @@ applyEvents eventFn startWorld events worldUpdate =
WindowClosedEvent _ -> Nothing
_ -> f w e
-- applyResizeExits :: (world -> Event -> Maybe world) -> (world -> Event -> Maybe world)
-- applyResizeExits f w e
-- = case eventPayload e of
-- QuitEvent -> Nothing
-- WindowClosedEvent _ -> Nothing
-- WindowSizeChangedEvent
-- (WindowSizeChangedEventData {windowSizeChangedEventWindow = V2 x y})
-- -> GL.viewport
-- _ -> f w e
applyEventIO :: (world -> Event -> Maybe world) -> Maybe world -> Event -> IO (Maybe world)
applyEventIO fn mw e = case eventPayload e of
QuitEvent -> return Nothing