forked from OpenDreamProject/OpenDream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to RT v195.0.1 and .NET 8 (OpenDreamProject#1562)
* Update to RT v194.1.0 and .NET 8 * Update workflows to .NET 8 * Update .NET version in README.md * Some file-scoped namespaces * Reduce allocations in the renderer using a new feature You can pass an existing HashSet to `GetEntitiesIntersecting()` now * Re-add global.json * Update to RT v195.0.1
- Loading branch information
Showing
27 changed files
with
572 additions
and
599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@echo off | ||
if not exist bin\Debug\net7.0\DMStandard mkdir bin\Debug\net7.0\DMStandard | ||
xcopy DMStandard bin\Debug\net7.0\DMStandard /y /s /e | ||
if not exist bin\Release\net7.0\DMStandard mkdir bin\Release\net7.0\DMStandard | ||
xcopy DMStandard bin\Release\net7.0\DMStandard /y /s /e | ||
if not exist bin\Debug\net8.0\DMStandard mkdir bin\Debug\net8.0\DMStandard | ||
xcopy DMStandard bin\Debug\net8.0\DMStandard /y /s /e | ||
if not exist bin\Release\net8.0\DMStandard mkdir bin\Release\net8.0\DMStandard | ||
xcopy DMStandard bin\Release\net8.0\DMStandard /y /s /e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Audio; | ||
using Robust.Shared.Audio.Components; | ||
|
||
namespace OpenDreamClient.Audio; | ||
|
||
public sealed class DreamSoundChannel : IDisposable { | ||
public IClydeAudioSource Source { get; } | ||
|
||
public DreamSoundChannel(IClydeAudioSource source) { | ||
Source = source; | ||
} | ||
public sealed class DreamSoundChannel(AudioSystem audioSystem, (EntityUid Entity, AudioComponent Component) source) { | ||
public readonly (EntityUid Entity, AudioComponent Component) Source = source; | ||
|
||
public void Stop() { | ||
Source.StopPlaying(); | ||
} | ||
|
||
public void Dispose() { | ||
Stop(); | ||
Source.Dispose(); | ||
audioSystem.Stop(Source.Entity, Source.Component); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,103 @@ | ||
using OpenDreamClient.Resources; | ||
using OpenDreamClient.Resources.ResourceTypes; | ||
using OpenDreamShared.Network.Messages; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Audio; | ||
using Robust.Shared.Audio; | ||
using Robust.Shared.Network; | ||
|
||
namespace OpenDreamClient.Audio { | ||
public sealed class DreamSoundEngine : IDreamSoundEngine { | ||
private const int SoundChannelLimit = 1024; | ||
namespace OpenDreamClient.Audio; | ||
|
||
[Dependency] private readonly IDreamResourceManager _resourceManager = default!; | ||
[Dependency] private readonly ILogManager _logManager = default!; | ||
[Dependency] private readonly INetManager _netManager = default!; | ||
public sealed class DreamSoundEngine : IDreamSoundEngine { | ||
private const int SoundChannelLimit = 1024; | ||
|
||
private ISawmill _sawmill = default!; | ||
[Dependency] private readonly IDreamResourceManager _resourceManager = default!; | ||
[Dependency] private readonly ILogManager _logManager = default!; | ||
[Dependency] private readonly INetManager _netManager = default!; | ||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; | ||
[Dependency] private readonly IAudioManager _audioManager = default!; | ||
private AudioSystem? _audioSystem; | ||
|
||
private readonly DreamSoundChannel?[] _channels = new DreamSoundChannel[SoundChannelLimit]; | ||
private ISawmill _sawmill = default!; | ||
|
||
public void Initialize() { | ||
_sawmill = _logManager.GetSawmill("opendream.audio"); | ||
private readonly DreamSoundChannel?[] _channels = new DreamSoundChannel[SoundChannelLimit]; | ||
|
||
_netManager.RegisterNetMessage<MsgSound>(RxSound); | ||
public void Initialize() { | ||
_sawmill = _logManager.GetSawmill("opendream.audio"); | ||
|
||
_netManager.Disconnect += DisconnectedFromServer; | ||
} | ||
_netManager.RegisterNetMessage<MsgSound>(RxSound); | ||
|
||
public void StopFinishedChannels() { | ||
for (int i = 0; i < SoundChannelLimit; i++) { | ||
if (_channels[i]?.Source.IsPlaying is false or null) | ||
StopChannel(i + 1); | ||
} | ||
_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 (channel == 0) { | ||
//First available channel | ||
for (int i = 0; i < _channels.Length; i++) { | ||
if (_channels[i] == null) { | ||
channel = i + 1; | ||
break; | ||
} | ||
} | ||
public void PlaySound(int channel, MsgSound.FormatType format, ResourceSound sound, float volume) { | ||
if (_audioSystem == null) | ||
_entitySystemManager.Resolve(ref _audioSystem); | ||
|
||
if (channel == 0) { | ||
_sawmill.Error("Failed to find a free audio channel to play a sound on"); | ||
return; | ||
if (channel == 0) { | ||
//First available channel | ||
for (int i = 0; i < _channels.Length; i++) { | ||
if (_channels[i] == null) { | ||
channel = i + 1; | ||
break; | ||
} | ||
} | ||
|
||
StopChannel(channel); | ||
|
||
// convert from DM volume (0-100) to OpenAL volume (db) | ||
IClydeAudioSource? source = sound.Play(format, AudioParams.Default.WithVolume(20 * MathF.Log10(volume))); | ||
if (source == null) | ||
if (channel == 0) { | ||
_sawmill.Error("Failed to find a free audio channel to play a sound on"); | ||
return; | ||
|
||
_channels[channel - 1] = new DreamSoundChannel(source); | ||
} | ||
} | ||
|
||
StopChannel(channel); | ||
|
||
public void StopChannel(int channel) { | ||
ref DreamSoundChannel? ch = ref _channels[channel - 1]; | ||
|
||
ch?.Dispose(); | ||
// This will null the corresponding index in the array. | ||
ch = null; | ||
var stream = sound.GetStream(format, _audioManager); | ||
if (stream == null) { | ||
_sawmill.Error($"Failed to load audio ${sound}"); | ||
return; | ||
} | ||
|
||
public void StopAllChannels() { | ||
for (int i = 0; i < SoundChannelLimit; i++) { | ||
StopChannel(i + 1); | ||
} | ||
var db = 20 * MathF.Log10(volume); // convert from DM volume (0-100) to OpenAL volume (db) | ||
var source = _audioSystem.PlayGlobal(stream, AudioParams.Default.WithVolume(db)); // TODO: Positional audio. | ||
if (source == null) { | ||
_sawmill.Error($"Failed to play audio ${sound}"); | ||
return; | ||
} | ||
|
||
private void RxSound(MsgSound msg) { | ||
if (msg.ResourceId.HasValue) { | ||
_resourceManager.LoadResourceAsync<ResourceSound>(msg.ResourceId.Value, | ||
sound => PlaySound(msg.Channel, msg.Format!.Value, sound, msg.Volume / 100.0f)); | ||
} else { | ||
StopChannel(msg.Channel); | ||
} | ||
_channels[channel - 1] = new DreamSoundChannel(_audioSystem, source.Value); | ||
} | ||
|
||
|
||
public void StopChannel(int channel) { | ||
ref DreamSoundChannel? ch = ref _channels[channel - 1]; | ||
|
||
ch?.Stop(); | ||
// This will null the corresponding index in the array. | ||
ch = null; | ||
} | ||
|
||
public void StopAllChannels() { | ||
for (int i = 0; i < SoundChannelLimit; i++) { | ||
StopChannel(i + 1); | ||
} | ||
} | ||
|
||
private void DisconnectedFromServer(object? sender, NetDisconnectedArgs e) { | ||
StopAllChannels(); | ||
private void RxSound(MsgSound msg) { | ||
if (msg.ResourceId.HasValue) { | ||
_resourceManager.LoadResourceAsync<ResourceSound>(msg.ResourceId.Value, | ||
sound => PlaySound(msg.Channel, msg.Format!.Value, sound, msg.Volume / 100.0f)); | ||
} else { | ||
StopChannel(msg.Channel); | ||
} | ||
} | ||
|
||
private void DisconnectedFromServer(object? sender, NetDisconnectedArgs e) { | ||
StopAllChannels(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.