Performance improvements to ParticleSystem.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[ParticleEmitterSettings]
|
[ParticleEmitterSettings]
|
||||||
|
|
||||||
MaxParticles = 4096
|
MaxParticles = 8096
|
||||||
EmitRadius = 128
|
EmitRadius = 128
|
||||||
Explosiveness = 1.0
|
Explosiveness = 1.0
|
||||||
LifeTime = 1.0
|
LifeTime = 1.0
|
||||||
|
|||||||
@@ -165,23 +165,21 @@ public class ParticleEmitter : IUpdatableSystem
|
|||||||
Emit();
|
Emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deltaTimeVector = new Vector2((float)deltaTime);
|
||||||
|
var lifeTimeInv = 1.0f / Settings.LifeTime;
|
||||||
|
var gravityVector = Settings.Gravity * (float)deltaTime;
|
||||||
|
var dampingFactor = Settings.Damping * (float)deltaTime;
|
||||||
|
|
||||||
for (int i = 0; i < _maxParticles; i++)
|
for (int i = 0; i < _maxParticles; i++)
|
||||||
{
|
{
|
||||||
// var particle = _particles[i];
|
|
||||||
|
|
||||||
_lifetimes[i] = Math.Max(0.0f, _lifetimes[i] - (float)deltaTime);
|
_lifetimes[i] = Math.Max(0.0f, _lifetimes[i] - (float)deltaTime);
|
||||||
|
|
||||||
var t = _lifetimes[i] / Settings.LifeTime;
|
var t = _lifetimes[i] * lifeTimeInv;
|
||||||
|
|
||||||
_velocities[i] += Settings.Gravity * (float)deltaTime;
|
_velocities[i] += gravityVector;
|
||||||
_positions[i] += _velocities[i] * (float)deltaTime;
|
_positions[i] += _velocities[i] * deltaTimeVector;
|
||||||
// particle.Rotation += particle.AngularVelocity * (float)deltaTime;
|
|
||||||
// particle.Scale = MathUtils.Lerp(Settings.ScaleEnd, Settings.ScaleBegin, t);
|
|
||||||
|
|
||||||
var color = MathUtils.LerpColor(Settings.ColorEnd, Settings.ColorBegin, t);
|
_velocities[i] -= _velocities[i] * dampingFactor;
|
||||||
// particle.ColorArgb = color.Argb;
|
|
||||||
|
|
||||||
_velocities[i] -= _velocities[i] * Settings.Damping * (float)deltaTime;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user