Skip to content

chore(backport): Updating collections and UTP (#1451) #1452

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

Merged
merged 1 commit into from
Nov 24, 2021
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
2 changes: 2 additions & 0 deletions com.unity.netcode.adapter.utp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to this package will be documented in this file. The format
### Changed

- Removed 'Maximum Packet Size' configuration field in the inspector. This would cause confusion since the maximum packet size is in effect always the MTU (1400 bytes on most platforms).
- Updated com.unity.transport to 1.0.0-pre.8


### Fixed

Expand Down
56 changes: 25 additions & 31 deletions com.unity.netcode.adapter.utp/Runtime/UnityTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static implicit operator ConnectionAddressData(NetworkEndPoint d) =>

private State m_State = State.Disconnected;
private NetworkDriver m_Driver;
private List<INetworkParameter> m_NetworkParameters;
private NetworkSettings m_NetworkSettings;
private byte[] m_MessageBuffer;
private NetworkConnection m_ServerConnection;
private ulong m_ServerClientId;
Expand Down Expand Up @@ -240,7 +240,7 @@ private bool ClientBindAndConnect()
return false;
}

m_NetworkParameters.Add(new RelayNetworkParameter { ServerData = m_RelayServerData });
m_NetworkSettings.WithRelayParameters(ref m_RelayServerData);
}
else
{
Expand Down Expand Up @@ -394,7 +394,7 @@ private bool StartRelayServer()
}
else
{
m_NetworkParameters.Add(new RelayNetworkParameter { ServerData = m_RelayServerData });
m_NetworkSettings.WithRelayParameters(ref m_RelayServerData);
return ServerBindAndListen(NetworkEndPoint.AnyIpv4);
}
}
Expand Down Expand Up @@ -597,21 +597,20 @@ public override void Initialize()
Debug.Assert(sizeof(ulong) == UnsafeUtility.SizeOf<NetworkConnection>(),
"Netcode connection id size does not match UTP connection id size");

m_NetworkParameters = new List<INetworkParameter>();
m_NetworkSettings = new NetworkSettings(Allocator.Persistent);

// If the user sends a message of exactly m_SendQueueBatchSize length, we'll need an
// extra byte to mark it as non-batched and 4 bytes for its length. If the user fills
// up the send queue to its capacity (batched messages total m_SendQueueBatchSize), we
// still need one extra byte to mark the payload as batched.
var fragmentationCapacity = m_SendQueueBatchSize + 1 + 4;
m_NetworkParameters.Add(new FragmentationUtility.Parameters() { PayloadCapacity = fragmentationCapacity });

m_NetworkParameters.Add(new BaselibNetworkParameter()
{
maximumPayloadSize = 2000, // Default value in UTP.
receiveQueueCapacity = m_MaxPacketQueueSize,
sendQueueCapacity = m_MaxPacketQueueSize
});
m_NetworkSettings
.WithFragmentationStageParameters(payloadCapacity: fragmentationCapacity)
.WithBaselibNetworkInterfaceParameters(
maximumPayloadSize: 2000,
receiveQueueCapacity: m_MaxPacketQueueSize,
sendQueueCapacity: m_MaxPacketQueueSize);
}

public override NetcodeNetworkEvent PollEvent(out ulong clientId, out ArraySegment<byte> payload, out float receiveTime)
Expand Down Expand Up @@ -774,13 +773,16 @@ public override void Shutdown()
return;
}


// Flush the driver's internal send queue. If we're shutting down because the
// NetworkManager is shutting down, it probably has disconnected some peer(s)
// in the process and we want to get these disconnect messages on the wire.
m_Driver.ScheduleFlushSend(default).Complete();

DisposeDriver();

m_NetworkSettings.Dispose();

