38f1ddb...178a853: v0.8.9.1, removed content folder
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user