Пример #1
0
        private void InitCue(string cueName)
        {
            if (string.IsNullOrEmpty(cueName))
            {
                CueId = new MyCueId(MyStringHash.NullOrEmpty);
            }
            else
            {
                var cueId = new MyCueId(MyStringHash.GetOrCompute(cueName));
                MySoundCategoryDefinition.SoundDescription soundDesc = null;
                var soundCategories = MyDefinitionManager.Static.GetSoundCategoryDefinitions();

                // check whether saved cue is in some category
                foreach (var category in soundCategories)
                {
                    foreach (var soundDescTmp in category.Sounds)
                    {
                        if (MySoundPair.GetCueId(soundDescTmp.SoundId) == cueId)
                        {
                            soundDesc = soundDescTmp;
                        }
                    }
                }

                if (soundDesc != null)
                {
                    SelectSound(cueId, false);
                }
                else
                {
                    CueId = new MyCueId(MyStringHash.NullOrEmpty);
                }
            }
        }
Пример #2
0
 public void PlaySingleSound(MyCueId soundId, bool stopPrevious = false, bool skipIntro = false, bool?force3D = new bool?())
 {
     if (this.m_cueEnum != soundId)
     {
         this.PlaySoundWithDistance(soundId, stopPrevious, skipIntro, false, true, false, false, force3D);
     }
 }
Пример #3
0
        public void PlaySoundWithDistance(MyCueId soundId, bool stopPrevious = false, bool skipIntro = false, bool force2D = false, bool useDistanceCheck = true, bool alwaysHearOnRealistic = false)
        {
            m_lastSoundData = MyAudio.Static.GetCue(soundId);
            if (useDistanceCheck)
            {
                m_closeSoundCueId = soundId;
            }
            if (useDistanceCheck && ShouldPlay2D() == false && force2D == false)
            {
                soundId = CheckDistanceSounds(soundId);
            }
            bool usesDistanceSoundsCache = m_usesDistanceSounds;

            if (m_sound != null)
            {
                if (stopPrevious)
                {
                    StopSound(true);
                }
                else if (m_sound.IsLoopable)
                {
                    var sound = Sound;
                    StopSound(true);
                    m_soundsQueue.Add(sound.CueEnum);
                }
            }
            if (m_secondarySound != null)
            {
                m_secondarySound.Stop(true);
            }
            SoundId = soundId;
            PlaySoundInternal(skipIntro, force2D: force2D, alwaysHearOnRealistic: alwaysHearOnRealistic);
            m_usesDistanceSounds = usesDistanceSoundsCache;
        }
Пример #4
0
        public void PlaySoundWithDistance(MyCueId soundId, bool stopPrevious = false, bool skipIntro = false, bool force2D = false, bool useDistanceCheck = true, bool alwaysHearOnRealistic = false, bool skipToEnd = false, bool?force3D = new bool?())
        {
            this.m_lastSoundData = MyAudio.Static.GetCue(soundId);
            if (useDistanceCheck)
            {
                this.m_closeSoundCueId = soundId;
                MyCueId id1 = this.CheckDistanceSounds(soundId);
                soundId = id1;
            }
            bool usesDistanceSounds = this.m_usesDistanceSounds;

            if (this.Sound != null)
            {
                if (stopPrevious)
                {
                    this.StopSound(true, true);
                }
                else if (this.Loop)
                {
                    IMySourceVoice sound = this.Sound;
                    this.StopSound(true, true);
                    this.m_soundsQueue.Add(sound.CueEnum);
                }
            }
            if (this.m_secondarySound != null)
            {
                this.m_secondarySound.Stop(true);
            }
            this.SoundId = soundId;
            bool flag2 = force2D;

            this.PlaySoundInternal(skipIntro | skipToEnd, skipToEnd, flag2, alwaysHearOnRealistic, force3D);
            this.m_usesDistanceSounds = usesDistanceSounds;
        }
        public void Init(string cueName)
        {
            if (string.IsNullOrEmpty(cueName) || MySandboxGame.IsDedicated || MyAudio.Static == null)
            {
                m_arcade = new MyCueId(MyStringHash.NullOrEmpty);
                m_realistic = new MyCueId(MyStringHash.NullOrEmpty);
            }
            else
            {
                m_arcade = MyAudio.Static.GetCueId(cueName);
                if (m_arcade.Hash != MyStringHash.NullOrEmpty)
                {
                    m_realistic = m_arcade;
                    return;
                }
                m_cache.Clear();
                m_cache.Append("Arc").Append(cueName);
                m_arcade = MyAudio.Static.GetCueId(m_cache.ToString());
                m_cache.Clear();
                m_cache.Append("Real").Append(cueName);
                m_realistic = MyAudio.Static.GetCueId(m_cache.ToString());

                //Debug.Assert(m_arcade != MySpaceTexts.NullOrEmpty || m_realistic != MySpaceTexts.NullOrEmpty, string.Format("Could not find any sound for '{0}'", cueName));
                if (m_arcade.Hash == MyStringHash.NullOrEmpty && m_realistic.Hash == MyStringHash.NullOrEmpty)
                    MySandboxGame.Log.WriteLine(string.Format("Could not find any sound for '{0}'", cueName));
            }
        }
