Пример #1
0
 protected virtual void PacketDropped(PacketNotify note)
 {
     if (StringTable != null)
     {
         StringTable.PacketDropped(note.StringList);
     }
 }
Пример #2
0
        protected override void PacketReceived(PacketNotify note)
        {
            base.PacketReceived(note);

            var notify = note as EventPacketNotify;

            if (notify == null)
            {
                throw new ArgumentException("Note must be EventPacketNotify", "note");
            }

            var walk         = notify.EventList;
            var noteList     = _notifyEventList;
            var noteListPrev = _notifyEventList;

            while (walk != null)
            {
                var next = walk.NextEvent;

                if (walk.Event.GuaranteeType != GuaranteeType.GuaranteedOrdered)
                {
                    walk.Event.NotifyDelivered(this, true);
                }
                else
                {
                    while (noteList != null && noteList.SeqCount < walk.SeqCount)
                    {
                        noteListPrev = noteList;
                        noteList     = noteList.NextEvent;
                    }

                    walk.NextEvent = noteList;

                    if (noteListPrev == null)
                    {
                        _notifyEventList = walk;
                    }
                    else
                    {
                        noteListPrev.NextEvent = walk;
                    }

                    noteListPrev = walk;
                    noteList     = walk.NextEvent;
                }

                walk = next;
            }

            while (_notifyEventList != null && _notifyEventList.SeqCount == _lastAckedEventSeq + 1)
            {
                ++_lastAckedEventSeq;
                var next = _notifyEventList.NextEvent;

                _notifyEventList.Event.NotifyDelivered(this, true);

                _notifyEventList = next;
            }
        }
Пример #3
0
        protected override void PacketDropped(PacketNotify note)
        {
            base.PacketDropped(note);

            var notify = note as GhostPacketNotify;

            if (notify == null)
            {
                throw new ArgumentException("Note must be GhostPacketNotify", "note");
            }

            var packRef = notify.GhostList;

            while (packRef != null)
            {
                var temp = packRef.NextRef;

                var updateFlags = packRef.Mask;

                for (var walk = packRef.UpdateChain; walk != null && updateFlags != 0UL; walk = walk.UpdateChain)
                {
                    updateFlags &= ~walk.Mask;
                }

                if (updateFlags != 0UL)
                {
                    if (packRef.Ghost.UpdateMask == 0UL)
                    {
                        packRef.Ghost.UpdateMask = updateFlags;
                        GhostPushNonZero(packRef.Ghost);
                    }
                    else
                    {
                        packRef.Ghost.UpdateMask |= updateFlags;
                    }
                }

                if (packRef.Ghost.LastUpdateChain == packRef)
                {
                    packRef.Ghost.LastUpdateChain = null;
                }

                if ((packRef.GhostInfoFlags & (uint)GhostInfoFlags.Ghosting) != 0U)
                {
                    packRef.Ghost.Flags |= (uint)GhostInfoFlags.NotYetGhosted;
                    packRef.Ghost.Flags &= ~(uint)GhostInfoFlags.Ghosting;
                }
                else if ((packRef.GhostInfoFlags & (uint)GhostInfoFlags.KillingGhost) != 0U)
                {
                    packRef.Ghost.Flags |= (uint)GhostInfoFlags.KillGhost;
                    packRef.Ghost.Flags &= ~(uint)GhostInfoFlags.KillingGhost;
                }

                packRef = temp;
            }
        }
Пример #4
0
        protected void WritePacketRateInfo(BitStream stream, PacketNotify note)
        {
            note.RateChanged = LocalRateChanged;
            LocalRateChanged = false;

            if (stream.WriteFlag(note.RateChanged) && !stream.WriteFlag(TypeFlags.Test((uint)NetConnectionTypeFlags.ConnectionAdaptive)))
            {
                stream.WriteRangedU32(LocalRate.MaxRecvBandwidth, 0, MaxFixedBandwidth);
                stream.WriteRangedU32(LocalRate.MaxSendBandwidth, 0, MaxFixedBandwidth);
                stream.WriteRangedU32(LocalRate.MinPacketRecvPeriod, 1, MaxFixedSendPeriod);
                stream.WriteRangedU32(LocalRate.MinPacketSendPeriod, 1, MaxFixedSendPeriod);
            }
        }
