コード例 #1
0
        public void OnInbound(NetInboundPacket packet)
        {
            SnapshotConnectionInterface sci = GetOrCreateInterface(packet.Sender);

            ushort numDeltaSnapshots = packet.ReadUInt16();

            for (int i = 0; i < numDeltaSnapshots; i++)
            {
                ushort snapshotId = packet.ReadUInt16();
                ushort numAcks    = packet.ReadUInt16();

                Snapshot snapshot;
                if (sci.TryGetDeltaSnapshot(snapshotId, true, out snapshot))
                {
                    for (int k = 0; k < numAcks; k++)
                    {
                        snapshot.Acknowledge(packet.ReadByte());
                    }
                }
                else
                {
                    packet.Position += numAcks * 1;
                }
            }
        }
コード例 #2
0
        public void AwaitAllocation(Snapshot snapshot)
        {
            SnapshotConnectionInterface sci = GetOrCreateInterface(snapshot.OtherConnection);
            string snapshotId = snapshot.GetUniqueId();

            ushort stashedId;

            // First check stash to see if we are late
            if (sci.IdStash.TryGetValue(snapshotId, out stashedId))
            {
                // All set!
                sci.IdStash.Remove(snapshotId);
                snapshot.SetId(stashedId);
                WriteDebug("[SS:{0}] Setting snapshot '{1}'s id to {2}.",
                           snapshot.OtherConnection, snapshotId, stashedId);
            }
            else
            {
                // Wait for other connection to allocate the id
                if (sci.WaitingSnapshots.ContainsKey(snapshotId))
                {
                    sci.WaitingSnapshots[snapshotId] = snapshot;
                }
                else
                {
                    sci.WaitingSnapshots.Add(snapshotId, snapshot);
                }
            }
        }
コード例 #3
0
        void AddDeltaSnapshot(Snapshot snapshot)
        {
            WriteDebug("[SS:{0}] Supporting delta compression with snapshot '{1}'.",
                       snapshot.OtherConnection, snapshot.GetUniqueId());

            SnapshotConnectionInterface sci = GetOrCreateInterface(snapshot.OtherConnection);

            sci.AddDeltaSnapshot(snapshot);
        }
コード例 #4
0
        SnapshotConnectionInterface GetOrCreateInterface(NetConnection connection)
        {
            SnapshotConnectionInterface sci;

            if (interfaces.TryGetValue(connection, out sci))
            {
                return(sci);
            }
            else
            {
                sci = new SnapshotConnectionInterface(connection);
                interfaces.Add(connection, sci);
                return(sci);
            }
        }
コード例 #5
0
        public void OnOutbound(NetOutboundPacket packet, NetConnection connection)
        {
            // For each snapshot with delta support,
            // we will write every snapshot version
            // that was acknowledged.

            SnapshotConnectionInterface sci = GetOrCreateInterface(connection);

            packet.Write((ushort)sci.InboundDeltaSnapshots.Count);
            foreach (KeyValuePair <ushort, Snapshot> pair in sci.InboundDeltaSnapshots)
            {
                packet.Write(pair.Key);
                packet.Write((ushort)pair.Value.AcknowledgedDeltaIds.Count);

                foreach (byte deltaId in pair.Value.AcknowledgedDeltaIds)
                {
                    packet.Write(deltaId);
                }

                pair.Value.AcknowledgedDeltaIds.Clear();
            }
        }
コード例 #6
0
        public bool Deallocate(Snapshot snapshot)
        {
            // Don't deallocate unready snapshots because
            // it would deallocate a snapshot that is ready
            // with the id of 0.
            if (!snapshot.IsReady)
            {
                return(false);
            }
            {
                WriteDebug("[SS:{0}] Deallocating snapshot '{0}' with id {1}.",
                           snapshot.OtherConnection, snapshot.GetUniqueId(), snapshot.Id);

                SnapshotConnectionInterface sci = GetOrCreateInterface(snapshot.OtherConnection);

                if (snapshot.IsDeltaCompressing)
                {
                    sci.RemoveDeltaSnapshot(snapshot);
                }

                return(idAllocator.Deallocate(snapshot.Id));
            }
        }
コード例 #7
0
        void R_AllocateSnapshotId(NetConnection connection, NetBuffer data, ushort numArgs)
        {
            ushort id         = data.ReadUInt16();
            string snapshotId = data.ReadString();

            SnapshotConnectionInterface sci = GetOrCreateInterface(connection);

            Snapshot unallocatedSnapshot;

            if (sci.WaitingSnapshots.TryGetValue(snapshotId, out unallocatedSnapshot))
            {
                WriteDebug("[SS:{0}] Setting snapshot '{1}'s id to {2}.",
                           connection, snapshotId, id);

                // Set id of unallocated snapshot
                sci.IdStash.Remove(snapshotId);
                sci.WaitingSnapshots.Remove(snapshotId);
                unallocatedSnapshot.SetId(id);

                // Be sure to enable delta compression if the snapshot
                // requested it before it got it's id.
                if (snapshotsAwaitingDeltaSupport.Contains(unallocatedSnapshot))
                {
                    snapshotsAwaitingDeltaSupport.Remove(unallocatedSnapshot);
                    AddDeltaSnapshot(unallocatedSnapshot);
                }
            }
            else
            {
                WriteDebug("[SS:{0}] Stashing snapshot '{1}'s id {2}.",
                           connection, snapshotId, id);

                // Stash id for later
                sci.IdStash.Add(snapshotId, id);
            }
        }