Esempio n. 1
0
        public bool TryOrderedDequeue(out EntityUpdate value, out Int32 timeinqueue)
        {
            MinHeap <MinHeapItem> curheap;

            for (int iq = 0; iq < NumberOfQueues; ++iq)
            {
                curheap = m_heaps[iq];
                if (curheap.Count > 0)
                {
                    MinHeapItem item = curheap.RemoveMin();
                    m_lookupTable.Remove(item.Value.Entity.LocalId);
                    timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime);
                    value       = item.Value;
                    return(true);
                }
            }

            timeinqueue = 0;
            value       = default(EntityUpdate);
            if (m_lookupTable.Count == 0 && m_added > 8 * m_capacity)
            {
                m_lookupTable = new Dictionary <uint, LookupItem>(m_capacity);
                m_added       = 0;
            }
            return(false);
        }
Esempio n. 2
0
        internal bool TryDequeue(out IEntityUpdate value, out Int32 timeinqueue)
        {
            for (int i = 0; i < m_numberOfQueues; ++i)
            {
                // To get the fair queing, we cycle through each of the
                // queues when finding an element to dequeue, this code
                // assumes that the distribution of updates in the queues
                // is polynomial, probably quadractic (eg distance of PI * R^2)
                uint h = (uint)((m_nextQueue + i) % m_numberOfQueues);
                if (m_heaps[h].Count > 0)
                {
                    m_nextQueue = (uint)((h + 1) % m_numberOfQueues);

                    MinHeapItem item = m_heaps[h].RemoveMin();
                    m_lookupTable.Remove(item.Value.Entity.LocalId);
                    timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime);
                    value       = item.Value;

                    return(true);
                }
            }

            timeinqueue = 0;
            value       = default(IEntityUpdate);
            return(false);
        }
Esempio n. 3
0
        public bool TryOrderedDequeue(out EntityUpdate value, out Int32 timeinqueue)
        {
            // If there is anything in imediate queues, return it first no
            // matter what else. Breaks fairness. But very useful.
            for (int iq = 0; iq < NumberOfQueues; iq++)
            {
                if (m_heaps[iq].Count > 0)
                {
                    MinHeapItem item = m_heaps[iq].RemoveMin();
                    m_lookupTable.Remove(item.Value.Entity.LocalId);
                    timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime);
                    value       = item.Value;
                    return(true);
                }
            }

            timeinqueue = 0;
            value       = default(EntityUpdate);
            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Remove an item from one of the queues. Specifically, it removes the
        /// oldest item from the next queue in order to provide fair access to
        /// all of the queues
        /// </summary>
        public bool TryDequeue(out EntityUpdate value, out Int32 timeinqueue)
        {
            // If there is anything in immediate queues, return it first no
            // matter what else. Breaks fairness. But very useful.

            for (int iq = 0; iq < NumberOfImmediateQueues; iq++)
            {
                if (m_heaps[iq].Count > 0)
                {
                    MinHeapItem item = m_heaps[iq].RemoveMin();
                    m_lookupTable.Remove(item.Value.Entity.LocalId);
                    timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime);
                    value       = item.Value;

                    return(true);
                }
            }

            // To get the fair queing, we cycle through each of the
            // queues when finding an element to dequeue.
            // We pull (NumberOfQueues - QueueIndex) items from each queue in order
            // to give lower numbered queues a higher priority and higher percentage
            // of the bandwidth.

            MinHeap <MinHeapItem> curheap = m_heaps[m_nextQueue];

            // Check for more items to be pulled from the current queue
            if (m_countFromQueue > 0 && curheap.Count > 0)
            {
                --m_countFromQueue;

                MinHeapItem item = curheap.RemoveMin();
                m_lookupTable.Remove(item.Value.Entity.LocalId);
                timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime);
                value       = item.Value;

                return(true);
            }

            // Find the next non-immediate queue with updates in it
            for (uint i = NumberOfImmediateQueues; i < NumberOfQueues; ++i)
            {
                m_nextQueue++;
                if (m_nextQueue >= NumberOfQueues)
                {
                    m_nextQueue = NumberOfImmediateQueues;
                }

                curheap = m_heaps[m_nextQueue];
                if (curheap.Count == 0)
                {
                    continue;
                }

                m_countFromQueue = m_queueCounts[m_nextQueue];
                --m_countFromQueue;

                MinHeapItem item = curheap.RemoveMin();
                m_lookupTable.Remove(item.Value.Entity.LocalId);
                timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime);
                value       = item.Value;
                return(true);
            }

            timeinqueue = 0;
            value       = default(EntityUpdate);
            if (m_lookupTable.Count == 0 && m_added > 8 * m_capacity)
            {
                m_lookupTable = new Dictionary <uint, LookupItem>(m_capacity);
                m_added       = 0;
            }
            return(false);
        }
        /// <summary>
        /// Remove an item from one of the queues. Specifically, it removes the
        /// oldest item from the next queue in order to provide fair access to
        /// all of the queues
        /// </summary>
        public bool TryDequeue(out IEntityUpdate value, out Int32 timeinqueue)
        {
            // If there is anything in priority queue 0, return it first no
            // matter what else. Breaks fairness. But very useful.
            for (int iq = 0; iq < NumberOfImmediateQueues; iq++)
            {
                if (m_heaps[iq].Count > 0)
                {
                    MinHeapItem item = m_heaps[iq].RemoveMin();
                    m_lookupTable.Remove(item.Value.Entity.LocalId);
                    timeinqueue = Environment.TickCount - item.EntryTime;
                    value       = item.Value;

                    return(true);
                }
            }

            // To get the fair queing, we cycle through each of the
            // queues when finding an element to dequeue.
            // We pull (NumberOfQueues - QueueIndex) items from each queue in order
            // to give lower numbered queues a higher priority and higher percentage
            // of the bandwidth.

            // Check for more items to be pulled from the current queue
            if (m_heaps[m_nextQueue].Count > 0 && m_countFromQueue > 0)
            {
                m_countFromQueue--;

                MinHeapItem item = m_heaps[m_nextQueue].RemoveMin();
                m_lookupTable.Remove(item.Value.Entity.LocalId);
                timeinqueue = Environment.TickCount - item.EntryTime;
                value       = item.Value;

                return(true);
            }

            // Find the next non-immediate queue with updates in it
            for (int i = 0; i < NumberOfQueues; ++i)
            {
                m_nextQueue      = (uint)((m_nextQueue + 1) % NumberOfQueues);
                m_countFromQueue = m_queueCounts[m_nextQueue];

                // if this is one of the immediate queues, just skip it
                if (m_nextQueue < NumberOfImmediateQueues)
                {
                    continue;
                }

                if (m_heaps[m_nextQueue].Count > 0)
                {
                    m_countFromQueue--;

                    MinHeapItem item = m_heaps[m_nextQueue].RemoveMin();
                    m_lookupTable.Remove(item.Value.Entity.LocalId);
                    timeinqueue = Environment.TickCount - item.EntryTime;
                    value       = item.Value;

                    return(true);
                }
            }

            timeinqueue = 0;
            value       = default(IEntityUpdate);
            return(false);
        }