Пример #6
0
        private MyCueId SelectCueFromCategory(MyStringId category)
        {
            //check list of cues for selected category - if empty copy cues from storage
            if (m_musicCuesRemaining.ContainsKey(category) == false)
            {
                m_musicCuesRemaining.Add(category, new List <MyCueId>());
            }
            if (m_musicCuesRemaining[category].Count == 0)
            {
                if (m_musicCuesAll.ContainsKey(category) == false || m_musicCuesAll[category] == null || m_musicCuesAll[category].Count == 0)
                {
                    return(m_cueEmpty);
                }
                foreach (var option in m_musicCuesAll[category])
                {
                    m_musicCuesRemaining[category].Add(option);
                }
                m_musicCuesRemaining[category].ShuffleList();
            }

            //pick from cue list
            MyCueId result = m_musicCuesRemaining[category][0];

            m_musicCuesRemaining[category].RemoveAt(0);
            return(result);
        }
Пример #7
0
        public void Update()
        {
            bool validSoundIsPlaying = m_sound != null && m_sound.IsPlaying;

            if (!CanHearSound())
            {
                if (validSoundIsPlaying)
                {
                    StopSound(true, false);
                    m_sound = null;
                }
                return;
            }
            else if (!validSoundIsPlaying && Loop)
            {
                PlaySoundInternal(true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D != ShouldPlay2D())
            {
                StopSound(true, false);
                PlaySoundInternal(true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D == false && usesDistanceSounds)
            {
                MyCueId newSound = CheckDistanceSounds(closeSound);
                if (MyStringHash.Comparer.Equals(newSound.Hash, SoundId.Hash) == false)
                {
                    PlaySound(newSound, true, useDistanceCheck: false);
                }
            }
        }
Пример #8
0
        public void PlaySound(MyCueId soundId, bool stopPrevious = false, bool skipIntro = false, bool force2D = false, bool useDistanceCheck = true)
        {
            closeSound = soundId;
            if (useDistanceCheck && ShouldPlay2D() == false && force2D == false)
            {
                soundId = CheckDistanceSounds(soundId);
            }
            bool usesDistanceSoundsCache = usesDistanceSounds;

            if (m_sound != null)
            {
                if (stopPrevious)
                {
                    StopSound(true);
                }
                else if (m_sound.IsLoopable)
                {
                    var sound = Sound;
                    StopSound(true);
                    m_soundsQueue.Add(sound.CueEnum);
                }
            }
            SoundId            = soundId;
            usesDistanceSounds = usesDistanceSoundsCache;
            PlaySoundInternal(skipIntro, force2D: force2D);
        }
Пример #9
0
 private MyCueId CheckDistanceSounds(MyCueId soundId)
 {
     if (soundId.IsNull == false)
     {
         MySoundData cueDefinition = MyAudio.Static.GetCue(soundId);
         if (cueDefinition != null && cueDefinition.DistantSounds != null && cueDefinition.DistantSounds.Count > 0)
         {
             float distanceToSoundSquered = Vector3.DistanceSquared(MySector.MainCamera.Position, this.SourcePosition);
             int   bestSoundIndex         = -1;
             usesDistanceSounds = true;
             for (int i = 0; i < cueDefinition.DistantSounds.Count; i++)
             {
                 if (distanceToSoundSquered > cueDefinition.DistantSounds[i].distance * cueDefinition.DistantSounds[i].distance)
                 {
                     bestSoundIndex = i;
                 }
                 else
                 {
                     break;
                 }
             }
             if (bestSoundIndex >= 0)
             {
                 soundId = new MyCueId(MyStringHash.GetOrCompute(cueDefinition.DistantSounds[bestSoundIndex].sound));
             }
         }
         else
         {
             usesDistanceSounds = false;
         }
     }
     return(soundId);
 }
Пример #10
0
        public void Init(string cueName)
        {
            if (string.IsNullOrEmpty(cueName) || MySandboxGame.IsDedicated || MyAudio.Static == null)
            {
                m_arcade    = new MyCueId(MyStringHash.NullOrEmpty);
                m_realistic = new MyCueId(MyStringHash.NullOrEmpty);
            }
            else
            {
                m_arcade = MyAudio.Static.GetCueId(cueName);
                if (m_arcade.Hash != MyStringHash.NullOrEmpty)
                {
                    m_realistic = m_arcade;
                    return;
                }
                m_cache.Clear();
                m_cache.Append("Arc").Append(cueName);
                m_arcade = MyAudio.Static.GetCueId(m_cache.ToString());
                m_cache.Clear();
                m_cache.Append("Real").Append(cueName);
                m_realistic = MyAudio.Static.GetCueId(m_cache.ToString());

                //Debug.Assert(m_arcade != MySpaceTexts.NullOrEmpty || m_realistic != MySpaceTexts.NullOrEmpty, string.Format("Could not find any sound for '{0}'", cueName));
                if (m_arcade.Hash == MyStringHash.NullOrEmpty && m_realistic.Hash == MyStringHash.NullOrEmpty)
                {
                    MySandboxGame.Log.WriteLine(string.Format("Could not find any sound for '{0}'", cueName));
                }
            }
        }
Пример #11
0
        public void Update()
        {
            bool validSoundIsPlaying = m_sound != null && m_sound.IsPlaying;

            if (!CanHearSound())
            {
                if (validSoundIsPlaying)
                {
                    StopSound(true, false);
                    m_sound = null;
                }
                return;
            }
            else if (!validSoundIsPlaying && Loop)
            {
                PlaySound(m_closeSoundSoundPair, true, true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D != ShouldPlay2D() && ((Force2D == true && m_playing2D == false) || (Force3D == true && m_playing2D == true)))
            {
                StopSound(true, false);
                PlaySound(m_closeSoundSoundPair, true, true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D == false && m_usesDistanceSounds)
            {
                MyCueId oldSecondary = (m_secondaryEnabled ? m_secondaryCueEnum : myEmptyCueId);
                MyCueId newSound     = CheckDistanceSounds(m_closeSoundCueId);
                if (newSound != m_cueEnum || oldSecondary != m_secondaryCueEnum)
                {
                    PlaySoundWithDistance(newSound, true, true, useDistanceCheck: false);
                }
                else if (m_secondaryEnabled)
                {
                    if (Sound != null)
                    {
                        Sound.SetVolume(RealisticVolumeChange * m_baseVolume * (1f - m_secondaryVolumeRatio));
                    }
                    if (m_secondarySound != null)
                    {
                        m_secondarySound.SetVolume(RealisticVolumeChange * m_secondaryBaseVolume * m_secondaryVolumeRatio);
                    }
                }
            }
            if (validSoundIsPlaying && Loop)
            {
                //arcade/real sound change
                MyCueId newCueId = SelectCue(m_soundPair);
                if (newCueId.Equals(m_cueEnum) == false)
                {
                    PlaySoundWithDistance(newCueId, true, true);
                }

                //active filter changed
                MyStringHash newEffect = SelectEffect();
                if (m_activeEffect != newEffect)
                {
                    PlaySoundWithDistance(newCueId, true, true);
                }
            }
        }
Пример #12
0
 public void AddMusicCue(MyStringId category, MyCueId cueId)
 {
     if (!this.m_musicCuesAll.ContainsKey(category))
     {
         this.m_musicCuesAll.Add(category, new List <MyCueId>());
     }
     this.m_musicCuesAll[category].Add(cueId);
 }
Пример #13
0
 public void AddMusicCue(MyStringId category, MyCueId cueId)
 {
     if (m_musicCuesAll.ContainsKey(category) == false)
     {
         m_musicCuesAll.Add(category, new List <MyCueId>());
     }
     m_musicCuesAll[category].Add(cueId);
 }
Пример #14
0
        public void SendSelectSoundRequest(MyCueId cueId)
        {
            SelectSoundMsg msg = new SelectSoundMsg();

            msg.EntityId = Entity.EntityId;
            msg.CueId    = cueId;

            Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
        }
Пример #15
0
        void cuesCombo_OnSelect()
        {
            m_currentCueSelectedItem = (int)m_cuesCombo.GetSelectedKey();
            var cue = new MyCueId(MyStringHash.TryGet(m_cuesCombo.GetSelectedValue().ToString()));

            m_currentCue = MyAudio.Static.GetCue(cue);

            UpdateCueValues();
            //RecreateControls(false);
        }
Пример #16
0
 public static void RequestThrow(MyObjectBuilder_CubeGrid grid, Vector3D position, Vector3D linearVelocity, float mass, MyCueId throwSound)
 {
     ThrowMsg msg = new ThrowMsg();
     msg.Grid = grid;
     msg.Position = position;
     msg.LinearVelocity = linearVelocity;
     msg.Mass = mass;
     msg.ThrowSound = throwSound;
     MySession.Static.SyncLayer.SendMessageToServer(ref msg);
 }
Пример #17
0
 public void PlaySingleSound(MyCueId soundId, /*bool loop = false,*/ bool stopPrevious = false, bool skipIntro = false)
 {
     if (m_cueEnum == soundId)
     {
         return;
     }
     else
     {
         PlaySoundWithDistance(soundId, stopPrevious, skipIntro);
     }
 }
Пример #18
0
 public void Flush()
 {
     m_cueId = new MyCueId(MyStringHash.NullOrEmpty);
     m_voice.Stop();
     m_voice.FlushSourceBuffers();
     for (int i = 0; i < m_loopBuffers.Length; i++ )
         m_loopBuffers[i] = null;
     m_isPlaying = false;
     m_isPaused = false;
     m_isLoopable = false;
     m_currentDescriptor = null;
 }
 private void PlaySound(MyCueId soundId)
 {
     if (m_sound != null && m_sound.IsPlaying)
     {
         var effect = MyAudio.Static.ApplyEffect(m_sound, MyStringHash.GetOrCompute("CrossFade"), new MyCueId[] { soundId }, 2000);
         m_sound = effect.OutputSound;
     }
     else
     {
         m_sound = MyAudio.Static.PlaySound(soundId, null, MySoundDimensions.D2);
     }
 }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_PrefabThrowerDefinition;
            if (ob.Mass.HasValue)
                Mass = ob.Mass;

            MaxSpeed = ob.MaxSpeed;
            MinSpeed = ob.MinSpeed;
            PushTime = ob.PushTime;
            PrefabToThrow = ob.PrefabToThrow;
            ThrowSound = new MyCueId(MyStringHash.GetOrCompute(ob.ThrowSound));
        }
Пример #21
0
        public void StartSecondarySound(MyCueId cueId, bool sync = false)
        {
            if (cueId.IsNull)
            {
                return;
            }

            m_soundEmitters[(int)MySoundEmitterEnum.SecondaryState].PlaySoundWithDistance(cueId);

            if (sync)
            {
                m_character.PlaySecondarySound(cueId);
            }
        }
Пример #22
0
        public void PlaySound(MySoundPair soundId, bool stopPrevious = false, bool skipIntro = false, bool force2D = false, bool alwaysHearOnRealistic = false, bool skipToEnd = false, bool?force3D = new bool?())
        {
            this.m_closeSoundSoundPair = soundId;
            this.m_soundPair           = soundId;
            MyCueId id = this.m_useRealisticByDefault ? soundId.Realistic : soundId.Arcade;

            if (this.EmitterMethods[2].Count > 0)
            {
                id = ((Func <MySoundPair, MyCueId>) this.EmitterMethods[2][0])(soundId);
            }
            bool?nullable = force3D;

            this.PlaySoundWithDistance(id, stopPrevious, skipIntro, force2D, true, alwaysHearOnRealistic, skipToEnd, nullable);
        }
Пример #23
0
 private void PlayFightingMusic(bool light)
 {
     this.CategoryPlaying        = light ? m_stringIdLightFight : m_stringIdHeavyFight;
     this.m_currentMusicCategory = light ? MusicCategory.lightFight : MusicCategory.heavyFight;
     if ((this.m_musicSourceVoice == null) || !this.m_musicSourceVoice.IsPlaying)
     {
         this.PlayMusic(this.SelectCueFromCategory(this.CategoryPlaying), m_hashFadeIn, 0x3e8, new MyCueId[0], true);
     }
     else
     {
         MyCueId[] cueIds = new MyCueId[] { this.SelectCueFromCategory(this.CategoryPlaying) };
         this.PlayMusic(this.CueIdPlaying, m_hashCrossfade, 0x7d0, cueIds, false);
     }
     this.m_noMusicTimer = this.m_random.Next(1, 4);
 }
Пример #24
0
 private void PlayDangerMusic()
 {
     this.CategoryPlaying        = m_stringIdDanger;
     this.m_currentMusicCategory = MusicCategory.danger;
     if ((this.m_musicSourceVoice == null) || !this.m_musicSourceVoice.IsPlaying)
     {
         this.PlayMusic(this.SelectCueFromCategory(this.CategoryPlaying), m_hashFadeIn, 0x3e8, new MyCueId[0], true);
     }
     else
     {
         MyCueId[] cueIds = new MyCueId[] { this.SelectCueFromCategory(m_stringIdDanger) };
         this.PlayMusic(this.CueIdPlaying, m_hashCrossfade, 0x7d0, cueIds, false);
     }
     this.m_noMusicTimer = this.m_random.Next(2, 8);
 }
Пример #25
0
        public void PlaySingleSound(MySoundPair soundId, bool stopPrevious = false, bool skipIntro = false, bool skipToEnd = false, bool?force3D = new bool?())
        {
            this.m_closeSoundSoundPair = soundId;
            this.m_soundPair           = soundId;
            MyCueId id = this.m_useRealisticByDefault ? soundId.Realistic : soundId.Arcade;

            if (this.EmitterMethods[2].Count > 0)
            {
                id = ((Func <MySoundPair, MyCueId>) this.EmitterMethods[2][0])(soundId);
            }
            if (!this.m_cueEnum.Equals(id))
            {
                this.PlaySoundWithDistance(id, stopPrevious, skipIntro, false, true, false, skipToEnd, force3D);
            }
        }
Пример #26
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_PrefabThrowerDefinition definition = builder as MyObjectBuilder_PrefabThrowerDefinition;

            if (definition.Mass != null)
            {
                this.Mass = definition.Mass;
            }
            this.MaxSpeed      = definition.MaxSpeed;
            this.MinSpeed      = definition.MinSpeed;
            this.PushTime      = definition.PushTime;
            this.PrefabToThrow = definition.PrefabToThrow;
            this.ThrowSound    = new MyCueId(MyStringHash.GetOrCompute(definition.ThrowSound));
        }
        private void PlaySound(MyCueId sound)
        {
            if (m_sound == null || !m_sound.IsPlaying)
            {
                m_sound = MyAudio.Static.PlaySound(sound);
                if (!sound.IsNull)
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeIn, null);
                }
                if (m_effect != null)
                {
                    m_sound = m_effect.OutputSound;
                }
            }
            else if (m_effect != null && m_effect.Finished && sound.IsNull)
            {
                m_sound.Stop(true);
            }
            else if (m_sound.CueEnum != sound)
            {
                if (m_effect != null && !m_effect.Finished)
                {
                    //m_effect.SetPositionRelative(1f);
                    m_effect.AutoUpdate = true;
                }
                if (sound.IsNull)
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeOut, null, 5000f);
                }
                else
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_crossFade, new MyCueId[] { sound }, 5000f);
                }

                if (m_effect != null && !m_effect.Finished)
                {
                    m_effect.AutoUpdate = true;
                    m_sound             = m_effect.OutputSound;
                }
            }
            if (m_sound != null)
            {
                MySoundData data = MyAudio.Static.GetCue(sound);
                m_volumeOriginal = data != null ? data.Volume :1f;
                m_sound.SetVolume(m_volumeOriginal * m_volumeModifier * VolumeModifierGlobal);
            }
        }
