Beispiel #1
0
        private static Queue <RenewalEvent> InitializeRenewalTimes(int particleCount, int lifespan)
        {
            var renewalEvents = new Queue <RenewalEvent>();

            for (int i = 0; i < particleCount; i++)
            {
                var renewalEvent = new RenewalEvent {
                    Index = i, Time = i * lifespan / particleCount
                };
                renewalEvents.Enqueue(renewalEvent);
            }

            return(renewalEvents);
        }
Beispiel #2
0
        /// <summary>
        /// Should be called once per frame. Returns a list of the indices of particles which have reached the
        /// end of their lifespan.
        /// </summary>
        /// <returns></returns>
        public List <int> IndicesToBeRenewed()
        {
            var lifespan = _options.ParticleLifespan;

            var indices = new List <int>(_options.ParticleCount / _options.ParticleLifespan);

            while (_renewalSchedule.Peek().Time < _timesCalled)
            {
                var renewalEvent = _renewalSchedule.Dequeue();
                indices.Add(renewalEvent.Index);

                var newRenewalEvent = new RenewalEvent
                {
                    Index = renewalEvent.Index,
                    Time  = _timesCalled + lifespan
                };
                _renewalSchedule.Enqueue(newRenewalEvent);
            }

            _timesCalled = _timesCalled + 1;

            return(indices);
        }