Try to move sound into world, slightly broken now
This commit is contained in:
+14
-37
@@ -21,7 +21,6 @@ import Sound.Data
|
||||
import Music
|
||||
import Data.Preload
|
||||
import Data.Preload.Render
|
||||
import Shader.Poke
|
||||
|
||||
import Control.Lens
|
||||
--import Foreign (Word32)
|
||||
@@ -33,59 +32,37 @@ 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
|
||||
theKeyConfig <- loadKeyConfig
|
||||
dodgeConfig <- loadDodgeConfig
|
||||
setupLoop
|
||||
(sizex,sizey)
|
||||
(SDL.cursorVisible $= False >> doPreload >>= applyWorldConfig dodgeConfig)
|
||||
(\x -> (SDL.cursorVisible $= True) >> cleanUpPreload x)
|
||||
(fmap (setWindowSize sizex sizey . (keyConfig .~ theKeyConfig) . (config .~ dodgeConfig)) firstWorld)
|
||||
doSideEffects
|
||||
handleEvent
|
||||
(Just . update)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
(sizex,sizey) <- loadConfig
|
||||
theKeyConfig <- loadKeyConfig
|
||||
dodgeConfig <- loadDodgeConfig
|
||||
setupLoop'
|
||||
(sizex,sizey)
|
||||
theCleanup
|
||||
(firstWorldLoad (sizex,sizey) theKeyConfig dodgeConfig)
|
||||
(firstWorldLoad (sizex,sizey))
|
||||
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
|
||||
firstWorldLoad :: (Int,Int) -> IO World
|
||||
firstWorldLoad (sizex,sizey) = do
|
||||
SDL.cursorVisible $= False
|
||||
theKeyConfig <- loadKeyConfig
|
||||
theConfig <- loadDodgeConfig
|
||||
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
|
||||
theUpdateStep = doSideEffects . 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
|
||||
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) (_sounds w)
|
||||
newPlayingSounds <- playSoundAndUpdate (_soundData preData) (_playingSounds w) (_sounds w)
|
||||
|
||||
endTicks <- SDL.ticks
|
||||
let lastFrameTicks = _frameTimer preData
|
||||
@@ -96,14 +73,14 @@ doSideEffects preData w = do
|
||||
. translate (-0.5) (-0.8) . scale 0.0005 0.0005
|
||||
. text $ "ms/frame " ++ show (endTicks - lastFrameTicks)
|
||||
)
|
||||
foldr (=<<) (return (preData & soundData . playingSounds .~ newPlayingSounds
|
||||
& frameTimer .~ endTicks)) (_doneSideEffects w)
|
||||
newpdata <- foldr (=<<) (return (preData & frameTimer .~ endTicks)) (_doneSideEffects w)
|
||||
return $ w & preloadData .~ newpdata
|
||||
|
||||
doPreload :: IO (PreloadData a)
|
||||
doPreload :: IO PreloadData
|
||||
doPreload = do
|
||||
lChunks <- loadSounds
|
||||
lMusic <- loadMusic
|
||||
let sData = SoundData {_loadedChunks = lChunks, _playingSounds = M.empty}
|
||||
let sData = SoundData {_loadedChunks = lChunks}
|
||||
mData = MusicData {_loadedMusic = lMusic}
|
||||
Mix.playMusic Mix.Forever (lMusic IM.! 0)
|
||||
rData <- preloadRender
|
||||
|
||||
Reference in New Issue
Block a user