From 4ffe4ec517f9699088bc25c29f528f82221595f0 Mon Sep 17 00:00:00 2001 From: astei Date: Sat, 14 Aug 2010 02:56:13 +0000 Subject: [PATCH] Initial temp support. (Thanks, Jack) git-svn-id: https://desert.svn.sourceforge.net/svnroot/desert@121 cbff3641-ea5c-438d-a1bd-c9f42921e016 --- src/net/sourceforge/desert/Particle.java | 46 ++++++++++++++++------ .../desert/ParticleDefaultImplementation.java | 16 +++++++- src/net/sourceforge/desert/ParticleEngine.java | 20 ++++++---- src/net/sourceforge/desert/ui/DrawingBoard.java | 8 ++-- .../net/sourceforge/desert/ParticleEngineTest.java | 42 ++++++++++---------- 5 files changed, 84 insertions(+), 48 deletions(-) diff --git a/src/net/sourceforge/desert/Particle.java b/src/net/sourceforge/desert/Particle.java index 59a097d..1b3e179 100644 --- a/src/net/sourceforge/desert/Particle.java +++ b/src/net/sourceforge/desert/Particle.java @@ -74,35 +74,39 @@ public interface Particle { */ public abstract float getMass(); + public abstract Integer getTemp(); + + public abstract Integer setTemp(Integer temp); + /** * * @author codistmonk (creation 2010-04-17) */ public static enum Type { - IMMOBILE(IMMOBILE_MASS, DEFAULT_RADIUS, Color.DARK_GRAY), + IMMOBILE(IMMOBILE_MASS, DEFAULT_RADIUS, Color.DARK_GRAY, 0), - ROCK(12.5F, DEFAULT_RADIUS, Color.LIGHT_GRAY), + ROCK(12.5F, DEFAULT_RADIUS, Color.LIGHT_GRAY, 0), - SAND(2F, DEFAULT_RADIUS, Color.YELLOW), + SAND(2F, DEFAULT_RADIUS, Color.YELLOW, 0), - WATER(2.5F, DEFAULT_RADIUS, Color.BLUE), + WATER(2.5F, DEFAULT_RADIUS, Color.BLUE, 10), - SALT(1F, DEFAULT_RADIUS, Color.WHITE), + SALT(1F, DEFAULT_RADIUS, Color.WHITE, 2), - LAVA(4.3f, DEFAULT_RADIUS+3, Color.RED), + LAVA(4.3f, DEFAULT_RADIUS+3, Color.RED, 300), - METAL(5F, DEFAULT_RADIUS, Color.GRAY), + METAL(5F, DEFAULT_RADIUS, Color.GRAY, 0), - GLASS(IMMOBILE_MASS, DEFAULT_RADIUS, Color.BLACK), // as in powder game + GLASS(IMMOBILE_MASS, DEFAULT_RADIUS, Color.BLACK, 0), // as in powder game - GRASS(IMMOBILE_MASS, DEFAULT_RADIUS, Color.GREEN), + GRASS(IMMOBILE_MASS, DEFAULT_RADIUS, Color.GREEN, 0), - OIL(2.5F, DEFAULT_RADIUS, Color.decode("#7D343D")), + OIL(2.5F, DEFAULT_RADIUS, Color.decode("#7D343D"), 3), - ZINC(7.14F, DEFAULT_RADIUS, Color.decode("#414961")), + ZINC(7.14F, DEFAULT_RADIUS, Color.decode("#414961"), 3), - GAS(-1.0F, DEFAULT_RADIUS, Color.decode("#996D72")); + GAS(-1.0F, DEFAULT_RADIUS, Color.decode("#996D72"), 2); private final float mass; @@ -110,6 +114,8 @@ public interface Particle { private final Color color; + private Integer temp; + /** * * @param mass @@ -120,10 +126,11 @@ public interface Particle { *
Can be null *
Reference parameter */ - private Type(final float mass, final float radius, final Color color) { + private Type(final float mass, final float radius, final Color color, final Integer temp) { this.mass = mass; this.radius = radius; this.color = color; + this.temp = temp; } /** @@ -162,6 +169,19 @@ public interface Particle { return this.radius; } + /** + * + * @return + *
Range: [0F .. Float.POSITIVE_INFINITY[ + */ + public Integer getTemp() { + return this.temp; + } + + public Integer setTemp(Integer t) { + this.temp = t; + return this.temp; + } } public static final float DEFAULT_RADIUS = 0.49F; diff --git a/src/net/sourceforge/desert/ParticleDefaultImplementation.java b/src/net/sourceforge/desert/ParticleDefaultImplementation.java index 5efe5f8..6136949 100644 --- a/src/net/sourceforge/desert/ParticleDefaultImplementation.java +++ b/src/net/sourceforge/desert/ParticleDefaultImplementation.java @@ -41,8 +41,10 @@ public class ParticleDefaultImplementation implements Particle { private float speedY; + private Integer temp; + public ParticleDefaultImplementation() { - this(Type.values()[0], 0F, 0F, 0F, 0F); + this(Type.values()[0], 0F, 0F, 0F, 0F, 0); } /** @@ -62,12 +64,13 @@ public class ParticleDefaultImplementation implements Particle { *
Should not be null *
Range: ]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[ */ - public ParticleDefaultImplementation(final Type type, final float x, final float y, final float speedX, final float speedY) { + public ParticleDefaultImplementation(final Type type, final float x, final float y, final float speedX, final float speedY, final Integer temp) { this.type = type; this.x = x; this.y = y; this.speedX = speedX; this.speedY = speedY; + this.temp = temp; } @Override @@ -193,4 +196,13 @@ public class ParticleDefaultImplementation implements Particle { return hash; } + public Integer getTemp() { + return this.temp; + } + + public Integer setTemp(Integer temp) { + this.temp = temp; + return temp; + } + } diff --git a/src/net/sourceforge/desert/ParticleEngine.java b/src/net/sourceforge/desert/ParticleEngine.java index 431ad72..ee5632e 100644 --- a/src/net/sourceforge/desert/ParticleEngine.java +++ b/src/net/sourceforge/desert/ParticleEngine.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; +import net.sourceforge.desert.Particle.Type; /** * A particle engine is an object responsible for the creation, storage, enumeration and update of particles. @@ -67,7 +68,7 @@ public class ParticleEngine implements Iterable { this.particles = new ArrayList(); this.newParticleId = Long.MIN_VALUE; this.borderParticle = this.new ParticleCellularImplementation(Particle.Type.IMMOBILE, - Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, 0F, 0F); + Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, 0F, 0F, 0); this.setGravity(MAXIMUM_SPEED * signum(DEFAULT_GRAVITY)); } @@ -134,8 +135,8 @@ public class ParticleEngine implements Iterable { *
Range: ]Float.NEGATIVE_INFINITY .. Float.POSITIVE_INFINITY[ */ public final void addParticle(final Particle.Type type, final float x, final float y, - final float speedX, final float speedY, final float mass) { - final ParticleDefaultImplementation particle = this.createParticle(type, x, y, speedX, speedY); + final float speedX, final float speedY, final float mass, final Integer temp) { + final ParticleDefaultImplementation particle = this.createParticle(type, x, y, speedX, speedY, temp); this.particles.add(particle); this.particleAdded(particle); @@ -185,8 +186,8 @@ public class ParticleEngine implements Iterable { *
A new value */ protected final ParticleDefaultImplementation createParticle(final Particle.Type type, final float x, final float y, - final float speedX, final float speedY) { - return new ParticleCellularImplementation(type, x, y, speedX, speedY); + final float speedX, final float speedY, final Integer temp) { + return new ParticleCellularImplementation(type, x, y, speedX, speedY, temp); } /** @@ -304,6 +305,9 @@ public class ParticleEngine implements Iterable { particle.setSpeedY(signum(particle.getSpeedY()) * MAXIMUM_SPEED); } } + // Apply temp - TODO finish + //Integer t = particle.getTemp(); + //particle.setTemp(t); } } @@ -482,13 +486,13 @@ public class ParticleEngine implements Iterable { *
Range: ]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[ */ public ParticleCellularImplementation(final Type type, final float x, final float y, - final float speedX, final float speedY) { - super(type, x, y, speedX, speedY); + final float speedX, final float speedY, final Integer temp) { + super(type, x, y, speedX, speedY, temp); this.id = ParticleEngine.this.generateNewId(); } public ParticleCellularImplementation() { - this(Type.values()[0], 0F, 0F, 0F, 0F); + this(Type.values()[0], 0F, 0F, 0F, 0F, 0); } /** diff --git a/src/net/sourceforge/desert/ui/DrawingBoard.java b/src/net/sourceforge/desert/ui/DrawingBoard.java index 4c6029d..0d7aa6b 100644 --- a/src/net/sourceforge/desert/ui/DrawingBoard.java +++ b/src/net/sourceforge/desert/ui/DrawingBoard.java @@ -218,7 +218,7 @@ public class DrawingBoard extends Canvas implements ActionListener { public final void setParticleEngine(final ParticleEngine particleEngine) { if (particleEngine != this.getParticleEngine()) { for (final Particle particle : this.getParticleEngine()) { - particleEngine.addParticle(particle.getType(), particle.getX(), particle.getY(), particle.getSpeedX(), particle.getSpeedY(), particle.getMass()); + particleEngine.addParticle(particle.getType(), particle.getX(), particle.getY(), particle.getSpeedX(), particle.getSpeedY(), particle.getMass(), particle.getTemp()); } this.particleEngine = particleEngine; @@ -258,8 +258,8 @@ public class DrawingBoard extends Canvas implements ActionListener { * @param mass *
Range: [Float.NEGATIVE_INFINITY .. Float.POSITIVE_INFINITY] */ - final void addParticle(final float x, final float y, final float speedX, final float speedY, final float mass) { - this.getParticleEngine().addParticle(this.getParticleType(), x, y, speedX, speedY, mass); + final void addParticle(final float x, final float y, final float speedX, final float speedY, final float mass, final Integer temp) { + this.getParticleEngine().addParticle(this.getParticleType(), x, y, speedX, speedY, mass, temp); } final void resizeBuffer() { @@ -441,7 +441,7 @@ public class DrawingBoard extends Canvas implements ActionListener { if (brush[i][j] && DrawingBoard.this.canAddParticle(x2, y2)) { DrawingBoard.this.particleMask[y2][x2] = true; - DrawingBoard.this.addParticle(jitter(x2), jitter(y2), 0F, 0F, jitter(DrawingBoard.this.getParticleType().getMass())); + DrawingBoard.this.addParticle(jitter(x2), jitter(y2), 0F, 0F, jitter(DrawingBoard.this.getParticleType().getMass()), DrawingBoard.this.getParticleType().getTemp()); } } } diff --git a/test/net/sourceforge/desert/ParticleEngineTest.java b/test/net/sourceforge/desert/ParticleEngineTest.java index 9c71a2b..caafefc 100644 --- a/test/net/sourceforge/desert/ParticleEngineTest.java +++ b/test/net/sourceforge/desert/ParticleEngineTest.java @@ -50,11 +50,11 @@ public final class ParticleEngineTest { assertNotNull(particleEngine.getBoardSize()); assertEquals(0, particleEngine.getParticleCount()); - particleEngine.addParticle(IMMOBILE_TYPE, 0F, 0F, 0F, 0F, 0F); + particleEngine.addParticle(IMMOBILE_TYPE, 0F, 0F, 0F, 0F, 0F, 0); assertEquals(1, particleEngine.getParticleCount()); - particleEngine.addParticle(MOBILE_TYPE_1, 0F, 0F, 0F, 0F, 0F); + particleEngine.addParticle(MOBILE_TYPE_1, 0F, 0F, 0F, 0F, 0F, 0); assertEquals(2, particleEngine.getParticleCount()); @@ -75,7 +75,7 @@ public final class ParticleEngineTest { particleEngine.setGravity(ParticleEngine.DEFAULT_GRAVITY); particleEngine.setBoardSize(null); - particleEngine.addParticle(IMMOBILE_TYPE, x, y, 0F, 0F, 0F); + particleEngine.addParticle(IMMOBILE_TYPE, x, y, 0F, 0F, 0F, 0); update(particleEngine, deltaTime, SIMULATION_STEP); final Particle particle = particleEngine.iterator().next(); @@ -115,7 +115,7 @@ public final class ParticleEngineTest { particleEngine.setGravity(0F); particleEngine.setBoardSize(new Dimension(width, height)); - particleEngine.addParticle(MOBILE_TYPE_1, x, y, speedX, speedY, 0F); + particleEngine.addParticle(MOBILE_TYPE_1, x, y, speedX, speedY, 0F, 0); update(particleEngine, deltaTime, SIMULATION_STEP); final Particle particle = particleEngine.iterator().next(); @@ -136,7 +136,7 @@ public final class ParticleEngineTest { particleEngine.setGravity(0F); particleEngine.setBoardSize(new Dimension(width, height)); - particleEngine.addParticle(MOBILE_TYPE_1, x, y, speedX, speedY, 0F); + particleEngine.addParticle(MOBILE_TYPE_1, x, y, speedX, speedY, 0F, 0); update(particleEngine, deltaTime, SIMULATION_STEP); final Particle particle = particleEngine.iterator().next(); @@ -157,7 +157,7 @@ public final class ParticleEngineTest { particleEngine.setGravity(0F); particleEngine.setBoardSize(new Dimension(width, height)); - particleEngine.addParticle(MOBILE_TYPE_1, x, y, speedX, speedY, 0F); + particleEngine.addParticle(MOBILE_TYPE_1, x, y, speedX, speedY, 0F, 0); update(particleEngine, deltaTime, SIMULATION_STEP); final Particle particle = particleEngine.iterator().next(); @@ -178,7 +178,7 @@ public final class ParticleEngineTest { particleEngine.setGravity(0F); particleEngine.setBoardSize(new Dimension(width, height)); - particleEngine.addParticle(MOBILE_TYPE_1, x, y, speedX, speedY, 0F); + particleEngine.addParticle(MOBILE_TYPE_1, x, y, speedX, speedY, 0F, 0); update(particleEngine, deltaTime, SIMULATION_STEP); final Particle particle = particleEngine.iterator().next(); @@ -224,11 +224,11 @@ public final class ParticleEngineTest { assertEquals(0, particleEngine.getParticleCount()); - particleEngine.addParticle(Particle.Type.values()[0], 0F, 0F, 0F, 0F, 0F); + particleEngine.addParticle(Particle.Type.values()[0], 0F, 0F, 0F, 0F, 0F, 0); assertEquals(1, particleEngine.getParticleCount()); - particleEngine.addParticle(Particle.Type.values()[0], 0F, 0F, 0F, 0F, 0F); + particleEngine.addParticle(Particle.Type.values()[0], 0F, 0F, 0F, 0F, 0F, 0); assertEquals(2, particleEngine.getParticleCount()); } @@ -241,11 +241,11 @@ public final class ParticleEngineTest { assertEquals(0, particleEngine.getParticleCount()); - particleEngine.addParticle(Particle.Type.values()[0], 0F, 0F, 0F, 0F, 0F); + particleEngine.addParticle(Particle.Type.values()[0], 0F, 0F, 0F, 0F, 0F, 0); assertEquals(1, particleEngine.getParticleCount()); - particleEngine.addParticle(Particle.Type.values()[0], 0F, 0F, 0F, 0F, 0F); + particleEngine.addParticle(Particle.Type.values()[0], 0F, 0F, 0F, 0F, 0F, 0); assertEquals(2, particleEngine.getParticleCount()); } @@ -254,9 +254,9 @@ public final class ParticleEngineTest { public final void testUpdate() { final ParticleEngine particleEngine = this.createParticleEngine(); final ParticleDefaultImplementation particle1 = new ParticleDefaultImplementation( - MOBILE_TYPE_1, 2F, 3F, 5F, 7F); + MOBILE_TYPE_1, 2F, 3F, 5F, 7F, 0); final ParticleDefaultImplementation particle2 = new ParticleDefaultImplementation( - MOBILE_TYPE_2, 11F, 13F, 17F, 19F); + MOBILE_TYPE_2, 11F, 13F, 17F, 19F, 0); particleEngine.setBoardSize(new Dimension(100, 100)); particleEngine.setGravity(0F); @@ -276,9 +276,9 @@ public final class ParticleEngineTest { public final void testIteratorWithoutBounds() { final ParticleEngine particleEngine = this.createParticleEngine(); final ParticleDefaultImplementation particle1 = new ParticleDefaultImplementation( - MOBILE_TYPE_1, 2F, 3F, 5F, 7F); + MOBILE_TYPE_1, 2F, 3F, 5F, 7F, 0); final ParticleDefaultImplementation particle2 = new ParticleDefaultImplementation( - MOBILE_TYPE_2, 11F, 13F, 17F, 19F); + MOBILE_TYPE_2, 11F, 13F, 17F, 19F, 0); particleEngine.setBoardSize(null); addParticle(particleEngine, particle1); @@ -307,9 +307,9 @@ public final class ParticleEngineTest { public final void testIteratorWithBounds() { final ParticleEngine particleEngine = this.createParticleEngine(); final ParticleDefaultImplementation particle1 = new ParticleDefaultImplementation( - MOBILE_TYPE_1, 2F, 3F, 5F, 7F); + MOBILE_TYPE_1, 2F, 3F, 5F, 7F, 0); final ParticleDefaultImplementation particle2 = new ParticleDefaultImplementation( - MOBILE_TYPE_2, 11F, 13F, 17F, 19F); + MOBILE_TYPE_2, 11F, 13F, 17F, 19F, 0); particleEngine.setBoardSize(new Dimension()); addParticle(particleEngine, particle1); @@ -339,9 +339,9 @@ public final class ParticleEngineTest { final ParticleEngine particleEngine = this.createParticleEngine(); particleEngine.setBoardSize(null); - particleEngine.addParticle(IMMOBILE_TYPE, 0F, 0F, 0F, 0F, 0F); - particleEngine.addParticle(MOBILE_TYPE_1, 0F, 0F, 0F, 0F, 0F); - particleEngine.addParticle(MOBILE_TYPE_2, 0F, 0F, 0F, 0F, 0F); + particleEngine.addParticle(IMMOBILE_TYPE, 0F, 0F, 0F, 0F, 0F, 0); + particleEngine.addParticle(MOBILE_TYPE_1, 0F, 0F, 0F, 0F, 0F, 0); + particleEngine.addParticle(MOBILE_TYPE_2, 0F, 0F, 0F, 0F, 0F, 0); { final Set types = new HashSet(); @@ -404,7 +404,7 @@ public final class ParticleEngineTest { *
Should not be null */ protected static final void addParticle(final ParticleEngine particleEngine, final Particle particle) { - particleEngine.addParticle(particle.getType(), particle.getX(), particle.getY(), particle.getSpeedX(), particle.getSpeedY(), particle.getMass()); + particleEngine.addParticle(particle.getType(), particle.getX(), particle.getY(), particle.getSpeedX(), particle.getSpeedY(), particle.getMass(), particle.getTemp()); } /** -- 2.11.4.GIT