Push preloaddata into the universe
This commit is contained in:
+17
-19
@@ -48,8 +48,7 @@ main = do
|
||||
(flip handleEvent)
|
||||
|
||||
theCleanup :: Universe -> IO ()
|
||||
theCleanup uv = let w = _uvWorld uv
|
||||
in SDL.cursorVisible $= True >> cleanUpPreload (_preloadData w)
|
||||
theCleanup uv = SDL.cursorVisible $= True >> cleanUpPreload (_preloadData uv)
|
||||
|
||||
firstWorldLoad :: Configuration -> IO Universe
|
||||
firstWorldLoad theConfig = do
|
||||
@@ -57,34 +56,33 @@ firstWorldLoad theConfig = do
|
||||
theKeyConfig <- loadKeyConfig
|
||||
pdata <- doPreload >>= applyWorldConfig theConfig
|
||||
w <- generateWorldFromSeed 0
|
||||
return $ Universe ( w & preloadData .~ pdata
|
||||
return $ Universe ( w
|
||||
& keyConfig .~ theKeyConfig
|
||||
& config .~ theConfig
|
||||
)
|
||||
) pdata
|
||||
|
||||
theUpdateStep :: Universe -> IO Universe
|
||||
theUpdateStep = doSideEffects <=< traverseOf uvWorld theUpdateStep'
|
||||
theUpdateStep = doSideEffects <=< updateRenderSplit
|
||||
|
||||
theUpdateStep' :: World -> IO World
|
||||
theUpdateStep' = updateRenderSplit
|
||||
updateRenderSplit :: Universe -> IO Universe
|
||||
updateRenderSplit u = do
|
||||
let preData = _preloadData u
|
||||
update (_uvWorld u) `par` void (doDrawing (_renderData preData) (_uvWorld u))
|
||||
return $ u {_uvWorld = update (_uvWorld u)}
|
||||
|
||||
updateRenderSplit :: World -> IO World
|
||||
updateRenderSplit w = do
|
||||
let preData = _preloadData w
|
||||
update w `par` void (doDrawing (_renderData preData) w)
|
||||
return $ update w
|
||||
|
||||
playSoundUnlessRewinding :: World -> IO (M.Map SoundOrigin Sound)
|
||||
playSoundUnlessRewinding w
|
||||
playSoundUnlessRewinding :: Universe -> IO (M.Map SoundOrigin Sound)
|
||||
playSoundUnlessRewinding u
|
||||
| _rewinding w = return M.empty
|
||||
| otherwise = playSoundAndUpdate (_soundData $ _preloadData w) (_playingSounds w) (_toPlaySounds w)
|
||||
| otherwise = playSoundAndUpdate (_soundData $ _preloadData u) (_playingSounds w) (_toPlaySounds w)
|
||||
where
|
||||
w = _uvWorld u
|
||||
|
||||
doSideEffects :: Universe -> IO Universe
|
||||
doSideEffects u = do
|
||||
let w = _uvWorld u
|
||||
let preData = _preloadData w
|
||||
let preData = _preloadData u
|
||||
--newPlayingSounds <- playSoundAndUpdate (_soundData preData) (_playingSounds w) (_toPlaySounds w)
|
||||
newPlayingSounds <- playSoundUnlessRewinding w
|
||||
newPlayingSounds <- playSoundUnlessRewinding u
|
||||
u' <- _sideEffects w u
|
||||
endTicks <- SDL.ticks
|
||||
let lastFrameTicks = _frameTimer preData
|
||||
@@ -95,7 +93,7 @@ doSideEffects u = do
|
||||
. text $ "ms/frame " ++ show (endTicks - lastFrameTicks)
|
||||
)
|
||||
return $ u'
|
||||
& uvWorld . preloadData . frameTimer .~ endTicks
|
||||
& preloadData . frameTimer .~ endTicks
|
||||
& uvWorld . playingSounds .~ newPlayingSounds
|
||||
& uvWorld . toPlaySounds .~ M.empty
|
||||
& uvWorld . sideEffects .~ return
|
||||
|
||||
Reference in New Issue
Block a user