using Azimuth; namespace Konis.Testbed { /// /// Sparks that each leave a puff of smoke where they die. Only this class joins the two defs. /// public class SparksAndSmoke : Effect { public SparksAndSmoke(string name, StandardEmitterDef sparks, StandardEmitterDef smoke) : base(name, sparks) { Smoke = smoke; } /// /// Gets the def of the puffs, one of which a spark leaves when it dies. /// public StandardEmitterDef Smoke { get; } /// /// Starts the smoke before the sparks, so the world steps it first and a puff keeps the spot where it was born. /// public override RunningEffect Start(ParticleWorld world, Vector3 position, float preWarmSeconds) { Emitter smoke = world.Spawn(Smoke, position); Emitter sparks = world.Spawn(Def, position); var noOffset = new Vector3(0, 0, 0); // A spark the clip kills has gone past the boundary, so the puff is put back on it. sparks.OnParticleDeath += (emitter, dead) => { emitter.ClampToClip(dead); smoke.Burst(emitter.Store.Particles, dead, noOffset, world.ParticleRoom); }; // The world's own pre-warm would run the sparks before the handler is attached. float left = preWarmSeconds; while (left > 0f) { float step = System.Math.Min(left, ParticleWorld.PreWarmStepSize); smoke.Update(step, world.ParticleRoom); sparks.Update(step, world.ParticleRoom); left -= step; } return new RunningEffect(sparks, smoke); } } }