This commit is contained in:
2022-12-28 10:21:00 +00:00
parent 2d4a55dee0
commit d1f80f1f7f
7 changed files with 76 additions and 138 deletions
+37 -103
View File
@@ -9,9 +9,9 @@ module Dodge.SoundLogic (
soundStart,
soundContinue,
soundContinueVol,
soundFromGeneral,
soundMultiFrom,
stopSoundFrom,
soundWithStatus,
-- * helper to determine the angle of a sound given a world position
soundAngle,
@@ -27,7 +27,7 @@ import Control.Lens
import Data.Int (Int16)
import qualified Data.Map as M
import Data.Maybe
import Dodge.Data.Universe
import Dodge.Data.World
import Dodge.SoundLogic.LoadSound
import Geometry.Data
import Geometry.Vector
@@ -42,43 +42,9 @@ pauseSound :: World -> World
pauseSound w = w
-- | Placeholder...
resumeSound :: Universe -> Universe
resumeSound :: World -> World
resumeSound w = w
soundWithStatusVolumeGeneral ::
-- | Volume factor, 0 - 1
Float ->
PlayStatus ->
-- | \"Creator\" of sound
SoundOrigin ->
-- | Position of sound
(World -> Point2) ->
-- | ID of sound to be played
SoundID ->
-- | Frames to play sound for, Nothing for until finished
Maybe Int ->
World ->
World
soundWithStatusVolumeGeneral vol status so fpos sType mtime w = w & toPlaySounds %~ M.insertWith f so sound
where
sound =
Sound
{ _soundChunkID = sType
, _soundTime = mtime
, _soundStatus =
SoundStatus
{ _playStatus = status
, _isLooping = isJust mtime
}
, _soundChannel = Nothing
, _soundAngDist = Just (a, floor (225 * (1 - vol)))
, _soundPos = fpos w
, _soundVolume = soundToVol sType * vol
, _soundVolumeFraction = vol
}
f _ s = s{_soundTime = mtime}
a = soundAngle (fpos w) w
soundWithStatusVolume ::
-- | Volume factor, 0 - 1
Float ->
@@ -93,25 +59,41 @@ soundWithStatusVolume ::
Maybe Int ->
World ->
World
soundWithStatusVolume vol status so pos = soundWithStatusVolumeGeneral vol status so (const pos)
soundWithStatusVolume vol status so fpos sType mtime w =
w & toPlaySounds
%~ M.insert
so
(aSound vol status fpos sType mtime w)
--soundWithStatusVolume vol status so pos sType mtime w = w & toPlaySounds %~ M.insertWith f so sound
-- where
-- sound = Sound
-- { _soundChunkID = sType
-- , _soundTime = mtime
-- , _soundStatus = SoundStatus
-- {_playStatus = status
-- ,_isLooping = isJust mtime
-- }
-- , _soundChannel = Nothing
-- , _soundAngDist = Just (a,floor (225 * (1 - vol)))
-- , _soundPos = pos
-- , _soundVolume = soundToVol sType * vol
-- , _soundVolumeFraction = vol
-- }
-- f _ s = s {_soundTime = mtime }
-- a = soundAngle pos w
aSound ::
-- | Volume factor, 0 - 1
Float ->
PlayStatus ->
-- | Position of sound
Point2 ->
-- | ID of sound to be played
SoundID ->
-- | Frames to play sound for, Nothing for until finished
Maybe Int ->
World ->
Sound
aSound vol status fpos sType mtime w =
Sound
{ _soundChunkID = sType
, _soundTime = mtime
, _soundStatus =
SoundStatus
{ _playStatus = status
, _isLooping = isJust mtime
}
, _soundChannel = Nothing
, _soundAngDist = Just (a, floor (225 * (1 - vol)))
, _soundPos = fpos
, _soundVolume = soundToVol sType * vol
, _soundVolumeFraction = vol
}
where
a = soundAngle fpos w
soundWithStatus ::
PlayStatus ->
@@ -169,37 +151,6 @@ soundContinueVol ::
World
soundContinueVol vol = soundWithStatusVolume vol ToContinueStart
soundFromGeneral ::
-- | \"Creator\" of sound
SoundOrigin ->
-- | Position of sound
(World -> Point2) ->
-- | ID of sound to be played
SoundID ->
-- | Frames to play sound for, Nothing for until finished
Maybe Int ->
World ->
World
soundFromGeneral = soundWithStatusVolumeGeneral 1 ToStart
--soundFromGeneral so fpos sType mtime w = w & toPlaySounds %~ M.insertWith f so sound
-- where
-- sound = Sound
-- { _soundChunkID = sType
-- , _soundTime = mtime
-- , _soundStatus = SoundStatus
-- { _playStatus = ToStart
-- , _isLooping = isJust mtime
-- }
-- , _soundChannel = Nothing
-- , _soundAngDist = Just (a,0)
-- , _soundPos = fpos w
-- , _soundVolume = soundToVol sType
-- , _soundVolumeFraction = 1
-- }
-- f _ s = s {_soundTime = mtime }
-- a = soundAngle (fpos w) w
{- | Calculates the angle of a sound with reference to '_cameraViewFrom'.
Within 10 units considers the sound to be directly in front.
-}
@@ -230,23 +181,6 @@ soundMultiFrom ::
World ->
World
soundMultiFrom [] _ _ _ w = w
--soundMultiFrom [so] pos sType mtime w
-- = over toPlaySounds (M.insert so sound) w
-- where
-- sound = Sound
-- { _soundChunkID = sType
-- , _soundTime = mtime
-- , _soundStatus = SoundStatus
-- { _playStatus = ToStart
-- , _isLooping = isJust mtime
-- }
-- , _soundChannel = Nothing
-- , _soundAngDist = Just (a,0)
-- , _soundPos = pos
-- , _soundVolume = soundToVol sType
-- , _soundVolumeFraction = 1
-- }
-- a = soundAngle pos w
soundMultiFrom (so : sos) pos sType mtime w
| so `M.member` _playingSounds w = soundMultiFrom sos pos sType mtime w
| otherwise = over toPlaySounds (M.insert so sound) w