Exemplo n.º 1
0
        /// <summary>Begins a threaded prune of the particles</summary>
        /// <param name="pruneDelegate">
        ///   Method that evaluates whether a particle should be pruned from the system
        /// </param>
        /// <param name="callback">
        ///   Callback that will be invoked when the update has finished
        /// </param>
        /// <param name="state">
        ///   User defined parameter that will be passed to the callback
        /// </param>
        /// <returns>An asynchronous result handle for the background operation</returns>
        public IAsyncResult BeginPrune(
            PrunePredicate pruneDelegate, AsyncCallback callback, object state
            )
        {
            Debug.Assert(
                !this.asyncPrune.IsRunning, "An asynchronous prune is already running"
                );
            Debug.Assert(
                !this.asyncUpdate.IsRunning, "Can't prune while an asynchronous update is running"
                );

            this.asyncPrune.Start(pruneDelegate, callback, state);
            return(this.asyncPrune);
        }
Exemplo n.º 2
0
 /// <summary>Prunes dead particles from the system</summary>
 /// <param name="pruneDelegate">
 ///   Delegate deciding which particles will be pruned
 /// </param>
 public void Prune(PrunePredicate pruneDelegate)
 {
     for (int index = 0; index < this.particleCount;)
     {
         bool keep = pruneDelegate(ref this.particles[index]);
         if (keep)
         {
             ++index;
         }
         else
         {
             this.particles[index] = this.particles[this.particleCount - 1];
             --this.particleCount;
         }
     }
 }
Exemplo n.º 3
0
            /// <summary>
            ///   Resets the asynchronous prune process for another use
            /// </summary>
            /// <param name="pruneDelegate">Method deciding which particles to prune</param>
            /// <param name="callback">
            ///   Callback that will be invoked when pruning has finished
            /// </param>
            /// <param name="state">User-defined state from the BeginPrune() method</param>
            public void Start(
                PrunePredicate pruneDelegate, AsyncCallback callback, object state
                )
            {
                this.running = true;
                lock (this) {
                    this.completed = false;

                    if (this.doneEvent != null)
                    {
                        this.doneEvent.Reset();
                    }
                }
                this.exception = null;

                this.pruneDelegate = pruneDelegate;
                this.callback      = callback;
                this.state         = state;

                ThreadPool.QueueUserWorkItem(this.runDelegate);
            }