Ejemplo n.º 1
0
        /// <summary>
        /// Update the pairs. This results in pair callbacks. This can only add pairs.
        /// </summary>
        /// <param name="callback"></param>
        public void UpdatePairs(IPairCallback callback)
        {
            // log.debug("beginning to update pairs");
            // Reset pair buffer
            m_pairCount = 0;

            // Perform tree queries for all moving proxies.
            for (int i = 0; i < m_moveCount; ++i)
            {
                m_queryProxyId = m_moveBuffer[i];
                if (m_queryProxyId == NULL_PROXY)
                {
                    continue;
                }

                // We have to query the tree with the fat AABB so that
                // we don't fail to create a pair that may touch later.
                var fatAABB = m_tree.GetFatAABB(m_queryProxyId);

                // Query tree, create pairs and add them pair buffer.
                // log.debug("quering aabb: "+m_queryProxy.aabb);
                m_tree.Query(this, fatAABB);
            }
            // log.debug("Number of pairs found: "+m_pairCount);

            // Reset move buffer
            m_moveCount = 0;

            // Sort the pair buffer to expose duplicates.
            Array.Sort(m_pairBuffer, 0, m_pairCount - 0);

            // Send the pairs back to the client.
            int i2 = 0;

            while (i2 < m_pairCount)
            {
                var primaryPair = m_pairBuffer[i2];
                var userDataA   = m_tree.GetUserData(primaryPair.ProxyIdA);
                var userDataB   = m_tree.GetUserData(primaryPair.ProxyIdB);

                // log.debug("returning pair: "+userDataA+", "+userDataB);
                callback.AddPair(userDataA, userDataB);
                ++i2;

                // Skip any duplicate pairs.
                while (i2 < m_pairCount)
                {
                    var pair = m_pairBuffer[i2];
                    if (pair.ProxyIdA != primaryPair.ProxyIdA || pair.ProxyIdB != primaryPair.ProxyIdB)
                    {
                        break;
                    }
                    // log.debug("skipping duplicate");
                    ++i2;
                }
            }

            // Try to keep the tree balanced.
            // m_tree.rebalance(Settings.TREE_REBALANCE_STEPS);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update the pairs. This results in pair callbacks. This can only add pairs.
        /// </summary>
        /// <param name="callback"></param>
        public void UpdatePairs(IPairCallback callback)
        {
            // log.debug("beginning to update pairs");
            // Reset pair buffer
            m_pairCount = 0;

            // Perform tree queries for all moving proxies.
            for (int i = 0; i < m_moveCount; ++i)
            {
                m_queryProxyId = m_moveBuffer[i];
                if (m_queryProxyId == NULL_PROXY)
                {
                    continue;
                }

                // We have to query the tree with the fat AABB so that
                // we don't fail to create a pair that may touch later.
                var fatAABB = m_tree.GetFatAABB(m_queryProxyId);

                // Query tree, create pairs and add them pair buffer.
                // log.debug("quering aabb: "+m_queryProxy.aabb);
                m_tree.Query(this, fatAABB);
            }
            // log.debug("Number of pairs found: "+m_pairCount);

            // Reset move buffer
            m_moveCount = 0;

            // Sort the pair buffer to expose duplicates.
            Array.Sort(m_pairBuffer, 0, m_pairCount - 0);

            // Send the pairs back to the client.
            int i2 = 0;
            while (i2 < m_pairCount)
            {
                var primaryPair = m_pairBuffer[i2];
                var userDataA = m_tree.GetUserData(primaryPair.ProxyIdA);
                var userDataB = m_tree.GetUserData(primaryPair.ProxyIdB);

                // log.debug("returning pair: "+userDataA+", "+userDataB);
                callback.AddPair(userDataA, userDataB);
                ++i2;

                // Skip any duplicate pairs.
                while (i2 < m_pairCount)
                {
                    var pair = m_pairBuffer[i2];
                    if (pair.ProxyIdA != primaryPair.ProxyIdA || pair.ProxyIdB != primaryPair.ProxyIdB)
                    {
                        break;
                    }
                    // log.debug("skipping duplicate");
                    ++i2;
                }
            }

            // Try to keep the tree balanced.
            // m_tree.rebalance(Settings.TREE_REBALANCE_STEPS);
        }