Remove loop dependency on loading dodge sounds

This commit is contained in:
2021-03-27 13:42:14 +01:00
parent 2897c65e9e
commit 2011728de5
10 changed files with 171 additions and 153 deletions
+4 -5
View File
@@ -13,8 +13,7 @@ import qualified Data.Map as M
import Control.Lens
playSoundQueue :: SoundData a -> [Int] -> IO ()
playSoundQueue sd ns =
forM_ ns $ \n -> playIfFree (_loadedChunks sd IM.! n) Mix.Once
playSoundQueue sd ns = forM_ ns $ \n -> playIfFree (_loadedChunks sd IM.! n) Mix.Once
playIfFree :: Mix.Chunk -> Mix.Times -> IO (Maybe Mix.Channel)
playIfFree c times = do
@@ -43,8 +42,8 @@ playSounds sd = do
updatePlaying :: Ord a => M.Map a Sound -> M.Map a Sound -> M.Map a Sound
updatePlaying new old = M.unionWith f new old
where f newSound oldSound = newSound {_soundChannel = _soundChannel oldSound}
where
f newSound oldSound = newSound {_soundChannel = _soundChannel oldSound}
playAndUpdate :: Ord a => M.Map a Sound -> SoundData a -> IO (SoundData a)
playAndUpdate new sd = do
playSounds $ over playingSounds (updatePlaying new) sd
playAndUpdate new sd = playSounds $ over playingSounds (updatePlaying new) sd