Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,7 @@ private void NetworkPreUpdate()
do
{
processedEvents++;
eventType = NetworkConfig.NetworkTransport.PollEvent(out ulong clientId, out string channelName, out ArraySegment<byte> payload, out float receiveTime);
// [MTT-443] This can be improved if the Transport implementations return the channel as a byte vs. string
// Holding off on this; refactoring the Transport package will be a separate step
byte channel = Transport.GetChannelByte(channelName);
eventType = NetworkConfig.NetworkTransport.PollEvent(out ulong clientId, out byte channel, out ArraySegment<byte> payload, out float receiveTime);
HandleRawTransportPoll(eventType, clientId, channel, 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ internal static void Send(ulong clientId, byte messageType, byte channel, BitStr
NetworkProfiler.StartEvent(TickType.Send, (uint) stream.Length, channel,
MLAPIConstants.MESSAGE_NAMES[messageType]);

// [MTT-433] refactor so that the transports receive a byte, not a string
// saving for a separate effort since transports live in their own package
string channelName = Transport.GetChannelString(channel);
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientId, new ArraySegment<byte>(stream.GetBuffer(), 0, (int)stream.Length), channelName);
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientId, new ArraySegment<byte>(stream.GetBuffer(), 0, (int)stream.Length), channel);
ProfilerStatManager.bytesSent.Record((int)stream.Length);

NetworkProfiler.EndEvent();
Expand Down Expand Up @@ -58,10 +55,7 @@ internal static void Send(byte messageType, byte channel, BitStream messageStrea
if (NetworkingManager.Singleton.IsServer && NetworkingManager.Singleton.ConnectedClientsList[i].ClientId == NetworkingManager.Singleton.ServerClientId)
continue;

// [MTT-433] refactor so that the transports receive a byte, not a string
// saving for a separate effort since transports live in their own package
string channelName = Transport.GetChannelString(channel);
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(NetworkingManager.Singleton.ConnectedClientsList[i].ClientId, new ArraySegment<byte>(stream.GetBuffer(), 0, (int)stream.Length), channelName);
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(NetworkingManager.Singleton.ConnectedClientsList[i].ClientId, new ArraySegment<byte>(stream.GetBuffer(), 0, (int)stream.Length), channel);
ProfilerStatManager.bytesSent.Record((int)stream.Length);
}
NetworkProfiler.EndEvent();
Expand Down Expand Up @@ -99,10 +93,7 @@ internal static void Send(byte messageType, byte channel, List<ulong> clientIds,
if (NetworkingManager.Singleton.IsServer && clientIds[i] == NetworkingManager.Singleton.ServerClientId)
continue;

// [MTT-433] refactor so that the transports receive a byte, not a string
// saving for a separate effort since transports live in their own package
string channelName = Transport.GetChannelString(channel);
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientIds[i], new ArraySegment<byte>(stream.GetBuffer(), 0, (int)stream.Length), channelName);
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientIds[i], new ArraySegment<byte>(stream.GetBuffer(), 0, (int)stream.Length), channel);
ProfilerStatManager.bytesSent.Record((int)stream.Length);
}
NetworkProfiler.EndEvent();
Expand Down Expand Up @@ -138,10 +129,7 @@ internal static void Send(byte messageType, byte channel, ulong clientIdToIgnore
(NetworkingManager.Singleton.IsServer && NetworkingManager.Singleton.ConnectedClientsList[i].ClientId == NetworkingManager.Singleton.ServerClientId))
continue;

