Exemplo n.º 1
0
        public override void Update(NodeReference reference, ParticleEffectInstance instance, TimeSpan delta, ref Matrix4 transform, float sparam)
        {
            if (reference.Paired.Count == 0)
            {
                return;
            }
            if (NodeLifeSpan < instance.GlobalTime)
            {
                return;
            }
            if (reference.Paired[0].Node.NodeLifeSpan < instance.GlobalTime)
            {
                return;
            }
            var maxCount = 1000;
            //var maxCount = MaxParticles == null ? int.MaxValue : (int)Math.Ceiling(MaxParticles.GetValue(sparam, 0f));
            var freq    = Frequency == null ? 0f : Frequency.GetValue(sparam, 0f);
            var spawnMs = freq <= 0 ? 0 : 1 / (double)freq;
            var state   = instance.GetEmitterState(reference);

            if (state.ParticleCount >= maxCount)
            {
                return;
            }
            int j = 0;

            if (spawnMs > 0)
            {
                //Spawn lots of particles
                var dt = Math.Min(delta.TotalSeconds, 1);                 //don't go crazy during debug pauses
                while (true)
                {
                    if (state.SpawnTimer < dt)
                    {
                        dt -= state.SpawnTimer;
                        state.SpawnTimer = spawnMs;
                    }
                    else
                    {
                        state.SpawnTimer -= dt;
                        break;
                    }
                    if (state.ParticleCount + 1 <= maxCount)
                    {
                        var idx = instance.GetNextFreeParticle();
                        if (idx == -1)
                        {
                            return;
                        }
                        j++;
                        state.ParticleCount++;
                        SpawnParticle(idx, reference, instance, ref transform, sparam, (float)instance.GlobalTime);
                        var app = (FxAppearance)reference.Paired[0].Node;
                        app.OnParticleSpawned(idx, instance.Pool.Particles[idx].Appearance, instance);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void SpawnInitialParticles(NodeReference reference, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam)
        {
            int j = 0;

            for (int i = 0; i < InitialParticles; i--)
            {
                var idx = instance.GetNextFreeParticle();
                if (idx == -1)
                {
                    break;
                }
                SpawnParticle(idx, reference, instance, ref transform, sparam, 0);
                j++;
            }
        }
Exemplo n.º 3
0
        public void SpawnInitialParticles(ParticleEffect fx, ParticleEffectInstance instance, ref Matrix4 transform, float sparam)
        {
            int j = 0;

            for (int i = 0; i < InitialParticles; i--)
            {
                var idx = instance.GetNextFreeParticle();
                if (idx == -1)
                {
                    break;
                }
                SpawnParticle(idx, fx, instance, ref transform, sparam);
                j++;
            }
            instance.GetEmitterState(this).ParticleCount = j;
        }
Exemplo n.º 4
0
        public override void Update(ParticleEffect fx, ParticleEffectInstance instance, TimeSpan delta, ref Matrix4 transform, float sparam)
        {
            if (!fx.Pairs.ContainsKey(this))
            {
                return;
            }
            var maxCount = MaxParticles == null ? int.MaxValue : (int)Math.Ceiling(MaxParticles.GetValue(sparam, 0f));
            var freq     = Frequency == null ? 0f : Frequency.GetValue(sparam, 0f);
            var spawnMs  = freq <= 0 ? 0 : 1 / (double)freq;
            var state    = instance.GetEmitterState(this);

            if (state.ParticleCount >= maxCount)
            {
                return;
            }
            if (spawnMs > 0)
            {
                //Spawn lots of particles
                var dt = Math.Min(delta.TotalSeconds, 1);                 //don't go crazy during debug pauses
                while (true)
                {
                    if (state.SpawnTimer < dt)
                    {
                        dt -= state.SpawnTimer;
                        state.SpawnTimer = spawnMs;
                    }
                    else
                    {
                        state.SpawnTimer -= dt;
                        break;
                    }
                    if (state.ParticleCount + 1 <= maxCount)
                    {
                        var idx = instance.GetNextFreeParticle();
                        if (idx == -1)
                        {
                            return;
                        }
                        state.ParticleCount++;
                        SpawnParticle(idx, fx, instance, ref transform, sparam);
                        instance.Particles[idx].Appearance.OnParticleSpawned(idx, instance);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public override void Update(NodeReference reference, ParticleEffectInstance instance, double delta, ref Matrix4x4 transform, float sparam)
        {
            if (reference.Paired.Count == 0)
            {
                return;
            }
            if (NodeLifeSpan < instance.GlobalTime)
            {
                return;
            }
            //if (reference.Paired[0].Node.NodeLifeSpan < instance.GlobalTime) return;
            var maxCount = MaxParticles == null ? int.MaxValue : (int)Math.Ceiling(MaxParticles.GetValue(sparam, (float)instance.GlobalTime));
            var freq     = Frequency == null ? 0f : Frequency.GetValue(sparam, (float)instance.GlobalTime);
            var spawnMs  = freq <= 0 ? 0 : 1 / (double)freq;
            int j        = 0;
            var count    = instance.ParticleCounts[reference.EmitterIndex];

            if (spawnMs > 0)
            {
                if (instance.SpawnTimers[reference.EmitterIndex] > spawnMs)
                {
                    instance.SpawnTimers[reference.EmitterIndex] = spawnMs;
                }
                //Spawn lots of particles
                var dt = Math.Min(delta, 1);                 //don't go crazy during debug pauses
                while (true)
                {
                    if (instance.SpawnTimers[reference.EmitterIndex] < dt)
                    {
                        dt -= instance.SpawnTimers[reference.EmitterIndex];
                        instance.SpawnTimers[reference.EmitterIndex] = spawnMs;
                    }
                    else
                    {
                        instance.SpawnTimers[reference.EmitterIndex] -= dt;
                        break;
                    }
                    if (count < maxCount)
                    {
                        var idx = instance.GetNextFreeParticle();
                        if (idx == -1)
                        {
                            return;
                        }
                        j++;
                        SpawnParticle(idx, reference, instance, ref transform, sparam, (float)instance.GlobalTime);
                        var app = (FxAppearance)reference.Paired[0].Node;
                        app.OnParticleSpawned(idx, instance.Pool.Particles[idx].Appearance, instance);
                        //Simulate time already alive (TODO fix the time loop properly)
                        instance.Pool.Particles[idx].TimeAlive = (float)dt;
                        instance.Pool.Particles[idx].Position += instance.Pool.Particles[idx].Normal * (float)dt;
                        count++;
                    }
                }
            }
            else
            {
                instance.SpawnTimers[reference.EmitterIndex] = 0;
            }
            instance.ParticleCounts[reference.EmitterIndex] = count;
        }