Пример #28
0
        internal void PlaySecondarySound(MyCueId soundId)
        {
            var msg = new PlaySecondarySoundMsg()
            {
                EntityId = this.SyncedEntityId,
                SoundId  = soundId,
            };

            if (Sync.IsServer)
            {
                Sync.Layer.SendMessageToAll(ref msg);
            }
            else
            {
                Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
            }
        }
Пример #29
0
 private void PlayMusic(MyCueId cue, MyStringHash effect, int effectDuration = 2000, MyCueId[] cueIds = null, bool play = true)
 {
     if (play)
     {
         m_musicSourceVoice = MyAudio.Static.PlayMusicCue(cue);
     }
     if (m_musicSourceVoice != null)
     {
         if (effect != MyStringHash.NullOrEmpty)
         {
             var effectSourceVoice = MyAudio.Static.ApplyEffect(m_musicSourceVoice, effect, cueIds, effectDuration);
             m_musicSourceVoice = effectSourceVoice.OutputSound;
         }
         m_musicSourceVoice.StoppedPlaying += MusicStopped;
     }
     m_lastMusicData = MyAudio.Static.GetCue(cue);
 }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_PrefabThrowerDefinition;

            if (ob.Mass.HasValue)
            {
                Mass = ob.Mass;
            }

            MaxSpeed      = ob.MaxSpeed;
            MinSpeed      = ob.MinSpeed;
            PushTime      = ob.PushTime;
            PrefabToThrow = ob.PrefabToThrow;
            ThrowSound    = new MyCueId(MyStringHash.GetOrCompute(ob.ThrowSound));
        }
