예제 #1
0
        private void SetupGeometry()
        {
            this.mesh.ClearGroups();
            this.mesh.AddGroup().Geometry = (IIndexedPrimitiveCollection)(this.Geometry = new ShaderInstancedIndexedPrimitives <VertexPositionTextureInstance, Matrix>(PrimitiveType.TriangleList, 60));
            this.Geometry.Vertices        = new VertexPositionTextureInstance[4]
            {
                new VertexPositionTextureInstance(new Vector3(-0.5f, -0.5f, 0.0f), new Vector2(0.0f, 1f)),
                new VertexPositionTextureInstance(new Vector3(-0.5f, 0.5f, 0.0f), new Vector2(0.0f, 0.0f)),
                new VertexPositionTextureInstance(new Vector3(0.5f, 0.5f, 0.0f), new Vector2(1f, 0.0f)),
                new VertexPositionTextureInstance(new Vector3(0.5f, -0.5f, 0.0f), new Vector2(1f, 1f))
            };
            this.Geometry.Indices = new int[6]
            {
                0,
                1,
                2,
                0,
                2,
                3
            };
            this.Geometry.Instances = new Matrix[this.MaximumCount];
            this.Geometry.MaximizeBuffers(this.MaximumCount);
            int size = this.particles.Size;
            List <PlaneParticleSystem.Particle> list = new List <PlaneParticleSystem.Particle>();

            while (this.particles.Available > 0)
            {
                PlaneParticleSystem.Particle particle = this.particles.Take();
                particle.InstanceIndex = --size;
                list.Add(particle);
            }
            foreach (PlaneParticleSystem.Particle particle in list)
            {
                this.particles.Return(particle);
            }
            this.mesh.Texture.Set((Texture)this.settings.Texture);
        }
예제 #2
0
        public void Update(TimeSpan elapsed)
        {
            if (!this.Enabled)
            {
                return;
            }
            BoundingFrustum boundingFrustum = this.CameraManager.Frustum;

            if (!this.effect.ForcedViewProjection.HasValue)
            {
                Vector3 position = this.CameraManager.Position;
                Vector3 center   = this.CameraManager.Center;
                this.BillboardingPhi = (float)Math.Atan2((double)position.X - (double)center.X, (double)position.Z - (double)center.Z);
            }
            else
            {
                boundingFrustum = this.cachedFrustum;
            }
            if ((double)this.settings.SystemLifetime != 0.0)
            {
                this.age += elapsed;
                if (this.age.TotalSeconds > (double)this.settings.SystemLifetime)
                {
                    this.Enabled = false;
                    this.Visible = false;
                    this.Dead    = true;
                    foreach (PlaneParticleSystem.Particle particle in this.activeParticles)
                    {
                        this.particles.Return(particle);
                    }
                    this.activeParticles.Clear();
                    return;
                }
            }
            if (this.FadingOut)
            {
                this.SinceFadingOut += (float)elapsed.TotalSeconds;
                this.FadeOutAge      = FezMath.Saturate(this.SinceFadingOut / this.FadeOutDuration);
                if ((double)this.FadeOutAge >= 1.0)
                {
                    this.Enabled = false;
                    this.Visible = false;
                    this.Dead    = true;
                    foreach (PlaneParticleSystem.Particle particle in this.activeParticles)
                    {
                        this.particles.Return(particle);
                    }
                    this.activeParticles.Clear();
                    return;
                }
            }
            if (!this.InScreen)
            {
                return;
            }
            this.sinceSpawned -= elapsed;
            bool flag = this.untilNextSpawn.Ticks > 0L;

            this.untilNextSpawn -= elapsed;
            while (this.sinceSpawned.Ticks <= 0L || flag && this.untilNextSpawn.Ticks <= 0L)
            {
                if (flag && this.untilNextSpawn.Ticks <= 0L)
                {
                    for (int index = 0; index < this.settings.SpawnBatchSize; ++index)
                    {
                        if (this.particles.Available > 0)
                        {
                            PlaneParticleSystem.Particle particle = this.particles.Take();
                            particle.Initialize(this);
                            this.activeParticles.Add(particle);
                        }
                    }
                    flag = false;
                }
                if (this.sinceSpawned.Ticks <= 0L)
                {
                    this.PrepareNextSpawn();
                }
            }
            int   val1           = -1;
            float elapsedSeconds = (float)elapsed.TotalSeconds;
            int   num1           = !this.HalfUpdate || !this.halfToProcess ? 0 : this.activeParticles.Count / 2;
            int   num2           = !this.HalfUpdate || this.halfToProcess ? this.activeParticles.Count : this.activeParticles.Count / 2;

            for (int index = num1; index < num2; ++index)
            {
                PlaneParticleSystem.Particle particle = this.activeParticles[index];
                particle.Update(elapsedSeconds);
                if (this.Settings.UseCallback && !particle.DeathProvoked)
                {
                    Vector3          vector3 = particle.Position;
                    TrileEmplacement id      = new TrileEmplacement((int)vector3.X, (int)vector3.Y, (int)vector3.Z);
                    if (this.LevelManager.IsInRange(ref id))
                    {
                        TrileInstance trileInstance = this.LevelManager.TrileInstanceAt(ref id);
                        if (trileInstance != null && trileInstance.Enabled && (!trileInstance.Trile.Immaterial && boundingFrustum.Contains(trileInstance.Center) != ContainmentType.Disjoint))
                        {
                            this.CollisionCallback(particle.Position * FezMath.XZMask + trileInstance.Center * Vector3.UnitY + trileInstance.Trile.Size.Y / 2f * Vector3.UnitY);
                            particle.ProvokeDeath();
                        }
                    }
                }
                if (particle.Dead)
                {
                    particle.Hide();
                    this.activeParticles.RemoveAt(index);
                    --index;
                    --num2;
                    this.particles.Return(particle);
                }
                else
                {
                    val1 = Math.Max(val1, particle.InstanceIndex);
                }
            }
            this.Geometry.InstanceCount = val1;
        }