-
Notifications
You must be signed in to change notification settings - Fork 459
refactor!: remove channels, instead use delivery QoS directly #1116
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,14 +260,14 @@ public void SendToClient(NativeArray<byte> packet, ulong clientId, int index) | |
| } | ||
| } | ||
|
|
||
| public override unsafe void Send(ulong clientId, ArraySegment<byte> data, NetworkChannel networkChannel) | ||
| public override unsafe void Send(ulong clientId, ArraySegment<byte> data, NetworkDelivery networkDelivery) | ||
| { | ||
| var pipelineIndex = 0; | ||
|
|
||
| GetUTPConnectionDetails(clientId, out uint peerId); | ||
|
|
||
| var writer = new DataStreamWriter(data.Count + 1 + 4, Allocator.Temp); | ||
| writer.WriteByte((byte)networkChannel); | ||
| writer.WriteByte((byte)networkDelivery); | ||
| writer.WriteInt(data.Count); | ||
|
|
||
| fixed (byte* dataArrayPtr = data.Array) | ||
|
|
@@ -278,10 +278,10 @@ public override unsafe void Send(ulong clientId, ArraySegment<byte> data, Networ | |
| SendToClient(writer.AsNativeArray(), peerId, pipelineIndex); | ||
| } | ||
|
|
||
| public override NetcodeEvent PollEvent(out ulong clientId, out NetworkChannel networkChannel, out ArraySegment<byte> payload, out float receiveTime) | ||
| public override NetcodeEvent PollEvent(out ulong clientId, out NetworkDelivery networkDelivery, out ArraySegment<byte> payload, out float receiveTime) | ||
| { | ||
| clientId = 0; | ||
| networkChannel = NetworkChannel.ChannelUnused; | ||
| networkDelivery = NetworkDelivery.ReliableSequenced; //?? | ||
|
Contributor
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. Do we actually need to pop this now? because we did this before so the NetworkManager would know the channel but thats not required anymore? |
||
|
|
||
| payload = new ArraySegment<byte>(Array.Empty<byte>()); | ||
| receiveTime = 0; | ||
|
|
@@ -315,20 +315,20 @@ private void Update() | |
| { | ||
| Marshal.Copy((IntPtr)message.Data, arr, 0, size); | ||
| var payload = new ArraySegment<byte>(arr); | ||
| InvokeOnTransportEvent((NetcodeEvent)message.Type, clientId, (NetworkChannel)message.ChannelId, payload, Time.realtimeSinceStartup); | ||
| InvokeOnTransportEvent((NetcodeEvent)message.Type, clientId, (NetworkDelivery)message.ChannelId, payload, Time.realtimeSinceStartup); | ||
|
Contributor
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. Same as above does the above caller need to know the QoS? |
||
| } | ||
|
|
||
| break; | ||
| case NetcodeEvent.Connect: | ||
| { | ||
| InvokeOnTransportEvent((NetcodeEvent)message.Type, clientId, NetworkChannel.ChannelUnused, new ArraySegment<byte>(), Time.realtimeSinceStartup); | ||
| InvokeOnTransportEvent((NetcodeEvent)message.Type, clientId, NetworkDelivery.ReliableSequenced, new ArraySegment<byte>(), Time.realtimeSinceStartup); | ||
| } | ||
| break; | ||
| case NetcodeEvent.Disconnect: | ||
| InvokeOnTransportEvent((NetcodeEvent)message.Type, clientId, NetworkChannel.ChannelUnused, new ArraySegment<byte>(), Time.realtimeSinceStartup); | ||
| InvokeOnTransportEvent((NetcodeEvent)message.Type, clientId, NetworkDelivery.ReliableSequenced, new ArraySegment<byte>(), Time.realtimeSinceStartup); | ||
| break; | ||
| case NetcodeEvent.Nothing: | ||
| InvokeOnTransportEvent((NetcodeEvent)message.Type, clientId, NetworkChannel.ChannelUnused, new ArraySegment<byte>(), Time.realtimeSinceStartup); | ||
| InvokeOnTransportEvent((NetcodeEvent)message.Type, clientId, NetworkDelivery.ReliableSequenced, new ArraySegment<byte>(), Time.realtimeSinceStartup); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1069,8 +1069,8 @@ private void OnNetworkEarlyUpdate() | |
| do | ||
| { | ||
| processedEvents++; | ||
| networkEvent = NetworkConfig.NetworkTransport.PollEvent(out ulong clientId, out NetworkChannel networkChannel, out ArraySegment<byte> payload, out float receiveTime); | ||
| HandleRawTransportPoll(networkEvent, clientId, networkChannel, payload, receiveTime); | ||
| networkEvent = NetworkConfig.NetworkTransport.PollEvent(out ulong clientId, out NetworkDelivery networkDelivery, out ArraySegment<byte> payload, out float receiveTime); | ||
| HandleRawTransportPoll(networkEvent, clientId, networkDelivery, payload, receiveTime); | ||
| // Only do another iteration if: there are no more messages AND (there is no limit to max events or we have processed less than the maximum) | ||
| } while (IsListening && networkEvent != NetworkEvent.Nothing); | ||
| } | ||
|
|
@@ -1122,7 +1122,7 @@ private void SendConnectionRequest() | |
| { | ||
| var clientIds = new[] { ServerClientId }; | ||
| var context = MessageQueueContainer.EnterInternalCommandContext( | ||
| MessageQueueContainer.MessageType.ConnectionRequest, NetworkChannel.Internal, | ||
| MessageQueueContainer.MessageType.ConnectionRequest, NetworkDelivery.ReliableSequenced, | ||
| clientIds, NetworkUpdateStage.EarlyUpdate); | ||
| if (context != null) | ||
| { | ||
|
|
@@ -1158,7 +1158,7 @@ private IEnumerator ApprovalTimeout(ulong clientId) | |
| } | ||
| } | ||
|
|
||
| private void HandleRawTransportPoll(NetworkEvent networkEvent, ulong clientId, NetworkChannel networkChannel, | ||
| private void HandleRawTransportPoll(NetworkEvent networkEvent, ulong clientId, NetworkDelivery networkDelivery, | ||
| ArraySegment<byte> payload, float receiveTime) | ||
| { | ||
| switch (networkEvent) | ||
|
|
@@ -1204,7 +1204,7 @@ private void HandleRawTransportPoll(NetworkEvent networkEvent, ulong clientId, N | |
| NetworkLog.LogInfo($"Incoming Data From {clientId}: {payload.Count} bytes"); | ||
| } | ||
|
|
||
| HandleIncomingData(clientId, networkChannel, payload, receiveTime); | ||
| HandleIncomingData(clientId, networkDelivery, payload, receiveTime); | ||
| break; | ||
| } | ||
| case NetworkEvent.Disconnect: | ||
|
|
@@ -1239,7 +1239,7 @@ private void HandleRawTransportPoll(NetworkEvent networkEvent, ulong clientId, N | |
| private readonly NetworkBuffer m_InputBufferWrapper = new NetworkBuffer(new byte[0]); | ||
| private readonly MessageBatcher m_MessageBatcher = new MessageBatcher(); | ||
|
|
||
| internal void HandleIncomingData(ulong clientId, NetworkChannel networkChannel, ArraySegment<byte> data, float receiveTime) | ||
| internal void HandleIncomingData(ulong clientId, NetworkDelivery networkDelivery, ArraySegment<byte> data, float receiveTime) | ||
| { | ||
| #if DEVELOPMENT_BUILD || UNITY_EDITOR | ||
| s_HandleIncomingData.Begin(); | ||
|
|
@@ -1258,22 +1258,22 @@ internal void HandleIncomingData(ulong clientId, NetworkChannel networkChannel, | |
|
|
||
| if (MessageQueueContainer.IsUsingBatching()) | ||
| { | ||
| m_MessageBatcher.ReceiveItems(messageStream, ReceiveCallback, clientId, receiveTime, networkChannel); | ||
| m_MessageBatcher.ReceiveItems(messageStream, ReceiveCallback, clientId, receiveTime, networkDelivery); | ||
|
Contributor
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. I assume the batching needs to know about the QoS? |
||
| } | ||
| else | ||
| { | ||
| var messageType = (MessageQueueContainer.MessageType)messageStream.ReadByte(); | ||
| MessageHandler.MessageReceiveQueueItem(clientId, messageStream, receiveTime, messageType, networkChannel); | ||
| MessageHandler.MessageReceiveQueueItem(clientId, messageStream, receiveTime, messageType, networkDelivery); | ||
| } | ||
| #if DEVELOPMENT_BUILD || UNITY_EDITOR | ||
| s_HandleIncomingData.End(); | ||
| #endif | ||
| } | ||
|
|
||
| private void ReceiveCallback(NetworkBuffer messageBuffer, MessageQueueContainer.MessageType messageType, ulong clientId, | ||
| float receiveTime, NetworkChannel receiveChannel) | ||
| float receiveTime, NetworkDelivery receiveDelivery) | ||
| { | ||
| MessageHandler.MessageReceiveQueueItem(clientId, messageBuffer, receiveTime, messageType, receiveChannel); | ||
| MessageHandler.MessageReceiveQueueItem(clientId, messageBuffer, receiveTime, messageType, receiveDelivery); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -1449,7 +1449,7 @@ private void SyncTime() | |
|
|
||
| ulong[] clientIds = ConnectedClientsIds; | ||
| var context = MessageQueueContainer.EnterInternalCommandContext( | ||
| MessageQueueContainer.MessageType.TimeSync, NetworkChannel.SyncChannel, | ||
| MessageQueueContainer.MessageType.TimeSync, NetworkDelivery.Unreliable, | ||
| clientIds, NetworkUpdateStage.EarlyUpdate); | ||
| if (context != null) | ||
| { | ||
|
|
@@ -1492,7 +1492,7 @@ internal void HandleApproval(ulong ownerClientId, bool createPlayerObject, uint? | |
| // Server doesn't send itself the connection approved message | ||
| if (ownerClientId != ServerClientId) | ||
| { | ||
| var context = MessageQueueContainer.EnterInternalCommandContext(MessageQueueContainer.MessageType.ConnectionApproved, NetworkChannel.Internal, | ||
| var context = MessageQueueContainer.EnterInternalCommandContext(MessageQueueContainer.MessageType.ConnectionApproved, NetworkDelivery.ReliableSequenced, | ||
| new ulong[] { ownerClientId }, NetworkUpdateStage.EarlyUpdate); | ||
|
|
||
| if (context != null) | ||
|
|
@@ -1555,7 +1555,7 @@ internal void ApprovedPlayerSpawn(ulong clientId, uint playerPrefabHash) | |
| continue; //The new client. | ||
| } | ||
|
|
||
| var context = MessageQueueContainer.EnterInternalCommandContext(MessageQueueContainer.MessageType.CreateObject, NetworkChannel.Internal, | ||
| var context = MessageQueueContainer.EnterInternalCommandContext(MessageQueueContainer.MessageType.CreateObject, NetworkDelivery.ReliableSequenced, | ||
| new[] { clientPair.Key }, NetworkUpdateLoop.UpdateStage); | ||
| if (context != null) | ||
| { | ||
|
|
||
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.
I'm assuming actually all these writes can be deleted, because this is probably so that the receiver can route the packet to the right channel, and if we don't care about channels this can be deleted.
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.
oh yeah, that'd be great!
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.
That is cirrect we can get rid of them.