38f1ddb...178a853: v0.8.9.1, removed content folder

This commit is contained in:
Joonas Rikkonen
2019-03-18 19:46:58 +02:00
parent 38f1ddb6fe
commit 6c0679c297
1054 changed files with 151673 additions and 144931 deletions
@@ -44,10 +44,11 @@ namespace Barotrauma.Particles
{
get
{
return position
Vector2 worldPos = position
+ clippedSourceRect.Size.ToVector2() / 2 * scale
+ hull.Rect.Location.ToVector2()
+ hull.Submarine.DrawPosition;
+ hull.Rect.Location.ToVector2();
if (hull.Submarine != null) { worldPos += hull.Submarine.DrawPosition; }
return worldPos;
}
}
@@ -108,7 +109,7 @@ namespace Barotrauma.Particles
public void Draw(SpriteBatch spriteBatch, Hull hull, float depth)
{
Vector2 drawPos = position + hull.Rect.Location.ToVector2();
drawPos += hull.Submarine.DrawPosition;
if (hull.Submarine != null) { drawPos += hull.Submarine.DrawPosition; }
drawPos.Y = -drawPos.Y;
spriteBatch.Draw(Sprite.Texture, drawPos, clippedSourceRect, Color * GetAlpha(), 0, Vector2.Zero, scale, SpriteEffects.None, depth);
@@ -11,7 +11,7 @@ namespace Barotrauma.Particles
public DecalManager()
{
prefabs = new Dictionary<string, DecalPrefab>();
foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Decals))
foreach (string configFile in GameMain.Instance.GetFilesOfType(ContentType.Decals))
{
XDocument doc = XMLExtensions.TryLoadXml(configFile);
if (doc == null || doc.Root == null) continue;
@@ -30,13 +30,15 @@ namespace Barotrauma.Particles
private Vector2 sizeChange;
private Color color;
private float alpha;
private bool changeColor;
private int spriteIndex;
private float totalLifeTime;
private float lifeTime;
private float startDelay;
private Vector2 velocityChange;
private Vector2 velocityChangeWater;
@@ -47,11 +49,14 @@ namespace Barotrauma.Particles
private List<Gap> hullGaps;
private bool hasSubEmitters;
private List<ParticleEmitter> subEmitters = new List<ParticleEmitter>();
private float animState;
private int animFrame;
private float collisionUpdateTimer;
public ParticlePrefab.DrawTargetType DrawTarget
{
get { return prefab.DrawTarget; }
@@ -61,35 +66,28 @@ namespace Barotrauma.Particles
{
get { return prefab.BlendState; }
}
public float StartDelay
{
get { return startDelay; }
set { startDelay = MathHelper.Clamp(value, Prefab.StartDelayMin, prefab.StartDelayMax); }
}
public Vector2 Size
{
get { return size; }
set { size = value; }
}
public Vector2 VelocityChange
{
get { return velocityChange; }
set { velocityChange = value; }
}
public Vector2 VelocityChangeWater
{
get { return velocityChangeWater; }
set { velocityChangeWater = value; }
}
public Vector2 Velocity
{
get { return velocity; }
set { velocity = value; }
}
public Hull CurrentHull
{
get { return currentHull; }
}
public ParticlePrefab Prefab
{
get { return prefab; }
}
public void Init(ParticlePrefab prefab, Vector2 position, Vector2 speed, float rotation, Hull hullGuess = null)
{
@@ -111,7 +109,7 @@ namespace Barotrauma.Particles
velocity = MathUtils.IsValid(speed) ? speed : Vector2.Zero;
if (currentHull != null && currentHull.Submarine != null)
if (currentHull?.Submarine != null)
{
velocity += ConvertUnits.ToDisplayUnits(currentHull.Submarine.Velocity);
}
@@ -123,13 +121,14 @@ namespace Barotrauma.Particles
totalLifeTime = prefab.LifeTime;
lifeTime = prefab.LifeTime;
startDelay = Rand.Range(prefab.StartDelayMin, prefab.StartDelayMax);
size = prefab.StartSizeMin + (prefab.StartSizeMax - prefab.StartSizeMin) * Rand.Range(0.0f, 1.0f);
sizeChange = prefab.SizeChangeMin + (prefab.SizeChangeMax - prefab.SizeChangeMin) * Rand.Range(0.0f, 1.0f);
color = new Color(prefab.StartColor, 1.0f);
alpha = prefab.StartAlpha;
color = prefab.StartColor;
changeColor = prefab.StartColor != prefab.EndColor;
velocityChange = prefab.VelocityChangeDisplay;
velocityChangeWater = prefab.VelocityChangeWaterDisplay;
@@ -137,12 +136,14 @@ namespace Barotrauma.Particles
OnChangeHull = null;
subEmitters.Clear();
hasSubEmitters = false;
foreach (ParticleEmitterPrefab emitterPrefab in prefab.SubEmitters)
{
subEmitters.Add(new ParticleEmitter(emitterPrefab));
hasSubEmitters = true;
}
if (prefab.DeleteOnCollision || prefab.CollidesWithWalls)
if (prefab.UseCollision)
{
hullGaps = currentHull == null ? new List<Gap>() : currentHull.ConnectedGaps;
}
@@ -154,9 +155,15 @@ namespace Barotrauma.Particles
prevRotation = rotation;
}
}
public bool Update(float deltaTime)
{
if (startDelay > 0.0f)
{
startDelay -= deltaTime;
return true;
}
prevPosition = position;
prevRotation = rotation;
@@ -204,13 +211,11 @@ namespace Barotrauma.Particles
size.X += sizeChange.X * deltaTime;
size.Y += sizeChange.Y * deltaTime;
alpha += prefab.ColorChange.W * deltaTime;
color = new Color(
color.R / 255.0f + prefab.ColorChange.X * deltaTime,
color.G / 255.0f + prefab.ColorChange.Y * deltaTime,
color.B / 255.0f + prefab.ColorChange.Z * deltaTime);
if (changeColor)
{
color = Color.Lerp(prefab.EndColor, prefab.StartColor, lifeTime / prefab.LifeTime);
}
if (prefab.Sprites[spriteIndex] is SpriteSheet)
{
animState += deltaTime;
@@ -219,15 +224,31 @@ namespace Barotrauma.Particles
}
lifeTime -= deltaTime;
if (lifeTime <= 0.0f || alpha <= 0.0f || size.X <= 0.0f || size.Y <= 0.0f) return false;
if (lifeTime <= 0.0f || color.A <= 0 || size.X <= 0.0f || size.Y <= 0.0f) return false;
foreach (ParticleEmitter emitter in subEmitters)
if (hasSubEmitters)
{
emitter.Emit(deltaTime, position, currentHull);
foreach (ParticleEmitter emitter in subEmitters)
{
emitter.Emit(deltaTime, position, currentHull);
}
}
if (!prefab.DeleteOnCollision && !prefab.CollidesWithWalls) return true;
if (!prefab.UseCollision) return true;
collisionUpdateTimer -= deltaTime;
if (collisionUpdateTimer <= 0.0f)
{
//more frequent collision updates if the particle is moving fast
collisionUpdateTimer = 0.5f - Math.Min((Math.Abs(velocity.X) + Math.Abs(velocity.Y)) * 0.001f, 0.4f);
return CollisionUpdate();
}
return true;
}
private bool CollisionUpdate()
{
if (currentHull == null)
{
Hull collidedHull = Hull.FindHull(position);
@@ -239,23 +260,24 @@ namespace Barotrauma.Particles
}
else
{
Rectangle hullRect = currentHull.WorldRect;
Vector2 collisionNormal = Vector2.Zero;
if (velocity.Y < 0.0f && position.Y - prefab.CollisionRadius * size.Y < currentHull.WorldRect.Y - currentHull.WorldRect.Height)
if (velocity.Y < 0.0f && position.Y - prefab.CollisionRadius * size.Y < hullRect.Y - hullRect.Height)
{
if (prefab.DeleteOnCollision) return false;
collisionNormal = new Vector2(0.0f, 1.0f);
}
else if (velocity.Y > 0.0f && position.Y + prefab.CollisionRadius * size.Y > currentHull.WorldRect.Y)
else if (velocity.Y > 0.0f && position.Y + prefab.CollisionRadius * size.Y > hullRect.Y)
{
if (prefab.DeleteOnCollision) return false;
collisionNormal = new Vector2(0.0f, -1.0f);
}
else if (velocity.X < 0.0f && position.X - prefab.CollisionRadius * size.X < currentHull.WorldRect.X)
else if (velocity.X < 0.0f && position.X - prefab.CollisionRadius * size.X < hullRect.X)
{
if (prefab.DeleteOnCollision) return false;
collisionNormal = new Vector2(1.0f, 0.0f);
}
else if (velocity.X > 0.0f && position.X + prefab.CollisionRadius * size.X > currentHull.WorldRect.Right)
else if (velocity.X > 0.0f && position.X + prefab.CollisionRadius * size.X > hullRect.Right)
{
if (prefab.DeleteOnCollision) return false;
collisionNormal = new Vector2(-1.0f, 0.0f);
@@ -292,7 +314,7 @@ namespace Barotrauma.Particles
}
else
{
Hull newHull = Hull.FindHull(position,currentHull);
Hull newHull = Hull.FindHull(position, currentHull);
if (newHull != currentHull)
{
currentHull = newHull;
@@ -335,7 +357,7 @@ namespace Barotrauma.Particles
{
Rectangle prevHullRect = prevHull.WorldRect;
Vector2 subVel = ConvertUnits.ToDisplayUnits(prevHull.Submarine.Velocity);
Vector2 subVel = prevHull?.Submarine != null ? ConvertUnits.ToDisplayUnits(prevHull.Submarine.Velocity) : Vector2.Zero;
velocity -= subVel;
if (Math.Abs(collisionNormal.X) > Math.Abs(collisionNormal.Y))
@@ -373,28 +395,33 @@ namespace Barotrauma.Particles
private void OnWallCollisionOutside(Hull collisionHull)
{
Rectangle hullRect = collisionHull.WorldRect;
if (position.Y < hullRect.Y - hullRect.Height)
Vector2 center = new Vector2(hullRect.X + hullRect.Width /2, hullRect.Y - hullRect.Height / 2);
if (position.Y < center.Y)
{
position.Y = hullRect.Y - hullRect.Height - prefab.CollisionRadius;
velocity.Y = -velocity.Y;
velocity.X *= (1.0f - prefab.Friction);
velocity.Y = -velocity.Y * prefab.Restitution;
}
else if (position.Y > hullRect.Y)
else if (position.Y > center.Y)
{
position.Y = hullRect.Y + prefab.CollisionRadius;
velocity.X = Math.Abs(velocity.Y) * Math.Sign(velocity.X);
velocity.Y = -velocity.Y;
velocity.X *= (1.0f - prefab.Friction);
velocity.Y = -velocity.Y * prefab.Restitution;
}
if (position.X < hullRect.X)
if (position.X < center.X)
{
position.X = hullRect.X - prefab.CollisionRadius;
velocity.X = -velocity.X;
velocity.X = -velocity.X * prefab.Restitution;
velocity.Y *= (1.0f - prefab.Friction);
}
else if (position.X > hullRect.X + hullRect.Width)
else if (position.X > center.X)
{
position.X = hullRect.X + hullRect.Width + prefab.CollisionRadius;
velocity.X = -velocity.X;
velocity.X = -velocity.X * prefab.Restitution;
velocity.Y *= (1.0f - prefab.Friction);
}
velocity *= prefab.Restitution;
@@ -423,7 +450,7 @@ namespace Barotrauma.Particles
((SpriteSheet)prefab.Sprites[spriteIndex]).Draw(
spriteBatch, animFrame,
new Vector2(drawPosition.X, -drawPosition.Y),
color * alpha,
color * (color.A / 255.0f),
prefab.Sprites[spriteIndex].Origin, drawRotation,
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth);
}
@@ -431,7 +458,7 @@ namespace Barotrauma.Particles
{
prefab.Sprites[spriteIndex].Draw(spriteBatch,
new Vector2(drawPosition.X, -drawPosition.Y),
color * alpha,
color * (color.A / 255.0f),
prefab.Sprites[spriteIndex].Origin, drawRotation,
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth);
}
@@ -7,6 +7,7 @@ namespace Barotrauma.Particles
class ParticleEmitter
{
private float emitTimer;
private float burstEmitTimer;
public readonly ParticleEmitterPrefab Prefab;
@@ -21,30 +22,34 @@ namespace Barotrauma.Particles
Prefab = prefab;
}
public void Emit(float deltaTime, Vector2 position, Hull hullGuess = null, float angle = 0.0f, float particleRotation = 0.0f)
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)
{
emitTimer += deltaTime;
emitTimer += deltaTime * amountMultiplier;
burstEmitTimer += deltaTime;
if (Prefab.ParticlesPerSecond > 0)
{
float emitInterval = 1.0f / Prefab.ParticlesPerSecond;
while (emitTimer > emitInterval)
{
Emit(position, hullGuess, angle, particleRotation);
Emit(position, hullGuess, angle, particleRotation, velocityMultiplier, sizeMultiplier);
emitTimer -= emitInterval;
}
}
for (int i = 0; i < Prefab.ParticleAmount; i++)
if (burstEmitTimer < Prefab.EmitInterval) return;
burstEmitTimer = 0.0f;
for (int i = 0; i < Prefab.ParticleAmount * amountMultiplier; i++)
{
Emit(position, hullGuess, particleRotation);
Emit(position, hullGuess, angle, particleRotation, velocityMultiplier, sizeMultiplier);
}
}
private void Emit(Vector2 position, Hull hullGuess = null, float angle = 0.0f, float particleRotation = 0.0f)
private void Emit(Vector2 position, Hull hullGuess, float angle, float particleRotation, float velocityMultiplier, float sizeMultiplier)
{
angle += Rand.Range(Prefab.AngleMin, Prefab.AngleMax);
Vector2 velocity = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Rand.Range(Prefab.VelocityMin, Prefab.VelocityMax);
Vector2 velocity = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Rand.Range(Prefab.VelocityMin, Prefab.VelocityMax) * velocityMultiplier;
var particle = GameMain.ParticleManager.CreateParticle(Prefab.ParticlePrefab, position, velocity, particleRotation, hullGuess);
@@ -87,9 +92,13 @@ namespace Barotrauma.Particles
public readonly float VelocityMin, VelocityMax;
public readonly float ScaleMin, ScaleMax;
public readonly float EmitInterval;
public readonly int ParticleAmount;
public readonly float ParticlesPerSecond;
public readonly float ParticlesPerSecond;
public readonly bool CopyEntityAngle;
public ParticleEmitterPrefab(XElement element)
{
@@ -111,14 +120,14 @@ namespace Barotrauma.Particles
AngleMin = MathHelper.ToRadians(MathHelper.Clamp(AngleMin, -360.0f, 360.0f));
AngleMax = MathHelper.ToRadians(MathHelper.Clamp(AngleMax, -360.0f, 360.0f));
if (element.Attribute("scalemin")==null)
if (element.Attribute("scalemin") == null)
{
ScaleMin = 1.0f;
ScaleMax = 1.0f;
}
else
{
ScaleMin = element.GetAttributeFloat("scalemin",1.0f);
ScaleMin = element.GetAttributeFloat("scalemin", 1.0f);
ScaleMax = Math.Max(ScaleMin, element.GetAttributeFloat("scalemax", 1.0f));
}
@@ -133,8 +142,11 @@ namespace Barotrauma.Particles
VelocityMax = VelocityMin;
}
EmitInterval = element.GetAttributeFloat("emitinterval", 0.0f);
ParticlesPerSecond = element.GetAttributeInt("particlespersecond", 0);
ParticleAmount = element.GetAttributeInt("particleamount", 0);
CopyEntityAngle = element.GetAttributeBool("copyentityangle", false);
}
}
}
@@ -9,33 +9,62 @@ namespace Barotrauma.Particles
{
enum ParticleBlendState
{
AlphaBlend, Additive, Distortion
AlphaBlend, Additive//, Distortion
}
class ParticleManager
{
public static int particleCount;
private const int MaxOutOfViewDist = 500;
private const int MaxParticles = 1500;
private int particleCount;
public int ParticleCount
{
get { return particleCount; }
}
private int maxParticles;
public int MaxParticles
{
get { return maxParticles; }
set
{
if (maxParticles == value || value < 4) return;
Particle[] newParticles = new Particle[value];
for (int i = 0; i < Math.Min(maxParticles, value); i++)
{
newParticles[i] = particles[i];
}
particleCount = Math.Min(particleCount, value);
particles = newParticles;
maxParticles = value;
}
}
private Particle[] particles;
private Dictionary<string, ParticlePrefab> prefabs;
private Camera cam;
public Camera Camera
{
get { return cam; }
set { cam = value; }
}
public ParticleManager(Camera cam)
{
this.cam = cam;
particles = new Particle[MaxParticles];
MaxParticles = GameMain.Config.ParticleLimit;
}
public void LoadPrefabs()
{
prefabs = new Dictionary<string, ParticlePrefab>();
foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Particles))
foreach (string configFile in GameMain.Instance.GetFilesOfType(ContentType.Particles))
{
XDocument doc = XMLExtensions.TryLoadXml(configFile);
if (doc == null || doc.Root == null) continue;
@@ -123,6 +152,8 @@ namespace Barotrauma.Particles
public void Update(float deltaTime)
{
MaxParticles = GameMain.Config.ParticleLimit;
for (int i = 0; i < particleCount; i++)
{
bool remove = false;
@@ -148,6 +179,17 @@ namespace Barotrauma.Particles
}
}
public Dictionary<ParticlePrefab, int> CountActiveParticles()
{
Dictionary<ParticlePrefab, int> activeParticles = new Dictionary<ParticlePrefab, int>();
for (int i = 0; i < particleCount; i++)
{
if (!activeParticles.ContainsKey(particles[i].Prefab)) activeParticles[particles[i].Prefab] = 0;
activeParticles[particles[i].Prefab]++;
}
return activeParticles;
}
public void Draw(SpriteBatch spriteBatch, bool inWater, bool? inSub, ParticleBlendState blendState)
{
ParticlePrefab.DrawTargetType drawTarget = inWater ? ParticlePrefab.DrawTargetType.Water : ParticlePrefab.DrawTargetType.Air;
@@ -155,7 +197,8 @@ namespace Barotrauma.Particles
for (int i = 0; i < particleCount; i++)
{
if (particles[i].BlendState != blendState) continue;
if (!particles[i].DrawTarget.HasFlag(drawTarget)) continue;
//equivalent to !particles[i].DrawTarget.HasFlag(drawTarget) but garbage free and faster
if ((particles[i].DrawTarget & drawTarget) == 0) continue;
if (inSub.HasValue && (particles[i].CurrentHull == null) == inSub.Value) continue;
particles[i].Draw(spriteBatch);
@@ -20,6 +20,10 @@ namespace Barotrauma.Particles
[Editable(0.0f, float.MaxValue, ToolTip = "How many seconds the particle remains alive."), Serialize(5.0f, false)]
public float LifeTime { get; private set; }
[Editable(ToolTip = "How long it takes for the particle to appear after spawning it."), Serialize(0.0f, false)]
public float StartDelayMin { get; private set; }
[Editable(ToolTip = "How long it takes for the particle to appear after spawning it."), Serialize(0.0f, false)]
public float StartDelayMax { get; private set; }
//movement -----------------------------------------
private float angularVelocityMin;
@@ -119,7 +123,7 @@ namespace Barotrauma.Particles
public float CollisionRadius { get; private set; }
[Editable(ToolTip = "Does the particle collide with the walls of the submarine and the level."), Serialize(false, false)]
public bool CollidesWithWalls { get; private set; }
public bool UseCollision { get; private set; }
[Editable(ToolTip = "Does the particle disappear when it collides with something."), Serialize(false, false)]
public bool DeleteOnCollision { get; private set; }
@@ -153,15 +157,12 @@ namespace Barotrauma.Particles
//rendering -----------------------------------------
[Editable(ToolTip = "The initial color of the particle"), Serialize("1.0,1.0,1.0,1.0", false)]
[Editable(ToolTip = "The initial color of the particle."), Serialize("1.0,1.0,1.0,1.0", false)]
public Color StartColor { get; private set; }
[Editable(ToolTip = "The initial alpha value of the particle"), Serialize(1.0f, false)]
public float StartAlpha { get; private set; }
[Editable(ToolTip = "How much the color of the particle changes per second."), Serialize("0.0,0.0,0.0,0.0", false)]
public Vector4 ColorChange { get; private set; }
[Editable(ToolTip = "The color of the particle at the end of its lifetime."), Serialize("1.0,1.0,1.0,1.0", false)]
public Color EndColor { get; private set; }
[Editable(ToolTip = "Should the particle be rendered in air, water or both."), Serialize(DrawTargetType.Air, false)]
public DrawTargetType DrawTarget { get; private set; }
@@ -177,7 +178,7 @@ namespace Barotrauma.Particles
public bool LoopAnim { get; private set; }
//----------------------------------------------------
public readonly List<ParticleEmitterPrefab> SubEmitters = new List<ParticleEmitterPrefab>();
public Dictionary<string, SerializableProperty> SerializableProperties