Beispiel #1
0
        public ParticleList(RTSRenderer renderer, int maxCount, ParticleType pt)
        {
            Type = pt;

            // Make The Lists
            particles = new List <PType>();
            vertices  = new VType[maxCount];

            // Create The Instance Buffer
            InstanceBuffer = renderer.CreateDynamicVertexBuffer(vertices[0].VertexDeclaration, MaxCount, BufferUsage.WriteOnly);
            InstanceBuffer.SetData(vertices);

            VBBinds    = new VertexBufferBinding[2];
            VBBinds[1] = new VertexBufferBinding(InstanceBuffer, 0, 1);
        }
Beispiel #2
0
        public void Update(List <Particle> newParticles, float dt)
        {
            // Update The Particles
            Action <Particle> fp = (p) => { p.Update(dt); };

            particles.AsParallel().ForAll(fp);

            bool add = particles.RemoveAll(Particle.IsParticleDead) > 0;

            // Add New Particles
            for (int i = 0; i < newParticles.Count; i++)
            {
                if (newParticles[i] == null)
                {
                    continue;
                }
                if (newParticles[i].Type == Type)
                {
                    particles.Add(newParticles[i] as PType);
                    add = true;
                }
            }

            if (add)
            {
                // Make Sure We Don't Run Over
                if (particles.Count > MaxCount)
                {
                    particles.RemoveRange(0, particles.Count - MaxCount);
                }
                for (int i = 0; i < particles.Count; i++)
                {
                    vertices[i] = (VType)particles[i].Vertex;
                }
                InstanceBuffer.SetData(vertices);
            }
        }
Beispiel #3
0
 public void UpdateInstanceBuffer()
 {
     // dirty flag?
     InstanceBuffer.SetData(Instances_);
 }