Пример #31
0
 private void PlaySound(MyCueId soundId, bool useCrossfade)
 {
     if (((this.m_sound != null) && this.m_sound.IsPlaying) & useCrossfade)
     {
         MyCueId[]      cueIds = new MyCueId[] { soundId };
         IMyAudioEffect effect = MyAudio.Static.ApplyEffect(this.m_sound, MyStringHash.GetOrCompute("CrossFade"), cueIds, new float?((float)0x7d0), false);
         this.m_sound = effect.OutputSound;
     }
     else
     {
         if (this.m_sound != null)
         {
             this.m_sound.Stop(true);
         }
         this.m_sound = MyAudio.Static.PlaySound(soundId, null, MySoundDimensions.D2, false, false);
     }
 }
        public void StartSecondarySound(MyCueId cueId, bool sync = false)
        {
            if (cueId.IsNull)
            {
                return;
            }

            if (!m_soundEmitters[(int)MySoundEmitterEnum.SecondaryState].IsPlaying)
            {
                m_soundEmitters[(int)MySoundEmitterEnum.SecondaryState].PlaySound(cueId);
            }

            if (sync)
            {
                m_character.SyncObject.PlaySecondarySound(cueId);
            }
        }
        public void PlaySpecificMusicTrack(MyCueId cue, bool playAtLeastOnce)
        {
            if (!cue.IsNull)
            {
                if (m_musicSourceVoice != null && m_musicSourceVoice.IsPlaying)
                {
                    PlayMusic(CueIdPlaying, m_hashCrossfade, BUILDING_CROSSFADE_LENGTH, new MyCueId[] { cue }, false);
                }
                else
                {
                    PlayMusic(cue, m_hashFadeIn, BUILDING_CROSSFADE_LENGTH / 2, new MyCueId[] { });
                }

                m_noMusicTimer         = m_random.Next(DEFAULT_NO_MUSIC_TIME_MIN, DEFAULT_NO_MUSIC_TIME_MAX);
                CanChangeCategoryLocal = !playAtLeastOnce;
                m_currentMusicCategory = MusicCategory.location;
            }
        }
