Exemplo n.º 1
0
        // Returns existing pair or creates a new one.
        /// <summary>
        ///     Adds the pair using the specified proxy id 1
        /// </summary>
        /// <param name="proxyId1">The proxy id</param>
        /// <param name="proxyId2">The proxy id</param>
        /// <returns>The pair</returns>
        private Pair AddPair(int proxyId1, int proxyId2)
        {
            if (proxyId1 > proxyId2)
            {
                Math.Swap(ref proxyId1, ref proxyId2);
            }

            int hash = (int)(Hash((uint)proxyId1, (uint)proxyId2) & TableMask);

            Pair pair = Find(proxyId1, proxyId2, (uint)hash);

            if (pair != null)
            {
                return(pair);
            }

            Box2DxDebug.Assert(PairCount < Settings.MaxPairs && FreePair != NullPair);

            ushort pairIndex = FreePair;

            pair     = Pairs[pairIndex];
            FreePair = pair.Next;

            pair.ProxyId1 = (ushort)proxyId1;
            pair.ProxyId2 = (ushort)proxyId2;
            pair.Status   = 0;
            pair.UserData = null;
            pair.Next     = HashTable[hash];

            HashTable[hash] = pairIndex;

            ++PairCount;

            return(pair);
        }
Exemplo n.º 2
0
        // Removes a pair. The pair must exist.
        /// <summary>
        ///     Removes the pair using the specified proxy id 1
        /// </summary>
        /// <param name="proxyId1">The proxy id</param>
        /// <param name="proxyId2">The proxy id</param>
        /// <returns>The object</returns>
        private object RemovePair(int proxyId1, int proxyId2)
        {
            Box2DxDebug.Assert(PairCount > 0);

            if (proxyId1 > proxyId2)
            {
                Math.Swap(ref proxyId1, ref proxyId2);
            }

            int hash = (int)(Hash((uint)proxyId1, (uint)proxyId2) & TableMask);

            //uint16* node = &m_hashTable[hash];
            ushort node = HashTable[hash];
            bool   ion  = false;
            int    ni   = 0;

            while (node != NullPair)
            {
                if (Equals(Pairs[node], proxyId1, proxyId2))
                {
                    //uint16 index = *node;
                    //*node = m_pairs[*node].next;

                    ushort index = node;
                    node = Pairs[node].Next;
                    if (ion)
                    {
                        Pairs[ni].Next = node;
                    }
                    else
                    {
                        HashTable[hash] = node;
                    }

                    Pair   pair     = Pairs[index];
                    object userData = pair.UserData;

                    // Scrub
                    pair.Next     = FreePair;
                    pair.ProxyId1 = NullProxy;
                    pair.ProxyId2 = NullProxy;
                    pair.UserData = null;
                    pair.Status   = 0;

                    FreePair = index;
                    --PairCount;
                    return(userData);
                }

                //node = &m_pairs[*node].next;
                ni   = node;
                node = Pairs[ni].Next;
                ion  = true;
            }

            Box2DxDebug.Assert(false);
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Finds the proxy id 1
        /// </summary>
        /// <param name="proxyId1">The proxy id</param>
        /// <param name="proxyId2">The proxy id</param>
        /// <returns>The pair</returns>
        private Pair Find(int proxyId1, int proxyId2)
        {
            if (proxyId1 > proxyId2)
            {
                Math.Swap(ref proxyId1, ref proxyId2);
            }

            uint hash = (uint)(Hash((uint)proxyId1, (uint)proxyId2) & TableMask);

            return(Find(proxyId1, proxyId2, hash));
        }