-
Notifications
You must be signed in to change notification settings - Fork 125
Initial SoundQuery() implementation
#2485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ike709
wants to merge
6
commits into
OpenDreamProject:master
Choose a base branch
from
ike709:soundquery
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+231
−23
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -30,10 +30,12 @@ public void Initialize() { | |
| _netManager.Disconnect += DisconnectedFromServer; | ||
| } | ||
|
|
||
| public void PlaySound(int channel, MsgSound.FormatType format, ResourceSound sound, float volume, float offset) { | ||
| public void PlaySound(SoundData soundData, MsgSound.FormatType format, ResourceSound sound) { | ||
| if (_audioSystem == null) | ||
| _entitySystemManager.Resolve(ref _audioSystem); | ||
|
|
||
| var channel = (int)soundData.Channel; | ||
|
|
||
| if (channel == 0) { | ||
| //First available channel | ||
| for (int i = 0; i < _channels.Length; i++) { | ||
|
|
@@ -58,14 +60,14 @@ public void PlaySound(int channel, MsgSound.FormatType format, ResourceSound sou | |
| return; | ||
| } | ||
|
|
||
| var db = 20 * MathF.Log10(volume); // convert from DM volume (0-100) to OpenAL volume (db) | ||
| var source = _audioSystem.PlayGlobal(stream, null, AudioParams.Default.WithVolume(db).WithPlayOffset(offset)); // TODO: Positional audio. | ||
| var db = 20 * MathF.Log10(soundData.Volume / 100.0f); // convert from DM volume (0-100) to OpenAL volume (db) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| var source = _audioSystem.PlayGlobal(stream, null, AudioParams.Default.WithVolume(db).WithPlayOffset(soundData.Offset).WithLoop(soundData.Repeat != 0)); // TODO: Positional audio. | ||
| if (source == null) { | ||
| _sawmill.Error($"Failed to play audio ${sound}"); | ||
| return; | ||
| } | ||
|
|
||
| _channels[channel - 1] = new DreamSoundChannel(_audioSystem, source.Value); | ||
| _channels[channel - 1] = new DreamSoundChannel(_audioSystem, source.Value, soundData); | ||
| } | ||
|
|
||
| public void StopChannel(int channel) { | ||
|
|
@@ -85,12 +87,22 @@ public void 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, msg.Offset)); | ||
| sound => PlaySound(msg.SoundData, msg.Format!.Value, sound)); | ||
| } else { | ||
| StopChannel(msg.Channel); | ||
| StopChannel(msg.SoundData.Channel); | ||
| } | ||
| } | ||
|
|
||
| public List<SoundData> GetSoundQuery() { | ||
| List<SoundData> result = new List<SoundData>(); | ||
| foreach (var channel in _channels) { | ||
| if(channel is null) continue; | ||
| result.Add(channel.SoundData); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| private void DisconnectedFromServer(object? sender, NetDisconnectedArgs e) { | ||
| StopAllChannels(); | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using System.Threading.Tasks; | ||
| using OpenDreamRuntime.Objects.Types; | ||
|
|
||
| namespace OpenDreamRuntime.Procs.Native; | ||
|
|
||
| internal static class DreamProcNativeClient { | ||
| [DreamProc("SoundQuery")] | ||
| public static async Task<DreamValue> NativeProc_SoundQuery(AsyncNativeProc.State state) { | ||
| var client = (DreamObjectClient)state.Src!; | ||
| return await client.Connection.SoundQuery(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using Lidgren.Network; | ||
| using Robust.Shared.Network; | ||
| using Robust.Shared.Serialization; | ||
|
|
||
| namespace OpenDreamShared.Network.Messages; | ||
|
|
||
| public sealed class MsgSoundQuery : NetMessage { | ||
| public override MsgGroups MsgGroup => MsgGroups.EntityEvent; | ||
|
|
||
| public int PromptId; | ||
|
|
||
| public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer) { | ||
| PromptId = buffer.ReadVariableInt32(); | ||
| } | ||
|
|
||
| public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer) { | ||
| buffer.WriteVariableInt32(PromptId); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / InspectCode
Use of obsolete symbol Warning
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Electing to ignore this as converting a bunch of audio code to use sound specifiers is out of scope and
GetAudioLength(SoundSpecifier)just calls thisGetAudioLength(string)overload currently anyways.