Engage multiple threads

This commit is contained in:
2021-09-23 21:19:38 +01:00
parent 85edd98d62
commit 4a1501a358
6 changed files with 69 additions and 35 deletions
+10 -4
View File
@@ -31,6 +31,8 @@ import qualified Data.IntMap as IM
import Graphics.Rendering.OpenGL hiding (color, rotate, scale, translate)
import qualified SDL
import qualified SDL.Mixer as Mix
--import qualified Control.Monad.Parallel as MP
import Control.Parallel
main :: IO ()
main = do
@@ -40,7 +42,7 @@ main = do
theCleanup
(firstWorldLoad (sizex,sizey))
theUpdateStep
handleEvent
(flip handleEvent)
theCleanup :: World -> IO ()
theCleanup w = SDL.cursorVisible $= True >> cleanUpPreload (_preloadData w)
@@ -55,13 +57,17 @@ firstWorldLoad (sizex,sizey) = do
return $ w & preloadData .~ pdata
theUpdateStep :: World -> IO World
theUpdateStep = doSideEffects . update
theUpdateStep = doSideEffects <=< updateRenderSplit
updateRenderSplit :: World -> IO World
updateRenderSplit w = do
let preData = _preloadData w
update w `par` void (doDrawing (_renderData preData) w)
return $ update w
doSideEffects :: World -> IO World
doSideEffects w = do
let preData = _preloadData w
void $ doDrawing (_renderData preData) w
--playPositionalSoundQueue (_loadedChunks $ _soundData preData) (_soundQueue w)
newPlayingSounds <- playSoundAndUpdate (_soundData preData) (_playingSounds w) (_sounds w)
w' <- _sideEffects w w