com.unity.netcode.gameobjects@1.0.0-pre.3
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.3] - 2021-10-22 ### Added - ResetTrigger function to NetworkAnimator (#1327) ### Fixed - Overflow exception when syncing Animator state. (#1327) - Added `try`/`catch` around RPC calls, preventing exception from causing further RPC calls to fail (#1329) - Fixed an issue where ServerClientId and LocalClientId could have the same value, causing potential confusion, and also fixed an issue with the UNet where the server could be identified with two different values, one of which might be the same as LocalClientId, and the other of which would not.(#1368) - IL2CPP would not properly compile (#1359)
This commit is contained in:
@@ -24,6 +24,8 @@ namespace Unity.Netcode
|
||||
|
||||
internal readonly unsafe WriterHandle* Handle;
|
||||
|
||||
private static byte[] s_ByteArrayCache = new byte[65535];
|
||||
|
||||
/// <summary>
|
||||
/// The current write position
|
||||
/// </summary>
|
||||
@@ -78,6 +80,10 @@ namespace Unity.Netcode
|
||||
/// <param name="maxSize">Maximum size the buffer can grow to. If less than size, buffer cannot grow.</param>
|
||||
public unsafe FastBufferWriter(int size, Allocator allocator, int maxSize = -1)
|
||||
{
|
||||
// Allocating both the Handle struct and the buffer in a single allocation - sizeof(WriterHandle) + size
|
||||
// The buffer for the initial allocation is the next block of memory after the handle itself.
|
||||
// If the buffer grows, a new buffer will be allocated and the handle pointer pointed at the new location...
|
||||
// The original buffer won't be deallocated until the writer is destroyed since it's part of the handle allocation.
|
||||
Handle = (WriterHandle*)UnsafeUtility.Malloc(sizeof(WriterHandle) + size, UnsafeUtility.AlignOf<WriterHandle>(), allocator);
|
||||
#if DEVELOPMENT_BUILD || UNITY_EDITOR
|
||||
UnsafeUtility.MemSet(Handle, 0, sizeof(WriterHandle) + size);
|
||||
@@ -349,6 +355,29 @@ namespace Unity.Netcode
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses a static cached array to create an array segment with no allocations.
|
||||
/// This array can only be used until the next time ToTempByteArray() is called on ANY FastBufferWriter,
|
||||
/// as the cached buffer is shared by all of them and will be overwritten.
|
||||
/// As such, this should be used with care.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal unsafe ArraySegment<byte> ToTempByteArray()
|
||||
{
|
||||
var length = Length;
|
||||
if (length > s_ByteArrayCache.Length)
|
||||
{
|
||||
return new ArraySegment<byte>(ToArray(), 0, length);
|
||||
}
|
||||
|
||||
fixed (byte* b = s_ByteArrayCache)
|
||||
{
|
||||
UnsafeUtility.MemCpy(b, Handle->BufferPointer, length);
|
||||
}
|
||||
|
||||
return new ArraySegment<byte>(s_ByteArrayCache, 0, length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a direct pointer to the underlying buffer
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user