Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
62c9c9e
chore: adding preprocessor define in Netcode for GameObjects, when UT…
jeffreyrainy Aug 29, 2022
3d83ba5
chore: adding preprocessor define in Netcode for GameObjects, when UT…
jeffreyrainy Aug 29, 2022
f15fd09
Merge branch 'chore/utp-2.0-support' of github.com:Unity-Technologies…
jeffreyrainy Aug 29, 2022
6c77377
chore: adding preprocessor define in Netcode for GameObjects tests, w…
jeffreyrainy Aug 29, 2022
01223b6
chore: conditional use of UTP 2.0
jeffreyrainy Aug 29, 2022
e755408
Merge branch 'develop' into chore/utp-2.0-support
jeffreyrainy Aug 29, 2022
393b3e6
Merge remote-tracking branch 'origin' into chore/utp-2.0-support-2
jeffreyrainy Aug 29, 2022
ff84b38
Merge branch 'chore/utp-2.0-support-2' into chore/utp-2.0-support
jeffreyrainy Aug 29, 2022
5160f57
style: coding standards
jeffreyrainy Aug 29, 2022
d280313
style: coding standards
jeffreyrainy Aug 29, 2022
e27a803
Merge branch 'chore/utp-2.0-support' of github.com:Unity-Technologies…
jeffreyrainy Aug 29, 2022
5e7ef43
Adding some fixed from PR review comment
jeffreyrainy Aug 29, 2022
ab067fd
Merge branch 'develop' into chore/utp-2.0-support
jeffreyrainy Aug 30, 2022
9e1eccf
Merge branch 'develop' into chore/utp-2.0-support
jeffreyrainy Aug 30, 2022
48e3034
fix: fixing tools package compilation, when used in netcode for gameo…
jeffreyrainy Aug 30, 2022
595c6bf
fix: fixing tools package compilation, when used in netcode for gameo…
jeffreyrainy Aug 30, 2022
2623010
Merge branch 'chore/utp-2.0-support' of github.com:Unity-Technologies…
jeffreyrainy Aug 30, 2022
1c9f2fa
fix: build break for UTP 2.0 builds without tools installed
jeffreyrainy Aug 30, 2022
3ec816a
fix: fixing build errors with Collection 2.1.0-exp3
jeffreyrainy Aug 31, 2022
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 @@ -53,7 +53,7 @@ public override void ResetDirty()
if (m_DirtyEvents.Length > 0)
{
m_DirtyEvents.Clear();
m_ListAtLastReset.CopyFrom(m_List);
m_ListAtLastReset.CopyFrom(m_List.AsArray());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using Unity.Networking.Transport;
#if UTP_TRANSPORT_2_0_ABOVE
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
#endif

namespace Unity.Netcode.Transports.UTP
{
Expand All @@ -25,7 +29,11 @@ public BatchedReceiveQueue(DataStreamReader reader)
{
fixed (byte* dataPtr = m_Data)
{
#if UTP_TRANSPORT_2_0_ABOVE
reader.ReadBytesUnsafe(dataPtr, reader.Length);
#else
reader.ReadBytes(dataPtr, reader.Length);
#endif
}
}

Expand Down Expand Up @@ -62,7 +70,11 @@ public void PushReader(DataStreamReader reader)
{
fixed (byte* dataPtr = m_Data)
{
#if UTP_TRANSPORT_2_0_ABOVE
reader.ReadBytesUnsafe(dataPtr + m_Offset + m_Length, reader.Length);
#else
reader.ReadBytes(dataPtr + m_Offset + m_Length, reader.Length);
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ private void AppendDataAtTail(ArraySegment<byte> data)

fixed (byte* dataPtr = data.Array)
{
#if UTP_TRANSPORT_2_0_ABOVE
writer.WriteBytesUnsafe(dataPtr + data.Offset, data.Count);
#else
writer.WriteBytes(dataPtr + data.Offset, data.Count);
#endif
}
}

Expand Down Expand Up @@ -149,7 +153,12 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)

unsafe
{
#if UTP_TRANSPORT_2_0_ABOVE
var slice = m_Data.GetSubArray(HeadIndex, Length);
var reader = new DataStreamReader(slice);
#else
var reader = new DataStreamReader((byte*)m_Data.GetUnsafePtr() + HeadIndex, Length);
#endif

var writerAvailable = writer.Capacity;
var readerOffset = 0;
Expand All @@ -168,7 +177,11 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
writer.WriteInt(messageLength);

var messageOffset = HeadIndex + reader.GetBytesRead();
#if UTP_TRANSPORT_2_0_ABOVE
writer.WriteBytesUnsafe((byte*)m_Data.GetUnsafePtr() + messageOffset, messageLength);
#else
writer.WriteBytes((byte*)m_Data.GetUnsafePtr() + messageOffset, messageLength);
#endif

writerAvailable -= sizeof(int) + messageLength;
readerOffset += sizeof(int) + messageLength;
Expand Down Expand Up @@ -205,7 +218,11 @@ public int FillWriterWithBytes(ref DataStreamWriter writer)

unsafe
{
#if UTP_TRANSPORT_2_0_ABOVE
writer.WriteBytesUnsafe((byte*)m_Data.GetUnsafePtr() + HeadIndex, copyLength);
#else
writer.WriteBytes((byte*)m_Data.GetUnsafePtr() + HeadIndex, copyLength);
#endif
}

return copyLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
using Unity.Networking.Transport.Relay;
using Unity.Networking.Transport.Utilities;

#if !UTP_TRANSPORT_2_0_ABOVE
using NetworkEndpoint = Unity.Networking.Transport.NetworkEndPoint;
#endif

namespace Unity.Netcode.Transports.UTP
{
/// <summary>
Expand Down Expand Up @@ -263,9 +267,9 @@ public struct ConnectionAddressData
[SerializeField]
public string ServerListenAddress;

private static NetworkEndPoint ParseNetworkEndpoint(string ip, ushort port)
private static NetworkEndpoint ParseNetworkEndpoint(string ip, ushort port)
{
if (!NetworkEndPoint.TryParse(ip, port, out var endpoint))
if (!NetworkEndpoint.TryParse(ip, port, out var endpoint))
{
Debug.LogError($"Invalid network endpoint: {ip}:{port}.");
return default;
Expand All @@ -277,12 +281,12 @@ private static NetworkEndPoint ParseNetworkEndpoint(string ip, ushort port)
/// <summary>
/// Endpoint (IP address and port) clients will connect to.
/// </summary>
public NetworkEndPoint ServerEndPoint => ParseNetworkEndpoint(Address, Port);
public NetworkEndpoint ServerEndPoint => ParseNetworkEndpoint(Address, Port);

/// <summary>
/// Endpoint (IP address and port) server will listen/bind on.
/// </summary>
public NetworkEndPoint ListenEndPoint => ParseNetworkEndpoint((ServerListenAddress == string.Empty) ? Address : ServerListenAddress, Port);
public NetworkEndpoint ListenEndPoint => ParseNetworkEndpoint((ServerListenAddress == string.Empty) ? Address : ServerListenAddress, Port);
}

/// <summary>
Expand Down Expand Up @@ -425,7 +429,7 @@ private NetworkPipeline SelectSendPipeline(NetworkDelivery delivery)

private bool ClientBindAndConnect()
{
var serverEndpoint = default(NetworkEndPoint);
var serverEndpoint = default(NetworkEndpoint);

if (m_ProtocolType == ProtocolType.RelayUnityTransport)
{
Expand All @@ -446,7 +450,7 @@ private bool ClientBindAndConnect()

InitDriver();

int result = m_Driver.Bind(NetworkEndPoint.AnyIpv4);
int result = m_Driver.Bind(NetworkEndpoint.AnyIpv4);
if (result != 0)
{
Debug.LogError("Client failed to bind");
Expand All @@ -459,7 +463,7 @@ private bool ClientBindAndConnect()
return true;
}

private bool ServerBindAndListen(NetworkEndPoint endPoint)
private bool ServerBindAndListen(NetworkEndpoint endPoint)
{
InitDriver();

Expand Down Expand Up @@ -536,7 +540,7 @@ public void SetRelayServerData(string ipv4Address, ushort port, byte[] allocatio
{
RelayConnectionData hostConnectionData;

if (!NetworkEndPoint.TryParse(ipv4Address, port, out var serverEndpoint))
if (!NetworkEndpoint.TryParse(ipv4Address, port, out var serverEndpoint))
{
Debug.LogError($"Invalid address {ipv4Address}:{port}");

Expand Down Expand Up @@ -613,7 +617,7 @@ public void SetConnectionData(string ipv4Address, ushort port, string listenAddr
/// </summary>
/// <param name="endPoint">The remote end point</param>
/// <param name="listenEndPoint">The local listen endpoint</param>
public void SetConnectionData(NetworkEndPoint endPoint, NetworkEndPoint listenEndPoint = default)
public void SetConnectionData(NetworkEndpoint endPoint, NetworkEndpoint listenEndPoint = default)
{
string serverAddress = endPoint.Address.Split(':')[0];

Expand Down Expand Up @@ -662,7 +666,7 @@ private bool StartRelayServer()
else
{
m_NetworkSettings.WithRelayParameters(ref m_RelayServerData, m_HeartbeatTimeoutMS);
return ServerBindAndListen(NetworkEndPoint.AnyIpv4);
return ServerBindAndListen(NetworkEndpoint.AnyIpv4);
}
}

Expand Down Expand Up @@ -907,7 +911,11 @@ private void ExtractNetworkMetricsFromPipeline(NetworkPipeline pipeline, Network
{
//Don't need to dispose of the buffers, they are filled with data pointers.
m_Driver.GetPipelineBuffers(pipeline,
#if UTP_TRANSPORT_2_0_ABOVE
NetworkPipelineStageId.Get<NetworkMetricsPipelineStage>(),
#else
NetworkPipelineStageCollection.GetStageId(typeof(NetworkMetricsPipelineStage)),
#endif
networkConnection,
out _,
out _,
Expand All @@ -934,7 +942,11 @@ private int ExtractRtt(NetworkConnection networkConnection)
}

m_Driver.GetPipelineBuffers(m_ReliableSequencedPipeline,
#if UTP_TRANSPORT_2_0_ABOVE
NetworkPipelineStageId.Get<ReliableSequencedPipelineStage>(),
#else
NetworkPipelineStageCollection.GetStageId(typeof(ReliableSequencedPipelineStage)),
#endif
networkConnection,
out _,
out _,
Expand All @@ -956,7 +968,11 @@ private float ExtractPacketLoss(NetworkConnection networkConnection)
}

m_Driver.GetPipelineBuffers(m_ReliableSequencedPipeline,
#if UTP_TRANSPORT_2_0_ABOVE
NetworkPipelineStageId.Get<ReliableSequencedPipelineStage>(),
#else
NetworkPipelineStageCollection.GetStageId(typeof(ReliableSequencedPipelineStage)),
#endif
networkConnection,
out _,
out _,
Expand Down Expand Up @@ -1117,11 +1133,12 @@ public override void Initialize(NetworkManager networkManager = null)
// account for the overhead of its length when we store it in the send queue.
var fragmentationCapacity = m_MaxPayloadSize + BatchedSendQueue.PerMessageOverhead;

m_NetworkSettings
.WithFragmentationStageParameters(payloadCapacity: fragmentationCapacity)
.WithBaselibNetworkInterfaceParameters(
receiveQueueCapacity: m_MaxPacketQueueSize,
sendQueueCapacity: m_MaxPacketQueueSize);
m_NetworkSettings.WithFragmentationStageParameters(payloadCapacity: fragmentationCapacity);
#if !UTP_TRANSPORT_2_0_ABOVE
m_NetworkSettings.WithBaselibNetworkInterfaceParameters(
receiveQueueCapacity: m_MaxPacketQueueSize,
sendQueueCapacity: m_MaxPacketQueueSize);
#endif
#endif
}

Expand Down Expand Up @@ -1306,6 +1323,9 @@ private void ConfigureSimulator()
packetDelayMs: DebugSimulator.PacketDelayMS,
packetJitterMs: DebugSimulator.PacketJitterMS,
packetDropPercentage: DebugSimulator.PacketDropRate
#if UTP_TRANSPORT_2_0_ABOVE
, mode: ApplyMode.AllPackets
#endif
);
}

Expand All @@ -1323,8 +1343,10 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver,
out NetworkPipeline reliableSequencedPipeline)
{
#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
#if !UTP_TRANSPORT_2_0_ABOVE
NetworkPipelineStageCollection.RegisterPipelineStage(new NetworkMetricsPipelineStage());
#endif
#endif

#if UNITY_EDITOR || DEVELOPMENT_BUILD
ConfigureSimulator();
Expand All @@ -1334,34 +1356,50 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver,
maxConnectAttempts: transport.m_MaxConnectAttempts,
connectTimeoutMS: transport.m_ConnectTimeoutMS,
disconnectTimeoutMS: transport.m_DisconnectTimeoutMS,
#if UTP_TRANSPORT_2_0_ABOVE
sendQueueCapacity: m_MaxPacketQueueSize,
receiveQueueCapacity: m_MaxPacketQueueSize,
#endif
heartbeatTimeoutMS: transport.m_HeartbeatTimeoutMS);

driver = NetworkDriver.Create(m_NetworkSettings);

#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
#if UTP_TRANSPORT_2_0_ABOVE
Comment thread
jeffreyrainy marked this conversation as resolved.
driver.RegisterPipelineStage<NetworkMetricsPipelineStage>(new NetworkMetricsPipelineStage());
#endif
#endif

#if UNITY_EDITOR || DEVELOPMENT_BUILD
if (DebugSimulator.PacketDelayMS > 0 || DebugSimulator.PacketDropRate > 0)
{
unreliableFragmentedPipeline = driver.CreatePipeline(
typeof(FragmentationPipelineStage),
typeof(SimulatorPipelineStage),
typeof(SimulatorPipelineStageInSend)
typeof(SimulatorPipelineStage)
#if !UTP_TRANSPORT_2_0_ABOVE
, typeof(SimulatorPipelineStageInSend)
#endif
#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
, typeof(NetworkMetricsPipelineStage)
#endif
);
unreliableSequencedFragmentedPipeline = driver.CreatePipeline(
typeof(FragmentationPipelineStage),
typeof(UnreliableSequencedPipelineStage),
typeof(SimulatorPipelineStage),
typeof(SimulatorPipelineStageInSend)
typeof(SimulatorPipelineStage)
#if !UTP_TRANSPORT_2_0_ABOVE
, typeof(SimulatorPipelineStageInSend)
#endif
#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
,typeof(NetworkMetricsPipelineStage)
#endif
);
reliableSequencedPipeline = driver.CreatePipeline(
typeof(ReliableSequencedPipelineStage),
typeof(SimulatorPipelineStage),
typeof(SimulatorPipelineStageInSend)
typeof(SimulatorPipelineStage)
#if !UTP_TRANSPORT_2_0_ABOVE
, typeof(SimulatorPipelineStageInSend)
#endif
#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
,typeof(NetworkMetricsPipelineStage)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"name": "com.unity.multiplayer.tools",
"expression": "1.0.0-pre.7",
"define": "MULTIPLAYER_TOOLS_1_0_0_PRE_7"
},
{
"name": "com.unity.transport",
"expression": "2.0.0-exp",
Comment thread
jeffreyrainy marked this conversation as resolved.
"define": "UTP_TRANSPORT_2_0_ABOVE"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public IEnumerator TrackPacketLossAsServer()
}

[UnityTest]
#if UTP_TRANSPORT_2_0_ABOVE
[Ignore("Pending adjustment for UTP 2.0")]
Comment thread
jeffreyrainy marked this conversation as resolved.
#endif
public IEnumerator TrackPacketLossAsClient()
{
double packetLossRateMinRange = (m_PacketLossRate-m_PacketLossRangeDelta) / 100d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ private void OnDestroy()

public void Connect()
{
#if UTP_TRANSPORT_2_0_ABOVE
var endpoint = NetworkEndpoint.LoopbackIpv4;
#else
var endpoint = NetworkEndPoint.LoopbackIpv4;
#endif
endpoint.Port = 7777;

m_Connection = m_Driver.Connect(endpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"name": "com.unity.modules.physics",
"expression": "",
"define": "COM_UNITY_MODULES_PHYSICS"
},
{
"name": "com.unity.transport",
"expression": "2.0.0-exp",
"define": "UTP_TRANSPORT_2_0_ABOVE"
}
]
}
}