Пример #34
0
 public void PlaySpecificMusicTrack(MyCueId cue, bool playAtLeastOnce)
 {
     if (!cue.IsNull)
     {
         if ((this.m_musicSourceVoice == null) || !this.m_musicSourceVoice.IsPlaying)
         {
             this.PlayMusic(cue, m_hashFadeIn, 0x3e8, new MyCueId[0], true);
         }
         else
         {
             MyCueId[] cueIds = new MyCueId[] { cue };
             this.PlayMusic(this.CueIdPlaying, m_hashCrossfade, 0x7d0, cueIds, false);
         }
         this.m_noMusicTimer         = this.m_random.Next(2, 8);
         this.CanChangeCategoryLocal = !playAtLeastOnce;
         this.m_currentMusicCategory = MusicCategory.location;
     }
 }
 public void Init(MyCueId cueId)
 {
     if (!MySandboxGame.IsDedicated)
     {
         if (MySession.Static.Settings.RealisticSound && MyFakes.ENABLE_NEW_SOUNDS)
         {
             m_realistic = cueId;
             m_arcade = new MyCueId(MyStringHash.NullOrEmpty);
         }
         else
         {
             m_arcade = cueId;
             m_realistic = new MyCueId(MyStringHash.NullOrEmpty);
         }
     }
     else
     {
         m_arcade = new MyCueId(MyStringHash.NullOrEmpty);
         m_realistic = new MyCueId(MyStringHash.NullOrEmpty);
     }
 }
