Improved rendering performance.
[desert.git] / src / net / sourceforge / desert / ParticleRenderer.java
blob4112389eae513411aabf35b132d5ba6915f11719
1 package net.sourceforge.desert;
3 import java.awt.image.BufferedImage;
5 /**
7 * @author codistmonk (creation 2010-04-17)
8 */
9 public class ParticleRenderer {
11 private final int[] colorComponents = new int[4];
13 private BufferedImage buffer;
15 /**
17 * @param particle
18 * <br>Not null
20 public final void draw(final Particle particle) {
21 if (this.getBuffer() == null) {
22 return;
25 final int x = (int) particle.getX();
26 final int y = this.getBuffer().getHeight() - (int) particle.getY() - 1;
28 this.getBuffer().getRaster().setPixel(x, y, this.getColorComponents(particle));
31 /**
33 * @return
34 * <br>Maybe null
35 * <br>Shared
37 public final BufferedImage getBuffer() {
38 return this.buffer;
41 /**
43 * @param buffer
44 * <br>Maybe null
45 * <br>Shared
47 public final void setBuffer(final BufferedImage buffer) {
48 this.buffer = buffer;
51 /**
53 * @param particle
54 * <br>Not null
55 * @return
56 * <br>Not null
57 * <br>Shared
59 private final int[] getColorComponents(final Particle particle) {
60 this.colorComponents[0] = particle.getType().getColor().getRed();
61 this.colorComponents[1] = particle.getType().getColor().getGreen();
62 this.colorComponents[2] = particle.getType().getColor().getBlue();
63 this.colorComponents[3] = particle.getType().getColor().getAlpha();
65 return this.colorComponents;