Skip to content

Commit

Permalink
check if sounds are deleted (#2010)
Browse files Browse the repository at this point in the history
Co-authored-by: amylizzle <[email protected]>
  • Loading branch information
amylizzle and amylizzle authored Oct 4, 2024
1 parent 6d8131e commit f5850dd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
11 changes: 3 additions & 8 deletions OpenDreamClient/Audio/DreamSoundEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public sealed class DreamSoundEngine : IDreamSoundEngine {
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly INetManager _netManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IAudioManager _audioManager = default!;
private AudioSystem? _audioSystem;

Expand All @@ -29,21 +30,15 @@ public void Initialize() {
_netManager.Disconnect += DisconnectedFromServer;
}

public void StopFinishedChannels() {
for (int i = 0; i < SoundChannelLimit; i++) {
if (_channels[i]?.Source.Component.Playing is false or null)
StopChannel(i + 1);
}
}

public void PlaySound(int channel, MsgSound.FormatType format, ResourceSound sound, float volume) {
if (_audioSystem == null)
_entitySystemManager.Resolve(ref _audioSystem);

if (channel == 0) {
//First available channel
for (int i = 0; i < _channels.Length; i++) {
if (_channels[i] == null) {
//if it's null, deleted, or queued for deletion, it's free
if (_channels[i] == null || _entityManager.Deleted(_channels[i]!.Source.Entity) || _entityManager.IsQueuedForDeletion(_channels[i]!.Source.Entity) ) {
channel = i + 1;
break;
}
Expand Down
1 change: 0 additions & 1 deletion OpenDreamClient/Audio/IDreamSoundEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace OpenDreamClient.Audio;

public interface IDreamSoundEngine {
void Initialize();
public void StopFinishedChannels();
void PlaySound(int channel, MsgSound.FormatType format, ResourceSound sound, float volume);
void StopChannel(int channel);
void StopAllChannels();
Expand Down
1 change: 0 additions & 1 deletion OpenDreamClient/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs)
_dreamInterface.FrameUpdate(frameEventArgs);
break;
case ModUpdateLevel.PostEngine:
_soundEngine.StopFinishedChannels();
break;
}
}
Expand Down

0 comments on commit f5850dd

Please sign in to comment.