|
@@ -15,32 +15,30 @@ import eu.tankernn.gameEngine.entities.Camera;
|
|
import eu.tankernn.gameEngine.loader.Loader;
|
|
import eu.tankernn.gameEngine.loader.Loader;
|
|
import eu.tankernn.gameEngine.loader.font.Font;
|
|
import eu.tankernn.gameEngine.loader.font.Font;
|
|
import eu.tankernn.gameEngine.loader.font.GUIText;
|
|
import eu.tankernn.gameEngine.loader.font.GUIText;
|
|
-import eu.tankernn.gameEngine.loader.font.Word;
|
|
|
|
import eu.tankernn.gameEngine.renderEngine.Fbo;
|
|
import eu.tankernn.gameEngine.renderEngine.Fbo;
|
|
import eu.tankernn.gameEngine.renderEngine.font.FontRenderer;
|
|
import eu.tankernn.gameEngine.renderEngine.font.FontRenderer;
|
|
import eu.tankernn.gameEngine.util.DistanceSorter;
|
|
import eu.tankernn.gameEngine.util.DistanceSorter;
|
|
|
|
|
|
public class ParticleMaster {
|
|
public class ParticleMaster {
|
|
private Loader loader;
|
|
private Loader loader;
|
|
-
|
|
|
|
- private Map<ParticleTexture, List<Particle>> particles = new HashMap<ParticleTexture, List<Particle>>();
|
|
|
|
- private List<ParticleSystem> systems = new ArrayList<ParticleSystem>();
|
|
|
|
|
|
+
|
|
|
|
+ private Map<ParticleTexture, List<Particle>> particles = new HashMap<>();
|
|
|
|
+ private List<ParticleSystem> systems = new ArrayList<>();
|
|
private ParticleRenderer renderer;
|
|
private ParticleRenderer renderer;
|
|
- private FontRenderer fontRenderer;
|
|
|
|
-
|
|
|
|
|
|
+ private FontRenderer fontRenderer = new FontRenderer();
|
|
|
|
+
|
|
public ParticleMaster(Loader loader, Matrix4f projectionMatrix) {
|
|
public ParticleMaster(Loader loader, Matrix4f projectionMatrix) {
|
|
this.loader = loader;
|
|
this.loader = loader;
|
|
renderer = new ParticleRenderer(loader, projectionMatrix);
|
|
renderer = new ParticleRenderer(loader, projectionMatrix);
|
|
- fontRenderer = new FontRenderer();
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void update(Camera camera) {
|
|
public void update(Camera camera) {
|
|
- for (ParticleSystem sys: systems) {
|
|
|
|
- for (Particle particle: sys.generateParticles()) {
|
|
|
|
|
|
+ for (ParticleSystem sys : systems) {
|
|
|
|
+ for (Particle particle : sys.generateParticles()) {
|
|
addParticle(particle);
|
|
addParticle(particle);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Iterator<Entry<ParticleTexture, List<Particle>>> mapIterator = particles.entrySet().iterator();
|
|
Iterator<Entry<ParticleTexture, List<Particle>>> mapIterator = particles.entrySet().iterator();
|
|
while (mapIterator.hasNext()) {
|
|
while (mapIterator.hasNext()) {
|
|
Entry<ParticleTexture, List<Particle>> entry = mapIterator.next();
|
|
Entry<ParticleTexture, List<Particle>> entry = mapIterator.next();
|
|
@@ -59,30 +57,31 @@ public class ParticleMaster {
|
|
if (!entry.getKey().usesAdditiveBlending())
|
|
if (!entry.getKey().usesAdditiveBlending())
|
|
DistanceSorter.sort(list, camera);
|
|
DistanceSorter.sort(list, camera);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
systems.removeIf(ParticleSystem::isDead);
|
|
systems.removeIf(ParticleSystem::isDead);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void renderParticles(Camera camera) {
|
|
public void renderParticles(Camera camera) {
|
|
renderer.render(particles, camera);
|
|
renderer.render(particles, camera);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void finalize() {
|
|
public void finalize() {
|
|
renderer.finalize();
|
|
renderer.finalize();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void addTextParticle(String text, Font font, Vector3f position) {
|
|
public void addTextParticle(String text, Font font, Vector3f position) {
|
|
-
|
|
|
|
|
|
+
|
|
GUIText guiText = new GUIText(text, font, new Vector2f(0, 0), 1.0f, false);
|
|
GUIText guiText = new GUIText(text, font, new Vector2f(0, 0), 1.0f, false);
|
|
guiText.update(loader);
|
|
guiText.update(loader);
|
|
Fbo fbo = new Fbo((int) (100 * font.size), (int) (100 * font.size), 0);
|
|
Fbo fbo = new Fbo((int) (100 * font.size), (int) (100 * font.size), 0);
|
|
fbo.bindFrameBuffer();
|
|
fbo.bindFrameBuffer();
|
|
fontRenderer.render(guiText);
|
|
fontRenderer.render(guiText);
|
|
fbo.unbindFrameBuffer();
|
|
fbo.unbindFrameBuffer();
|
|
- addParticle(new Particle(new ParticleTexture(fbo.getColourTexture(), 1, true), position, new Vector3f(0, 0, 0), 0.1f, 4, 0, font.size));
|
|
|
|
|
|
+ addParticle(new Particle(new ParticleTexture(fbo.getColourTexture(), 1, true), position, new Vector3f(0, 0, 0),
|
|
|
|
+ 0.1f, 4, 0, font.size));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void addParticle(Particle particle) {
|
|
public void addParticle(Particle particle) {
|
|
List<Particle> list = particles.get(particle.getTexture());
|
|
List<Particle> list = particles.get(particle.getTexture());
|
|
if (list == null) {
|
|
if (list == null) {
|
|
@@ -91,7 +90,7 @@ public class ParticleMaster {
|
|
}
|
|
}
|
|
list.add(particle);
|
|
list.add(particle);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void addSystem(ParticleSystem system) {
|
|
public void addSystem(ParticleSystem system) {
|
|
this.systems.add(system);
|
|
this.systems.add(system);
|
|
}
|
|
}
|