foreach (var queue in m_SendQueue.Values)
{
queue.Dispose();
Expand All @@ -795,31 +797,23 @@ public override void Shutdown()

public void CreateDriver(UnityTransport transport, out NetworkDriver driver, out NetworkPipeline unreliableSequencedPipeline, out NetworkPipeline reliableSequencedFragmentedPipeline)
{
var netParams = new NetworkConfigParameter
{
maxConnectAttempts = transport.m_MaxConnectAttempts,
connectTimeoutMS = transport.m_ConnectTimeoutMS,
disconnectTimeoutMS = transport.m_DisconnectTimeoutMS,
heartbeatTimeoutMS = transport.m_HeartbeatTimeoutMS,
maxFrameTimeMS = 0
};
var maxFrameTimeMS = 0;

#if UNITY_EDITOR || DEVELOPMENT_BUILD
netParams.maxFrameTimeMS = 100;
maxFrameTimeMS = 100;

var simulatorParams = ClientSimulatorParameters;
transport.m_NetworkParameters.Insert(0, simulatorParams);
#endif
transport.m_NetworkParameters.Insert(0, netParams);

if (transport.m_NetworkParameters.Count > 0)
{
driver = NetworkDriver.Create(transport.m_NetworkParameters.ToArray());
}
else
{
driver = NetworkDriver.Create();
}
m_NetworkSettings.AddRawParameterStruct(ref simulatorParams);
#endif
m_NetworkSettings.WithNetworkConfigParameters(
maxConnectAttempts: transport.m_MaxConnectAttempts,
connectTimeoutMS: transport.m_ConnectTimeoutMS,
disconnectTimeoutMS: transport.m_DisconnectTimeoutMS,
heartbeatTimeoutMS: transport.m_HeartbeatTimeoutMS,
maxFrameTimeMS: maxFrameTimeMS);

driver = NetworkDriver.Create(m_NetworkSettings);
#if UNITY_EDITOR || DEVELOPMENT_BUILD
if (simulatorParams.PacketDelayMs > 0 || simulatorParams.PacketDropInterval > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ public class DriverClient : MonoBehaviour

private void Awake()
{

var maxCap = UnityTransport.InitialBatchQueueSize + 128;

var settings = new NetworkSettings();
settings.WithFragmentationStageParameters(payloadCapacity: maxCap);

var fragParams = new FragmentationUtility.Parameters() { PayloadCapacity = maxCap };

m_Driver = NetworkDriver.Create(fragParams);
m_Driver = NetworkDriver.Create(settings);

m_UnreliableSequencedPipeline = m_Driver.CreatePipeline(typeof(UnreliableSequencedPipelineStage));
m_ReliableSequencedPipeline = m_Driver.CreatePipeline(typeof(ReliableSequencedPipelineStage));
Expand Down
2 changes: 1 addition & 1 deletion com.unity.netcode.adapter.utp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"unity": "2020.3",
"dependencies": {
"com.unity.netcode.gameobjects": "1.0.0-pre.3",
"com.unity.transport": "1.0.0-pre.7"
"com.unity.transport": "1.0.0-pre.8"
}
}
28 changes: 28 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).

## [Unreleased]

### Added

### Removed

- Removed `FixedQueue` (#1398)
- Removed `StreamExtensions` (#1398)
- Removed `TypeExtensions` (#1398)

### Fixed

- Fixed in-scene NetworkObjects that are moved into the DDOL scene not getting restored to their original active state (enabled/disabled) after a full scene transition (#1354)
- Fixed invalid IL code being generated when using `this` instead of `this ref` for the FastBufferReader/FastBufferWriter parameter of an extension method. (#1393)
- Fixed an issue where if you are running as a server (not host) the LoadEventCompleted and UnloadEventCompleted events would fire early by the NetworkSceneManager (#1379)
- Fixed a runtime error when sending an array of an INetworkSerializable type that's implemented as a struct (#1402)
- NetworkConfig will no longer throw an OverflowException in GetConfig() when ForceSamePrefabs is enabled and the number of prefabs causes the config blob size to exceed 1300 bytes. (#1385)
- Fixed NetworkVariable not calling NetworkSerialize on INetworkSerializable types (#1383)
- Fixed NullReferenceException on ImportReferences call in NetworkBehaviourILPP (#1434)

- Fixed NetworkObjects not being despawned before they are destroyed during shutdown for client, host, and server instances. (#1390)

### Changed

- The SDK no longer limits message size to 64k. (The transport may still impose its own limits, but the SDK no longer does.) (#1384)
- Updated com.unity.collections to 1.1.0 (#1451)


## [1.0.0-pre.3] - 2021-10-22

### Added
Expand Down
2 changes: 1 addition & 1 deletion com.unity.netcode.gameobjects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.nuget.mono-cecil": "1.10.1",
"com.unity.collections": "1.0.0-pre.5"
"com.unity.collections": "1.1.0"
}
}