Пример #5
0
        protected override void PacketReceived(PacketNotify note)
        {
            base.PacketReceived(note);

            var notify = note as GhostPacketNotify;

            if (notify == null)
            {
                throw new ArgumentException("Note must be GhostPacketNotify", "note");
            }

            var packRef = notify.GhostList;

            while (packRef != null)
            {
                if (packRef.Ghost.LastUpdateChain == packRef)
                {
                    packRef.Ghost.LastUpdateChain = null;
                }

                var temp = packRef.NextRef;

                if ((packRef.GhostInfoFlags & (uint)GhostInfoFlags.Ghosting) != 0U)
                {
                    packRef.Ghost.Flags &= ~(uint)GhostInfoFlags.Ghosting;

                    if (packRef.Ghost.Obj != null)
                    {
                        packRef.Ghost.Obj.OnGhostAvailable(this);
                    }
                }
                else if ((packRef.GhostInfoFlags & (uint)GhostInfoFlags.KillingGhost) != 0U)
                {
                    FreeGhostInfo(packRef.Ghost);
                }

                packRef = temp;
            }
        }
Пример #6
0
        protected override void WritePacket(BitStream stream, PacketNotify note)
        {
            base.WritePacket(stream, note);

            var notify = note as GhostPacketNotify;

            if (notify == null)
            {
                throw new ArgumentException("Note must be GhostPacketNotify", "note");
            }

            if (ConnectionParameters.DebugObjectSizes)
            {
                stream.WriteInt(DebugCheckSum, 32);
            }

            notify.GhostList = null;

            if (!DoesGhostFrom())
            {
                return;
            }

            if (!stream.WriteFlag(Ghosting && ScopeObject != null))
            {
                return;
            }

            for (var i = GhostZeroUpdateIndex - 1; i >= 0; --i)
            {
                if ((GhostArray[i].Flags & (uint)GhostInfoFlags.InScope) == 0)
                {
                    DetachObject(GhostArray[i]);
                }
            }

            var maxIndex = 0U;

            for (var i = GhostZeroUpdateIndex - 1; i >= 0; --i)
            {
                var walk = GhostArray[i];
                if (walk.Index > maxIndex)
                {
                    maxIndex = walk.Index;
                }

                if ((walk.Flags & (uint)GhostInfoFlags.KillGhost) != 0U &&
                    (walk.Flags & (uint)GhostInfoFlags.NotYetGhosted) != 0U)
                {
                    FreeGhostInfo(walk);
                    continue;
                }

                if ((walk.Flags & (uint)(GhostInfoFlags.KillingGhost | GhostInfoFlags.Ghosting)) == 0U)
                {
                    walk.Priority = (walk.Flags & (uint)GhostInfoFlags.KillGhost) != 0U ? 10000.0f : walk.Obj.GetUpdatePriority(ScopeObject, walk.UpdateMask, (int)walk.UpdateSkipCount);
                }
                else
                {
                    walk.Priority = 0.0f;
                }
            }

            GhostRef updateList = null;

            var list = new List <GhostInfo>();

            for (var i = 0; i < GhostZeroUpdateIndex; ++i)
            {
                list.Add(GhostArray[i]);
            }

            list.Sort(new GhostInfoComparer());

            for (var i = 0; i < list.Count; ++i)
            {
                GhostArray[i]            = list[i];
                GhostArray[i].ArrayIndex = i;
            }

            var sendSize = 1;

            while ((maxIndex >>= 1) != 0)
            {
                ++sendSize;
            }

            if (sendSize < 3)
            {
                sendSize = 3;
            }

            stream.WriteInt((uint)sendSize - 3U, 3);

            for (var i = GhostZeroUpdateIndex - 1; i >= 0 && !stream.IsFull(); --i)
            {
                var walk = GhostArray[i];
                if ((walk.Flags & (uint)(GhostInfoFlags.KillingGhost | GhostInfoFlags.Ghosting)) != 0U)
                {
                    continue;
                }

                var updateStart = stream.GetBitPosition();
                var updateMask  = walk.UpdateMask;
                var retMask     = 0UL;

                stream.WriteFlag(true);
                stream.WriteInt(walk.Index, (byte)sendSize);

                if (!stream.WriteFlag((walk.Flags & (uint)GhostInfoFlags.KillGhost) != 0U))
                {
                    if (ConnectionParameters.DebugObjectSizes)
                    {
                        stream.AdvanceBitPosition(BitStreamPosBitSize);
                    }

                    var startPos = stream.GetBitPosition();

                    if ((walk.Flags & (uint)GhostInfoFlags.NotYetGhosted) != 0U)
                    {
                        var classId = walk.Obj.GetClassId(GetNetClassGroup());
                        stream.WriteClassId(classId, (uint)NetClassType.NetClassTypeObject, (uint)GetNetClassGroup());
                        NetObject.PIsInitialUpdate = true;
                    }

                    retMask = walk.Obj.PackUpdate(this, updateMask, stream);

                    if (NetObject.PIsInitialUpdate)
                    {
                        NetObject.PIsInitialUpdate = false;
                        walk.Obj.GetClassRep().AddInitialUpdate(stream.GetBitPosition() - startPos);
                    }
                    else
                    {
                        walk.Obj.GetClassRep().AddPartialUpdate(stream.GetBitPosition() - startPos);
                    }

                    if (ConnectionParameters.DebugObjectSizes)
                    {
                        stream.WriteIntAt(stream.GetBitPosition(), BitStreamPosBitSize, startPos - BitStreamPosBitSize);
                    }
                }

                if (stream.GetBitSpaceAvailable() < MinimumPaddingBits)
                {
                    stream.SetBitPosition(updateStart);
                    stream.ClearError();
                    break;
                }

                var upd = new GhostRef
                {
                    NextRef = updateList
                };

                updateList = upd;

                if (walk.LastUpdateChain != null)
                {
                    walk.LastUpdateChain.UpdateChain = upd;
                }

                walk.LastUpdateChain = upd;

                upd.Ghost          = walk;
                upd.GhostInfoFlags = 0U;
                upd.UpdateChain    = null;

                if ((walk.Flags & (uint)GhostInfoFlags.KillGhost) != 0U)
                {
                    walk.Flags     &= ~(uint)GhostInfoFlags.KillGhost;
                    walk.Flags     |= (uint)GhostInfoFlags.KillingGhost;
                    walk.UpdateMask = 0UL;
                    upd.Mask        = updateMask;
                    GhostPushToZero(walk);
                    upd.GhostInfoFlags = (uint)GhostInfoFlags.KillingGhost;
                }
                else
                {
                    if ((walk.Flags & (uint)GhostInfoFlags.NotYetGhosted) != 0U)
                    {
                        walk.Flags        &= ~(uint)GhostInfoFlags.NotYetGhosted;
                        walk.Flags        |= (uint)GhostInfoFlags.Ghosting;
                        upd.GhostInfoFlags = (uint)GhostInfoFlags.Ghosting;
                    }

                    walk.UpdateMask = retMask;
                    if (retMask == 0UL)
                    {
                        GhostPushToZero(walk);
                    }

                    upd.Mask             = updateMask & ~retMask;
                    walk.UpdateSkipCount = 0U;
                }
            }

            stream.WriteFlag(false);
            notify.GhostList = updateList;
        }
Пример #7
0
        protected override void WritePacket(BitStream stream, PacketNotify note)
        {
            base.WritePacket(stream, note);

            var notify = note as EventPacketNotify;

            if (notify == null)
            {
                throw new ArgumentException("Note must be EventPacketNotify", "note");
            }

            if (ConnectionParameters.DebugObjectSizes)
            {
                stream.WriteInt(DebugCheckSum, 32);
            }

            EventNote packQueueHead = null, packQueueTail = null;

            var totalPacketSpaceFraction = 1.0f / stream.MaxWriteBitNum;

            while (_unorderedSendEventQueueHead != null)
            {
                if (stream.IsFull() || (stream.GetBitPosition() * totalPacketSpaceFraction) > _packetFillFraction)
                {
                    break;
                }

                var ev = _unorderedSendEventQueueHead;
                stream.WriteFlag(true);

                var start = stream.GetBitPosition();

                if (ConnectionParameters.DebugObjectSizes)
                {
                    stream.AdvanceBitPosition(BitStreamPosBitSize);
                }

                var classId = ev.Event.GetClassId(GetNetClassGroup());
                stream.WriteInt(classId, (byte)EventClassBitSize);

                ev.Event.Pack(this, stream);

                if (ConnectionParameters.DebugObjectSizes)
                {
                    stream.WriteIntAt(stream.GetBitPosition(), BitStreamPosBitSize, start);
                }

                if (stream.GetBitSpaceAvailable() < MinimumPaddingBits)
                {
                    stream.SetBitPosition(start - 1);
                    stream.ClearError();
                    break;
                }

                --NumEventsWaiting;

                _unorderedSendEventQueueHead = ev.NextEvent;
                ev.NextEvent = null;

                if (packQueueHead == null)
                {
                    packQueueHead = ev;
                }
                else
                {
                    packQueueTail.NextEvent = ev;
                }

                packQueueTail = ev;
            }

            stream.WriteFlag(false);
            var prevSeq = -2;

            while (_sendEventQueueHead != null)
            {
                if (stream.IsFull())
                {
                    break;
                }

                if (_sendEventQueueHead.SeqCount > _lastAckedEventSeq + 126)
                {
                    break;
                }

                var ev         = _sendEventQueueHead;
                var eventStart = stream.GetBitPosition();

                stream.WriteFlag(true);

                if (!stream.WriteFlag(ev.SeqCount == prevSeq + 1))
                {
                    stream.WriteInt((uint)ev.SeqCount, 7);
                }

                prevSeq = ev.SeqCount;

                if (ConnectionParameters.DebugObjectSizes)
                {
                    stream.AdvanceBitPosition(BitStreamPosBitSize);
                }

                var start = stream.GetBitPosition();

                var classId = ev.Event.GetClassId(GetNetClassGroup());

                stream.WriteInt(classId, (byte)EventClassBitSize);

                ev.Event.Pack(this, stream);

                ev.Event.GetClassRep().AddInitialUpdate(stream.GetBitPosition() - start);

                if (ConnectionParameters.DebugObjectSizes)
                {
                    stream.WriteIntAt(stream.GetBitPosition(), BitStreamPosBitSize, start - BitStreamPosBitSize);
                }

                if (stream.GetBitSpaceAvailable() < MinimumPaddingBits)
                {
                    stream.SetBitPosition(eventStart);
                    stream.ClearError();
                    break;
                }

                --NumEventsWaiting;

                _sendEventQueueHead = ev.NextEvent;
                ev.NextEvent        = null;

                if (packQueueHead == null)
                {
                    packQueueHead = ev;
                }
                else
                {
                    packQueueTail.NextEvent = ev;
                }

                packQueueTail = ev;
            }

            for (var ev = packQueueHead; ev != null; ev = ev.NextEvent)
            {
                ev.Event.NotifySent(this);
            }

            notify.EventList = packQueueHead;
            stream.WriteFlag(false);
        }
