Struct GhostComponentSerializer
Mostly for internal use. A collection helper functions used by code-gen and some runtime systems.
See Ghost
Inherited Members
Namespace: Unity.NetCode .LowLevel .Unsafe
Assembly: Unity.NetCode.dll
Syntax
public struct GhostComponentSerializer
Fields
DynamicBufferComponentMaskBits
The number of change mask bits used the shadow buffer data. The change mask for the buffer is like this:
- 00 : nothing change
- 01 : len is the same, content has changed.
- 10 : len is changed, we consider the content has changed too. (may change in the future).
Declaration
public const int DynamicBufferComponentMaskBits = 2
Field Value
Type | Description |
---|---|
int |
DynamicBufferComponentSnapshotSize
Dynamic Buffer have a special entry in the snapshot data that is used to track the len and offset of the
the buffer data inside the Snapshot
- uint Length: the length of the buffer
- uint Offset: the position in bytes from the beginning of the dynamic data buffer (for that specific history slot)
Declaration
public const int DynamicBufferComponentSnapshotSize = 8
Field Value
Type | Description |
---|---|
int |
Methods
ChangeMaskArraySizeInBytes(int)
Compute the number of bytes necessary to encode the required number of bits
Declaration
public static int ChangeMaskArraySizeInBytes(int numBits)
Parameters
Type | Name | Description |
---|---|---|
int | numBits | Number of bits to convert. |
Returns
Type | Description |
---|---|
int | The min number of bytes to store this number of bits, rounded to the nearest 4 bytes (for data-alignment). |
ChangeMaskArraySizeInUInts(int)
Compute the number of uint necessary to encode the required number of bits
Declaration
public static int ChangeMaskArraySizeInUInts(int numBits)
Parameters
Type | Name | Description |
---|---|---|
int | numBits | Number of bits to convert. |
Returns
Type | Description |
---|---|
int | The uint mask to encode this number of bits. |
ClearSnapshotDataAndMask(IntPtr, int, int, IntPtr, int, int)
Reset the changemask and the snapshot data to the default value (all 0)
Declaration
public static void ClearSnapshotDataAndMask(IntPtr snapshot, int snapshotOffset, int snapshotSize, IntPtr changeMask, int maskOffset, int changeMaskBits)
Parameters
Type | Name | Description |
---|---|---|
Int |
snapshot | Snapshot data |
int | snapshotOffset | Snapshot offset |
int | snapshotSize | Snapshot size |
Int |
changeMask | Change mask |
int | maskOffset | Mask offset |
int | changeMaskBits | Change mask bits |
ConvertToUnsafeList(IntPtr, int)
Helper method to construct an Unsafe
Declaration
public static UnsafeList<float> ConvertToUnsafeList(IntPtr floatData, int len)
Parameters
Returns
Type | Description |
---|---|
Unsafe |
List of converted floats |
CopyFromChangeMask(IntPtr, int, int)
Extract from the source buffer an unsigned integer, representing a portion of a bitmask starting from the given offset and number of bits (up to 32 bits max).
Declaration
public static uint CopyFromChangeMask(IntPtr bitData, int offset, int numBits)
Parameters
Type | Name | Description |
---|---|---|
Int |
bitData | Bitmask array |
int | offset | Offset to extract integer |
int | numBits | Number of bits to extract |
Returns
Type | Description |
---|---|
uint | Extracted unsigned integer |
CopyToChangeMask(IntPtr, uint, int, int)
For internal use only, copy the src
bitmask to a destination buffer,
to the given offset
and for the required number of bits.
Declaration
public static void CopyToChangeMask(IntPtr bitData, uint src, int offset, int numBits)
Parameters
Type | Name | Description |
---|---|---|
Int |
bitData | Destination buffer |
uint | src | Bitmask |
int | offset | Offset to copy to |
int | numBits | Number of bits to copy |
GetDeltaCompressedSizeInBits(uint, uint, in StreamCompressionModel)
The compressed size in bits necessary to encode a given unsigned int value
in delta in respect
to the given baseline
.
Declaration
public static int GetDeltaCompressedSizeInBits(uint value, uint baseline, in StreamCompressionModel model)
Parameters
Type | Name | Description |
---|---|---|
uint | value | the value to encode |
uint | baseline | the baseline used to calculate the delta |
Stream |
model | the compression model to use |
Returns
Type | Description |
---|---|
int | the number of bits necessary to encode the value |
IntPtrCast<T>(ref T)
Return a pointer to the memory address for the given value
instance.
Declaration
public static IntPtr IntPtrCast<T>(ref T value) where T : struct
Parameters
Type | Name | Description |
---|---|---|
T | value | Data |
Returns
Type | Description |
---|---|
Int |
Reference to component type in data |
Type Parameters
Name | Description |
---|---|
T | Component type |
ResetChangeMask(IntPtr, int, int)
For internal use only, reset the bitData
bitmask bits from the given offset
and for the required number of bits.
Declaration
public static void ResetChangeMask(IntPtr bitData, int offset, int numBits)
Parameters
ResetEntityStartBits(int, ref DataStreamWriter, IntPtr)
For internal use only (mostly code gen), reset the recorded start and end position in the compressed bit stream for each individual entity.
Declaration
public static void ResetEntityStartBits(int count, ref DataStreamWriter writer, IntPtr entityStartBit)
Parameters
Type | Name | Description |
---|---|---|
int | count | the lenght of the entityStartBits array to reset |
Data |
writer | the output stream |
Int |
entityStartBit | the array of start/end offset pair to reset |
SizeInSnapshot(in State)
Helper that returns the size in bytes (aligned to 16 bytes boundary) used to store the component data inside Snapshot
Declaration
public static int SizeInSnapshot(in GhostComponentSerializer.State serializer)
Parameters
Type | Name | Description |
---|---|---|
Ghost |
serializer | Serializer state |
Returns
Type | Description |
---|---|
int | Size in bytes (aligned to 16 bytes boundary) |
Remarks
For buffers in particular, the Snapshot
SnapshotSizeAligned(int)
Align the give size to 16 byte boundary.
Declaration
public static int SnapshotSizeAligned(int size)
Parameters
Type | Name | Description |
---|---|---|
int | size | Size to align |
Returns
Type | Description |
---|---|
int | New size aligned to 16 byte |
SnapshotSizeAligned(uint)
Align the give size to 16 byte boundary
Declaration
public static uint SnapshotSizeAligned(uint size)
Parameters
Type | Name | Description |
---|---|---|
uint | size | Size to align |
Returns
Type | Description |
---|---|
uint | New size aligned to 16 byte |
TypeCastReadonly<T>(IntPtr, int)
Helper method to get a reference to a struct data from its address in memory.
Declaration
public static ref readonly T TypeCastReadonly<T>(IntPtr value, int offset = 0) where T : struct
Parameters
Returns
Type | Description |
---|---|
T | Reference to component type in data |
Type Parameters
Name | Description |
---|---|
T | Component type |
TypeCast<T>(IntPtr, int)
Helper method to get a reference to a struct data from its address in memory.
Declaration
public static ref T TypeCast<T>(IntPtr value, int offset = 0) where T : struct
Parameters
Returns
Type | Description |
---|---|
T | Reference to component type in data |
Type Parameters
Name | Description |
---|---|
T | Component type |