Example #1
0
        public bool UpdateParticles()
        {
            if (Info == null || PhysicsObj == null)
            {
                return(false);
            }

            if (!PhysicsObj.ShouldDrawParticles(DegradeDistance))
            {
                if (DegradedOut != 0)
                {
                    PhysicsObj.SetNoDraw(true);
                    DegradedOut = 1;
                }
                LastUpdateTime = PhysicsTimer.CurrentTime;
                if (Info.TotalParticles > 0 || Info.TotalSeconds > 0.0f)
                {
                    if (Info.MaxParticles > 0)
                    {
                        for (var i = 0; i < Info.MaxParticles; i++)
                        {
                            var particle = Particles[i];
                            if (particle != null)
                            {
                                particle.Lifetime = PhysicsTimer.CurrentTime - particle.Birthtime;
                                KillParticle(i);
                            }
                        }
                    }
                    if (!Stopped)
                    {
                        if (ShouldEmitParticle())
                        {
                            RecordParticleEmission();
                        }
                        StopEmitter();
                        return(true);
                    }
                    else
                    {
                        return(NumParticles != 0);
                    }
                }
                else
                {
                    if (Info.MaxParticles > 0)
                    {
                        for (var i = 0; i < Info.MaxParticles; i++)
                        {
                            Particles[i].Birthtime = PhysicsTimer.CurrentTime;
                        }
                    }
                    return(true);
                }
            }
            else
            {
                if (DegradedOut != 0)
                {
                    DegradedOut = 0;
                    PhysicsObj.SetNoDraw(false);
                }
                if (Info.MaxParticles > 0)
                {
                    for (var i = 0; i < Info.MaxParticles; i++)
                    {
                        AFrame frame = null;
                        var    part  = Parts[i];
                        if (part != null)
                        {
                            if (Info.IsParentLocal)
                            {
                                if (PartIndex == -1)
                                {
                                    frame = Parent.Position.Frame;
                                }
                                else
                                {
                                    frame = Parent.PartArray.Parts[PartIndex].Pos.Frame;
                                }
                            }
                            else
                            {
                                frame = Particles[i].StartFrame;
                            }

                            var firstParticle = Info.TotalParticles == 0 && Info.TotalSeconds == 0.0f;
                            Particles[i].Update(Info.ParticleType, firstParticle, part, frame);
                            KillParticle(i);
                        }
                    }
                }
                var hasParticles = true;
                if (!Stopped)
                {
                    if (ShouldEmitParticle())
                    {
                        EmitParticle();
                    }

                    StopEmitter();
                }
                else
                {
                    hasParticles = NumParticles != 0;
                }

                LastUpdateTime = PhysicsTimer.CurrentTime;

                return(hasParticles);
            }
        }