Пример #36
0
        private void InitCue(string cueName)
        {
            if (string.IsNullOrEmpty(cueName))
            {
                CueId = new MyCueId(MyStringHash.NullOrEmpty);
            }
            else
            {
                var cueId = new MyCueId(MyStringHash.GetOrCompute(cueName));
                MySoundCategoryDefinition.SoundDescription soundDesc = null;
                var soundCategories = MyDefinitionManager.Static.GetSoundCategoryDefinitions();

                // check whether saved cue is in some category
                foreach (var category in soundCategories)
                {
                    foreach (var soundDescTmp in category.Sounds)
                    {
                        if (MySoundPair.GetCueId(soundDescTmp.SoundId) == cueId)
                            soundDesc = soundDescTmp;
                    }     
                }

                if (soundDesc != null)
                    SelectSound(cueId, false);
                else
                    CueId = new MyCueId(MyStringHash.NullOrEmpty);
            }
        }
		public void StartSecondarySound(MyCueId cueId, bool sync = false)
		{
			if (cueId.IsNull) return;

			m_soundEmitters[(int)MySoundEmitterEnum.SecondaryState].PlaySoundWithDistance(cueId);            

			if (sync)
			{
				m_character.PlaySecondarySound(cueId);
			}
		}
Пример #38
0
 IMyAudioEffect IMyAudio.ApplyEffect(IMySourceVoice input, MyStringHash effect, MyCueId[] cueIds, float? duration) { return null; }
        private void PlaySound(MyCueId sound)
        {
            if (m_sound == null || !m_sound.IsPlaying)
            {
                m_sound = MyAudio.Static.PlaySound(sound);
                if (!sound.IsNull)
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeIn, null);
                if (m_effect != null)
                    m_sound = m_effect.OutputSound;
            }
            else if (m_effect != null && m_effect.Finished && sound.IsNull)
                m_sound.Stop(true);
            else if (m_sound.CueEnum != sound)
            {
                if (m_effect != null && !m_effect.Finished)
                {
                    //m_effect.SetPositionRelative(1f);
                    m_effect.AutoUpdate = true;
                }
                if (sound.IsNull)
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeOut, null, 5000f);
                else
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_crossFade, new MyCueId[] { sound }, 5000f);

                if (m_effect != null && !m_effect.Finished)
                {
                    m_effect.AutoUpdate = true;
                    m_sound = m_effect.OutputSound;
                }
            }
            if (m_sound != null)
            {
                MySoundData data = MyAudio.Static.GetCue(sound);
                m_volumeOriginal = data != null ? data.Volume :1f;
                m_sound.SetVolume(m_volumeOriginal * m_volumeModifier * VolumeModifierGlobal);
            }
        }
Пример #40
0
 public IMySourceVoice PlayMusicCue(MyCueId musicCue, bool overrideMusicAllowed = false)
 {
     if (!m_canPlay || (!m_musicAllowed && !overrideMusicAllowed))
         return null;
     Mute = false;
     m_musicCue = PlaySound(musicCue);
     if (m_musicCue != null)
     {
         m_musicCue.SetOutputVoices(m_musicAudioVoiceDesc);
         m_musicAudioVoice.SetVolume(m_volumeMusic);
     }
     return m_musicCue;
 }
Пример #41
0
        public bool IsLoopable(MyCueId cueId)
        {
            if (cueId.Hash == MyStringHash.NullOrEmpty || m_cueBank == null)
                return false;
            MySoundData cueDefinition = m_cueBank.GetCue(cueId);
            if (cueDefinition == null)
                return false;

            return cueDefinition.Loopable;
        }
Пример #42
0
        internal MySourceVoice PlaySound(MyCueId cueId, IMy3DSoundEmitter source = null, MySoundDimensions type = MySoundDimensions.D2, bool skipIntro = false, bool skipToEnd = false)
        {
			int waveNumber = -1;
			var sound = GetSound(cueId, out waveNumber, source, type);
			if(source != null)
				source.LastPlayedWaveNumber = -1;
			if (sound != null)
			{
                sound.Start(skipIntro, skipToEnd);
				if (source != null)
					source.LastPlayedWaveNumber = waveNumber;
			}
            return sound;
        }
Пример #43
0
 MySoundData IMyAudio.GetCue(MyCueId cueId) { return m_canPlay ? m_cueBank.GetCue(cueId) : null; }
