/// <summary> /// Adds a single <see cref="SoundSourceBase"/> to the playable sounds. /// </summary> /// <param name="owner">The object to which the sound is attached.</param> /// <param name="source">The sound source to add.</param> public void AddSoundSource(object owner, SoundSourceBase source) { #if DEBUG_SOURCE_SOURCES Trace.TraceInformation("SoundProcess: AddSoundSource on " + Thread.CurrentThread.Name + " by " + owner); #endif // We use lock to thread-safely update the list. Interlocked compare-exchange // is used to interrupt the update. int j; while (ASyncUpdatePending < 1) { j = Interlocked.CompareExchange(ref ASyncUpdatePending, 1, 0); } lock (SoundSources) { if (!SoundSources.ContainsKey(owner)) { SoundSources.Add(owner, new List <SoundSourceBase>()); } SoundSources[owner].Add(source); } while (ASyncUpdatePending > 0) { j = Interlocked.CompareExchange(ref ASyncUpdatePending, 0, 1); } }
/// <summary> /// Returns whether a particular sound source in the playable sounds is owned by a particular <paramref name="owner"/>. /// </summary> /// <param name="owner">The object to which the sound might be owned.</param> /// <param name="source">The sound source to check.</param> /// <returns><see cref="true"/> for a match between <paramref name="owner"/> and <paramref name="source"/>, <see cref="false"/> otherwise.</returns> public bool IsSoundSourceOwnedBy(object owner, SoundSourceBase source) { var soundSources = SoundSources; return(soundSources.ContainsKey(owner) && soundSources[owner].Contains(source)); }