From 28c1f3d23b10475857c456ca16cbd6d925c51e96 Mon Sep 17 00:00:00 2001 From: jgk Date: Thu, 8 Apr 2021 11:18:10 +0200 Subject: [PATCH] Cleanup --- app/Main.hs | 66 +++++++++++++++++++++++------------------------ src/Preload.hs | 7 +++-- src/Sound/Data.hs | 2 -- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 74cdf0f16..c75aff5ed 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -30,6 +30,39 @@ import Graphics.Rendering.OpenGL hiding (color, rotate, scale, translate) import qualified SDL import qualified SDL.Mixer as Mix +main :: IO () +main = do + (sizex,sizey) <- loadConfig + keyConfig <- loadKeyConfig + dodgeConfig <- loadDodgeConfig + setupLoop + (sizex,sizey) + (SDL.cursorVisible $= False >> doPreload' dodgeConfig >>= resizeSpareFBO sizex sizey) + (\x -> (SDL.cursorVisible $= True) >> cleanUpPreload x) + (fmap (setWindowSize sizex sizey keyConfig . (config .~ dodgeConfig)) firstWorld) + doSideEffects + handleEvent + (Just . update) + +doSideEffects :: PreloadData SoundOrigin -> World -> IO (PreloadData SoundOrigin) +doSideEffects preData w = do + startTicks <- SDL.ticks + updateDodgeConfig w + void $ doDrawing (_renderData preData) w + playPositionalSoundQueue (_loadedChunks $ _soundData preData) (_soundQueue w) + newPlayingSounds <- playAndUpdate (_soundData preData) (_sounds w) + + endTicks <- SDL.ticks + let lastFrameTicks = _frameTimer preData + when (_debugMode w) $ void $ renderFoldable + (_renderData preData) + (picToLTree Nothing . setLayer 1 . setDepth (-1) + . translate (-0.5) (-0.8) . scale 0.0005 0.0005 + . text $ "ms/frame " ++ show (endTicks - lastFrameTicks) + ) + return $ preData & soundData . playingSounds .~ newPlayingSounds + & frameTimer .~ endTicks + doPreload' :: Dodge.LoadConfig.Configuration -> IO (PreloadData a) doPreload' config = do lChunks <- loadSounds @@ -46,39 +79,6 @@ doPreload' config = do , _frameTimer = 0 } -main :: IO () -main = do - (sizex,sizey) <- loadConfig - keyConfig <- loadKeyConfig - dodgeConfig <- loadDodgeConfig - setupLoop - (sizex,sizey) - (SDL.cursorVisible $= False >> doPreload' dodgeConfig >>= resizeSpareFBO sizex sizey) - (\x -> (SDL.cursorVisible $= True) >> cleanUpPreload x) - (fmap (setWindowSize sizex sizey keyConfig . (config .~ dodgeConfig)) firstWorld) - ( \preData w -> do - startTicks <- SDL.ticks - updateDodgeConfig w - void $ doDrawing (_renderData preData) w - playPositionalSoundQueue (_loadedChunks $ _soundData preData) (_soundQueue w) - newPlayingSounds <- playAndUpdate (_soundData preData) (_sounds w) - - endTicks <- SDL.ticks - let lastFrameTicks = _frameTimer preData - when (_debugMode w) $ void $ renderFoldable - (_renderData preData) - (picToLTree Nothing . setLayer 1 . setDepth (-1) - . translate (-0.5) (-0.8) . scale 0.0005 0.0005 - . text $ "ms/frame " ++ show (endTicks - lastFrameTicks) - ) - - - return $ preData & soundData . playingSounds .~ newPlayingSounds - & frameTimer .~ endTicks - ) - handleEvent - (Just . update) - Mix.closeAudio checkForGlErrors :: IO () checkForGlErrors = do diff --git a/src/Preload.hs b/src/Preload.hs index e642f3e64..e43222568 100644 --- a/src/Preload.hs +++ b/src/Preload.hs @@ -6,15 +6,18 @@ module Preload where import Preload.Data import Preload.Update - import Picture.Preload import Sound.Data -import Control.Lens +import Control.Lens import GHC.Word (Word32) +import qualified SDL.Mixer as Mix cleanUpPreload :: PreloadData a -> IO () cleanUpPreload pd = do cleanUpRenderPreload $ _renderData pd cleanUpSoundPreload $ _soundData pd + +cleanUpSoundPreload :: SoundData a -> IO () +cleanUpSoundPreload sd = Mix.closeAudio diff --git a/src/Sound/Data.hs b/src/Sound/Data.hs index 758a0cc7b..dbc415a31 100644 --- a/src/Sound/Data.hs +++ b/src/Sound/Data.hs @@ -32,5 +32,3 @@ data Sound = Sound makeLenses ''SoundData makeLenses ''Sound -cleanUpSoundPreload :: SoundData a -> IO () -cleanUpSoundPreload sd = Mix.closeAudio