Пример #44
0
 bool IMyAudio.IsLoopable(MyCueId cueId) { return false; }
		public void StartSecondarySound(MyCueId cueId, bool sync = false)
		{
			if (cueId.IsNull) return;

			if (!m_soundEmitters[(int)MySoundEmitterEnum.SecondaryState].IsPlaying)
			{
				m_soundEmitters[(int)MySoundEmitterEnum.SecondaryState].PlaySound(cueId);
			}

			if (sync)
			{
				m_character.SyncObject.PlaySecondarySound(cueId);
			}
		}
Пример #46
0
 IMySourceVoice IMyAudio.GetSound(MyCueId cue, IMy3DSoundEmitter source, MySoundDimensions type) { return null; }
Пример #47
0
        public void SelectSound(MyCueId cueId, bool sync)
        {
            if (sync)
            {
                SyncObject.SendSelectSoundRequest(cueId);
            }
            else
            {
                CueId = cueId;

                if (!MySandboxGame.IsDedicated)
                {
                    m_soundPair.Init(cueId);
                    var soundData = MyAudio.Static.GetCue(cueId);
                    if (soundData != null)
                        IsLoopable = soundData.Loopable;
                }

                RaisePropertiesChanged();
            }
        }
Пример #48
0
 IMySourceVoice IMyAudio.PlaySound(MyCueId cueId, IMy3DSoundEmitter source, MySoundDimensions type, bool skipIntro, bool skipToEnd)
 {
     return PlaySound(cueId, source, type, skipIntro, skipToEnd);
 }
Пример #49
0
 private bool IsSameLoopCue(MyCueId newCue)
 {
     return newCue == m_soundEmitters[m_soundEmitterIndex].SoundId;
 }
Пример #50
0
 public void AddMusicCue(MyStringId category, MyCueId cueId)
 {
     if (m_musicCuesAll.ContainsKey(category) == false)
         m_musicCuesAll.Add(category, new List<MyCueId>());
     m_musicCuesAll[category].Add(cueId);
 }
Пример #51
0
        public bool SourceIsCloseEnoughToPlaySound(Vector3 sourcePosition, MyCueId cueId, float? customMaxDistance = 0)
        {
            if (m_cueBank == null || cueId.Hash == MyStringHash.NullOrEmpty)
                return false;

            MySoundData cueDefinition = m_cueBank.GetCue(cueId);
            if (cueDefinition == null)
                return false;

            float distanceToSound = Vector3.DistanceSquared(new Vector3(m_listener.Position.X, m_listener.Position.Y, m_listener.Position.Z), sourcePosition);

            if (customMaxDistance > 0)
                return (distanceToSound <= customMaxDistance * customMaxDistance);
            else if (cueDefinition.UpdateDistance > 0)
                return (distanceToSound <= cueDefinition.UpdateDistance * cueDefinition.UpdateDistance);
            else
                return (distanceToSound <= cueDefinition.MaxDistance * cueDefinition.MaxDistance);
        }
Пример #52
0
 MySoundData IMyAudio.GetCue(MyCueId cue) { return null; }
Пример #53
0
        internal MySourceVoice GetSound(MyCueId cueId, out int waveNumber, IMy3DSoundEmitter source = null, MySoundDimensions type = MySoundDimensions.D2)
        {
			waveNumber = -1;
            //  If this computer can't play sound, we don't create cues
            if (cueId.Hash == MyStringHash.NullOrEmpty || !m_canPlay || m_cueBank == null)
                return null;

            //  If this is one-time cue, we check if it is close enough to hear it and if not, we don't even play - this is for optimization only.
            //  We must add loopable cues always, because if source of cue comes near the camera, we need to update the position, but of course we can do that only if we have reference to it.
            MySoundData cue = m_cueBank.GetCue(cueId);

            if ((SoloCue != null) && (SoloCue != cue))
                return null;

			int waveNumberToIgnore = (source != null ? source.LastPlayedWaveNumber : -1);
			var sound = m_cueBank.GetVoice(cueId, out waveNumber, type, waveNumberToIgnore);
            var originalType = type;
            if (sound == null && source != null && source.Force3D)
            {
                originalType = type == MySoundDimensions.D3 ? MySoundDimensions.D2 : MySoundDimensions.D3;
                sound = m_cueBank.GetVoice(cueId, out waveNumber, originalType, waveNumberToIgnore);
            }
            if (sound == null)
                return null;

            float volume = cue.Volume;
            if (source != null && source.CustomVolume.HasValue)
                volume = source.CustomVolume.Value;
            if (cue.VolumeVariation != 0f)
            {
                float variation = VolumeVariation(cue);
                volume = MathHelper.Clamp(volume + variation, 0f, 1f);
            }       
            sound.SetVolume(volume);
            var wave = m_cueBank.GetWave(m_sounds.ItemAt(0), MySoundDimensions.D2, 0, MyCueBank.CuePart.Start);

            float semitones = cue.Pitch;
            if (cue.PitchVariation != 0f)
                semitones += PitchVariation(cue);
            if (cue.DisablePitchEffects)
                semitones = 0f;
            if(semitones != 0f)
                sound.FrequencyRatio = SemitonesToFrequencyRatio(semitones);
            else
                sound.FrequencyRatio = 1f;

            if (cue.IsHudCue)
                sound.Voice.SetOutputVoices(m_hudAudioVoiceDesc);
            else
                sound.Voice.SetOutputVoices(m_gameAudioVoiceDesc);

            if (type == MySoundDimensions.D3)
            {
                m_helperEmitter.UpdateValuesOmni(source.SourcePosition, source.Velocity, cue, m_deviceDetails.OutputFormat.Channels, source.CustomMaxDistance);
                float maxDistance = source.CustomMaxDistance.HasValue ? source.CustomMaxDistance.Value : cue.MaxDistance;

                source.SourceChannels = 1;
                if (originalType == MySoundDimensions.D2)
                    source.SourceChannels = 2;
                sound.distanceToListener = m_x3dAudio.Apply3D(sound.Voice, m_listener, m_helperEmitter, source.SourceChannels, m_deviceDetails.OutputFormat.Channels, m_calculateFlags, maxDistance, sound.FrequencyRatio, sound.Silent, source.Realistic);

                Update3DCuesState();

                // why was this only for loops?
                //if (sound.IsLoopable)
                Add3DCueToUpdateList(source);

                ++m_soundInstancesTotal3D;
            }
            else
            {
                if (m_3Dsounds.Contains(source))
                    StopUpdating3DCue(source);
                ++m_soundInstancesTotal2D;
            }
            return sound;
        }
