Remove loop dependency on loading dodge sounds
This commit is contained in:
@@ -6,6 +6,8 @@ import Dodge.Default
|
||||
import Dodge.CreatureState
|
||||
import Dodge.LightSources
|
||||
|
||||
import Dodge.WorldEvent.Sound
|
||||
|
||||
import Dodge.Creature.Update hiding (CRUpdate)
|
||||
|
||||
import Picture
|
||||
@@ -30,7 +32,7 @@ updateLamp :: Int -> CRUpdate
|
||||
updateLamp i = unrandUpdate handleLS internalUpdate
|
||||
where
|
||||
handleLS cr w
|
||||
| _crHP cr < 0 = w & lightSources %~ IM.delete i
|
||||
| _crHP cr < 0 = mkSoundBreakGlass w & lightSources %~ IM.delete i
|
||||
| otherwise = w & lightSources . ix i . lsPos .~ _crPos cr
|
||||
internalUpdate cr
|
||||
| _crHP cr < 0 = Nothing
|
||||
|
||||
@@ -3,7 +3,6 @@ module Dodge.Item.Weapon
|
||||
( module Dodge.Item.Weapon
|
||||
)
|
||||
where
|
||||
-- imports {{{
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.SoundLogic
|
||||
@@ -50,7 +49,6 @@ pistol,lasGun,tractorGun,launcher,autoGun
|
||||
,multGun
|
||||
-- ,shatterGun
|
||||
,longGun,flamer,blinkGun,forceFieldGun :: Item
|
||||
|
||||
pistol = Weapon
|
||||
{ _itName = "PISTOL"
|
||||
, _itIdentity = Pistol
|
||||
|
||||
@@ -4,6 +4,8 @@ import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.SoundLogic
|
||||
|
||||
import Dodge.WorldEvent.Sound
|
||||
|
||||
import Dodge.LevelGen.Pathing
|
||||
|
||||
import Geometry
|
||||
@@ -40,9 +42,11 @@ killBlock bl w = f bl .
|
||||
where
|
||||
f bl@(Block {_blDegrades = (x:xs)}) = degradeBlock bl . hitSound bl
|
||||
f bl = hitSound' bl
|
||||
hitSound bl | _wlIsSeeThrough bl = soundMultiFrom sos (soundid+8) 25 0
|
||||
hitSound bl | _wlIsSeeThrough bl = mkSoundBreakGlass
|
||||
-- hitSound bl | _wlIsSeeThrough bl = soundMultiFrom sos (soundid+8) 25 0
|
||||
| otherwise = soundMultiFrom sos soundid 25 0
|
||||
hitSound' bl | _wlIsSeeThrough bl = soundMultiFrom sos (soundid+4) 25 0
|
||||
hitSound' bl | _wlIsSeeThrough bl = mkSoundSplinterGlass
|
||||
-- hitSound' bl | _wlIsSeeThrough bl = soundMultiFrom sos (soundid+4) 25 0
|
||||
| otherwise = soundMultiFrom sos soundid 25 0
|
||||
sos = [BlockDegradeSound 0,BlockDegradeSound 1]
|
||||
(soundid,_) = randomR (29,32) $ _randGen w
|
||||
|
||||
@@ -14,12 +14,12 @@ import qualified SDL.Mixer as Mix
|
||||
-- }}}
|
||||
loadSounds :: IO (IM.IntMap Mix.Chunk)
|
||||
loadSounds = do
|
||||
-- pFireSound <- Mix.load "./data/sound/tap3.wav"
|
||||
pFireSound <- Mix.load "./data/sound/tap3.wav"
|
||||
click <- Mix.load "./data/sound/click1.wav"
|
||||
reloadSound' <- Mix.load "./data/sound/reload1.wav"
|
||||
tone440 <- Mix.load "./data/sound/tone440.wav"
|
||||
pickupSound' <- Mix.load "./data/sound/pickUp.wav"
|
||||
Mix.openAudio Mix.defaultAudio 256
|
||||
pFireSound <- Mix.load "./data/sound/tap3.wav"
|
||||
click <- Mix.load "./data/sound/click1.wav"
|
||||
reloadSound' <- Mix.load "./data/sound/reload1.wav"
|
||||
tone440 <- Mix.load "./data/sound/tone440.wav"
|
||||
pickupSound' <- Mix.load "./data/sound/pickUp.wav"
|
||||
putdownSound' <- Mix.load "./data/sound/whiteNoiseFadeOut.wav"
|
||||
fireSound' <- Mix.load "./data/sound/fire1.wav"
|
||||
grenadeBang' <- Mix.load "./data/sound/grenade.wav"
|
||||
|
||||
+20
-24
@@ -1,12 +1,7 @@
|
||||
module Dodge.SoundLogic where
|
||||
-- imports {{{
|
||||
import Dodge.Data
|
||||
|
||||
import Control.Lens
|
||||
import qualified Data.Map as M
|
||||
-- }}}
|
||||
--
|
||||
-- PLACEHOLDERS:
|
||||
|
||||
haltSound :: World -> World
|
||||
haltSound w = w
|
||||
@@ -21,26 +16,28 @@ soundOnce :: Int -> World -> World
|
||||
soundOnce i = over soundQueue ((:) i)
|
||||
|
||||
continueSoundFrom :: SoundOrigin -> Int -> Int -> Int -> World -> World
|
||||
continueSoundFrom so sType time fadeTime w
|
||||
= over sounds (M.insertWith f so sound) w
|
||||
where sound = Sound { _soundType = sType
|
||||
, _soundTime = time
|
||||
, _soundFadeTime = fadeTime
|
||||
, _soundChannel = Nothing
|
||||
, _soundPos = Nothing
|
||||
}
|
||||
f _ s = s {_soundTime = time, _soundFadeTime = fadeTime}
|
||||
continueSoundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
|
||||
where
|
||||
sound = Sound
|
||||
{ _soundType = sType
|
||||
, _soundTime = time
|
||||
, _soundFadeTime = fadeTime
|
||||
, _soundChannel = Nothing
|
||||
, _soundPos = Nothing
|
||||
}
|
||||
f _ s = s {_soundTime = time, _soundFadeTime = fadeTime}
|
||||
|
||||
soundFrom :: SoundOrigin -> Int -> Int -> Int -> World -> World
|
||||
soundFrom so sType time fadeTime w
|
||||
= over sounds (M.insertWith f so sound) w
|
||||
where sound = Sound { _soundType = sType
|
||||
, _soundTime = time
|
||||
, _soundFadeTime = fadeTime
|
||||
, _soundChannel = Nothing
|
||||
, _soundPos = Nothing
|
||||
}
|
||||
f _ s = s {_soundTime = time, _soundFadeTime = fadeTime}
|
||||
soundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
|
||||
where
|
||||
sound = Sound
|
||||
{ _soundType = sType
|
||||
, _soundTime = time
|
||||
, _soundFadeTime = fadeTime
|
||||
, _soundChannel = Nothing
|
||||
, _soundPos = Nothing
|
||||
}
|
||||
f _ s = s {_soundTime = time, _soundFadeTime = fadeTime}
|
||||
|
||||
soundMultiFrom :: [SoundOrigin] -> Int -> Int -> Int -> World -> World
|
||||
soundMultiFrom [] _ _ _ w = w
|
||||
@@ -57,7 +54,6 @@ soundMultiFrom (so:sos) sType time fadeTime w
|
||||
stopSoundFrom :: SoundOrigin -> World -> World
|
||||
stopSoundFrom so = over (sounds . ix so . soundTime) (min 0)
|
||||
|
||||
|
||||
-- idea: pass the id of the sound to the world and send it to some queue for
|
||||
-- playback
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
module Dodge.WorldEvent.Sound
|
||||
where
|
||||
import Dodge.Data
|
||||
|
||||
import Dodge.SoundLogic
|
||||
import System.Random
|
||||
|
||||
import Control.Lens
|
||||
|
||||
mkSoundBreakGlass :: World -> World
|
||||
mkSoundBreakGlass w = soundOnce soundid $ set randGen g w
|
||||
where
|
||||
(soundid,g) = _randGen w & randomR (37,40)
|
||||
|
||||
mkSoundSplinterGlass :: World -> World
|
||||
mkSoundSplinterGlass w = soundOnce soundid $ set randGen g w
|
||||
where
|
||||
(soundid,g) = _randGen w & randomR (33,36)
|
||||
Reference in New Issue
Block a user