// O(1) complexity, since there is no big loop to go through
        public void Create(double x, double y, double velocityX, double velocityY, int lifetime)
        {
            // Make sure the pool isn't full
            Debug.Assert(_firstAvilable != null);

            // remove if from the avilable list
            ParticleWithFreeList newParticle = _firstAvilable;
            _firstAvilable = newParticle.GetNext();

            newParticle.Initialize(x,y,velocityX,velocityY, lifetime);
        }
Example #2
0
 public void Animate()
 {
     for (int i = 0; i < POOL_SIZE; i++)
     {
         if (_particlesFreeList[i].Animate())
         {
             // add this particle to the front of the list
             _particlesFreeList[i].SetNext(_firstAvilable);
             _firstAvilable = _particlesFreeList[i];
         }
     }
 }
 public void Animate()
 {
     for (int i = 0; i < POOL_SIZE; i++)
     {
         if (_particlesFreeList[i].Animate())
         {
             // add this particle to the front of the list
             _particlesFreeList[i].SetNext(_firstAvilable);
             _firstAvilable = _particlesFreeList[i];
         }
     }
 }
Example #4
0
        // O(1) complexity, since there is no big loop to go through
        public void Create(double x, double y, double velocityX, double velocityY, int lifetime)
        {
            // Make sure the pool isn't full
            Debug.Assert(_firstAvilable != null);

            // remove if from the avilable list
            ParticleWithFreeList newParticle = _firstAvilable;

            _firstAvilable = newParticle.GetNext();

            newParticle.Initialize(x, y, velocityX, velocityY, lifetime);
        }
        public ParticlePoolWithFreeList()
        {
            // these initialization loops are not totally correct (according to the book)
            // since I cannot use pointers in C#

            _particlesFreeList = new ParticleWithFreeList[POOL_SIZE];

            for (int i = 0; i < POOL_SIZE; i++)
            {
                _particlesFreeList[i] = new ParticleWithFreeList(i.ToString());
            }

            for (int i = 0; i < POOL_SIZE; i++)
            {
                _particlesFreeList[i].SetNext(_particlesFreeList[i + 1]);
            }

            _firstAvilable = _particlesFreeList[0];
            _particlesFreeList[POOL_SIZE - 1].SetNext(null);
        }
Example #6
0
        public ParticlePoolWithFreeList()
        {
            // these initialization loops are not totally correct (according to the book)
            // since I cannot use pointers in C#

            _particlesFreeList = new ParticleWithFreeList[POOL_SIZE];

            for (int i = 0; i < POOL_SIZE; i++)
            {
                _particlesFreeList[i] = new ParticleWithFreeList(i.ToString());
            }

            for (int i = 0; i < POOL_SIZE; i++)
            {
                _particlesFreeList[i].SetNext(_particlesFreeList[i + 1]);
            }

            _firstAvilable = _particlesFreeList[0];
            _particlesFreeList[POOL_SIZE - 1].SetNext(null);
        }
Example #7
0
 // some kind of linked list
 public void SetNext(ParticleWithFreeList next)
 {
     _next = next;
 }
Example #8
0
 public ParticleWithFreeList(string name)
 {
     _framesLeft = 0;
     _name       = name;
     _next       = null;
 }
 // some kind of linked list
 public void SetNext(ParticleWithFreeList next)
 {
     _next = next;
 }
 public ParticleWithFreeList(string name)
 {
     _framesLeft = 0;
     _name = name;
     _next = null;
 }