parameters

This commit is contained in:
mischa 2024-09-05 15:12:07 +02:00
parent f948c5135e
commit a0aa1dc9a4
2 changed files with 29 additions and 4 deletions

View File

@ -1217,7 +1217,10 @@ internal void DeserializeClient(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.
// calls SerializeServer, so this function is to be called on server.
internal NetworkIdentitySerialization GetServerSerializationAtTick(int tick)
//
// unreliableBaselineElapsed: indicates that unreliable sync components need a reliable baseline sync this time.
// for reliable components, it just means sync as usual.
internal NetworkIdentitySerialization GetServerSerializationAtTick(int tick, bool unreliableBaselineElapsed)
{
// only rebuild serialization once per tick. reuse otherwise.
// except for tests, where Time.frameCount never increases.

View File

@ -1883,11 +1883,15 @@ public static void RebuildObservers(NetworkIdentity identity, bool initialize)
// broadcasting ////////////////////////////////////////////////////////
// helper function to get the right serialization for a connection
static NetworkWriter SerializeForConnection(NetworkIdentity identity, NetworkConnectionToClient connection, bool unreliableBaselineElapsed)
static NetworkWriter SerializeForConnection(
NetworkIdentity identity,
NetworkConnectionToClient connection,
SyncMethod method,
bool unreliableBaselineElapsed)
{
// get serialization for this entity (cached)
// IMPORTANT: int tick avoids floating point inaccuracy over days/weeks
NetworkIdentitySerialization serialization = identity.GetServerSerializationAtTick(Time.frameCount);
NetworkIdentitySerialization serialization = identity.GetServerSerializationAtTick(Time.frameCount, unreliableBaselineElapsed);
// is this entity owned by this connection?
bool owned = identity.connectionToClient == connection;
@ -1925,9 +1929,10 @@ static void BroadcastToConnection(NetworkConnectionToClient connection, bool unr
// NetworkServer.Destroy)
if (identity != null)
{
// 'Reliable' sync: send Reliable components over reliable with initial/delta
// get serialization for this entity viewed by this connection
// (if anything was serialized this time)
NetworkWriter serialization = SerializeForConnection(identity, connection, unreliableBaselineElapsed);
NetworkWriter serialization = SerializeForConnection(identity, connection, SyncMethod.Reliable, unreliableBaselineElapsed);
if (serialization != null)
{
EntityStateMessage message = new EntityStateMessage
@ -1937,6 +1942,23 @@ static void BroadcastToConnection(NetworkConnectionToClient connection, bool unr
};
connection.Send(message);
}
// 'Unreliable' sync: send Unreliable components over unreliable
// state is 'initial' for reliable baseline, and 'not initial' for unreliable deltas.
// note that syncInterval is always ignored for unreliable in order to have tick aligned [SyncVars].
// even if we pass SyncMethod.Reliable, it serializes with initialState=true.
serialization = SerializeForConnection(identity, connection, SyncMethod.Unreliable, unreliableBaselineElapsed);
if (serialization != null)
{
EntityStateMessageUnreliable message = new EntityStateMessageUnreliable
{
netId = identity.netId,
payload = serialization.ToArraySegment()
};
// Unreliable mode still sends a reliable baseline every full interval.
int channel = unreliableBaselineElapsed ? Channels.Reliable : Channels.Unreliable;
connection.Send(message, channel);
}
}
// spawned list should have no null entries because we
// always call Remove in OnObjectDestroy everywhere.