// [MTT-433] refactor so that the transports receive a byte, not a string
// saving for a separate effort since transports live in their own package
string channelName = Transport.GetChannelString(channel);
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(NetworkingManager.Singleton.ConnectedClientsList[i].ClientId, new ArraySegment<byte>(stream.GetBuffer(), 0, (int)stream.Length), channelName);
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(NetworkingManager.Singleton.ConnectedClientsList[i].ClientId, new ArraySegment<byte>(stream.GetBuffer(), 0, (int)stream.Length), channel);
ProfilerStatManager.bytesSent.Record((int)stream.Length);
}
NetworkProfiler.EndEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ private static void SendCallback(ulong clientId, MLAPI.MessageBatcher.SendStream
var bytes = sendStream.Stream.GetBuffer();
ArraySegment<byte> sendBuffer = new ArraySegment<byte>(bytes, 0, length);

// [MTT-433] refactor so that the transports receive a byte, not a string
// saving for a separate effort since transports live in their own package
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientId, sendBuffer, Transport.GetChannelString(sendStream.channel));
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientId, sendBuffer, sendStream.channel);
}

/// <summary>
Expand All @@ -231,9 +229,7 @@ private void SendFrameQueueItem(FrameQueueItem queueItem)
{
case RpcQueueContainer.QueueItemType.ServerRpc:
{
// [MTT-433] refactor so that the transports receive a byte, not a string
// saving for a separate effort since transports live in their own package
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(queueItem.networkId, queueItem.messageData, Transport.GetChannelString(queueItem.channel));
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(queueItem.networkId, queueItem.messageData, queueItem.channel);

//For each packet sent, we want to record how much data we have sent
ProfilerStatManager.bytesSent.Record((int)queueItem.streamSize);
Expand All @@ -244,9 +240,7 @@ private void SendFrameQueueItem(FrameQueueItem queueItem)
{
foreach (ulong clientid in queueItem.clientIds)
{
// [MTT-433] refactor so that the transports receive a byte, not a string
// saving for a separate effort since transports live in their own package
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientid, queueItem.messageData, Transport.GetChannelString(queueItem.channel));
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientid, queueItem.messageData, queueItem.channel);

//For each packet sent, we want to record how much data we have sent
ProfilerStatManager.bytesSent.Record((int)queueItem.streamSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void Init()
}
}

public override NetEventType PollEvent(out ulong clientId, out string channelName, out ArraySegment<byte> payload, out float receiveTime)
public override NetEventType PollEvent(out ulong clientId, out byte channel, out ArraySegment<byte> payload, out float receiveTime)
{
if (_lastProcessedTransportIndex >= Transports.Length - 1)
_lastProcessedTransportIndex = 0;
Expand All @@ -93,7 +93,7 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam

if (Transports[i].IsSupported)
{
NetEventType @eventType = Transports[i].PollEvent(out ulong connectionId, out channelName, out payload, out receiveTime);
NetEventType @eventType = Transports[i].PollEvent(out ulong connectionId, out channel, out payload, out receiveTime);

if (@eventType != NetEventType.Nothing)
{
Expand All @@ -105,18 +105,18 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam
}

clientId = 0;
channelName = null;
channel = 0;
payload = new ArraySegment<byte>();
receiveTime = 0;

return NetEventType.Nothing;
}

public override void Send(ulong clientId, ArraySegment<byte> data, string channelName)
public override void Send(ulong clientId, ArraySegment<byte> data, byte channel)
{
GetMultiplexTransportDetails(clientId, out byte transportId, out ulong connectionId);

Transports[transportId].Send(connectionId, data, channelName);
Transports[transportId].Send(connectionId, data, channel);
}

public override void Shutdown()
Expand Down
4 changes: 2 additions & 2 deletions com.unity.multiplayer.mlapi/Runtime/Transports/Transport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected void InvokeOnTransportEvent(NetEventType type, ulong clientId, byte ch
/// <param name="clientId">The clientId to send to</param>
/// <param name="data">The data to send</param>
/// <param name="channelName">The channel to send data to</param>
public abstract void Send(ulong clientId, ArraySegment<byte> data, string channelName);
public abstract void Send(ulong clientId, ArraySegment<byte> data, byte channel);

/// <summary>
/// Polls for incoming events, with an extra output parameter to report the precise time the event was received.
Expand All @@ -148,7 +148,7 @@ protected void InvokeOnTransportEvent(NetEventType type, ulong clientId, byte ch
/// <param name="payload">The incoming data payload</param>
/// <param name="receiveTime">The time the event was received, as reported by Time.realtimeSinceStartup.</param>
/// <returns>Returns the event type</returns>
public abstract NetEventType PollEvent(out ulong clientId, out string channelName, out ArraySegment<byte> payload, out float receiveTime);
public abstract NetEventType PollEvent(out ulong clientId, out byte channel, out ArraySegment<byte> payload, out float receiveTime);

/// <summary>
/// Connects client to server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class UnetChannel
/// <summary>
/// The name of the channel
/// </summary>
public string Name;
public byte Id;

/// <summary>
/// The type of channel
/// </summary>
public QosType Type;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public enum SendMode
private WeakReference temporaryBufferReference;

// Lookup / translation
private readonly Dictionary<string, int> channelNameToId = new Dictionary<string, int>();
private readonly Dictionary<int, string> channelIdToName = new Dictionary<int, string>();
private readonly Dictionary<byte, int> channelNameToId = new Dictionary<byte, int>();
private readonly Dictionary<int, byte> channelIdToName = new Dictionary<int, byte>();
Comment on lines -44 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we actually need these by now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I was too chicken to muck with the logic down and into ConnectionConfig::AddChannel. @TwoTenPvP I wonder if you could give your thoughts?

private int serverConnectionId;
private int serverHostId;

Expand All @@ -63,19 +63,19 @@ protected void LateUpdate()
}
}

public override void Send(ulong clientId, ArraySegment<byte> data, string channelName)
public override void Send(ulong clientId, ArraySegment<byte> data, byte channel)
{
GetUnetConnectionDetails(clientId, out byte hostId, out ushort connectionId);

int channelId = 0;

if (channelNameToId.ContainsKey(channelName))
if (channelNameToId.ContainsKey(channel))
{
channelId = channelNameToId[channelName];
channelId = channelNameToId[channel];
}
else
{
channelId = channelNameToId["MLAPI_INTERNAL"];
channelId = channelNameToId[MLAPI_INTERNAL_CHANNEL];
}

byte[] buffer;
Expand Down Expand Up @@ -125,7 +125,7 @@ public void SendQueued(ulong clientId)
RelayTransport.SendQueuedMessages(hostId, connectionId, out byte error);
}

public override NetEventType PollEvent(out ulong clientId, out string channelName, out ArraySegment<byte> payload, out float receiveTime)
public override NetEventType PollEvent(out ulong clientId, out byte channel, out ArraySegment<byte> payload, out float receiveTime)
{
NetworkEventType eventType = RelayTransport.Receive(out int hostId, out int connectionId, out int channelId, messageBuffer, messageBuffer.Length, out int receivedSize, out byte error);

Expand Down Expand Up @@ -159,11 +159,11 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam

if (channelIdToName.ContainsKey(channelId))
{
channelName = channelIdToName[channelId];
channel = channelIdToName[channelId];
}
else
{
channelName = "MLAPI_INTERNAL";
channel = MLAPI_INTERNAL_CHANNEL;
}

if (connectTask != null && hostId == serverHostId && connectionId == serverConnectionId)
Expand Down Expand Up @@ -349,16 +349,16 @@ public ConnectionConfig GetConfig()
{
int channelId = AddMLAPIChannel(MLAPI_CHANNELS[i].Type, config);

channelIdToName.Add(channelId, MLAPI_CHANNELS[i].Name);
channelNameToId.Add(MLAPI_CHANNELS[i].Name, channelId);
channelIdToName.Add(channelId, MLAPI_CHANNELS[i].Id);
channelNameToId.Add(MLAPI_CHANNELS[i].Id, channelId);
}

for (int i = 0; i < Channels.Count; i++)
{
int channelId = AddUNETChannel(Channels[i].Type, config);

channelIdToName.Add(channelId, Channels[i].Name);
channelNameToId.Add(Channels[i].Name, channelId);
channelIdToName.Add(channelId, Channels[i].Id);
channelNameToId.Add(Channels[i].Id, channelId);
}

config.MaxSentMessageQueueSize = (ushort)MaxSentMessageQueueSize;
Expand Down
Loading