Example #1
0
        public Particle GetNew()
        {
            if (freeIds.Count == 0)
            {
                // Extending pool
                pool.Capacity += pool.Count/2 + 1;
                var extendSize = pool.Capacity - pool.Count;
                for (var n = 0; n < extendSize; n++)
                {
                    var p = new Particle(this, pool.Count);
                    pool.Add(p);
                    freeIds.Enqueue(p.ID);
                }
#if DEBUG
                Console.WriteLine("Particle pool upsized to {0}", pool.Capacity);
#endif
            }
            var index = freeIds.Dequeue();
            pool[index].Destroyed = false;
            return pool[index];
        }
Example #2
0
 internal void Destroy(Particle particle)
 {
     particle.Destroyed = true;
     freeIds.Enqueue(particle.ID);
 }