Skip to content

Commit 9e55374

Browse files
author
ike709
committed
review
1 parent d6713e9 commit 9e55374

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

OpenDreamClient/Audio/DreamSoundEngine.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public void Initialize() {
2626
_sawmill = _logManager.GetSawmill("opendream.audio");
2727

2828
_netManager.RegisterNetMessage<MsgSound>(RxSound);
29+
_netManager.RegisterNetMessage<MsgSoundQuery>(RxSoundQuery);
30+
_netManager.RegisterNetMessage<MsgSoundQueryResponse>();
2931

3032
_netManager.Disconnect += DisconnectedFromServer;
3133
}
@@ -93,6 +95,14 @@ private void RxSound(MsgSound msg) {
9395
}
9496
}
9597

98+
private void RxSoundQuery(MsgSoundQuery soundQuery) {
99+
var response = new MsgSoundQueryResponse {
100+
PromptId = soundQuery.PromptId,
101+
Sounds = GetSoundQuery()
102+
};
103+
_netManager.ClientSendMessage(response);
104+
}
105+
96106
public List<SoundData> GetSoundQuery() {
97107
List<SoundData> result = new List<SoundData>();
98108
foreach (var channel in _channels) {

OpenDreamClient/Interface/DreamInterfaceManager.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ public void Initialize() {
122122
_netManager.RegisterNetMessage<MsgPrompt>(RxPrompt);
123123
_netManager.RegisterNetMessage<MsgPromptList>(RxPromptList);
124124
_netManager.RegisterNetMessage<MsgPromptResponse>();
125-
_netManager.RegisterNetMessage<MsgSoundQuery>(RxSoundQuery);
126-
_netManager.RegisterNetMessage<MsgSoundQueryResponse>();
127125
_netManager.RegisterNetMessage<MsgBrowse>(RxBrowse);
128126
_netManager.RegisterNetMessage<MsgTopic>();
129127
_netManager.RegisterNetMessage<MsgWinSet>(RxWinSet);
@@ -190,15 +188,6 @@ private void RxPromptList(MsgPromptList pPromptList) {
190188
ShowPrompt(prompt);
191189
}
192190

193-
private void RxSoundQuery(MsgSoundQuery soundQuery) {
194-
var allSounds = _dreamSoundEngine.GetSoundQuery();
195-
var response = new MsgSoundQueryResponse {
196-
PromptId = soundQuery.PromptId,
197-
Sounds = allSounds,
198-
};
199-
_netManager.ClientSendMessage(response);
200-
}
201-
202191
private void RxBrowse(MsgBrowse pBrowse) {
203192
var referencedElement = (pBrowse.Window != null) ? FindElementWithId(pBrowse.Window) : DefaultWindow;
204193

OpenDreamRuntime/DreamConnection.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,17 @@ public void HandleMsgSoundQueryResponse(MsgSoundQueryResponse message) {
211211
return;
212212
}
213213

214-
DreamList allSounds = new DreamList(_objectTree.List.ObjectDefinition, message.Sounds?.Count ?? 0);
215-
if (message.Sounds is not null) {
216-
foreach (var soundData in message.Sounds) {
217-
var sound = new DreamObjectSound(_objectTree.GetObjectDefinition(_objectTree.Sound.Id));
218-
sound.SetVariableValue("channel", new DreamValue(soundData.Channel));
219-
sound.SetVariableValue("offset", new DreamValue(soundData.Offset));
220-
sound.SetVariableValue("volume", new DreamValue(soundData.Volume));
221-
sound.SetVariableValue("len", new DreamValue(soundData.Length));
222-
sound.SetVariableValue("repeat", new DreamValue(soundData.Repeat));
223-
sound.SetVariableValue("file", string.IsNullOrEmpty(soundData.File) ? DreamValue.Null : new DreamValue(soundData.File));
224-
225-
allSounds.AddValue(new DreamValue(sound));
226-
}
214+
DreamList allSounds = _objectTree.CreateList(message.Sounds.Count);
215+
foreach (var soundData in message.Sounds) {
216+
var sound = _objectTree.CreateObject(_objectTree.Sound);
217+
sound.SetVariableValue("channel", new DreamValue(soundData.Channel));
218+
sound.SetVariableValue("offset", new DreamValue(soundData.Offset));
219+
sound.SetVariableValue("volume", new DreamValue(soundData.Volume));
220+
sound.SetVariableValue("len", new DreamValue(soundData.Length));
221+
sound.SetVariableValue("repeat", new DreamValue(soundData.Repeat));
222+
sound.SetVariableValue("file", string.IsNullOrEmpty(soundData.File) ? DreamValue.Null : new DreamValue(soundData.File));
223+
224+
allSounds.AddValue(new DreamValue(sound));
227225
}
228226

229227
promptEvent.Invoke(new DreamValue(allSounds));

OpenDreamShared/Network/Messages/MsgSoundQueryResponse.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ public sealed class MsgSoundQueryResponse : NetMessage {
99
public override MsgGroups MsgGroup => MsgGroups.EntityEvent;
1010

1111
public int PromptId;
12-
public List<SoundData>? Sounds;
12+
public required List<SoundData> Sounds;
1313

1414
public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer) {
1515
PromptId = buffer.ReadVariableInt32();
1616
var soundCount = buffer.ReadUInt16();
1717

18-
if(soundCount == 0) return;
18+
Sounds = new List<SoundData>(soundCount);
1919

20-
Sounds ??= new List<SoundData>(soundCount);
20+
if(soundCount == 0) return;
2121

2222
for (var i = 0; i < soundCount; i++) {
2323
Sounds.Add(new SoundData(buffer));
@@ -27,11 +27,11 @@ public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer
2727
public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer) {
2828
buffer.WriteVariableInt32(PromptId);
2929

30-
var soundCount = Sounds?.Count ?? 0;
30+
var soundCount = Sounds.Count;
3131
buffer.Write((ushort)soundCount);
3232

3333
for (var i = 0; i < soundCount; i++) {
34-
Sounds![i].WriteToBuffer(buffer);
34+
Sounds[i].WriteToBuffer(buffer);
3535
}
3636
}
3737
}

0 commit comments

Comments
 (0)