NetworkServer.Broadcast: TrackIdentityAtTick

This commit is contained in:
mischa 2024-07-20 13:03:14 +02:00
parent 9fbbcca347
commit c52ab5ce74
2 changed files with 17 additions and 0 deletions

View File

@ -61,6 +61,19 @@ public abstract class NetworkConnection
// different connections.
public double remoteTimeStamp { get; internal set; }
// unreliable delta compression: we need to keep track of which identities were in which sent batch @ timestamp.
// so when the ack comes back, we know which identities were acked.
// this is necessary since we sync per-identity not per-worldstate.
internal readonly SortedList<double, HashSet<uint>> identityTicks = new SortedList<double, HashSet<uint>>();
// unreliable delta compression: we need to know the last acked state for each connection.
// currently we sync one entity at a time in batches, so we also need to store acks for one at a time.
// <netId, timestamp>
// TODO remove old when unspawned
readonly Dictionary<uint, double> identityAcks = new Dictionary<uint, double>();
//
internal NetworkConnection()
{
// set lastTime to current time when creating connection to make

View File

@ -1986,6 +1986,10 @@ static void BroadcastToConnection(NetworkConnectionToClient connection)
payload = serialization.ToArraySegment()
};
connection.Send(message, Channels.Unreliable);
// keep track of which entities we sent to the connection on this tick.
// so when the connection sends back an ack, we know which entities were acked.
AckDeltaCompression.TrackIdentityAtTick(NetworkTime.localTime, identity.netId, connection.identityTicks, tickHistorySize);
}
}
// spawned list should have no null entries because we