Minor cleanups

This commit is contained in:
2022-02-10 10:50:29 +00:00
parent 0a860e6f68
commit 700ab8d930
8 changed files with 26 additions and 36 deletions
+8 -7
View File
@@ -56,9 +56,10 @@ playSoundAndUpdate sData oldSounds newSounds
mergeSound :: Sound -> Sound -> Sound
mergeSound oldS newS
| _soundChunkID newS == _soundChunkID oldS && _soundStatus newS == ToContinueStart
= newS & soundChannel .~ _soundChannel oldS
& soundStatus .~ _soundStatus oldS
| otherwise = newS & soundChannel .~ _soundChannel oldS
= newOldChannel & soundStatus .~ _soundStatus oldS
| otherwise = newOldChannel
where
newOldChannel = newS & soundChannel .~ _soundChannel oldS
updateSounds :: IM.IntMap Mix.Chunk -> M.Map a Sound -> IO (M.Map a Sound)
updateSounds sd ss = do
@@ -95,7 +96,7 @@ tryGetChannel s = case _soundChannel s of
decrementTimer :: Sound -> IO Sound
decrementTimer s = case _soundTime s of
Just t
| t > 0 -> return $ s & soundTime ?~ t - 1
| t > 0 -> return $ s & soundTime . _Just -~ 1
| otherwise -> do
forM_ (_soundChannel s) Mix.halt
return $ s & soundTime .~ Nothing
@@ -120,7 +121,6 @@ cleanupHalted s = do
For each index, the corresponding sound starts playing if there is a free channel.
Use this if you don't care about timing, overlapping, fading, or sound positions. -}
playSoundQueue :: IM.IntMap Mix.Chunk -> [Int] -> IO ()
--playSoundQueue chunkMap ns = forM_ ns $ \n -> runMaybeT $ playIfFree (chunkMap IM.! n) Mix.Once
playSoundQueue chunkMap = mapM_ $ \n -> runMaybeT $ playIfFree (chunkMap IM.! n) Mix.Once
{- | Given a chunk, attempt to play this on a free channel a given number of
@@ -134,8 +134,9 @@ playIfFree c times = do
{- | Play sounds from a list of index/position pairs.
As for 'playSoundQueue', but with positional information in the form of an Int16. -}
playPositionalSoundQueue :: IM.IntMap Mix.Chunk -> [(Int,Int16)] -> IO ()
playPositionalSoundQueue chunkMap = VS.mapM_ ( \(n,a) ->
runMaybeT $ playIfFree (chunkMap IM.! n) Mix.Once >>= setChannelPos a )
playPositionalSoundQueue chunkMap
= VS.mapM_ ( \(n,a) ->
runMaybeT $ playIfFree (chunkMap IM.! n) Mix.Once >>= setChannelPos a )
. VS.fromList
setChannelPos :: Int16 -> Mix.Channel -> MaybeT IO Mix.Channel