Пример #54
0
 void cuesCombo_OnSelect()
 {
     m_currentCueSelectedItem = (int)m_cuesCombo.GetSelectedKey();
     var cue = new MyCueId(MyStringHash.TryGet(m_cuesCombo.GetSelectedValue().ToString()));
     m_currentCue = MyAudio.Static.GetCue(cue);
    
     UpdateCueValues();
     //RecreateControls(false);
 }
Пример #55
0
        IMySourceVoice IMyAudio.GetSound(MyCueId cueId, IMy3DSoundEmitter source, MySoundDimensions type)
        {
			int waveNumber;
            return GetSound(cueId, out waveNumber, source, type);
        }
Пример #56
0
 void OnPlaySelected(MyGuiControlButton button)
 {
     if ((m_sound != null) && (m_sound.IsPlaying))
         m_sound.Stop(true);
     var cue = new MyCueId(MyStringHash.TryGet(m_cuesCombo.GetSelectedValue().ToString()));
     m_sound = MyAudio.Static.PlaySound(cue);
     var effect = MyStringHash.TryGet(m_effects.GetSelectedValue().ToString());
     if(effect != MyStringHash.NullOrEmpty)
     {
         foreach(var box in m_cues)
         {
             var effCue = new MyCueId(MyStringHash.TryGet(box.GetSelectedValue().ToString()));
             m_cueCache.Add(effCue);
         }
         var eff = MyAudio.Static.ApplyEffect(m_sound, effect, m_cueCache.ToArray());
         m_sound = eff.OutputSound;
         m_cueCache.Clear();
     }
 }
Пример #57
0
        public IMyAudioEffect ApplyEffect(IMySourceVoice input, MyStringHash effect, MyCueId[] cueIds = null, float? duration = null, bool musicEffect = false)
        {
            if (m_effectBank == null)
                return null;
			int waveNumber;
            List<MySourceVoice> voices = new List<MySourceVoice>();
            if (cueIds != null)
            {
                foreach (var cueId in cueIds)
                {
                    var sound = GetSound(cueId, out waveNumber);
                    System.Diagnostics.Debug.Assert(sound != null, "Missing sound " + cueId);
                    if (sound != null)
                        voices.Add(sound);
                }
            }
            IMyAudioEffect result = m_effectBank.CreateEffect(input, effect, voices.ToArray(), duration);
            if (musicEffect && result.OutputSound is MySourceVoice)
                (result.OutputSound as MySourceVoice).SetOutputVoices(m_musicAudioVoiceDesc);
            return result;
        }
Пример #58
0
 bool IMyAudio.SourceIsCloseEnoughToPlaySound(Vector3 position, MyCueId cueId, float? customMaxDistance) { return false; }
Пример #59
0
 private void PlayMusic(MyCueId cue, MyStringHash effect, int effectDuration = 2000, MyCueId[] cueIds = null, bool play = true)
 {
     if (MyAudio.Static == null)
         return;
     if(play)
         m_musicSourceVoice = MyAudio.Static.PlayMusicCue(cue, true);
     if (m_musicSourceVoice != null)
     {
         if (effect != MyStringHash.NullOrEmpty)
         {
             m_musicSourceVoice = MyAudio.Static.ApplyEffect(m_musicSourceVoice, effect, cueIds, effectDuration, true).OutputSound;
         }
         if (m_musicSourceVoice != null)
             m_musicSourceVoice.StoppedPlaying += MusicStopped;
     }
     m_lastMusicData = MyAudio.Static.GetCue(cue);
 }
 public void SelectSound(MyCueId cueId, bool sync)
 {
     CueId = cueId;
 }