示例#1
0
        private void TestAddRemoveListenerImpl(Game game)
        {
            var audio = game.Audio;
            var notAddedToEntityListener = new AudioListenerComponent();
            var addedToEntityListener    = new AudioListenerComponent();

            // Add a listenerComponent not present in the entity system yet and check that it is correctly added to the AudioSystem internal data structures
            Assert.DoesNotThrow(() => audio.AddListener(notAddedToEntityListener), "Adding a listener not present in the entity system failed");
            Assert.IsTrue(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem does not contains the notAddedToEntityListener.");

            // Add a listenerComponent already present in the entity system and check that it is correctly added to the AudioSystem internal data structures
            var entity = new Entity("Test");

            entity.Add(addedToEntityListener);
            throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer");
            //game.Entities.Add(entity);
            Assert.DoesNotThrow(() => audio.AddListener(addedToEntityListener), "Adding a listener present in the entity system failed");
            Assert.IsTrue(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem does not contains the addedToEntityListener.");

            // Add a listenerComponent already added to audio System and check that it does not crash
            Assert.DoesNotThrow(() => audio.AddListener(addedToEntityListener), "Adding a listener already added to the audio system failed.");

            // Remove the listeners from the AudioSystem and check that they are removed from internal data structures.
            Assert.DoesNotThrow(() => audio.RemoveListener(notAddedToEntityListener), "Removing an listener not present in the entity system failed.");
            Assert.IsFalse(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem still contains the notAddedToEntityListener.");
            Assert.DoesNotThrow(() => audio.RemoveListener(addedToEntityListener), "Removing an listener present in the entity system fails");
            Assert.IsFalse(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem still contains the addedToEntityListener.");

            // Remove a listener not present in the AudioSystem anymore and check the thrown exception
            Assert.Throws <ArgumentException>(() => audio.RemoveListener(addedToEntityListener), "Removing the a non-existing listener did not throw ArgumentException.");
        }
        internal void DestroySoundInstances(AudioListenerComponent listener)
        {
            var deferRemoval = new List <SoundInstance>();

            foreach (var instance in InstanceToListener.Keys)
            {
                deferRemoval.Add(instance);
            }

            foreach (var soundInstance in deferRemoval)
            {
                DestroySoundInstance(soundInstance);
            }

            for (var i = 0; i < FastInstances.Count; i++)
            {
                var instance = FastInstances[i];
                if (instance.Listener == listener.Listener)
                {
                    //Decrement the loop counter to iterate this index again, since later elements will get moved down during the remove operation.
                    FastInstances.RemoveAt(i--);
                    instance.Dispose();
                }
            }
        }
示例#3
0
 /// <summary>
 /// Add and activate a <see cref="AudioListenerComponent" /> to the Audio System.
 /// After this call sounds played via <see cref="AudioEmitterSoundController" />s will be heard by this listener.
 /// </summary>
 /// <param name="listener">The listener to add to the audio system.</param>
 /// <remarks>Adding a listener already added as no effects.</remarks>
 public void AddListener(AudioListenerComponent listener)
 {
     if (!Listeners.ContainsKey(listener))
     {
         Listeners[listener] = null;
     }
 }
示例#4
0
        public override Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent)
        {
            var name      = ComputeNewName(parent, "AudioListener");
            var component = new AudioListenerComponent();

            return(CreateEntityWithComponent(name, component));
        }
 internal void DestroySoundInstances(AudioListenerComponent listener)
 {
     foreach (var instance in listener.AttachedInstances)
     {
         instance.Dispose();
         InstanceToListener.Remove(instance);
     }
 }
示例#6
0
        private void CreateAndComponentToEntities()
        {
            listComp1 = new AudioListenerComponent();
            listComp2 = new AudioListenerComponent();

            listComp1Entity.Add(listComp1);
            listComp2Entity.Add(listComp2);
        }
示例#7
0
        /// <summary>
        /// Remove a <see cref="AudioListenerComponent" /> from the Audio System.
        /// After this call sounds played via <see cref="AudioEmitterSoundController" />s will not be heard by this listener anymore.
        /// </summary>
        /// <param name="listener">The listener to remove from the audio system.</param>
        /// <exception cref="System.ArgumentException">The provided listener was not present in the Audio System.</exception>
        public void RemoveListener(AudioListenerComponent listener)
        {
            if (!Listeners.ContainsKey(listener))
            {
                throw new ArgumentException("The provided listener was not present in the Audio System.");
            }

            Listeners.Remove(listener);
        }
        /// <summary>
        /// Create an new instance of underlying sound, and register it in the controller's sound instance list.
        /// </summary>
        /// <returns>The new sound effect instance created</returns>
        internal SoundInstance CreateSoundInstance(AudioListenerComponent listener)
        {
            var newInstance = sound.CreateInstance(listener.Listener);

            InstanceToListener.Add(newInstance, listener);

            listener.AttachedInstances.Add(newInstance);

            return(newInstance);
        }
        /// <summary>
        /// Create an new instance of underlying sound, and register it in the controller's sound instance list.
        /// </summary>
        /// <returns>The new sound effect instance created</returns>
        internal SoundInstance CreateSoundInstance(AudioListenerComponent listener, bool forget)
        {
            var newInstance = sound.CreateInstance(listener.Listener, emitter.UseHRTF, emitter.DirectionalFactor, emitter.Environment);

            if (!forget)
            {
                InstanceToListener.Add(newInstance, listener);
            }

            return(newInstance);
        }
示例#10
0
        /// <summary>
        /// Create an new instance of underlying sound, and register it in the controller's sound instance list.
        /// </summary>
        /// <returns>The new sound effect instance created</returns>
        internal SoundInstance CreateSoundInstance(AudioListenerComponent listener, bool forget)
        {
            var newInstance = sound.CreateInstance(listener.Listener);

            if (!forget)
            {
                InstanceToListener.Add(newInstance, listener);
            }

            return(newInstance);
        }
示例#11
0
        internal void DestroySoundInstances(AudioListenerComponent listener)
        {
            foreach (var instance in InstanceToListener.Keys)
            {
                instance.Dispose();
                listener.AttachedInstances.Remove(instance);
            }
            InstanceToListener.Clear();

            for (var i = 0; i < FastInstances.Count; i++)
            {
                var instance = FastInstances[i];
                if (instance.Listener == listener.Listener)
                {
                    //Decrement the loop counter to iterate this index again, since later elements will get moved down during the remove operation.
                    FastInstances.RemoveAt(i--);
                    DestroySoundInstance(instance);
                }
            }
        }
示例#12
0
        private void TestPlayStateSetup(Game game)
        {
            BuildEntityHierarchy();
            CreateAndAddListenerComponentToEntities();
            CreateAndAddEmitterComponentToEntities();
            AddSoundEffectToEmitterComponents(game);
            AddRootEntityToEntitySystem(game);

            // add an extra listener.
            var extraList       = new AudioListenerComponent();
            var extraListEntity = new Entity();

            extraListEntity.Add(extraList);
            Internal.Refactor.ThrowNotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer");
            //game.Entities.Add(extraListEntity);

            // check that PlayState always returns 'PlayState.Stopped' when there are no listeners
            mainController.Play();
            Assert.True(PlayState.Stopped == mainController.PlayState, "Value of playState without listeners is not valid after call to play.");
            mainController.Pause();
            Assert.True(PlayState.Stopped == mainController.PlayState, "Value of playState without listeners is not valid after call to Pause.");
            mainController.Stop();
            Assert.True(PlayState.Stopped == mainController.PlayState, "Value of playState without listeners is not valid after call to Stop.");

            // check values with listeners

            AddListenersToAudioSystem(game);

            mainController.Play();
            Assert.True(PlayState.Playing == mainController.PlayState, "Value of playState with listeners is not valid after call to play.");
            mainController.Pause();
            Assert.True(PlayState.Paused == mainController.PlayState, "Value of playState with listeners is not valid after call to Pause.");
            mainController.Stop();
            Assert.True(PlayState.Stopped == mainController.PlayState, "Value of playState with listeners is not valid after call to Stop.");
            mainController.Play();
            Assert.True(PlayState.Playing == mainController.PlayState, "Value of playState with listeners is not valid after a second call to play.");
            mainController.Pause();
            Assert.True(PlayState.Paused == mainController.PlayState, "Value of playState with listeners is not valid after a second call to Pause.");
            mainController.Play();
            Assert.True(PlayState.Playing == mainController.PlayState, "Value of playState with listeners is not valid after a third call to play.");
        }
示例#13
0
        private void TestPlayStateSetup(Game game)
        {
            BuildEntityHierarchy();
            CreateAndAddListenerComponentToEntities();
            CreateAndAddEmitterComponentToEntities();
            AddSoundEffectToEmitterComponents(game);
            AddRootEntityToEntitySystem(game);

            // add an extra listener.
            var extraList       = new AudioListenerComponent();
            var extraListEntity = new Entity();

            extraListEntity.Add(extraList);
            game.Entities.Add(extraListEntity);

            // check that PlayState always returns 'SoundPlayState.Stopped' when there are no listeners
            mainController.Play();
            Assert.AreEqual(SoundPlayState.Stopped, mainController.PlayState, "Value of playState without listeners is not valid after call to play.");
            mainController.Pause();
            Assert.AreEqual(SoundPlayState.Stopped, mainController.PlayState, "Value of playState without listeners is not valid after call to Pause.");
            mainController.Stop();
            Assert.AreEqual(SoundPlayState.Stopped, mainController.PlayState, "Value of playState without listeners is not valid after call to Stop.");

            // check values with listeners

            AddListenersToAudioSystem(game);

            mainController.Play();
            Assert.AreEqual(SoundPlayState.Playing, mainController.PlayState, "Value of playState with listeners is not valid after call to play.");
            mainController.Pause();
            Assert.AreEqual(SoundPlayState.Paused, mainController.PlayState, "Value of playState with listeners is not valid after call to Pause.");
            mainController.Stop();
            Assert.AreEqual(SoundPlayState.Stopped, mainController.PlayState, "Value of playState with listeners is not valid after call to Stop.");
            mainController.Play();
            Assert.AreEqual(SoundPlayState.Playing, mainController.PlayState, "Value of playState with listeners is not valid after a second call to play.");
            mainController.Pause();
            Assert.AreEqual(SoundPlayState.Paused, mainController.PlayState, "Value of playState with listeners is not valid after a second call to Pause.");
            mainController.Play();
            Assert.AreEqual(SoundPlayState.Playing, mainController.PlayState, "Value of playState with listeners is not valid after a third call to play.");
        }