This commit is contained in:
2021-04-08 11:18:10 +02:00
parent ea0dfbe1df
commit 28c1f3d23b
3 changed files with 38 additions and 37 deletions
+33 -33
View File
@@ -30,6 +30,39 @@ import Graphics.Rendering.OpenGL hiding (color, rotate, scale, translate)
import qualified SDL import qualified SDL
import qualified SDL.Mixer as Mix 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' :: Dodge.LoadConfig.Configuration -> IO (PreloadData a)
doPreload' config = do doPreload' config = do
lChunks <- loadSounds lChunks <- loadSounds
@@ -46,39 +79,6 @@ doPreload' config = do
, _frameTimer = 0 , _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 :: IO ()
checkForGlErrors = do checkForGlErrors = do
+5 -2
View File
@@ -6,15 +6,18 @@ module Preload
where where
import Preload.Data import Preload.Data
import Preload.Update import Preload.Update
import Picture.Preload import Picture.Preload
import Sound.Data import Sound.Data
import Control.Lens
import Control.Lens
import GHC.Word (Word32) import GHC.Word (Word32)
import qualified SDL.Mixer as Mix
cleanUpPreload :: PreloadData a -> IO () cleanUpPreload :: PreloadData a -> IO ()
cleanUpPreload pd = do cleanUpPreload pd = do
cleanUpRenderPreload $ _renderData pd cleanUpRenderPreload $ _renderData pd
cleanUpSoundPreload $ _soundData pd cleanUpSoundPreload $ _soundData pd
cleanUpSoundPreload :: SoundData a -> IO ()
cleanUpSoundPreload sd = Mix.closeAudio
-2
View File
@@ -32,5 +32,3 @@ data Sound = Sound
makeLenses ''SoundData makeLenses ''SoundData
makeLenses ''Sound makeLenses ''Sound
cleanUpSoundPreload :: SoundData a -> IO ()
cleanUpSoundPreload sd = Mix.closeAudio