Engage multiple threads
This commit is contained in:
+10
-4
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user