diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index db18af086..7551056bb 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -5,6 +5,8 @@ module Dodge.Data ( module Dodge.Data , Point2 (..) + , Sound (..) + , soundTime ) where -- imports {{{ @@ -13,6 +15,8 @@ import Picture.Data import Geometry.Data +import Sound.Preload + import Control.Lens import Control.Monad.State import System.Random @@ -243,15 +247,6 @@ data MenuState | InGame deriving (Eq,Ord) -data Sound = Sound { _soundTime :: Int - , _soundFadeTime :: Int - --, _soundChannel :: Maybe Int - , _soundChannel :: Maybe Mix.Channel - , _soundPos :: Maybe Point2 - , _soundType :: Int - } - deriving (Eq,Ord,Show) - data Button = Button { _btPict :: Drawing , _btPos :: Point2 @@ -696,7 +691,6 @@ makeLenses ''Button makeLenses ''PSType makeLenses ''PlacementSpot makeLenses ''Room -makeLenses ''Sound -- -- }}} diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index d3b0db06e..12bd715eb 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -65,30 +65,6 @@ update w updateSoundQueue = set soundQueue [] . set sounds M.empty ---updateSound :: World -> World ---updateSound = set soundQueue [] . stepSoundTimers ---stepSoundTimers :: World -> IO World ---stepSoundTimers w = M.foldrWithKey stepSoundTimer (return w) (_sounds w) - ----- ok, this is hard to reason about-- bugs can occur because I am unsure when ----- everything is evaluated ---stepSoundTimer :: SoundOrigin -> Sound -> IO World -> IO World ---stepSoundTimer so s w = --- case _soundChannel s of --- Nothing -> do w1 <- w --- let soundChunk = _loadedSounds w1 IM.! _soundType s ----- n <- Mix.playingCount --- channel <- Mix.playOn (-1) (-1) soundChunk --- -- w2 <- w -- Note that using w2 instead of w1 in the --- -- final return breaks the sound sometimes, must be --- -- something to do with order of evaluation --- return $ set (sounds . ix so . soundChannel) (Just $ fromIntegral channel) w1 --- Just channel -> case _soundTime s of --- x | x > 0 -> fmap (set (sounds . ix so . soundTime) (x-1)) w --- | x <= 0 -> do Mix.fadeOut channel (fromIntegral $ _soundFadeTime s+ 1) --- fmap (over sounds (M.delete so)) w ----- the sound fade doesn't seem to like being 0 - updateLightSources w = set tempLightSources (catMaybes tlss) w' where (w',tlss) = mapAccumR (\a b -> _tlsUpdate b a b) w $ _tempLightSources w diff --git a/src/Sound.hs b/src/Sound.hs index face9d388..01a9c4b7d 100644 --- a/src/Sound.hs +++ b/src/Sound.hs @@ -12,7 +12,6 @@ import qualified Data.Map as M import Control.Lens -import Dodge.Data playSoundQueue :: SoundData a -> [Int] -> IO () playSoundQueue sd ns = diff --git a/src/Sound/Preload.hs b/src/Sound/Preload.hs index 8032d99e0..ac0ecbdf6 100644 --- a/src/Sound/Preload.hs +++ b/src/Sound/Preload.hs @@ -8,14 +8,25 @@ import qualified Data.Map as M import Control.Lens -import Dodge.Data +import Geometry + data SoundData a = SoundData {_loadedChunks :: IM.IntMap Mix.Chunk ,_playingSounds :: M.Map a Sound } +data Sound = Sound { _soundTime :: Int + , _soundFadeTime :: Int + --, _soundChannel :: Maybe Int + , _soundChannel :: Maybe Mix.Channel + , _soundPos :: Maybe Point2 + , _soundType :: Int + } + deriving (Eq,Ord,Show) + makeLenses ''SoundData +makeLenses ''Sound cleanUpSoundPreload :: SoundData a -> IO ()