Unstable 0.1400.2.0 (a mimir edition)
This commit is contained in:
@@ -26,8 +26,6 @@ namespace Barotrauma.Particles
|
||||
|
||||
private float angularVelocity;
|
||||
|
||||
private Vector2 dragVec = Vector2.Zero;
|
||||
private float dragWait = 0;
|
||||
private float collisionIgnoreTimer = 0;
|
||||
|
||||
private Vector2 size;
|
||||
@@ -35,6 +33,7 @@ namespace Barotrauma.Particles
|
||||
|
||||
private Color color;
|
||||
private bool changeColor;
|
||||
private bool UseMiddleColor;
|
||||
|
||||
private int spriteIndex;
|
||||
|
||||
@@ -112,9 +111,7 @@ namespace Barotrauma.Particles
|
||||
|
||||
animState = 0;
|
||||
animFrame = 0;
|
||||
dragWait = 0;
|
||||
dragVec = Vector2.Zero;
|
||||
|
||||
|
||||
currentHull = Hull.FindHull(position, hullGuess);
|
||||
|
||||
size = prefab.StartSizeMin + (prefab.StartSizeMax - prefab.StartSizeMin) * Rand.Range(0.0f, 1.0f);
|
||||
@@ -144,10 +141,21 @@ namespace Barotrauma.Particles
|
||||
|
||||
angularVelocity = Rand.Range(prefab.AngularVelocityMinRad, prefab.AngularVelocityMaxRad);
|
||||
|
||||
totalLifeTime = prefab.LifeTime;
|
||||
lifeTime = prefab.LifeTime;
|
||||
|
||||
if (prefab.LifeTimeMin <= 0.0f)
|
||||
{
|
||||
totalLifeTime = prefab.LifeTime;
|
||||
lifeTime = prefab.LifeTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
totalLifeTime = Rand.Range(prefab.LifeTimeMin, prefab.LifeTime);
|
||||
lifeTime = totalLifeTime;
|
||||
}
|
||||
|
||||
startDelay = Rand.Range(prefab.StartDelayMin, prefab.StartDelayMax);
|
||||
|
||||
UseMiddleColor = prefab.UseMiddleColor;
|
||||
color = prefab.StartColor;
|
||||
changeColor = prefab.StartColor != prefab.EndColor;
|
||||
ColorMultiplier = Vector4.One;
|
||||
@@ -243,13 +251,27 @@ namespace Barotrauma.Particles
|
||||
}
|
||||
|
||||
size.X += sizeChange.X * deltaTime;
|
||||
size.Y += sizeChange.Y * deltaTime;
|
||||
size.Y += sizeChange.Y * deltaTime;
|
||||
|
||||
if (changeColor)
|
||||
if (UseMiddleColor)
|
||||
{
|
||||
color = Color.Lerp(prefab.EndColor, prefab.StartColor, lifeTime / prefab.LifeTime);
|
||||
if (lifeTime > totalLifeTime * 0.5f)
|
||||
{
|
||||
color = Color.Lerp(prefab.MiddleColor, prefab.StartColor, (lifeTime / totalLifeTime - 0.5f) * 2.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = Color.Lerp(prefab.EndColor, prefab.MiddleColor, lifeTime / totalLifeTime * 2.0f);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (changeColor)
|
||||
{
|
||||
color = Color.Lerp(prefab.EndColor, prefab.StartColor, lifeTime / totalLifeTime);
|
||||
}
|
||||
}
|
||||
|
||||
if (prefab.Sprites[spriteIndex] is SpriteSheet)
|
||||
{
|
||||
animState += deltaTime;
|
||||
@@ -399,29 +421,24 @@ namespace Barotrauma.Particles
|
||||
|
||||
private void ApplyDrag(float dragCoefficient, float deltaTime)
|
||||
{
|
||||
if (velocity.LengthSquared() < dragVec.LengthSquared())
|
||||
|
||||
float speed = velocity.Length();
|
||||
velocity /= speed;
|
||||
|
||||
float drag = speed * speed * dragCoefficient * 0.01f * deltaTime;
|
||||
if (drag > speed)
|
||||
{
|
||||
velocity = Vector2.Zero;
|
||||
return;
|
||||
}
|
||||
if (Math.Abs(velocity.X) < 0.0001f && Math.Abs(velocity.Y) < 0.0001f) return;
|
||||
|
||||
//TODO: some better way to handle particle drag
|
||||
//this doesn't work that well because the drag vector is only updated every 0.5 seconds, allowing the particle to accelerate way more than it should
|
||||
//(e.g. a falling particle can freely accelerate for 0.5 seconds before the drag takes effect)
|
||||
dragWait-=deltaTime;
|
||||
if (dragWait <= 0f)
|
||||
else
|
||||
{
|
||||
dragWait = 0.5f;
|
||||
|
||||
float speed = velocity.Length();
|
||||
|
||||
dragVec = (velocity / speed) * Math.Min(speed * speed * dragCoefficient * deltaTime, 1.0f);
|
||||
speed -= drag;
|
||||
velocity *= speed;
|
||||
}
|
||||
|
||||
velocity -= dragVec;
|
||||
}
|
||||
|
||||
|
||||
private void OnWallCollisionInside(Hull prevHull, Vector2 collisionNormal)
|
||||
{
|
||||
if (prevHull == null) { return; }
|
||||
|
||||
@@ -51,25 +51,31 @@ namespace Barotrauma.Particles
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = MaxValue, MinValueFloat = MinValue), Serialize(0f, true)]
|
||||
public float VelocityMax { get; set; }
|
||||
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = MaxValue, MinValueFloat = MinValue), Serialize(1f, true)]
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = 100.0f, MinValueFloat = 0.0f), Serialize(1f, true)]
|
||||
public float ScaleMin { get; set; }
|
||||
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = MaxValue, MinValueFloat = MinValue), Serialize(1f, true)]
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = 100.0f, MinValueFloat = 0.0f), Serialize(1f, true)]
|
||||
public float ScaleMax { get; set; }
|
||||
|
||||
|
||||
[Editable(), Serialize("1,1", true)]
|
||||
public Vector2 ScaleMultiplier { get; set; }
|
||||
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = MaxValue, MinValueFloat = MinValue), Serialize(0f, true)]
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = 100.0f, MinValueFloat = 0.0f), Serialize(0f, true)]
|
||||
public float EmitInterval { get; set; }
|
||||
|
||||
[Editable, Serialize(0, true)]
|
||||
[Editable(ValueStep = 1, MinValueInt = 0, MaxValueInt = 1000), Serialize(0, true, description: "The number of particles to spawn per frame, or every x seconds if EmitInterval is set.")]
|
||||
public int ParticleAmount { get; set; }
|
||||
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = MaxValue, MinValueFloat = 0), Serialize(0f, true)]
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = 1000.0f, MinValueFloat = 0.0f), Serialize(0f, true)]
|
||||
public float ParticlesPerSecond { get; set; }
|
||||
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = 10.0f, MinValueFloat = 0.0f), Serialize(0f, true, description: "If larger than 0, a particle is spawned every x pixels across the ray cast by a hitscan weapon.")]
|
||||
public float EmitAcrossRayInterval { get; set; }
|
||||
|
||||
[Editable(ValueStep = 1, DecimalCount = 2, MaxValueFloat = 100.0f, MinValueFloat = 0.0f), Serialize(0f, true, description: "Delay before the emitter becomes active after being created.")]
|
||||
public float InitialDelay { get; set; }
|
||||
|
||||
[Editable, Serialize(false, true)]
|
||||
public bool HighQualityCollisionDetection { get; set; }
|
||||
|
||||
@@ -115,6 +121,7 @@ namespace Barotrauma.Particles
|
||||
{
|
||||
private float emitTimer;
|
||||
private float burstEmitTimer;
|
||||
private float initialDelay;
|
||||
|
||||
public readonly ParticleEmitterPrefab Prefab;
|
||||
|
||||
@@ -131,9 +138,30 @@ namespace Barotrauma.Particles
|
||||
|
||||
public void Emit(float deltaTime, Vector2 position, Hull hullGuess = null, float angle = 0.0f, float particleRotation = 0.0f, float velocityMultiplier = 1.0f, float sizeMultiplier = 1.0f, float amountMultiplier = 1.0f, Color? colorMultiplier = null, ParticlePrefab overrideParticle = null, Tuple<Vector2, Vector2> tracerPoints = null)
|
||||
{
|
||||
if (initialDelay < Prefab.Properties.InitialDelay)
|
||||
{
|
||||
initialDelay += deltaTime;
|
||||
return;
|
||||
}
|
||||
|
||||
emitTimer += deltaTime * amountMultiplier;
|
||||
burstEmitTimer -= deltaTime;
|
||||
|
||||
if (Prefab.Properties.EmitAcrossRayInterval > 0.0f && tracerPoints != null)
|
||||
{
|
||||
Vector2 dir = tracerPoints.Item2 - tracerPoints.Item1;
|
||||
if (dir.LengthSquared() > 0.001f)
|
||||
{
|
||||
float dist = dir.Length();
|
||||
dir /= dist;
|
||||
for (float z = 0.0f; z < dist; z += Prefab.Properties.EmitAcrossRayInterval)
|
||||
{
|
||||
Vector2 pos = tracerPoints.Item1 + dir * z;
|
||||
Emit(pos, hullGuess, angle, particleRotation, velocityMultiplier, sizeMultiplier, colorMultiplier, overrideParticle, tracerPoints: null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Prefab.Properties.ParticlesPerSecond > 0)
|
||||
{
|
||||
float emitInterval = 1.0f / Prefab.Properties.ParticlesPerSecond;
|
||||
|
||||
@@ -53,6 +53,10 @@ namespace Barotrauma.Particles
|
||||
[Editable(0.0f, float.MaxValue), Serialize(5.0f, false, description: "How many seconds the particle remains alive.")]
|
||||
public float LifeTime { get; private set; }
|
||||
|
||||
[Editable(0.0f, float.MaxValue), Serialize(0.0f, false, description: "Will randomize lifetime value between lifetime and lifetimeMin. If left to 0 will use only lifetime value.")]
|
||||
public float LifeTimeMin { get; private set; }
|
||||
|
||||
|
||||
[Editable, Serialize(0.0f, false, description: "How long it takes for the particle to appear after spawning it.")]
|
||||
public float StartDelayMin { get; private set; }
|
||||
[Editable, Serialize(0.0f, false, description: "How long it takes for the particle to appear after spawning it.")]
|
||||
@@ -118,10 +122,10 @@ namespace Barotrauma.Particles
|
||||
[Editable, Serialize(false, false, description: "Should the particle face the direction it's moving towards.")]
|
||||
public bool RotateToDirection { get; private set; }
|
||||
|
||||
[Editable, Serialize(0.0f, false, description: "Drag applied to the particle when it's moving through air.")]
|
||||
[Editable(0.0f, float.MaxValue, DecimalCount = 3), Serialize(0.0f, false, description: "Drag applied to the particle when it's moving through air.")]
|
||||
public float Drag { get; private set; }
|
||||
|
||||
[Editable, Serialize(0.0f, false, description: "Drag applied to the particle when it's moving through water.")]
|
||||
[Editable(0.0f, float.MaxValue, DecimalCount = 3), Serialize(0.0f, false, description: "Drag applied to the particle when it's moving through water.")]
|
||||
public float WaterDrag { get; private set; }
|
||||
|
||||
private Vector2 velocityChange;
|
||||
@@ -193,8 +197,14 @@ namespace Barotrauma.Particles
|
||||
[Editable, Serialize("1.0,1.0,1.0,1.0", false, description: "The initial color of the particle.")]
|
||||
public Color StartColor { get; private set; }
|
||||
|
||||
[Editable, Serialize("1.0,1.0,1.0,1.0", false, description: "The initial color of the particle.")]
|
||||
public Color MiddleColor { get; private set; }
|
||||
|
||||
[Editable, Serialize("1.0,1.0,1.0,1.0", false, description: "The color of the particle at the end of its lifetime.")]
|
||||
public Color EndColor { get; private set; }
|
||||
|
||||
[Editable, Serialize(false, false, description: "If true the color will go from StartColor to EndcColor and back to StartColor.")]
|
||||
public bool UseMiddleColor { get; private set; }
|
||||
|
||||
[Editable, Serialize(DrawTargetType.Air, false, description: "Should the particle be rendered in air, water or both.")]
|
||||
public DrawTargetType DrawTarget { get; private set; }
|
||||
@@ -289,7 +299,7 @@ namespace Barotrauma.Particles
|
||||
StartRotationMin = element.GetAttributeFloat("startrotation", 0.0f);
|
||||
StartRotationMax = StartRotationMin;
|
||||
}
|
||||
|
||||
|
||||
if (CollisionRadius <= 0.0f) CollisionRadius = Sprites.Count > 0 ? 1 : Sprites[0].SourceRect.Width / 2.0f;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user