5 using System.Collections.Generic;
6 using System.Collections.Specialized;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Collections;
10 using SiliconStudio.Core.Mathematics;
12 using SiliconStudio.Paradox.EntityModel;
13 using SiliconStudio.Paradox.Audio;
14 using SiliconStudio.Paradox.Games;
16 namespace SiliconStudio.
Paradox.Engine
38 internal Dictionary<Entity, AssociatedData> MatchingEntitiesForDebug {
get {
return matchingEntities; } }
44 : base(new
PropertyKey[] { AudioListenerComponent.Key, TransformationComponent.Key })
56 protected internal override void OnSystemAdd()
62 audioSystem.Listeners.CollectionChanged += OnListenerCollectionChanged;
65 protected internal override void OnSystemRemove()
67 base.OnSystemRemove();
69 audioSystem.Listeners.CollectionChanged -= OnListenerCollectionChanged;
72 foreach (var audioListenerComp
in audioSystem.Listeners.Keys)
73 audioSystem.Listeners[audioListenerComp] = null;
78 base.OnEntityAdding(entity, data);
83 InitializeAudioEmitter(data);
84 data.ShouldBeComputed =
true;
88 private void InitializeAudioEmitter(AssociatedData data)
91 data.TransformationComponent.UpdateWorldMatrix();
92 data.AudioListener =
new AudioListener { Position = data.TransformationComponent.WorldMatrix.TranslationVector };
94 if (!audioSystem.Listeners.ContainsKey(data.ListenerComponent))
95 throw new AudioEngineInternalExceptions(
"Initialized AudioListenerComponent was not in AudioSystem.ListenerList");
98 audioSystem.Listeners[data.ListenerComponent] = data.AudioListener;
103 base.OnEntityRemoved(entity, data);
108 audioSystem.Listeners[data.ListenerComponent] = null;
116 foreach (var listenerData
in matchingEntities.Values)
118 if(!listenerData.ShouldBeComputed)
121 var worldMatrix = listenerData.TransformationComponent.WorldMatrix;
122 var listener = listenerData.AudioListener;
123 var newPosition = worldMatrix.TranslationVector;
125 listener.Velocity = newPosition - listener.Position;
126 listener.Position = newPosition;
127 listener.Forward = Vector3.Normalize((
Vector3)worldMatrix.Row3);
128 listener.Up = Vector3.Normalize((
Vector3)worldMatrix.Row2);
144 var listenersData = matchingEntities.Values.Where(x => x.ListenerComponent == args.Key);
146 if (args.
Action == NotifyCollectionChangedAction.Add)
148 foreach (var listenerData
in listenersData)
150 InitializeAudioEmitter(listenerData);
151 listenerData.ShouldBeComputed =
true;
154 else if(args.
Action == NotifyCollectionChangedAction.Remove)
156 foreach (var listenerData
in listenersData)
157 listenerData.ShouldBeComputed =
false;
Represents a 3D audio listener in the audio scene. This object, used in combination with an AudioEmit...
override void OnEntityAdding(Entity entity, AssociatedData data)
AudioListenerComponent ListenerComponent
The AudioListenerComponent associated to the entity.
Game entity. It usually aggregates multiple EntityComponent
bool ShouldBeComputed
Boolean indicating whether the AudioEmitter need to be updated for the current loop turn or not...
AudioListener AudioListener
The Audio.AudioListener associated to the below AudioListenerComponent.
override AssociatedData GenerateAssociatedData(Entity entity)
Component representing an audio listener.
AudioListenerProcessor()
Create a new instance of AudioListenerProcessor.
override void OnEntityRemoved(Entity entity, AssociatedData data)
Entity processor, triggered on various EntitySystem events such as Entity and Component additions and...
TransformationComponent TransformationComponent
The TransformationComponent associated to the entity.
Current timing used for variable-step (real time) or fixed-step (game time) games.
static PropertyKey< AudioListenerComponent > Key
NotifyCollectionChangedAction Action
Gets the type of action performed. Allowed values are NotifyCollectionChangedAction.Add and NotifyCollectionChangedAction.Remove.
override void Draw(GameTime time)
bool CollectionChanged
Gets a value indicating whether [collection changed (not a replacement but real insertion/removal)].
SiliconStudio.Core.Mathematics.Vector3 Vector3
The Audio System. It creates an underlying instance of AudioEngine.
A class that represents a tag propety.
Processor in charge of creating and updating the AudioListener data associated to the scene AudioList...