Unstable 1.1.14.0
This commit is contained in:
@@ -85,7 +85,7 @@ namespace Barotrauma.Particles
|
||||
public float StartDelay
|
||||
{
|
||||
get { return startDelay; }
|
||||
set { startDelay = MathHelper.Clamp(value, Prefab.StartDelayMin, prefab.StartDelayMax); }
|
||||
set { startDelay = Math.Max(value, 0.0f); }
|
||||
}
|
||||
|
||||
public Vector2 Size
|
||||
@@ -311,7 +311,8 @@ namespace Barotrauma.Particles
|
||||
{
|
||||
foreach (ParticleEmitter emitter in subEmitters)
|
||||
{
|
||||
emitter.Emit(deltaTime, position, currentHull);
|
||||
emitter.Emit(deltaTime, position, currentHull, particleRotation: rotation,
|
||||
sizeMultiplier: emitter.Prefab.Properties.CopyParentParticleScale ? Math.Max(size.X, size.Y) : 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,11 +567,12 @@ namespace Barotrauma.Particles
|
||||
drawPosition = Timing.Interpolate(prevPosition, position);
|
||||
drawRotation = Timing.Interpolate(prevRotation, rotation);
|
||||
}
|
||||
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Vector2 drawSize = size;
|
||||
if (startDelay > 0.0f) { return; }
|
||||
|
||||
Vector2 drawSize = size;
|
||||
if (prefab.GrowTime > 0.0f && totalLifeTime - lifeTime < prefab.GrowTime)
|
||||
{
|
||||
drawSize *= MathUtils.SmoothStep((totalLifeTime - lifeTime) / prefab.GrowTime);
|
||||
|
||||
@@ -88,6 +88,9 @@ namespace Barotrauma.Particles
|
||||
[Editable, Serialize(false, IsPropertySaveable.Yes, description: "Only relevant for status effects. Makes the emitter copy the angle from the target of the effect instead of the entity applying the effect.")]
|
||||
public bool CopyTargetAngle { get; set; }
|
||||
|
||||
[Editable, Serialize(false, IsPropertySaveable.Yes, description: "Only relevant for particles spawned by another particle. Makes the emitter copy the scale of the parent particle.")]
|
||||
public bool CopyParentParticleScale { get; set; }
|
||||
|
||||
[Editable, Serialize("1,1,1,1", IsPropertySaveable.Yes)]
|
||||
public Color ColorMultiplier { get; set; }
|
||||
|
||||
@@ -195,7 +198,11 @@ namespace Barotrauma.Particles
|
||||
private void Emit(Vector2 position, Hull hullGuess, float angle, float particleRotation, float velocityMultiplier, float sizeMultiplier, Color? colorMultiplier = null, ParticlePrefab overrideParticle = null, bool mirrorAngle = false, Tuple<Vector2, Vector2> tracerPoints = null)
|
||||
{
|
||||
var particlePrefab = overrideParticle ?? Prefab.ParticlePrefab;
|
||||
if (particlePrefab == null) { return; }
|
||||
if (particlePrefab == null)
|
||||
{
|
||||
DebugConsole.AddWarning($"Could not find the particle prefab \"{Prefab.ParticlePrefabName}\".");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 velocity = Vector2.Zero;
|
||||
if (!MathUtils.NearlyEqual(Prefab.Properties.VelocityMax * velocityMultiplier, 0.0f) || !MathUtils.NearlyEqual(Prefab.Properties.DistanceMax, 0.0f))
|
||||
@@ -206,7 +213,7 @@ namespace Barotrauma.Particles
|
||||
position += dir * Rand.Range(Prefab.Properties.DistanceMin, Prefab.Properties.DistanceMax);
|
||||
}
|
||||
|
||||
var particle = GameMain.ParticleManager.CreateParticle(particlePrefab, position, velocity, particleRotation, hullGuess, lifeTimeMultiplier: Prefab.Properties.LifeTimeMultiplier, tracerPoints: tracerPoints);
|
||||
var particle = GameMain.ParticleManager.CreateParticle(particlePrefab, position, velocity, particleRotation, hullGuess, particlePrefab.DrawOnTop || Prefab.DrawOnTop, lifeTimeMultiplier: Prefab.Properties.LifeTimeMultiplier, tracerPoints: tracerPoints);
|
||||
|
||||
if (particle != null)
|
||||
{
|
||||
@@ -227,6 +234,7 @@ namespace Barotrauma.Particles
|
||||
public Rectangle CalculateParticleBounds(Vector2 startPosition)
|
||||
{
|
||||
Rectangle bounds = new Rectangle((int)startPosition.X, (int)startPosition.Y, (int)startPosition.X, (int)startPosition.Y);
|
||||
if (Prefab.ParticlePrefab == null) { return bounds; }
|
||||
|
||||
for (float angle = Prefab.Properties.AngleMinRad; angle <= Prefab.Properties.AngleMaxRad; angle += 0.1f)
|
||||
{
|
||||
@@ -255,16 +263,22 @@ namespace Barotrauma.Particles
|
||||
}
|
||||
|
||||
bounds = new Rectangle(bounds.X, bounds.Y, bounds.Width - bounds.X, bounds.Height - bounds.Y);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
|
||||
class ParticleEmitterPrefab
|
||||
{
|
||||
private readonly Identifier particlePrefabName;
|
||||
public readonly Identifier ParticlePrefabName;
|
||||
|
||||
public ParticlePrefab ParticlePrefab => ParticlePrefab.Prefabs[particlePrefabName];
|
||||
public ParticlePrefab ParticlePrefab
|
||||
{
|
||||
get
|
||||
{
|
||||
ParticlePrefab.Prefabs.TryGet(ParticlePrefabName, out var prefab);
|
||||
return prefab;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly ParticleEmitterProperties Properties;
|
||||
|
||||
@@ -273,13 +287,13 @@ namespace Barotrauma.Particles
|
||||
public ParticleEmitterPrefab(ContentXElement element)
|
||||
{
|
||||
Properties = new ParticleEmitterProperties(element);
|
||||
particlePrefabName = element.GetAttributeIdentifier("particle", "");
|
||||
ParticlePrefabName = element.GetAttributeIdentifier("particle", "");
|
||||
}
|
||||
|
||||
public ParticleEmitterPrefab(ParticlePrefab prefab, ParticleEmitterProperties properties)
|
||||
{
|
||||
Properties = properties;
|
||||
particlePrefabName = prefab.Identifier;
|
||||
ParticlePrefabName = prefab.Identifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,13 @@ namespace Barotrauma.Particles
|
||||
}
|
||||
private Particle[] particles;
|
||||
|
||||
/// <summary>
|
||||
/// Used for rendering the particles in the order in which they were created (starting from the most recent one)
|
||||
/// to avoid the order of the particles shuffling around when particles are removed from the pool.
|
||||
/// Linked list for fast additions and removals at the middle of the list.
|
||||
/// </summary>
|
||||
private readonly LinkedList<Particle> particlesInCreationOrder = new LinkedList<Particle>();
|
||||
|
||||
private Camera cam;
|
||||
|
||||
public Camera Camera
|
||||
@@ -75,7 +82,7 @@ namespace Barotrauma.Particles
|
||||
return CreateParticle(prefab, position, velocity, rotation, hullGuess, collisionIgnoreTimer: collisionIgnoreTimer, tracerPoints:tracerPoints);
|
||||
}
|
||||
|
||||
public Particle CreateParticle(ParticlePrefab prefab, Vector2 position, Vector2 velocity, float rotation = 0.0f, Hull hullGuess = null, float collisionIgnoreTimer = 0f, float lifeTimeMultiplier = 1f, Tuple<Vector2, Vector2> tracerPoints = null)
|
||||
public Particle CreateParticle(ParticlePrefab prefab, Vector2 position, Vector2 velocity, float rotation = 0.0f, Hull hullGuess = null, bool drawOnTop = false, float collisionIgnoreTimer = 0f, float lifeTimeMultiplier = 1f, Tuple<Vector2, Vector2> tracerPoints = null)
|
||||
{
|
||||
if (prefab == null || prefab.Sprites.Count == 0) { return null; }
|
||||
if (particleCount >= MaxParticles)
|
||||
@@ -116,12 +123,13 @@ namespace Barotrauma.Particles
|
||||
}
|
||||
|
||||
if (particles[particleCount] == null) { particles[particleCount] = new Particle(); }
|
||||
Particle particle = particles[particleCount];
|
||||
|
||||
particles[particleCount].Init(prefab, position, velocity, rotation, hullGuess, prefab.DrawOnTop, collisionIgnoreTimer, lifeTimeMultiplier, tracerPoints: tracerPoints);
|
||||
|
||||
particle.Init(prefab, position, velocity, rotation, hullGuess, drawOnTop, collisionIgnoreTimer, lifeTimeMultiplier, tracerPoints: tracerPoints);
|
||||
particleCount++;
|
||||
particlesInCreationOrder.AddFirst(particle);
|
||||
|
||||
return particles[particleCount - 1];
|
||||
return particle;
|
||||
}
|
||||
|
||||
public static List<ParticlePrefab> GetPrefabList()
|
||||
@@ -137,11 +145,10 @@ namespace Barotrauma.Particles
|
||||
|
||||
private void RemoveParticle(int index)
|
||||
{
|
||||
particlesInCreationOrder.Remove(particles[index]);
|
||||
particleCount--;
|
||||
|
||||
Particle swap = particles[index];
|
||||
particles[index] = particles[particleCount];
|
||||
particles[particleCount] = swap;
|
||||
(particles[particleCount], particles[index]) = (particles[index], particles[particleCount]);
|
||||
}
|
||||
|
||||
|
||||
@@ -201,9 +208,8 @@ namespace Barotrauma.Particles
|
||||
{
|
||||
ParticlePrefab.DrawTargetType drawTarget = inWater ? ParticlePrefab.DrawTargetType.Water : ParticlePrefab.DrawTargetType.Air;
|
||||
|
||||
for (int i = 0; i < particleCount; i++)
|
||||
foreach (var particle in particlesInCreationOrder)
|
||||
{
|
||||
var particle = particles[i];
|
||||
if (particle.BlendState != blendState) { continue; }
|
||||
//equivalent to !particles[i].DrawTarget.HasFlag(drawTarget) but garbage free and faster
|
||||
if ((particle.DrawTarget & drawTarget) == 0) { continue; }
|
||||
@@ -215,14 +221,15 @@ namespace Barotrauma.Particles
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
particles[i].Draw(spriteBatch);
|
||||
|
||||
particle.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearParticles()
|
||||
{
|
||||
particleCount = 0;
|
||||
particlesInCreationOrder.Clear();
|
||||
}
|
||||
|
||||
public void RemoveByPrefab(ParticlePrefab prefab)
|
||||
@@ -234,6 +241,7 @@ namespace Barotrauma.Particles
|
||||
{
|
||||
if (i < particleCount) { particleCount--; }
|
||||
|
||||
particlesInCreationOrder.Remove(particles[particleCount]);
|
||||
Particle swap = particles[particleCount];
|
||||
particles[particleCount] = null;
|
||||
particles[i] = swap;
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace Barotrauma.Particles
|
||||
[Editable, Serialize("0.0,0.0", IsPropertySaveable.No, description: "How much the size of the particle changes per second. The rate of growth for each particle is randomize between SizeChangeMin and SizeChangeMax.")]
|
||||
public Vector2 SizeChangeMax { get; private set; }
|
||||
|
||||
[Editable, Serialize(0.0f, IsPropertySaveable.No, description: "How many seconds it takes for the particle to grow to it's initial size.")]
|
||||
[Editable(minValue: 0, maxValue: float.MaxValue, decimals: 2), Serialize(0.0f, IsPropertySaveable.No, description: "How many seconds it takes for the particle to grow to it's initial size.")]
|
||||
public float GrowTime { get; private set; }
|
||||
|
||||
//rendering -----------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user