Add sound source files
This commit is contained in:
@@ -65,6 +65,7 @@ main = do
|
|||||||
-- ]
|
-- ]
|
||||||
-- )
|
-- )
|
||||||
)
|
)
|
||||||
|
(\_ _ -> return)
|
||||||
(flip $ menuEvents $ flip handleEvent)
|
(flip $ menuEvents $ flip handleEvent)
|
||||||
(\w -> Just $ update w)
|
(\w -> Just $ update w)
|
||||||
Mix.closeAudio
|
Mix.closeAudio
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ data World = World
|
|||||||
, _pressPlates :: IM.IntMap PressPlate
|
, _pressPlates :: IM.IntMap PressPlate
|
||||||
, _buttons :: IM.IntMap Button
|
, _buttons :: IM.IntMap Button
|
||||||
, _soundQueue :: [Int]
|
, _soundQueue :: [Int]
|
||||||
-- , _loadedSounds :: IM.IntMap Mix.Chunk
|
|
||||||
, _sounds :: M.Map SoundOrigin Sound
|
, _sounds :: M.Map SoundOrigin Sound
|
||||||
, _decorations :: IM.IntMap Drawing
|
, _decorations :: IM.IntMap Drawing
|
||||||
, _corpses :: IM.IntMap (IM.IntMap [Corpse])
|
, _corpses :: IM.IntMap (IM.IntMap [Corpse])
|
||||||
|
|||||||
+8
-21
@@ -111,27 +111,14 @@ loadSounds = do
|
|||||||
-- -- fmap (set soundQueue creatureSounds) $ return w
|
-- -- fmap (set soundQueue creatureSounds) $ return w
|
||||||
-- where creatureSounds = []
|
-- where creatureSounds = []
|
||||||
|
|
||||||
|
--playSounds :: a -> World -> IO ()
|
||||||
|
--playSounds _ w = do
|
||||||
|
-- forM_ (_soundQueue w) (\n -> Mix.playOn (-1) 0 (_loadedSounds w IM.! n))
|
||||||
|
-- -- = return $ set soundQueue creatureSounds w
|
||||||
|
-- -- = do forM_ (_soundQueue w) (\n -> Mix.playOn (-1) (_loadedSounds w IM.! n) 0)
|
||||||
|
-- -- fmap (set soundQueue creatureSounds) $ return w
|
||||||
|
-- where creatureSounds = []
|
||||||
|
|
||||||
soundOnce :: Int -> World -> World
|
soundOnce :: Int -> World -> World
|
||||||
soundOnce i = over soundQueue ((:) i)
|
soundOnce i = over soundQueue ((:) i)
|
||||||
|
|
||||||
--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
|
|
||||||
|
|||||||
@@ -61,6 +61,30 @@ update w
|
|||||||
where (x,y) = zoneOfPoint $ _clPos cr
|
where (x,y) = zoneOfPoint $ _clPos cr
|
||||||
cid = _clID cr
|
cid = _clID cr
|
||||||
|
|
||||||
|
--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'
|
updateLightSources w = set tempLightSources (catMaybes tlss) w'
|
||||||
where (w',tlss) = mapAccumR (\a b -> _tlsUpdate b a b) w $ _tempLightSources w
|
where (w',tlss) = mapAccumR (\a b -> _tlsUpdate b a b) w $ _tempLightSources w
|
||||||
|
|
||||||
|
|||||||
+12
-6
@@ -29,11 +29,12 @@ setupLoop :: String
|
|||||||
-> (setupParams -> IO ())
|
-> (setupParams -> IO ())
|
||||||
-> world
|
-> world
|
||||||
-> (setupParams -> world -> IO ())
|
-> (setupParams -> world -> IO ())
|
||||||
|
-> (setupParams -> world -> storableSideEffects -> IO storableSideEffects)
|
||||||
-> (world -> Event -> Maybe world)
|
-> (world -> Event -> Maybe world)
|
||||||
-> (world -> Maybe world)
|
-> (world -> Maybe world)
|
||||||
-> IO ()
|
-> IO ()
|
||||||
setupLoop wName xSize ySize
|
setupLoop wName xSize ySize
|
||||||
customInit initCleanup startWorld sideEffects eventFn worldFn = do
|
customInit initCleanup startWorld sideEffects storableFn eventFn worldFn = do
|
||||||
initializeAll
|
initializeAll
|
||||||
bracket (createWindow (T.pack wName) (winConfig xSize ySize)) destroyWindow
|
bracket (createWindow (T.pack wName) (winConfig xSize ySize)) destroyWindow
|
||||||
(\window ->
|
(\window ->
|
||||||
@@ -47,7 +48,7 @@ setupLoop wName xSize ySize
|
|||||||
GL.clearColor $= GL.Color4 0 0.5 0 1
|
GL.clearColor $= GL.Color4 0 0.5 0 1
|
||||||
GL.clearDepth $= (200)
|
GL.clearDepth $= (200)
|
||||||
doLoop setup window startWorld
|
doLoop setup window startWorld
|
||||||
sideEffects eventFn worldFn
|
sideEffects storableFn eventFn worldFn
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -59,9 +60,14 @@ setupLoop wName xSize ySize
|
|||||||
-- -> IO ()
|
-- -> IO ()
|
||||||
doLoop setup window startWorld
|
doLoop setup window startWorld
|
||||||
worldSideEffects
|
worldSideEffects
|
||||||
|
storableFn
|
||||||
eventFn
|
eventFn
|
||||||
worldUpdate
|
worldUpdate
|
||||||
= do
|
= do
|
||||||
|
GL.clear [GL.ColorBuffer,GL.DepthBuffer]
|
||||||
|
worldSideEffects setup startWorld
|
||||||
|
glSwapWindow window
|
||||||
|
--worldSideEffects setup updatedWorld
|
||||||
startLoopTicks <- ticks
|
startLoopTicks <- ticks
|
||||||
events <- pollEvents
|
events <- pollEvents
|
||||||
--let-- maybeUpdatedWorld :: Maybe (WorldView world0)
|
--let-- maybeUpdatedWorld :: Maybe (WorldView world0)
|
||||||
@@ -69,15 +75,15 @@ doLoop setup window startWorld
|
|||||||
maybeUpdatedWorld <- applyEventsIO eventFn startWorld events
|
maybeUpdatedWorld <- applyEventsIO eventFn startWorld events
|
||||||
case maybeUpdatedWorld >>= worldUpdate of
|
case maybeUpdatedWorld >>= worldUpdate of
|
||||||
Just updatedWorld -> do
|
Just updatedWorld -> do
|
||||||
GL.clear [GL.ColorBuffer,GL.DepthBuffer]
|
--GL.clear [GL.ColorBuffer,GL.DepthBuffer]
|
||||||
worldSideEffects setup updatedWorld
|
--worldSideEffects setup updatedWorld
|
||||||
glSwapWindow window
|
--glSwapWindow window
|
||||||
--GL.flush
|
--GL.flush
|
||||||
performGC
|
performGC
|
||||||
endLoopTicks <- ticks -- it might be better to use System.Clock (monotonic)
|
endLoopTicks <- ticks -- it might be better to use System.Clock (monotonic)
|
||||||
let delay = max 0 (10 + fromIntegral startLoopTicks - fromIntegral endLoopTicks)
|
let delay = max 0 (10 + fromIntegral startLoopTicks - fromIntegral endLoopTicks)
|
||||||
threadDelay (delay * 1000)
|
threadDelay (delay * 1000)
|
||||||
doLoop setup window updatedWorld worldSideEffects eventFn worldUpdate
|
doLoop setup window updatedWorld worldSideEffects storableFn eventFn worldUpdate
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
|
|
||||||
applyEvents :: (world0 -> Event -> Maybe world0)
|
applyEvents :: (world0 -> Event -> Maybe world0)
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
module Sound
|
||||||
|
where
|
||||||
|
|
||||||
|
-- ok, the problem here is that we need to be able to return the playing channel
|
||||||
|
-- so this thread cannot be a simple observer
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
module Sound.Preload
|
||||||
|
where
|
||||||
|
import qualified SDL.Mixer as Mix
|
||||||
|
|
||||||
|
import qualified Data.IntMap as IM
|
||||||
|
|
||||||
|
type LoadedSounds = IM.IntMap Mix.Chunk
|
||||||
Reference in New Issue
Block a user