com.unity.netcode.gameobjects@2.0.0-pre.1
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). ## [2.0.0-pre.1] - 2024-06-17 ### Added - Added event `NetworkManager.OnSessionOwnerPromoted` that is invoked when a new session owner promotion occurs. (#2948) - Added `NetworkRigidBodyBase.GetLinearVelocity` and `NetworkRigidBodyBase.SetLinearVelocity` convenience/helper methods. (#2948) - Added `NetworkRigidBodyBase.GetAngularVelocity` and `NetworkRigidBodyBase.SetAngularVelocity` convenience/helper methods. (#2948) ### Fixed - Fixed issue when `NetworkTransform` half float precision is enabled and ownership changes the current base position was not being synchronized. (#2948) - Fixed issue where `OnClientConnected` not being invoked on the session owner when connecting to a new distributed authority session. (#2948) - Fixed issue where Rigidbody micro-motion (i.e. relatively small velocities) would result in non-authority instances slightly stuttering as the body would come to a rest (i.e. no motion). Now, the threshold value can increase at higher velocities and can decrease slightly below the provided threshold to account for this. (#2948) ### Changed - Changed the client's owned objects is now returned (`NetworkClient` and `NetworkSpawnManager`) as an array as opposed to a list for performance purposes. (#2948) - Changed `NetworkTransfrom.TryCommitTransformToServer` to be internal as it will be removed by the final 2.0.0 release. (#2948) - Changed `NetworkTransformEditor.OnEnable` to a virtual method to be able to customize a `NetworkTransform` derived class by creating a derived editor control from `NetworkTransformEditor`. (#2948)
This commit is contained in:
@@ -523,8 +523,8 @@ namespace Unity.Netcode
|
||||
/// <param name="oneByteChars">Whether or not to use one byte per character. This will only allow ASCII</param>
|
||||
public unsafe void ReadValue(out string s, bool oneByteChars = false)
|
||||
{
|
||||
ReadValue(out uint length);
|
||||
s = "".PadRight((int)length);
|
||||
ReadLength(out int length);
|
||||
s = "".PadRight(length);
|
||||
int target = s.Length;
|
||||
fixed (char* native = s)
|
||||
{
|
||||
@@ -562,18 +562,18 @@ namespace Unity.Netcode
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!TryBeginReadInternal(sizeof(uint)))
|
||||
if (!TryBeginReadInternal(SizeOfLengthField()))
|
||||
{
|
||||
throw new OverflowException("Reading past the end of the buffer");
|
||||
}
|
||||
|
||||
ReadValue(out uint length);
|
||||
ReadLength(out int length);
|
||||
|
||||
if (!TryBeginReadInternal((int)length * (oneByteChars ? 1 : sizeof(char))))
|
||||
if (!TryBeginReadInternal(length * (oneByteChars ? 1 : sizeof(char))))
|
||||
{
|
||||
throw new OverflowException("Reading past the end of the buffer");
|
||||
}
|
||||
s = "".PadRight((int)length);
|
||||
s = "".PadRight(length);
|
||||
int target = s.Length;
|
||||
fixed (char* native = s)
|
||||
{
|
||||
@@ -592,6 +592,33 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int SizeOfLengthField() => sizeof(uint);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ReadLengthSafe(out uint length) => ReadUnmanagedSafe(out length);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ReadLength(out uint length) => ReadUnmanaged(out length);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ReadLengthSafe(out int length)
|
||||
{
|
||||
ReadLengthSafe(out uint temp);
|
||||
if (temp > int.MaxValue)
|
||||
{
|
||||
throw new InvalidCastException("length value outside of int32 range");
|
||||
}
|
||||
length = (int)temp;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ReadLength(out int length)
|
||||
{
|
||||
ReadLength(out uint temp);
|
||||
length = (int)temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a partial value. The value is zero-initialized and then the specified number of bytes is read into it.
|
||||
/// </summary>
|
||||
@@ -777,7 +804,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanaged<T>(out T[] value) where T : unmanaged
|
||||
{
|
||||
ReadUnmanaged(out int sizeInTs);
|
||||
ReadLength(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value = new T[sizeInTs];
|
||||
fixed (T* ptr = value)
|
||||
@@ -789,7 +816,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanagedSafe<T>(out T[] value) where T : unmanaged
|
||||
{
|
||||
ReadUnmanagedSafe(out int sizeInTs);
|
||||
ReadLengthSafe(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value = new T[sizeInTs];
|
||||
fixed (T* ptr = value)
|
||||
@@ -801,7 +828,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanaged<T>(out NativeArray<T> value, Allocator allocator) where T : unmanaged
|
||||
{
|
||||
ReadUnmanaged(out int sizeInTs);
|
||||
ReadLength(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value = new NativeArray<T>(sizeInTs, allocator);
|
||||
byte* bytes = (byte*)value.GetUnsafePtr();
|
||||
@@ -810,7 +837,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanagedSafe<T>(out NativeArray<T> value, Allocator allocator) where T : unmanaged
|
||||
{
|
||||
ReadUnmanagedSafe(out int sizeInTs);
|
||||
ReadLengthSafe(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value = new NativeArray<T>(sizeInTs, allocator);
|
||||
byte* bytes = (byte*)value.GetUnsafePtr();
|
||||
@@ -820,7 +847,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanagedInPlace<T>(ref NativeList<T> value) where T : unmanaged
|
||||
{
|
||||
ReadUnmanaged(out int sizeInTs);
|
||||
ReadLength(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value.Resize(sizeInTs, NativeArrayOptions.UninitializedMemory);
|
||||
byte* bytes = (byte*)value.GetUnsafePtr();
|
||||
@@ -829,7 +856,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanagedSafeInPlace<T>(ref NativeList<T> value) where T : unmanaged
|
||||
{
|
||||
ReadUnmanagedSafe(out int sizeInTs);
|
||||
ReadLengthSafe(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value.Resize(sizeInTs, NativeArrayOptions.UninitializedMemory);
|
||||
byte* bytes = (byte*)value.GetUnsafePtr();
|
||||
@@ -1078,7 +1105,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void ReadValueSafeInPlace<T>(ref NativeHashSet<T> value) where T : unmanaged, IEquatable<T>
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
ReadLengthSafe(out int length);
|
||||
value.Clear();
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
@@ -1093,7 +1120,7 @@ namespace Unity.Netcode
|
||||
where TKey : unmanaged, IEquatable<TKey>
|
||||
where TVal : unmanaged
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
ReadLengthSafe(out int length);
|
||||
value.Clear();
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
@@ -1553,7 +1580,7 @@ namespace Unity.Netcode
|
||||
/// This method is a little difficult to use, since you have to know the size of the string before
|
||||
/// reading it, but is useful when the string is a known, fixed size. Note that the size of the
|
||||
/// string is also encoded, so the size to call TryBeginRead on is actually the fixed size (in bytes)
|
||||
/// plus sizeof(int)
|
||||
/// plus sizeof(uint)
|
||||
/// </summary>
|
||||
/// <param name="value">the value to read</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
@@ -1562,7 +1589,7 @@ namespace Unity.Netcode
|
||||
public unsafe void ReadValue<T>(out T value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanaged(out int length);
|
||||
ReadLength(out int length);
|
||||
value = new T
|
||||
{
|
||||
Length = length
|
||||
@@ -1584,7 +1611,7 @@ namespace Unity.Netcode
|
||||
public unsafe void ReadValueSafe<T>(out T value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
ReadLengthSafe(out int length);
|
||||
value = new T
|
||||
{
|
||||
Length = length
|
||||
@@ -1606,7 +1633,7 @@ namespace Unity.Netcode
|
||||
public unsafe void ReadValueSafeInPlace<T>(ref T value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
ReadLengthSafe(out int length);
|
||||
value.Length = length;
|
||||
ReadBytesSafe(value.GetUnsafePtr(), length);
|
||||
}
|
||||
@@ -1625,7 +1652,7 @@ namespace Unity.Netcode
|
||||
public unsafe void ReadValueSafe<T>(out NativeArray<T> value, Allocator allocator)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
ReadLengthSafe(out int length);
|
||||
value = new NativeArray<T>(length, allocator);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
for (var i = 0; i < length; ++i)
|
||||
@@ -1647,7 +1674,7 @@ namespace Unity.Netcode
|
||||
public unsafe void ReadValueSafeTemp<T>(out NativeArray<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
ReadLengthSafe(out int length);
|
||||
value = new NativeArray<T>(length, Allocator.Temp);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
for (var i = 0; i < length; ++i)
|
||||
@@ -1669,7 +1696,7 @@ namespace Unity.Netcode
|
||||
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
ReadLengthSafe(out int length);
|
||||
value = new T[length];
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
@@ -1691,7 +1718,7 @@ namespace Unity.Netcode
|
||||
public void ReadValueSafeInPlace<T>(ref NativeList<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
ReadLengthSafe(out int length);
|
||||
value.Resize(length, NativeArrayOptions.UninitializedMemory);
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
|
||||
@@ -421,7 +421,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int GetWriteSize(string s, bool oneByteChars = false)
|
||||
{
|
||||
return sizeof(int) + s.Length * (oneByteChars ? sizeof(byte) : sizeof(char));
|
||||
return SizeOfLengthField() + s.Length * (oneByteChars ? sizeof(byte) : sizeof(char));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -445,7 +445,7 @@ namespace Unity.Netcode
|
||||
public void WriteNetworkSerializable<T>(T[] array, int count = -1, int offset = 0) where T : INetworkSerializable
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
WriteValueSafe(sizeInTs);
|
||||
WriteLengthSafe(sizeInTs);
|
||||
foreach (var item in array)
|
||||
{
|
||||
WriteNetworkSerializable(item);
|
||||
@@ -462,7 +462,7 @@ namespace Unity.Netcode
|
||||
public void WriteNetworkSerializable<T>(NativeArray<T> array, int count = -1, int offset = 0) where T : unmanaged, INetworkSerializable
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
WriteValueSafe(sizeInTs);
|
||||
WriteLengthSafe(sizeInTs);
|
||||
foreach (var item in array)
|
||||
{
|
||||
WriteNetworkSerializable(item);
|
||||
@@ -480,7 +480,7 @@ namespace Unity.Netcode
|
||||
public void WriteNetworkSerializable<T>(NativeList<T> array, int count = -1, int offset = 0) where T : unmanaged, INetworkSerializable
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
WriteValueSafe(sizeInTs);
|
||||
WriteLengthSafe(sizeInTs);
|
||||
foreach (var item in array)
|
||||
{
|
||||
WriteNetworkSerializable(item);
|
||||
@@ -495,7 +495,7 @@ namespace Unity.Netcode
|
||||
/// <param name="oneByteChars">Whether or not to use one byte per character. This will only allow ASCII</param>
|
||||
public unsafe void WriteValue(string s, bool oneByteChars = false)
|
||||
{
|
||||
WriteValue((uint)s.Length);
|
||||
WriteLength((uint)s.Length);
|
||||
int target = s.Length;
|
||||
if (oneByteChars)
|
||||
{
|
||||
@@ -538,7 +538,7 @@ namespace Unity.Netcode
|
||||
throw new OverflowException("Writing past the end of the buffer");
|
||||
}
|
||||
|
||||
WriteValue((uint)s.Length);
|
||||
WriteLength((uint)s.Length);
|
||||
int target = s.Length;
|
||||
if (oneByteChars)
|
||||
{
|
||||
@@ -569,7 +569,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
return sizeof(int) + sizeInBytes;
|
||||
return SizeOfLengthField() + sizeInBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -585,7 +585,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
return sizeof(int) + sizeInBytes;
|
||||
return SizeOfLengthField() + sizeInBytes;
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
@@ -602,7 +602,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
return sizeof(int) + sizeInBytes;
|
||||
return SizeOfLengthField() + sizeInBytes;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -876,7 +876,7 @@ namespace Unity.Netcode
|
||||
public static int GetWriteSize<T>(in T value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
return value.Length + sizeof(int);
|
||||
return SizeOfLengthField() + value.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -888,10 +888,10 @@ namespace Unity.Netcode
|
||||
public static int GetWriteSize<T>(in NativeArray<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
var size = sizeof(int);
|
||||
var size = SizeOfLengthField();
|
||||
foreach (var item in value)
|
||||
{
|
||||
size += sizeof(int) + item.Length;
|
||||
size += SizeOfLengthField() + item.Length;
|
||||
}
|
||||
|
||||
return size;
|
||||
@@ -907,10 +907,10 @@ namespace Unity.Netcode
|
||||
public static int GetWriteSize<T>(in NativeList<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
var size = sizeof(int);
|
||||
var size = SizeOfLengthField();
|
||||
foreach (var item in value)
|
||||
{
|
||||
size += sizeof(int) + item.Length;
|
||||
size += SizeOfLengthField() + item.Length;
|
||||
}
|
||||
|
||||
return size;
|
||||
@@ -946,10 +946,32 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int SizeOfLengthField() => sizeof(uint);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void WriteLengthSafe(uint length) => WriteUnmanagedSafe(length);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void WriteLength(uint length) => WriteUnmanaged(length);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void WriteLengthSafe(int length)
|
||||
{
|
||||
if (length < 0)
|
||||
{
|
||||
throw new InvalidCastException("Cannot write negative length");
|
||||
}
|
||||
WriteLengthSafe((uint)length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void WriteLength(int length) => WriteLength((uint)length);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanaged<T>(T[] value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
WriteLength(value.Length);
|
||||
fixed (T* ptr = value)
|
||||
{
|
||||
byte* bytes = (byte*)ptr;
|
||||
@@ -959,7 +981,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanagedSafe<T>(T[] value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanagedSafe(value.Length);
|
||||
WriteLengthSafe(value.Length);
|
||||
fixed (T* ptr = value)
|
||||
{
|
||||
byte* bytes = (byte*)ptr;
|
||||
@@ -970,7 +992,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanaged<T>(NativeArray<T> value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
WriteLength(value.Length);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
{
|
||||
byte* bytes = (byte*)ptr;
|
||||
@@ -980,7 +1002,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanagedSafe<T>(NativeArray<T> value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanagedSafe(value.Length);
|
||||
WriteLengthSafe(value.Length);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
{
|
||||
byte* bytes = (byte*)ptr;
|
||||
@@ -992,7 +1014,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanaged<T>(NativeList<T> value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
WriteLength(value.Length);
|
||||
#if UTP_TRANSPORT_2_0_ABOVE
|
||||
var ptr = value.GetUnsafePtr();
|
||||
#else
|
||||
@@ -1006,7 +1028,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanagedSafe<T>(NativeList<T> value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanagedSafe(value.Length);
|
||||
WriteLengthSafe(value.Length);
|
||||
#if UTP_TRANSPORT_2_0_ABOVE
|
||||
var ptr = value.GetUnsafePtr();
|
||||
#else
|
||||
@@ -1210,9 +1232,9 @@ namespace Unity.Netcode
|
||||
internal void WriteValueSafe<T>(NativeHashSet<T> value) where T : unmanaged, IEquatable<T>
|
||||
{
|
||||
#if UTP_TRANSPORT_2_0_ABOVE
|
||||
WriteUnmanagedSafe(value.Count);
|
||||
WriteLengthSafe(value.Count);
|
||||
#else
|
||||
WriteUnmanagedSafe(value.Count());
|
||||
WriteLengthSafe(value.Count());
|
||||
#endif
|
||||
foreach (var item in value)
|
||||
{
|
||||
@@ -1227,9 +1249,9 @@ namespace Unity.Netcode
|
||||
where TVal : unmanaged
|
||||
{
|
||||
#if UTP_TRANSPORT_2_0_ABOVE
|
||||
WriteUnmanagedSafe(value.Count);
|
||||
WriteLengthSafe(value.Count);
|
||||
#else
|
||||
WriteUnmanagedSafe(value.Count());
|
||||
WriteLengthSafe(value.Count());
|
||||
#endif
|
||||
foreach (var item in value)
|
||||
{
|
||||
@@ -1765,7 +1787,8 @@ namespace Unity.Netcode
|
||||
public unsafe void WriteValue<T>(in T value, ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
// BytePacker.WriteValuePacked(this, value.Length);
|
||||
WriteLength(value.Length);
|
||||
// This avoids a copy on the string, which could be costly for FixedString4096Bytes
|
||||
// Otherwise, GetUnsafePtr() is an impure function call and will result in a copy
|
||||
// for `in` parameters.
|
||||
@@ -1787,7 +1810,7 @@ namespace Unity.Netcode
|
||||
public void WriteValue<T>(T[] value, ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
WriteLength(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
@@ -1806,7 +1829,7 @@ namespace Unity.Netcode
|
||||
public void WriteValue<T>(in NativeArray<T> value, ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
WriteLength(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
@@ -1826,7 +1849,7 @@ namespace Unity.Netcode
|
||||
public void WriteValue<T>(in NativeList<T> value, ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
WriteLength(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
@@ -1848,7 +1871,7 @@ namespace Unity.Netcode
|
||||
public void WriteValueSafe<T>(in T value, ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
if (!TryBeginWriteInternal(sizeof(int) + value.Length))
|
||||
if (!TryBeginWriteInternal(SizeOfLengthField() + value.Length))
|
||||
{
|
||||
throw new OverflowException("Writing past the end of the buffer");
|
||||
}
|
||||
@@ -1871,7 +1894,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
throw new OverflowException("Writing past the end of the buffer");
|
||||
}
|
||||
WriteUnmanaged(value.Length);
|
||||
WriteLength(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
@@ -1894,7 +1917,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
throw new OverflowException("Writing past the end of the buffer");
|
||||
}
|
||||
WriteUnmanaged(value.Length);
|
||||
WriteLength(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
@@ -1918,7 +1941,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
throw new OverflowException("Writing past the end of the buffer");
|
||||
}
|
||||
WriteUnmanaged(value.Length);
|
||||
WriteLength(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
|
||||
Reference in New Issue
Block a user