Continue to refactor zoning to be more stream-based

This commit is contained in:
2022-06-28 03:21:55 +01:00
parent f6d96ec92c
commit e06527091e
34 changed files with 214 additions and 252 deletions
+3 -12
View File
@@ -20,8 +20,6 @@ setupLoop
:: Int -- ^ Target seconds per frame
-> T.Text -- ^ Window title
-> WindowConfig
-- -> (Int,Int) -- ^ The window size.
-- -> Maybe (Int,Int) -- ^ The window position.
-> (world -> IO ()) -- ^ Function for cleaning up parameters, applied when exiting loop.
-> IO world -- ^ Initial simulation state.
-> (world -> IO world) -- ^ update, called once per frame. Allows for side effects such as rendering.
@@ -39,7 +37,7 @@ setupLoop spf title winconfig paramCleanup ioStartWorld sideEffects eventFn = do
$ \_ -> bracket
ioStartWorld
paramCleanup
$ doLoop spf window sideEffects eventFn
(doLoop spf window sideEffects eventFn)
-- | The internal loop.
doLoop
:: Int -- ^ target msec per frame
@@ -48,18 +46,11 @@ doLoop
-> (world -> Event -> IO (Maybe world)) -- ^ SDL Event handling.
-> world -- ^ Current simulation state.
-> IO ()
doLoop
spf
window
worldSideEffects
eventFn
startWorld
= do
doLoop spf window worldSideEffects eventFn startWorld = do
startTicks <- ticks
worldAfterSimStep <- worldSideEffects startWorld
glSwapWindow window
events <- pollEvents
maybeUpdatedWorld <- foldM (applyEventIO eventFn) (Just worldAfterSimStep) events
maybeUpdatedWorld <- pollEvents >>= foldM (applyEventIO eventFn) (Just worldAfterSimStep)
case maybeUpdatedWorld of
Just updatedWorld -> do
performGC