public void SampleOneShotManagerUpdate() { for (int i = 0; i < samples.Count; i++) { samples[i].Update(); } cleanupList.Clear(); for (int j = 0; j < samples.Count; j++) { SampleOneShot sampleOneShot = samples[j]; if (sampleOneShot.source == null || (!sampleOneShot.source.isPlaying && (!sampleOneShot.subDef.tempoAffectedByGameSpeed || !Find.TickManager.Paused)) || !SoundDefHelper.CorrectContextNow(sampleOneShot.subDef.parentDef, sampleOneShot.Map)) { if (sampleOneShot.source != null && sampleOneShot.source.isPlaying) { sampleOneShot.source.Stop(); } sampleOneShot.SampleCleanup(); cleanupList.Add(sampleOneShot); } } if (cleanupList.Count > 0) { samples.RemoveAll((SampleOneShot s) => cleanupList.Contains(s)); } }
public void SampleOneShotManagerUpdate() { for (int i = 0; i < this.samples.Count; i++) { this.samples[i].Update(); } this.cleanupList.Clear(); for (int j = 0; j < this.samples.Count; j++) { SampleOneShot sampleOneShot = this.samples[j]; if (sampleOneShot.source == null || !sampleOneShot.source.isPlaying || !SoundDefHelper.CorrectContextNow(sampleOneShot.subDef.parentDef, sampleOneShot.Map)) { if (sampleOneShot.source != null && sampleOneShot.source.isPlaying) { sampleOneShot.source.Stop(); } sampleOneShot.SampleCleanup(); this.cleanupList.Add(sampleOneShot); } } if (this.cleanupList.Count > 0) { this.samples.RemoveAll((SampleOneShot s) => this.cleanupList.Contains(s)); } }
public static SampleOneShot TryMakeAndPlay(SubSoundDef def, AudioClip clip, SoundInfo info) { SampleOneShot result; if ((double)info.pitchFactor <= 0.0001) { Log.ErrorOnce(string.Concat(new object[] { "Played sound with pitchFactor ", info.pitchFactor, ": ", def, ", ", info }), 632321, false); result = null; } else { SampleOneShot sampleOneShot = new SampleOneShot(def); sampleOneShot.info = info; sampleOneShot.source = Find.SoundRoot.sourcePool.GetSource(def.onCamera); if (sampleOneShot.source == null) { result = null; } else { sampleOneShot.source.clip = clip; sampleOneShot.source.volume = sampleOneShot.SanitizedVolume; sampleOneShot.source.pitch = sampleOneShot.SanitizedPitch; sampleOneShot.source.minDistance = sampleOneShot.subDef.distRange.TrueMin; sampleOneShot.source.maxDistance = sampleOneShot.subDef.distRange.TrueMax; if (!def.onCamera) { sampleOneShot.source.gameObject.transform.position = info.Maker.Cell.ToVector3ShiftedWithAltitude(0f); sampleOneShot.source.minDistance = def.distRange.TrueMin; sampleOneShot.source.maxDistance = def.distRange.TrueMax; sampleOneShot.source.spatialBlend = 1f; } else { sampleOneShot.source.spatialBlend = 0f; } for (int i = 0; i < def.filters.Count; i++) { def.filters[i].SetupOn(sampleOneShot.source); } foreach (KeyValuePair <string, float> keyValuePair in info.DefinedParameters) { sampleOneShot.externalParams[keyValuePair.Key] = keyValuePair.Value; } sampleOneShot.Update(); sampleOneShot.source.Play(); Find.SoundRoot.oneShotManager.TryAddPlayingOneShot(sampleOneShot); result = sampleOneShot; } } return(result); }
public void TryAddPlayingOneShot(SampleOneShot newSample) { if (samples.Where((SampleOneShot s) => s.subDef == newSample.subDef).Count() >= newSample.subDef.parentDef.maxVoices) { SampleOneShot sampleOneShot = LeastImportantOf(newSample.subDef.parentDef); sampleOneShot.source.Stop(); samples.Remove(sampleOneShot); } samples.Add(newSample); }
public void TryAddPlayingOneShot(SampleOneShot newSample) { int num = (from s in this.samples where s.subDef == newSample.subDef select s).Count <SampleOneShot>(); if (num >= newSample.subDef.parentDef.maxVoices) { SampleOneShot sampleOneShot = this.LeastImportantOf(newSample.subDef.parentDef); sampleOneShot.source.Stop(); this.samples.Remove(sampleOneShot); } this.samples.Add(newSample); }
private SampleOneShot LeastImportantOf(SoundDef def) { SampleOneShot sampleOneShot = null; for (int i = 0; i < samples.Count; i++) { SampleOneShot sampleOneShot2 = samples[i]; if (sampleOneShot2.subDef.parentDef == def && (sampleOneShot == null || ImportanceOf(sampleOneShot2) < ImportanceOf(sampleOneShot))) { sampleOneShot = sampleOneShot2; } } return(sampleOneShot); }
public virtual void TryPlay(SoundInfo info) { if (this.resolvedGrains.Count == 0) { Log.Error(string.Concat(new object[] { "Cannot play ", this.parentDef, " (subSound ", this, "_: No resolved grains." }), false); return; } if (!Find.SoundRoot.oneShotManager.CanAddPlayingOneShot(this.parentDef, info)) { return; } ResolvedGrain resolvedGrain = this.RandomizedResolvedGrain(); ResolvedGrain_Clip resolvedGrain_Clip = resolvedGrain as ResolvedGrain_Clip; if (resolvedGrain_Clip != null) { if (SampleOneShot.TryMakeAndPlay(this, resolvedGrain_Clip.clip, info) == null) { return; } SoundSlotManager.Notify_Played(this.parentDef.slot, resolvedGrain_Clip.clip.length); } if (this.distinctResolvedGrainsCount > 1) { if (this.repeatMode == RepeatSelectMode.NeverLastHalf) { while (this.recentlyPlayedResolvedGrains.Count >= this.numToAvoid) { this.recentlyPlayedResolvedGrains.Dequeue(); } if (this.recentlyPlayedResolvedGrains.Count < this.numToAvoid) { this.recentlyPlayedResolvedGrains.Enqueue(resolvedGrain); } } else if (this.repeatMode == RepeatSelectMode.NeverTwice) { this.lastPlayedResolvedGrain = resolvedGrain; } } }
public bool CanAddPlayingOneShot(SoundDef def, SoundInfo info) { if (!SoundDefHelper.CorrectContextNow(def, info.Maker.Map)) { return(false); } if ((from s in this.samples where s.subDef.parentDef == def && s.AgeRealTime < 0.05f select s).Count <SampleOneShot>() >= def.MaxSimultaneousSamples) { return(false); } SampleOneShot sampleOneShot = this.LeastImportantOf(def); return(sampleOneShot == null || this.ImportanceOf(def, info, 0f) >= this.ImportanceOf(sampleOneShot)); }
public virtual void TryPlay(SoundInfo info) { ResolvedGrain resolvedGrain; if (this.resolvedGrains.Count == 0) { Log.Error("Cannot play " + this.parentDef + " (subSound " + this + "_: No resolved grains."); } else if (Find.SoundRoot.oneShotManager.CanAddPlayingOneShot(this.parentDef, info)) { resolvedGrain = this.RandomizedResolvedGrain(); ResolvedGrain_Clip resolvedGrain_Clip = resolvedGrain as ResolvedGrain_Clip; if (resolvedGrain_Clip != null) { SampleOneShot sampleOneShot = SampleOneShot.TryMakeAndPlay(this, resolvedGrain_Clip.clip, info); if (sampleOneShot != null) { SoundSlotManager.Notify_Played(this.parentDef.slot, resolvedGrain_Clip.clip.length); goto IL_00a6; } return; } goto IL_00a6; } return; IL_00a6: if (this.distinctResolvedGrainsCount > 1) { if (this.repeatMode == RepeatSelectMode.NeverLastHalf) { while (this.recentlyPlayedResolvedGrains.Count >= this.numToAvoid) { this.recentlyPlayedResolvedGrains.Dequeue(); } if (this.recentlyPlayedResolvedGrains.Count < this.numToAvoid) { this.recentlyPlayedResolvedGrains.Enqueue(resolvedGrain); } } else if (this.repeatMode == RepeatSelectMode.NeverTwice) { this.lastPlayedResolvedGrain = resolvedGrain; } } }
public bool CanAddPlayingOneShot(SoundDef def, SoundInfo info) { if (!SoundDefHelper.CorrectContextNow(def, info.Maker.Map)) { return(false); } if (samples.Where((SampleOneShot s) => s.subDef.parentDef == def && s.AgeRealTime < 0.05f).Count() >= def.MaxSimultaneousSamples) { return(false); } SampleOneShot sampleOneShot = LeastImportantOf(def); if (sampleOneShot != null && ImportanceOf(def, info, 0f) < ImportanceOf(sampleOneShot)) { return(false); } return(true); }
public virtual void TryPlay(SoundInfo info) { if (resolvedGrains.Count == 0) { //Log.Error("Cannot play " + parentDef + " (subSound " + this + "_: No resolved grains."); //Log.Message("Cannot play " + parentDef + " (subSound " + this + "_: No resolved grains."); } else { if (!Find.SoundRoot.oneShotManager.CanAddPlayingOneShot(parentDef, info) || (Current.Game != null && !gameSpeedRange.Includes((int)Find.TickManager.CurTimeSpeed))) { return; } ResolvedGrain resolvedGrain = RandomizedResolvedGrain(); ResolvedGrain_Clip resolvedGrain_Clip = resolvedGrain as ResolvedGrain_Clip; if (resolvedGrain_Clip != null) { if (SampleOneShot.TryMakeAndPlay(this, resolvedGrain_Clip.clip, info) == null) { return; } SoundSlotManager.Notify_Played(parentDef.slot, resolvedGrain_Clip.clip.length); } if (distinctResolvedGrainsCount <= 1) { return; } if (repeatMode == RepeatSelectMode.NeverLastHalf) { while (recentlyPlayedResolvedGrains.Count >= numToAvoid) { recentlyPlayedResolvedGrains.Dequeue(); } if (recentlyPlayedResolvedGrains.Count < numToAvoid) { recentlyPlayedResolvedGrains.Enqueue(resolvedGrain); } } else if (repeatMode == RepeatSelectMode.NeverTwice) { lastPlayedResolvedGrain = resolvedGrain; } } }
private float ImportanceOf(SampleOneShot sample) { return(this.ImportanceOf(sample.subDef.parentDef, sample.info, sample.AgeRealTime)); }
internal bool <> m__0(SampleOneShot s) { return(s.subDef.parentDef == this.def && s.AgeRealTime < 0.05f); }
private bool <SampleOneShotManagerUpdate> m__0(SampleOneShot s) { return(this.cleanupList.Contains(s)); }