mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
selective sync
This commit is contained in:
parent
b796b6d3e6
commit
23d5992404
@ -301,42 +301,67 @@ protected virtual bool Validate(Vector3 localPosition, Quaternion localRotation,
|
|||||||
// it's then either sent fully (initial) or delta compressed.
|
// it's then either sent fully (initial) or delta compressed.
|
||||||
void SerializeEverything(NetworkWriter writer)
|
void SerializeEverything(NetworkWriter writer)
|
||||||
{
|
{
|
||||||
|
// delta compression filters out unchanged data.
|
||||||
|
// however, we still only serialize selectively instead of writing all.
|
||||||
|
// reduces bittree hierarchy depth, initial spawn packet etc.
|
||||||
|
|
||||||
// position, quantized to longs
|
// position, quantized to longs
|
||||||
|
if (syncPosition)
|
||||||
|
{
|
||||||
Compression.ScaleToLong(targetComponent.localPosition, positionPrecision, out long pX, out long pY, out long pZ); // local for VR
|
Compression.ScaleToLong(targetComponent.localPosition, positionPrecision, out long pX, out long pY, out long pZ); // local for VR
|
||||||
writer.WriteLong(pX);
|
writer.WriteLong(pX);
|
||||||
writer.WriteLong(pY);
|
writer.WriteLong(pY);
|
||||||
writer.WriteLong(pZ);
|
writer.WriteLong(pZ);
|
||||||
|
}
|
||||||
|
|
||||||
// rotation:
|
// rotation
|
||||||
|
if (syncRotation)
|
||||||
|
{
|
||||||
// TODO quantization later.
|
// TODO quantization later.
|
||||||
// TODO ensure it's exactly the same if not rotated.
|
// TODO ensure it's exactly the same if not rotated.
|
||||||
writer.WriteQuaternion(targetComponent.localRotation);
|
writer.WriteQuaternion(targetComponent.localRotation);
|
||||||
|
}
|
||||||
|
|
||||||
// scale, quantized to longs
|
// scale, quantized to longs
|
||||||
|
if (syncScale)
|
||||||
|
{
|
||||||
Compression.ScaleToLong(targetComponent.localScale, scalePrecision, out long sX, out long sY, out long sZ); // local for VR
|
Compression.ScaleToLong(targetComponent.localScale, scalePrecision, out long sX, out long sY, out long sZ); // local for VR
|
||||||
writer.WriteLong(sX);
|
writer.WriteLong(sX);
|
||||||
writer.WriteLong(sY);
|
writer.WriteLong(sY);
|
||||||
writer.WriteLong(sZ);
|
writer.WriteLong(sZ);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// deserialize full data after delta compression
|
// deserialize data after delta compression
|
||||||
void DeserializeEverything(NetworkReader reader, out Vector3 position, out Quaternion rotation, out Vector3 scale)
|
void DeserializeEverything(NetworkReader reader, out Vector3 position, out Quaternion rotation, out Vector3 scale)
|
||||||
{
|
{
|
||||||
// position
|
// position
|
||||||
|
if (syncPosition)
|
||||||
|
{
|
||||||
long pX = reader.ReadLong();
|
long pX = reader.ReadLong();
|
||||||
long pY = reader.ReadLong();
|
long pY = reader.ReadLong();
|
||||||
long pZ = reader.ReadLong();
|
long pZ = reader.ReadLong();
|
||||||
position = Compression.ScaleToFloat(pX, pY, pZ, positionPrecision);
|
position = Compression.ScaleToFloat(pX, pY, pZ, positionPrecision);
|
||||||
|
}
|
||||||
|
else position = targetComponent.localPosition;
|
||||||
|
|
||||||
// rotation
|
// rotation
|
||||||
|
if (syncRotation)
|
||||||
|
{
|
||||||
rotation = reader.ReadQuaternion();
|
rotation = reader.ReadQuaternion();
|
||||||
|
}
|
||||||
|
else rotation = targetComponent.localRotation;
|
||||||
|
|
||||||
// scale
|
// scale
|
||||||
|
if (syncScale)
|
||||||
|
{
|
||||||
long sX = reader.ReadLong();
|
long sX = reader.ReadLong();
|
||||||
long sY = reader.ReadLong();
|
long sY = reader.ReadLong();
|
||||||
long sZ = reader.ReadLong();
|
long sZ = reader.ReadLong();
|
||||||
scale = Compression.ScaleToFloat(sX, sY, sZ, scalePrecision);
|
scale = Compression.ScaleToFloat(sX, sY, sZ, scalePrecision);
|
||||||
}
|
}
|
||||||
|
else scale = targetComponent.localScale;
|
||||||
|
}
|
||||||
|
|
||||||
// last serialization for delta compression
|
// last serialization for delta compression
|
||||||
public override void OnSerialize(NetworkWriter writer, bool initialState)
|
public override void OnSerialize(NetworkWriter writer, bool initialState)
|
||||||
|
Loading…
Reference in New Issue
Block a user