Move side effects into world (may be slower)

This commit is contained in:
2021-09-08 18:48:16 +01:00
parent 235e94cecb
commit 04e5b9b39f
6 changed files with 41 additions and 3 deletions
+35 -2
View File
@@ -33,8 +33,8 @@ import Graphics.Rendering.OpenGL hiding (color, rotate, scale, translate)
import qualified SDL
import qualified SDL.Mixer as Mix
main :: IO ()
main = do
main' :: IO ()
main' = do
(sizex,sizey) <- loadConfig
theKeyConfig <- loadKeyConfig
dodgeConfig <- loadDodgeConfig
@@ -47,6 +47,39 @@ main = do
handleEvent
(Just . update)
main :: IO ()
main = do
(sizex,sizey) <- loadConfig
theKeyConfig <- loadKeyConfig
dodgeConfig <- loadDodgeConfig
setupLoop'
(sizex,sizey)
theCleanup
(firstWorldLoad (sizex,sizey) theKeyConfig dodgeConfig)
theUpdateStep
handleEvent
-- (SDL.cursorVisible $= False >> doPreload >>= applyWorldConfig dodgeConfig)
-- (fmap (setWindowSize sizex sizey . (keyConfig .~ theKeyConfig) . (config .~ dodgeConfig)) firstWorld)
-- doSideEffects
theCleanup :: World -> IO ()
theCleanup w = SDL.cursorVisible $= True >> cleanUpPreload (_preloadData w)
--firstWorldLoad :: Configuration -> IO World
firstWorldLoad (sizex,sizey) theKeyConfig theConfig = do
SDL.cursorVisible $= False
pdata <- doPreload >>= applyWorldConfig theConfig
w <- fmap (setWindowSize sizex sizey . (keyConfig .~ theKeyConfig) . (config .~ theConfig)) firstWorld
return $ w & preloadData .~ pdata
theUpdateStep :: World -> IO World
theUpdateStep = applySideEffects . update
applySideEffects :: World -> IO (World)
applySideEffects w = do
newpdata <- doSideEffects (_preloadData w) w
return $ w & preloadData .~ newpdata
doSideEffects :: PreloadData SoundOrigin -> World -> IO (PreloadData SoundOrigin)
doSideEffects preData w = do
--startTicks <- SDL.ticks