Exemplo n.º 1
0
        /** Releases a path claim (pooling).
         * Removes the claim of the path by the specified object.
         * When the claim count reaches zero, the path will be pooled, all variables will be cleared and the path will be put in a pool to be used again.
         * This is great for performance since fewer allocations are made.
         *
         * If the silent parameter is true, this method will remove the claim by the specified object
         * but the path will not be pooled if the claim count reches zero unless a Release call (not silent) has been made earlier.
         * This is used by the internal pathfinding components such as Seeker and AstarPath so that they will not cause paths to be pooled.
         * This enables users to skip the claim/release calls if they want without the path being pooled by the Seeker or AstarPath and
         * thus causing strange bugs.
         *
         * \see Claim
         * \see PathPool
         */
        public void Release(System.Object o, bool silent = false)
        {
            if (o == null)
            {
                throw new System.ArgumentNullException("o");
            }

            for (int i = 0; i < claimed.Count; i++)
            {
                // Need to use ReferenceEquals because it might be called from another thread
                if (System.Object.ReferenceEquals(claimed[i], o))
                {
                    claimed.RemoveAt(i);
                    if (!silent)
                    {
                        releasedNotSilent = true;
                    }

                    if (claimed.Count == 0 && releasedNotSilent)
                    {
                        PathPool.Pool(this);
                    }
                    return;
                }
            }
            if (claimed.Count == 0)
            {
                throw new System.ArgumentException("You are releasing a path which is not claimed at all (most likely it has been pooled already). " +
                                                   "Are you releasing the path with the same object (" + o + ") twice?" +
                                                   "\nCheck out the documentation on path pooling for help.");
            }
            throw new System.ArgumentException("You are releasing a path which has not been claimed with this object (" + o + "). " +
                                               "Are you releasing the path with the same object twice?\n" +
                                               "Check out the documentation on path pooling for help.");
        }
Exemplo n.º 2
0
 public void Release(object o, bool silent = false)
 {
     if (o == null)
     {
         throw new ArgumentNullException("o");
     }
     for (int i = 0; i < this.claimed.Count; i++)
     {
         if (object.ReferenceEquals(this.claimed[i], o))
         {
             this.claimed.RemoveAt(i);
             if (!silent)
             {
                 this.releasedNotSilent = true;
             }
             if (this.claimed.Count == 0 && this.releasedNotSilent)
             {
                 PathPool.Pool(this);
             }
             return;
         }
     }
     if (this.claimed.Count == 0)
     {
         throw new ArgumentException("You are releasing a path which is not claimed at all (most likely it has been pooled already). Are you releasing the path with the same object (" + o + ") twice?\nCheck out the documentation on path pooling for help.");
     }
     throw new ArgumentException("You are releasing a path which has not been claimed with this object (" + o + "). Are you releasing the path with the same object twice?\nCheck out the documentation on path pooling for help.");
 }
 // Token: 0x0600230A RID: 8970 RVA: 0x00193416 File Offset: 0x00191616
 public static void Recycle(T path)
 {
     PathPool.Pool(path);
 }