-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
64 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,5 @@ void main() { | |
if (color.a <= 0) { | ||
discard; | ||
} | ||
color.a = max(color.a, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,40 @@ | ||
using Silk.NET.Maths; | ||
using TrippyGL; | ||
using Silk.NET.OpenGL; | ||
|
||
namespace BlockGame; | ||
|
||
public class ParticleManager { | ||
private Particle[] particles; | ||
private readonly List<Particle> particles = []; | ||
|
||
public ParticleManager(int maxParticles) { | ||
particles = new Particle[maxParticles]; | ||
public void add(Particle particle) { | ||
particles.Add(particle); | ||
} | ||
|
||
public void update(double dt) { | ||
for (int i = 0; i < particles.Length; i++) { | ||
if (particles[i] != null) { | ||
particles[i].update(dt); | ||
if (particles[i].ttl <= 0) { | ||
particles[i].active = false; | ||
} | ||
for (var i = 0; i < particles.Count; i++) { | ||
var particle = particles[i]; | ||
particle.update(dt); | ||
|
||
if (!particle.active) { | ||
particles.RemoveAt(i); | ||
// don't skip the next particle | ||
i--; | ||
} | ||
} | ||
} | ||
|
||
public void render(double interp) { | ||
for (int i = 0; i < particles.Length; i++) { | ||
if (particles[i].active) { | ||
particles[i].render(interp); | ||
} | ||
} | ||
} | ||
public void render(double dt, double interp) { | ||
|
||
// TODO implement pooling | ||
public Particle newParticle(Vector3D<double> position, Color4b color, double size, int ttl) { | ||
return new Particle(position, color, size, ttl); | ||
} | ||
var currentTexture = "textures/blocks.png"; | ||
Game.GL.ActiveTexture(TextureUnit.Texture0); | ||
Game.GL.BindTexture(TextureTarget.Texture2D, Game.textureManager.blockTexture.handle); | ||
|
||
public void addParticle(Particle particle) { | ||
for (int i = 0; i < particles.Length; i++) { | ||
if (!particles[i].active) { | ||
particles[i] = particle; | ||
return; | ||
foreach (var particle in particles) { | ||
if (particle.texture != currentTexture) { | ||
Game.textureManager.load(particle.texture, particle.texture); | ||
var tex = Game.textureManager.get(particle.texture); | ||
Game.GL.BindTexture(TextureTarget.Texture2D, tex.Handle); | ||
} | ||
} | ||
} | ||
|
||
public void clear() { | ||
for (int i = 0; i < particles.Length; i++) { | ||
particles[i].reset(); | ||
particle.render(dt, interp); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Silk.NET.Maths; | ||
|
||
namespace BlockGame; | ||
|
||
public class TerrainParticle : Particle { | ||
|
||
public TerrainParticle(Vector3D<double> position, string texture, float u, float v, double size, int ttl) : base(position, texture, u, v, size, ttl) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters