Exemple #1
0
        /// <summary>
        /// Updates this entity, flushes and handles any pending packets in the incoming queue.
        /// </summary>
        public void Update(TimeSpan dt)
        {
            //Handle all packets in the incoming queue
            IPacketBase packet = null;
            while (m_incomingQueue.TryDequeue(out packet))
            {
                HandlePacket(packet);
            }

            //Send any packets that have been deferred
            foreach (CoalescedData p in m_deferredSendList)
            {
                SendPacket(p);
            }
            m_deferredSendList.Clear();

            if (m_currentDeferredPacket.PacketCount > 0)
            {
                SendPacket(m_currentDeferredPacket);
            }

            //Reset the current deferred packet for next update
            m_currentDeferredPacket = PacketFactory.CreatePacket<CoalescedData>();

            //Warn if any of the queues are getting swamped
            if (m_outgoingQueue.Count > 25)
            {
                Console.WriteLine("Outgoing queue swamped: " + m_outgoingQueue.Count);
            }
            if (m_incomingQueue.Count > 25)
            {
                Console.WriteLine("Incoming queue swamped: " + m_incomingQueue.Count);
            }
        }
Exemple #2
0
 /// <summary>
 /// Queues a packet to be send on the next update. Will coalesce these packets together.
 /// </summary>
 public void DeferredSendPacket(IPacketBase packet)
 {
     if (!m_currentDeferredPacket.TryAddPacket(packet))
     {
         m_deferredSendList.Add(m_currentDeferredPacket);
         m_currentDeferredPacket = PacketFactory.CreatePacket<CoalescedData>();
         m_currentDeferredPacket.TryAddPacket(packet);
     }
 }