Esempio n. 1
0
        /// <summary>
        /// Adds a <see cref="IParticleEmitter"/> to this <see cref="IParticleEffect"/>. Should only be called from the
        /// <see cref="IParticleEmitter"/>'s constructor.
        /// </summary>
        /// <param name="emitter">The <see cref="IParticleEmitter"/> to add.</param>
        internal void AddParticleEmitter(ParticleEmitter emitter)
        {
            if (IsDisposed)
            {
                const string errmsg =
                    "Tried to add ParticleEmitter `{0}` to ParticleEffect `{1}`, but the ParticleEffect was disposed.";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, emitter, this);
                Debug.Fail(string.Format(errmsg, emitter, this));
                emitter.Dispose();
                return;
            }

            Debug.Assert(!_emitters.Contains(emitter));
            Debug.Assert(emitter.Owner == this);

            // Make sure the emitter's name is unique
            var newName = GenerateUniqueEmitterName(emitter.Name ?? ParticleEmitter.DefaultName);
            emitter.ChangeName(newName);

            // Add
            _emitters.Add(emitter);

            emitter.Disposed -= emitter_Disposed;
            emitter.Disposed += emitter_Disposed;

            if (EmitterAdded != null)
                EmitterAdded.Raise(this, EventArgsHelper.Create((IParticleEmitter)emitter));
        }
        /// <summary>
        /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
        /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
        /// </summary>
        /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
        /// came from.</param>
        /// <param name="particle">The <see cref="Particle"/> to process.</param>
        /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
        /// was last updated.</param>
        protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
        {
            Vector2 deltaGrav;

            Vector2.Multiply(ref _gravity, elapsedTime * 0.001f, out deltaGrav);

            particle.ApplyForce(ref deltaGrav);
        }
        /// <summary>
        /// When overridden in the derived class, handles updating the <see cref="ParticleEmitter"/>.
        /// </summary>
        /// <param name="emitter">The <see cref="ParticleEmitter"/> to be modified.</param>
        /// <param name="elapsedTime">The amount of time that has elapsed since the last update.</param>
        protected override void HandleUpdate(ParticleEmitter emitter, int elapsedTime)
        {
            _timeout -= elapsedTime;

            // Store the original value
            _emitterReleaseAmount = emitter.ReleaseAmount;

            // If bursting, set the release amount to 0 (it will be restored later in HandleRestore)
            if (!_isBursting)
                emitter.ReleaseAmount = 0;

            // After enough time has elapsed, flip between bursting and not bursting
            if (_timeout <= 0)
            {
                if (_isBursting)
                    _timeout = RestPeriod;
                else
                    _timeout = EmitPeriod;

                _isBursting = !_isBursting;
            }
        }
 /// <summary>
 /// When overridden in the derived class, handles reverting changes made to the <see cref="ParticleEmitter"/>
 /// by this <see cref="EmitterModifier"/>.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> to revert the changes to.</param>
 protected override void HandleRestore(ParticleEmitter emitter)
 {
     // Restore the release amount
     emitter.ReleaseAmount = _emitterReleaseAmount;
 }
Esempio n. 5
0
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
 {
     particle.Rotation += _rate * elapsedTime;
 }
Esempio n. 6
0
        /// <summary>
        /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
        /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
        /// </summary>
        /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
        /// came from.</param>
        /// <param name="particle">The <see cref="Particle"/> to process.</param>
        /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
        /// was last updated.</param>
        protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
        {
            var agePercent = particle.GetAgePercent(CurrentTime);

            if (AllBitsSet())
                particle.Color = ReleaseColor.Lerp(UltimateColor, agePercent);
            else
            {
                byte r, g, b, a;

                if (ModifyRed)
                    r = (byte)MathHelper.Lerp(ReleaseColor.R, UltimateColor.R, agePercent);
                else
                    r = particle.Color.R;

                if (ModifyGreen)
                    g = (byte)MathHelper.Lerp(ReleaseColor.G, UltimateColor.G, agePercent);
                else
                    g = particle.Color.G;

                if (ModifyBlue)
                    b = (byte)MathHelper.Lerp(ReleaseColor.B, UltimateColor.B, agePercent);
                else
                    b = particle.Color.B;

                if (ModifyAlpha)
                    a = (byte)MathHelper.Lerp(ReleaseColor.A, UltimateColor.A, agePercent);
                else
                    a = particle.Color.A;

                particle.Color = new Color(r, g, b, a);
            }
        }
 /// <summary>
 /// Writes a <see cref="ParticleEmitter"/> to an <see cref="IValueWriter"/>.
 /// </summary>
 /// <param name="writer">The <see cref="IValueWriter"/> to write to.</param>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> to write.</param>
 public static void Write(IValueWriter writer, ParticleEmitter emitter)
 {
     writer.Write(_emitterTypeKeyName, Instance.GetTypeName(emitter.GetType()));
     writer.WriteStartNode(_emitterNodeName);
     {
         emitter.WriteState(writer);
     }
     writer.WriteEndNode(_emitterNodeName);
 }
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is released. Only valid if <see cref="ParticleModifier.ProcessOnRelease"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 protected override void HandleProcessReleased(ParticleEmitter emitter, Particle particle)
 {
 }
