What happened to Pool<>?

Oct 2, 2010 at 1:10 PM

Hello everyone,

I upgraded from Farseer 2.1 to 3.0 and opened my current project in XNA 4.0 and noticed that many things have changed.  Geom is now Factory, PhysicSimulator is now World but what replaces Pool<>?  I use it for my bullet tracking and now it doesn't work?  I can't find anything in 3.0 that would replace it.

 

 

Thanks,


Adam

Oct 2, 2010 at 3:48 PM

Hey Adam,

I'm not part of the farseer crew, but I can answer this for you.
Pool is just a Stack. You can make your own Pool class by copying + pasting the following code. However, I recommend just using a Stack or a List as there are very few, if any, advantages of using a Pool (it literally just replaces the names of some functions).

A Stack is an extremely basic data structure utilizing the functions Push and Pop. Farseer's Pool class was basically identical, renaming Push and Pop to Insert and Fetch. Because it provided no additional functionality, it was probably just replaced by the Stack class.

 

using System.Collections.Generic;

namespace FarseerGames.FarseerPhysics
{
    /// 
    /// Pool used to cache objects.
    /// 
    /// 
    public class Pool : Stack where T : new()
    {
        public Pool()
        {
        }

        public Pool(int size)
        {
            for (int i = 0; i < size; i++)
            {
                Push(new T());
            }
        }

        public T Fetch()
        {
            if (Count > 0)
            {
                return Pop();
            }
            return new T();
        }

        public void Insert(T item)
        {
            Push(item);
        }
    }
}

-Casey

 

Oct 2, 2010 at 9:37 PM

Thanks for your reply.  I kind of figured it was the same type of class as a Stack or List but I figured it might have some unique optimizations for the physics system.  I'll just replace it.  Thanks.