mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
cleanup: remove ContructSnapshot
This commit is contained in:
parent
ae1edff268
commit
8e83da26b4
@ -122,26 +122,6 @@ protected override void OnValidate()
|
|||||||
syncInterval = 0;
|
syncInterval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// snapshot functions //////////////////////////////////////////////////
|
|
||||||
// construct a snapshot of the current state
|
|
||||||
// => internal for testing
|
|
||||||
protected virtual TransformSnapshot ConstructSnapshot()
|
|
||||||
{
|
|
||||||
// perf
|
|
||||||
target.GetLocalPositionAndRotation(out Vector3 localPosition, out Quaternion localRotation);
|
|
||||||
|
|
||||||
// NetworkTime.localTime for double precision until Unity has it too
|
|
||||||
return new TransformSnapshot(
|
|
||||||
// our local time is what the other end uses as remote time
|
|
||||||
Time.timeAsDouble,
|
|
||||||
// the other end fills out local time itself
|
|
||||||
0,
|
|
||||||
localPosition, // target.localPosition,
|
|
||||||
localRotation, // target.localRotation,
|
|
||||||
Vector3.zero // target.localScale
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply a snapshot to the Transform.
|
// apply a snapshot to the Transform.
|
||||||
// -> start, end, interpolated are all passed in caes they are needed
|
// -> start, end, interpolated are all passed in caes they are needed
|
||||||
// -> a regular game would apply the 'interpolated' snapshot
|
// -> a regular game would apply the 'interpolated' snapshot
|
||||||
@ -1020,14 +1000,16 @@ public override void OnSerialize(NetworkWriter writer, bool initialState)
|
|||||||
if (initialState)
|
if (initialState)
|
||||||
{
|
{
|
||||||
// spawn message is used as first baseline.
|
// spawn message is used as first baseline.
|
||||||
TransformSnapshot snapshot = ConstructSnapshot();
|
// perf: get position/rotation directly. TransformSnapshot is too expensive.
|
||||||
|
// TransformSnapshot snapshot = ConstructSnapshot();
|
||||||
|
target.GetLocalPositionAndRotation(out Vector3 position, out Quaternion rotation);
|
||||||
|
|
||||||
// always include the tick for deltas to compare against.
|
// always include the tick for deltas to compare against.
|
||||||
byte frameCount = (byte)Time.frameCount; // perf: only access Time.frameCount once!
|
byte frameCount = (byte)Time.frameCount; // perf: only access Time.frameCount once!
|
||||||
writer.WriteByte(frameCount);
|
writer.WriteByte(frameCount);
|
||||||
|
|
||||||
if (syncPosition) writer.WriteVector3(snapshot.position);
|
if (syncPosition) writer.WriteVector3(position);
|
||||||
if (syncRotation) writer.WriteQuaternion(snapshot.rotation);
|
if (syncRotation) writer.WriteQuaternion(rotation);
|
||||||
|
|
||||||
// IMPORTANT
|
// IMPORTANT
|
||||||
// OnSerialize(initial) is called for the spawn payload whenever
|
// OnSerialize(initial) is called for the spawn payload whenever
|
||||||
@ -1041,8 +1023,8 @@ public override void OnSerialize(NetworkWriter writer, bool initialState)
|
|||||||
// => client's baseline is t=2 but receives delta for t=1 _!_
|
// => client's baseline is t=2 but receives delta for t=1 _!_
|
||||||
lastSerializedBaselineTick = frameCount;
|
lastSerializedBaselineTick = frameCount;
|
||||||
lastBaselineTime = NetworkTime.localTime;
|
lastBaselineTime = NetworkTime.localTime;
|
||||||
lastSerializedBaselinePosition = snapshot.position;
|
lastSerializedBaselinePosition = position;
|
||||||
lastSerializedBaselineRotation = snapshot.rotation;
|
lastSerializedBaselineRotation = rotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user