Пример #8
0
        protected override void PacketDropped(PacketNotify note)
        {
            base.PacketDropped(note);

            var notify = note as EventPacketNotify;

            if (notify == null)
            {
                throw new ArgumentException("Note must be EventPacketNotify", "note");
            }

            var walk           = notify.EventList;
            var insertList     = _sendEventQueueHead;
            var insertListPrev = _sendEventQueueHead;

            while (walk != null)
            {
                var temp = walk.NextEvent;

                switch (walk.Event.GuaranteeType)
                {
                case GuaranteeType.GuaranteedOrdered:
                    while (insertList != null && insertList.SeqCount < walk.SeqCount)
                    {
                        insertListPrev = insertList;
                        insertList     = insertList.NextEvent;
                    }

                    walk.NextEvent = insertList;

                    if (walk.NextEvent == null)
                    {
                        _sendEventQueueTail = walk;
                    }

                    if (insertListPrev == null)
                    {
                        _sendEventQueueHead = walk;
                    }
                    else
                    {
                        insertListPrev.NextEvent = walk;
                    }

                    insertListPrev = walk;
                    insertList     = walk.NextEvent;
                    break;

                case GuaranteeType.Guaranteed:
                    walk.NextEvent = _unorderedSendEventQueueHead;
                    _unorderedSendEventQueueHead = walk;

                    if (walk.NextEvent == null)
                    {
                        _unorderedSendEventQueueTail = walk;
                    }

                    break;

                case GuaranteeType.Unguaranteed:
                    walk.Event.NotifyDelivered(this, false);
                    break;
                }

                walk = temp;
                ++NumEventsWaiting;
            }
        }
Пример #9
0
 protected virtual void WritePacket(BitStream stream, PacketNotify note)
 {
 }