This commit is contained in:
vis2k 2022-10-09 13:51:01 +02:00
parent 10e34488e2
commit 10296e0586

View File

@ -960,61 +960,6 @@ internal void SerializeAll(bool initialState, NetworkWriter ownerWriter, Network
} }
} }
// get cached serialization for this tick (or serialize if none yet)
// IMPORTANT: int tick avoids floating point inaccuracy over days/weeks
internal NetworkIdentitySerialization GetSerializationAtTick(int tick)
{
// only rebuild serialization once per tick. reuse otherwise.
// except for tests, where Time.frameCount never increases.
// so during tests, we always rebuild.
// (otherwise [SyncVar] changes would never be serialized in tests)
//
// NOTE: != instead of < because int.max+1 overflows at some point.
if (lastSerialization.tick != tick
#if UNITY_EDITOR
|| !Application.isPlaying
#endif
)
{
// reset
lastSerialization.ownerWriter.Position = 0;
lastSerialization.observersWriter.Position = 0;
// serialize
SerializeAll(false,
lastSerialization.ownerWriter,
lastSerialization.observersWriter);
// clear dirty bits for the components that we serialized.
// previously we did this in NetworkServer.BroadcastToConnection
// for every connection, for every entity.
// but we only serialize each entity once, right here in this
// 'lastSerialization.tick != tick' scope.
// so only do it once.
//
// NOTE: not in Serializell as that should only do one
// thing: serialize data.
//
//
// NOTE: DO NOT clear ALL component's dirty bits, because
// components can have different syncIntervals and we
// don't want to reset dirty bits for the ones that were
// not synced yet.
//
// NOTE: this used to be very important to avoid ever growing
// SyncList changes if they had no observers, but we've
// added SyncObject.isRecording since.
ClearDirtyComponentsDirtyBits();
// set tick
lastSerialization.tick = tick;
//Debug.Log($"{name} (netId={netId}) serialized for tick={tickTimeStamp}");
}
// return it
return lastSerialization;
}
void Deserialize(NetworkBehaviour comp, NetworkReader reader, bool initialState) void Deserialize(NetworkBehaviour comp, NetworkReader reader, bool initialState)
{ {
// read header as 4 bytes and calculate this chunk's start+end // read header as 4 bytes and calculate this chunk's start+end
@ -1078,6 +1023,61 @@ internal void DeserializeAll(NetworkReader reader, bool initialState)
} }
} }
// get cached serialization for this tick (or serialize if none yet)
// IMPORTANT: int tick avoids floating point inaccuracy over days/weeks
internal NetworkIdentitySerialization GetSerializationAtTick(int tick)
{
// only rebuild serialization once per tick. reuse otherwise.
// except for tests, where Time.frameCount never increases.
// so during tests, we always rebuild.
// (otherwise [SyncVar] changes would never be serialized in tests)
//
// NOTE: != instead of < because int.max+1 overflows at some point.
if (lastSerialization.tick != tick
#if UNITY_EDITOR
|| !Application.isPlaying
#endif
)
{
// reset
lastSerialization.ownerWriter.Position = 0;
lastSerialization.observersWriter.Position = 0;
// serialize
SerializeAll(false,
lastSerialization.ownerWriter,
lastSerialization.observersWriter);
// clear dirty bits for the components that we serialized.
// previously we did this in NetworkServer.BroadcastToConnection
// for every connection, for every entity.
// but we only serialize each entity once, right here in this
// 'lastSerialization.tick != tick' scope.
// so only do it once.
//
// NOTE: not in Serializell as that should only do one
// thing: serialize data.
//
//
// NOTE: DO NOT clear ALL component's dirty bits, because
// components can have different syncIntervals and we
// don't want to reset dirty bits for the ones that were
// not synced yet.
//
// NOTE: this used to be very important to avoid ever growing
// SyncList changes if they had no observers, but we've
// added SyncObject.isRecording since.
ClearDirtyComponentsDirtyBits();
// set tick
lastSerialization.tick = tick;
//Debug.Log($"{name} (netId={netId}) serialized for tick={tickTimeStamp}");
}
// return it
return lastSerialization;
}
// Helper function to handle Command/Rpc // Helper function to handle Command/Rpc
internal void HandleRemoteCall(byte componentIndex, ushort functionHash, RemoteCallType remoteCallType, NetworkReader reader, NetworkConnectionToClient senderConnection = null) internal void HandleRemoteCall(byte componentIndex, ushort functionHash, RemoteCallType remoteCallType, NetworkReader reader, NetworkConnectionToClient senderConnection = null)
{ {