com.unity.netcode.gameobjects@1.0.0-pre.8
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [1.0.0-pre.8] - 2022-04-27 ### Changed - `unmanaged` structs are no longer universally accepted as RPC parameters because some structs (i.e., structs with pointers in them, such as `NativeList<T>`) can't be supported by the default memcpy struct serializer. Structs that are intended to be serialized across the network must add `INetworkSerializeByMemcpy` to the interface list (i.e., `struct Foo : INetworkSerializeByMemcpy`). This interface is empty and just serves to mark the struct as compatible with memcpy serialization. For external structs you can't edit, you can pass them to RPCs by wrapping them in `ForceNetworkSerializeByMemcpy<T>`. (#1901) ### Removed - Removed `SIPTransport` (#1870) - Removed `ClientNetworkTransform` from the package samples and moved to Boss Room's Utilities package which can be found [here](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Packages/com.unity.multiplayer.samples.coop/Utilities/Net/ClientAuthority/ClientNetworkTransform.cs). ### Fixed - Fixed `NetworkTransform` generating false positive rotation delta checks when rolling over between 0 and 360 degrees. (#1890) - Fixed client throwing an exception if it has messages in the outbound queue when processing the `NetworkEvent.Disconnect` event and is using UTP. (#1884) - Fixed issue during client synchronization if 'ValidateSceneBeforeLoading' returned false it would halt the client synchronization process resulting in a client that was approved but not synchronized or fully connected with the server. (#1883) - Fixed an issue where UNetTransport.StartServer would return success even if the underlying transport failed to start (#854) - Passing generic types to RPCs no longer causes a native crash (#1901) - Fixed an issue where calling `Shutdown` on a `NetworkManager` that was already shut down would cause an immediate shutdown the next time it was started (basically the fix makes `Shutdown` idempotent). (#1877)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using NUnit.Framework;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
@@ -51,6 +52,184 @@ namespace Unity.Netcode.EditorTests
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
private void RunWriteMethod<T>(string methodName, FastBufferWriter writer, in T value) where T : unmanaged
|
||||
{
|
||||
MethodInfo method = typeof(FastBufferWriter).GetMethod(methodName, new[] { typeof(T).MakeByRefType() });
|
||||
if (method == null)
|
||||
{
|
||||
foreach (var candidateMethod in typeof(FastBufferWriter).GetMethods())
|
||||
{
|
||||
if (candidateMethod.Name == methodName && candidateMethod.IsGenericMethodDefinition)
|
||||
{
|
||||
if (candidateMethod.GetParameters().Length == 0 || (candidateMethod.GetParameters().Length > 1 && !candidateMethod.GetParameters()[1].HasDefaultValue))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (candidateMethod.GetParameters()[0].ParameterType.IsArray)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
method = candidateMethod.MakeGenericMethod(typeof(T));
|
||||
break;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.NotNull(method);
|
||||
|
||||
object[] args = new object[method.GetParameters().Length];
|
||||
args[0] = value;
|
||||
for (var i = 1; i < args.Length; ++i)
|
||||
{
|
||||
args[i] = method.GetParameters()[i].DefaultValue;
|
||||
}
|
||||
method.Invoke(writer, args);
|
||||
}
|
||||
|
||||
private void RunWriteMethod<T>(string methodName, FastBufferWriter writer, in T[] value) where T : unmanaged
|
||||
{
|
||||
MethodInfo method = typeof(FastBufferWriter).GetMethod(methodName, new[] { typeof(T[]) });
|
||||
if (method == null)
|
||||
{
|
||||
foreach (var candidateMethod in typeof(FastBufferWriter).GetMethods())
|
||||
{
|
||||
if (candidateMethod.Name == methodName && candidateMethod.IsGenericMethodDefinition)
|
||||
{
|
||||
if (candidateMethod.GetParameters().Length == 0 || (candidateMethod.GetParameters().Length > 1 && !candidateMethod.GetParameters()[1].HasDefaultValue))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!candidateMethod.GetParameters()[0].ParameterType.IsArray)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
method = candidateMethod.MakeGenericMethod(typeof(T));
|
||||
break;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.NotNull(method);
|
||||
|
||||
object[] args = new object[method.GetParameters().Length];
|
||||
args[0] = value;
|
||||
for (var i = 1; i < args.Length; ++i)
|
||||
{
|
||||
args[i] = method.GetParameters()[i].DefaultValue;
|
||||
}
|
||||
method.Invoke(writer, args);
|
||||
}
|
||||
|
||||
private void RunReadMethod<T>(string methodName, FastBufferReader reader, out T value) where T : unmanaged
|
||||
{
|
||||
MethodInfo method = typeof(FastBufferReader).GetMethod(methodName, new[] { typeof(T).MakeByRefType() });
|
||||
if (method == null)
|
||||
{
|
||||
foreach (var candidateMethod in typeof(FastBufferReader).GetMethods())
|
||||
{
|
||||
if (candidateMethod.Name == methodName && candidateMethod.IsGenericMethodDefinition)
|
||||
{
|
||||
if (candidateMethod.GetParameters().Length == 0 || (candidateMethod.GetParameters().Length > 1 && !candidateMethod.GetParameters()[1].HasDefaultValue))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (candidateMethod.GetParameters()[0].ParameterType.IsArray)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
method = candidateMethod.MakeGenericMethod(typeof(T));
|
||||
break;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
value = new T();
|
||||
|
||||
Assert.NotNull(method);
|
||||
|
||||
object[] args = new object[method.GetParameters().Length];
|
||||
args[0] = value;
|
||||
for (var i = 1; i < args.Length; ++i)
|
||||
{
|
||||
args[i] = method.GetParameters()[i].DefaultValue;
|
||||
}
|
||||
method.Invoke(reader, args);
|
||||
value = (T)args[0];
|
||||
}
|
||||
|
||||
private void RunReadMethod<T>(string methodName, FastBufferReader reader, out T[] value) where T : unmanaged
|
||||
{
|
||||
MethodInfo method = null;
|
||||
|
||||
try
|
||||
{
|
||||
method = typeof(FastBufferReader).GetMethod(methodName, new[] { typeof(T[]).MakeByRefType() });
|
||||
}
|
||||
catch (AmbiguousMatchException)
|
||||
{
|
||||
// skip.
|
||||
}
|
||||
if (method == null)
|
||||
{
|
||||
foreach (var candidateMethod in typeof(FastBufferReader).GetMethods())
|
||||
{
|
||||
if (candidateMethod.Name == methodName && candidateMethod.IsGenericMethodDefinition)
|
||||
{
|
||||
if (candidateMethod.GetParameters().Length == 0 || (candidateMethod.GetParameters().Length > 1 && !candidateMethod.GetParameters()[1].HasDefaultValue))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!candidateMethod.GetParameters()[0].ParameterType.HasElementType || !candidateMethod.GetParameters()[0].ParameterType.GetElementType().IsArray)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
method = candidateMethod.MakeGenericMethod(typeof(T));
|
||||
break;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.NotNull(method);
|
||||
|
||||
value = new T[] { };
|
||||
|
||||
object[] args = new object[method.GetParameters().Length];
|
||||
args[0] = value;
|
||||
for (var i = 1; i < args.Length; ++i)
|
||||
{
|
||||
args[i] = method.GetParameters()[i].DefaultValue;
|
||||
}
|
||||
method.Invoke(reader, args);
|
||||
value = (T[])args[0];
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Generic Checks
|
||||
@@ -66,14 +245,14 @@ namespace Unity.Netcode.EditorTests
|
||||
|
||||
var failMessage = $"RunTypeTest failed with type {typeof(T)} and value {valueToTest}";
|
||||
|
||||
writer.WriteValue(valueToTest);
|
||||
RunWriteMethod(nameof(FastBufferWriter.WriteValue), writer, valueToTest);
|
||||
|
||||
var reader = CommonChecks(writer, valueToTest, writeSize, failMessage);
|
||||
|
||||
using (reader)
|
||||
{
|
||||
Assert.IsTrue(reader.TryBeginRead(FastBufferWriter.GetWriteSize<T>()));
|
||||
reader.ReadValue(out T result);
|
||||
RunReadMethod(nameof(FastBufferReader.ReadValue), reader, out T result);
|
||||
Assert.AreEqual(valueToTest, result);
|
||||
}
|
||||
}
|
||||
@@ -89,14 +268,14 @@ namespace Unity.Netcode.EditorTests
|
||||
|
||||
var failMessage = $"RunTypeTest failed with type {typeof(T)} and value {valueToTest}";
|
||||
|
||||
writer.WriteValueSafe(valueToTest);
|
||||
RunWriteMethod(nameof(FastBufferWriter.WriteValueSafe), writer, valueToTest);
|
||||
|
||||
|
||||
var reader = CommonChecks(writer, valueToTest, writeSize, failMessage);
|
||||
|
||||
using (reader)
|
||||
{
|
||||
reader.ReadValueSafe(out T result);
|
||||
RunReadMethod(nameof(FastBufferReader.ReadValueSafe), reader, out T result);
|
||||
Assert.AreEqual(valueToTest, result);
|
||||
}
|
||||
}
|
||||
@@ -121,7 +300,7 @@ namespace Unity.Netcode.EditorTests
|
||||
Assert.AreEqual(sizeof(int) + sizeof(T) * valueToTest.Length, writeSize);
|
||||
Assert.IsTrue(writer.TryBeginWrite(writeSize + 2), "Writer denied write permission");
|
||||
|
||||
writer.WriteValue(valueToTest);
|
||||
RunWriteMethod(nameof(FastBufferWriter.WriteValue), writer, valueToTest);
|
||||
|
||||
WriteCheckBytes(writer, writeSize);
|
||||
|
||||
@@ -131,7 +310,7 @@ namespace Unity.Netcode.EditorTests
|
||||
VerifyPositionAndLength(reader, writer.Length);
|
||||
|
||||
Assert.IsTrue(reader.TryBeginRead(writeSize));
|
||||
reader.ReadValue(out T[] result);
|
||||
RunReadMethod(nameof(FastBufferReader.ReadValue), reader, out T[] result);
|
||||
VerifyArrayEquality(valueToTest, result, 0);
|
||||
|
||||
VerifyCheckBytes(reader, writeSize);
|
||||
@@ -147,7 +326,7 @@ namespace Unity.Netcode.EditorTests
|
||||
{
|
||||
Assert.AreEqual(sizeof(int) + sizeof(T) * valueToTest.Length, writeSize);
|
||||
|
||||
writer.WriteValueSafe(valueToTest);
|
||||
RunWriteMethod(nameof(FastBufferWriter.WriteValueSafe), writer, valueToTest);
|
||||
|
||||
WriteCheckBytes(writer, writeSize);
|
||||
|
||||
@@ -156,7 +335,7 @@ namespace Unity.Netcode.EditorTests
|
||||
{
|
||||
VerifyPositionAndLength(reader, writer.Length);
|
||||
|
||||
reader.ReadValueSafe(out T[] result);
|
||||
RunReadMethod(nameof(FastBufferReader.ReadValueSafe), reader, out T[] result);
|
||||
VerifyArrayEquality(valueToTest, result, 0);
|
||||
|
||||
VerifyCheckBytes(reader, writeSize);
|
||||
|
||||
Reference in New Issue
Block a user