Esempio n. 9
0
 /// <summary>
 /// Process a <see cref="Particle"/> that was released.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> the <paramref name="particle"/> came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 internal void ProcessReleased(ParticleEmitter emitter, Particle particle)
 {
     Debug.Assert(ProcessOnRelease, "This method should NOT be called when ProcessOnRelease is not set!");
     HandleProcessReleased(emitter, particle);
 }
Esempio n. 10
0
 /// <summary>
 /// When overridden in the derived class, handles updating the <see cref="ParticleEmitter"/>.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> to be modified.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the last update.</param>
 protected abstract void HandleUpdate(ParticleEmitter emitter, int elapsedTime);
Esempio n. 11
0
 /// <summary>
 /// When overridden in the derived class, handles reverting changes made to the <see cref="ParticleEmitter"/>
 /// by this <see cref="EmitterModifier"/>.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> to revert the changes to.</param>
 protected abstract void HandleRestore(ParticleEmitter emitter);
Esempio n. 12
0
 /// <summary>
 /// Updates the <see cref="EmitterModifier"/>.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> to modify.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the last update.</param>
 public void Update(ParticleEmitter emitter, int elapsedTime)
 {
     HandleUpdate(emitter, elapsedTime);
 }
Esempio n. 13
0
 /// <summary>
 /// Restores the <see cref="ParticleEmitter"/> from changes made by this <see cref="EmitterModifier"/>.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> to revert changes on.</param>
 public void Restore(ParticleEmitter emitter)
 {
     HandleRestore(emitter);
 }
Esempio n. 14
0
 /// <summary>
 /// When overridden in the derived class, handles updating the <see cref="ParticleEmitter"/>.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> to be modified.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the last update.</param>
 protected override void HandleUpdate(ParticleEmitter emitter, int elapsedTime)
 {
 }
Esempio n. 15
0
 /// <summary>
 /// When overridden in the derived class, handles reverting changes made to the <see cref="ParticleEmitter"/>
 /// by this <see cref="EmitterModifier"/>.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> to revert the changes to.</param>
 protected override void HandleRestore(ParticleEmitter emitter)
 {
 }
Esempio n. 16
0
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is released. Only valid if <see cref="ParticleModifier.ProcessOnRelease"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 protected abstract void HandleProcessReleased(ParticleEmitter emitter, Particle particle);
Esempio n. 17
0
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 protected abstract void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime);
Esempio n. 18
0
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
 {
     particle.Scale = MathHelper.Lerp(InitialScale, UltimateScale, particle.GetAgePercent(CurrentTime));
 }
Esempio n. 19
0
 /// <summary>
 /// Process a <see cref="Particle"/> that was updated.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> the <paramref name="particle"/> came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 internal void ProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
 {
     Debug.Assert(ProcessOnUpdate, "This method should NOT be called when ProcessOnUpdate is not set!");
     HandleProcessUpdated(emitter, particle, elapsedTime);
 }
Esempio n. 20
0
        /// <summary>
        /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
        /// it is released. Only valid if <see cref="ParticleModifier.ProcessOnRelease"/> is set.
        /// </summary>
        /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
        /// came from.</param>
        /// <param name="particle">The <see cref="Particle"/> to process.</param>
        protected override void HandleProcessReleased(ParticleEmitter emitter, Particle particle)
        {
            if (AllBitsSet())
                particle.Color = ReleaseColor;
            else
            {
                byte r, g, b, a;

                if (ModifyRed)
                    r = ReleaseColor.R;
                else
                    r = particle.Color.R;

                if (ModifyGreen)
                    g = ReleaseColor.G;
                else
                    g = particle.Color.G;

                if (ModifyBlue)
                    b = ReleaseColor.B;
                else
                    b = particle.Color.B;

                if (ModifyAlpha)
                    a = ReleaseColor.A;
                else
                    a = particle.Color.A;

                particle.Color = new Color(r, g, b, a);
            }
        }
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
 {
 }
Esempio n. 22
0
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is released. Only valid if <see cref="ParticleModifier.ProcessOnRelease"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 protected override void HandleProcessReleased(ParticleEmitter emitter, Particle particle)
 {
 }