Ejemplo n.º 1
0
        public void Dispose()
        {
            if (surfaceLoaded && bitmap != null)
            {
                bitmap.Dispose();

                surfaceLoaded = false;
            }
            freeParticles.Clear();
            ActiveParticles.Clear();
        }
Ejemplo n.º 2
0
        //===========================================================
        // Particle System Update Functions
        //===========================================================

        /// <summary>
        /// Sorts the particles to draw particles furthest from the camera first, in order to achieve proper depth perspective.
        ///
        /// <para>NOTE: This operation is very expensive and should only be used when you are
        /// drawing particles with both opaque and semi-transparent portions, and not using additive blending.</para>
        /// <para>Merge Sort is the sorting algorithm used, as it tends to be best for linked lists.
        /// TODO - WHILE MERGE SORT SHOULD BE USED, DUE TO TIME CONSTRAINTS A (PROBABLY) SLOWER METHOD (QUICK-SORT)
        /// IS BEING USED INSTEAD. THIS FUNCTION NEEDS TO BE UPDATED TO USE MERGE SORT STILL.
        /// THE LINKED LIST MERGE SORT ALGORITHM CAN BE FOUND AT http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html</para>
        /// </summary>
        /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
        protected void UpdateParticleSystemToSortParticlesByDistanceFromCamera(float fElapsedTimeInSeconds)
        {
            // Store the Number of Active Particles to sort
            int iNumberOfActiveParticles = ActiveParticles.Count;

            // If there is nothing to sort
            if (iNumberOfActiveParticles <= 1)
            {
                // Exit without sorting
                return;
            }

            // Create a List to put the Active Particles in to be sorted
            List <Particle> cActiveParticleList = new List <Particle>(iNumberOfActiveParticles);

            // Add all of the Particles to the List
            LinkedListNode <Particle> cNode = ActiveParticles.First;

            while (cNode != null)
            {
                // Copy this Particle into the Array
                cActiveParticleList.Add(cNode.Value);

                // Move to the next Active Particle
                cNode = cNode.Next;
            }

            // Now that the List is full, sort it
            cActiveParticleList.Sort(delegate(Particle Particle1, Particle Particle2)
            {
                DefaultSprite3DBillboardParticle cParticle1 = (DefaultSprite3DBillboardParticle)(DPSFParticle)Particle1;
                DefaultSprite3DBillboardParticle cParticle2 = (DefaultSprite3DBillboardParticle)(DPSFParticle)Particle2;
                return(cParticle1.DistanceFromCameraSquared.CompareTo(cParticle2.DistanceFromCameraSquared));
            });

            // Now that the List is sorted, add the Particles into the Active Particles Linked List in sorted order
            ActiveParticles.Clear();
            for (int iIndex = 0; iIndex < iNumberOfActiveParticles; iIndex++)
            {
                // Add this Particle to the Active Particles Linked List.
                // List is sorted from smallest to largest, but we want
                // our Linked List sorted from largest to smallest, since
                // the Particles at the end of the Linked List are drawn last.
                ActiveParticles.AddFirst(cActiveParticleList[iIndex]);
            }
        }