Fix ambient audio assert (#12938)

This commit is contained in:
Leon Friedrich
2022-12-09 14:16:39 +13:00
committed by GitHub
parent 92a62ac5c1
commit 75ab0a1127

View File

@@ -1,18 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.Player; using Robust.Client.Player;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using System.Linq;
namespace Content.Client.Audio namespace Content.Client.Audio
{ {
@@ -167,12 +163,13 @@ namespace Content.Client.Audio
private void ClearSounds() private void ClearSounds()
{ {
foreach (var (_, (stream, _)) in _playingSounds) foreach (var (stream, _) in _playingSounds.Values)
{ {
stream?.Stop(); stream?.Stop();
} }
_playingSounds.Clear(); _playingSounds.Clear();
_playingCount.Clear();
} }
private Dictionary<string, List<(float Importance, AmbientSoundComponent)>> GetNearbySources(TransformComponent playerXform, MapCoordinates coords, EntityQuery<TransformComponent> xformQuery) private Dictionary<string, List<(float Importance, AmbientSoundComponent)>> GetNearbySources(TransformComponent playerXform, MapCoordinates coords, EntityQuery<TransformComponent> xformQuery)
@@ -266,15 +263,18 @@ namespace Content.Client.Audio
.WithMaxDistance(comp.Range); .WithMaxDistance(comp.Range);
var stream = _audio.PlayPvs(comp.Sound, comp.Owner, audioParams); var stream = _audio.PlayPvs(comp.Sound, comp.Owner, audioParams);
if (stream != null) if (stream == null)
_playingSounds[comp] = (stream, key); continue;
_playingSounds[comp] = (stream, key);
playingCount++; playingCount++;
if (_playingSounds.Count >= _maxAmbientCount) if (_playingSounds.Count >= _maxAmbientCount)
break; break;
} }
_playingCount[key] = playingCount; if (playingCount != 0)
_playingCount[key] = playingCount;
} }
DebugTools.Assert(_playingCount.All(x => x.Value == PlayingCount(x.Key))); DebugTools.Assert(_playingCount.All(x => x.Value == PlayingCount(x.Key)));