You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
using Unity.Collections; |
|
using Unity.Collections.LowLevel.Unsafe; |
|
using Unity.Mathematics; |
|
|
|
namespace GameCore.Network |
|
{ |
|
public readonly struct FrameHistoryItem |
|
{ |
|
public readonly ulong mask; |
|
public readonly int frameId; |
|
|
|
public const int kMaxBitCount = 64; |
|
|
|
public bool IsDirty => mask != 0ul; |
|
|
|
private FrameHistoryItem(ulong mask, int frameId) |
|
{ |
|
this.mask = mask; |
|
this.frameId = frameId; |
|
} |
|
|
|
public static unsafe FrameHistoryItem Make<T>(T baseData, T newData, NativeArray<int> fieldSizeArray, int frameId) where T : unmanaged |
|
{ |
|
var basePtr = (byte*) &baseData; |
|
var newPtr = (byte*) &newData; |
|
|
|
ulong mask = 0ul; |
|
var offset = 0; |
|
for (int i = 0, n = math.min(64, fieldSizeArray.Length); i < n; ++i) |
|
{ |
|
var nextOffset = fieldSizeArray[i]; |
|
var fieldSize = nextOffset - offset; |
|
if (UnsafeUtility.MemCmp(basePtr + offset, newPtr + offset, fieldSize) != 0) |
|
{ |
|
mask |= 1ul << i; |
|
} |
|
|
|
offset = nextOffset; |
|
} |
|
|
|
return new FrameHistoryItem(mask, frameId); |
|
} |
|
} |
|
} |