Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Changed

- Improve performance of `ParentSyncMessage`. (#3814)
- Improve performance of `DestroyObjectMessage`. (#3801)
- Improve performance of `CreateObjectMessage`. (#3800)
- First pass of CoreCLR engine API changes. (#3799)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,23 @@ internal struct ParentSyncMessage : INetworkMessage

public ulong NetworkObjectId;

private byte m_BitField;
private const byte k_WorldPositionStays = 0x01;
private const byte k_IsLatestParentSet = 0x02;
private const byte k_RemoveParent = 0x04;
private const byte k_AuthorityApplied = 0x08;

public bool WorldPositionStays
{
get => ByteUtility.GetBit(m_BitField, 0);
set => ByteUtility.SetBit(ref m_BitField, 0, value);
}
public bool WorldPositionStays;

//If(Metadata.IsReparented)
public bool IsLatestParentSet
{
get => ByteUtility.GetBit(m_BitField, 1);
set => ByteUtility.SetBit(ref m_BitField, 1, value);
}
public bool IsLatestParentSet;

//If(IsLatestParentSet)
public ulong? LatestParent;

// Is set when the parent should be removed (similar to IsReparented functionality but only for removing the parent)
public bool RemoveParent
{
get => ByteUtility.GetBit(m_BitField, 2);
set => ByteUtility.SetBit(ref m_BitField, 2, value);
}
public bool RemoveParent;

public bool AuthorityApplied
{
get => ByteUtility.GetBit(m_BitField, 3);
set => ByteUtility.SetBit(ref m_BitField, 3, value);
}
public bool AuthorityApplied;

// These additional properties are used to synchronize clients with the current position,
// rotation, and scale after parenting/de-parenting (world/local space relative). This
Expand All @@ -51,8 +38,16 @@ public bool AuthorityApplied

public void Serialize(FastBufferWriter writer, int targetVersion)
{

byte bitset = 0x00;
if (WorldPositionStays) { bitset |= k_WorldPositionStays; }
if (IsLatestParentSet) { bitset |= k_IsLatestParentSet; }
if (RemoveParent) { bitset |= k_RemoveParent; }
if (AuthorityApplied) { bitset |= k_AuthorityApplied; }

BytePacker.WriteValueBitPacked(writer, NetworkObjectId);
writer.WriteValueSafe(m_BitField);
writer.WriteByteSafe(bitset);

if (!RemoveParent)
{
if (IsLatestParentSet)
Expand All @@ -72,7 +67,12 @@ public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int
var networkManager = (NetworkManager)context.SystemOwner;

ByteUnpacker.ReadValueBitPacked(reader, out NetworkObjectId);
reader.ReadValueSafe(out m_BitField);
reader.ReadByteSafe(out byte bitset);
WorldPositionStays = (bitset & k_WorldPositionStays) != 0;
IsLatestParentSet = (bitset & k_IsLatestParentSet) != 0;
RemoveParent = (bitset & k_RemoveParent) != 0;
AuthorityApplied = (bitset & k_AuthorityApplied) != 0;

if (!RemoveParent)
{
if (IsLatestParentSet)
Expand Down