From 66eaa9d9152f574cafc338440734e4163957d1c5 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 22 Apr 2025 11:56:45 +0200 Subject: [PATCH 1/8] NewtonianParticleInfluencer: remove unnecessary clone() method --- .../influencers/NewtonianParticleInfluencer.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/effect/influencers/NewtonianParticleInfluencer.java b/jme3-core/src/main/java/com/jme3/effect/influencers/NewtonianParticleInfluencer.java index a026040b20..2c0b4f8555 100644 --- a/jme3-core/src/main/java/com/jme3/effect/influencers/NewtonianParticleInfluencer.java +++ b/jme3-core/src/main/java/com/jme3/effect/influencers/NewtonianParticleInfluencer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012 jMonkeyEngine + * Copyright (c) 2009-2025 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -142,17 +142,6 @@ protected void applyVelocityVariation(Particle particle) { particle.velocity.addLocal(temp); } - @Override - public NewtonianParticleInfluencer clone() { - NewtonianParticleInfluencer result = new NewtonianParticleInfluencer(); - result.normalVelocity = normalVelocity; - result.initialVelocity = initialVelocity; - result.velocityVariation = velocityVariation; - result.surfaceTangentFactor = surfaceTangentFactor; - result.surfaceTangentRotation = surfaceTangentRotation; - return result; - } - @Override public void write(JmeExporter ex) throws IOException { super.write(ex); From 273e33b1ca30226ff85ccaa21c0091efbb430c41 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 22 Apr 2025 11:57:59 +0200 Subject: [PATCH 2/8] Add ParticleInfluencerTest class --- .../influencers/ParticleInfluencerTest.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java diff --git a/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java b/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java new file mode 100644 index 0000000000..48b7df0e82 --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java @@ -0,0 +1,75 @@ +package com.jme3.effect.influencers; + +import com.jme3.asset.AssetManager; +import com.jme3.asset.DesktopAssetManager; +import com.jme3.export.binary.BinaryExporter; +import com.jme3.math.Vector3f; +import org.junit.Assert; +import org.junit.Test; + +/** + * Automated tests for the {@code ParticleInfluencer} class. + * + * @author capdevon + */ +public class ParticleInfluencerTest { + + /** + * Tests cloning, serialization and de-serialization of a {@code NewtonianParticleInfluencer}. + */ + @Test + public void testNewtonianParticleInfluencer() { + AssetManager assetManager = new DesktopAssetManager(true); + + NewtonianParticleInfluencer inf = new NewtonianParticleInfluencer(); + inf.setNormalVelocity(1); + inf.setSurfaceTangentFactor(0.5f); + inf.setSurfaceTangentRotation(2.5f); + inf.setInitialVelocity(new Vector3f(0, 1, 0)); + inf.setVelocityVariation(2f); + + NewtonianParticleInfluencer clone = (NewtonianParticleInfluencer) inf.clone(); + assertEquals(inf, clone); + + NewtonianParticleInfluencer copy = BinaryExporter.saveAndLoad(assetManager, inf); + assertEquals(inf, copy); + } + + private void assertEquals(NewtonianParticleInfluencer inf, NewtonianParticleInfluencer clone) { + Assert.assertEquals(inf.getNormalVelocity(), clone.getNormalVelocity(), 0.001f); + Assert.assertEquals(inf.getSurfaceTangentFactor(), clone.getSurfaceTangentFactor(), 0.001f); + Assert.assertEquals(inf.getSurfaceTangentRotation(), clone.getSurfaceTangentRotation(), 0.001f); + Assert.assertEquals(inf.getInitialVelocity(), clone.getInitialVelocity()); + Assert.assertEquals(inf.getVelocityVariation(), clone.getVelocityVariation(), 0.001f); + } + + /** + * Tests cloning, serialization and de-serialization of a {@code RadialParticleInfluencer}. + */ + @Test + public void testRadialParticleInfluencer() { + AssetManager assetManager = new DesktopAssetManager(true); + + RadialParticleInfluencer inf = new RadialParticleInfluencer(); + inf.setHorizontal(true); + inf.setOrigin(new Vector3f(0, 1, 0)); + inf.setRadialVelocity(2f); + inf.setInitialVelocity(new Vector3f(0, 1, 0)); + inf.setVelocityVariation(2f); + + RadialParticleInfluencer clone = (RadialParticleInfluencer) inf.clone(); + assertEquals(inf, clone); + + RadialParticleInfluencer copy = BinaryExporter.saveAndLoad(assetManager, inf); + assertEquals(inf, copy); + } + + private void assertEquals(RadialParticleInfluencer inf, RadialParticleInfluencer clone) { + Assert.assertEquals(inf.isHorizontal(), clone.isHorizontal()); + Assert.assertEquals(inf.getOrigin(), clone.getOrigin()); + Assert.assertEquals(inf.getRadialVelocity(), clone.getRadialVelocity(), 0.001f); + Assert.assertEquals(inf.getInitialVelocity(), clone.getInitialVelocity()); + Assert.assertEquals(inf.getVelocityVariation(), clone.getVelocityVariation(), 0.001f); + } + +} From 0f4353ea2ceab9da944ccb4ba3a4b5dbaca2b9f1 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 22 Apr 2025 16:09:39 +0200 Subject: [PATCH 3/8] DefaultParticleInfluencer: clone temp Vector3f --- .../com/jme3/effect/influencers/DefaultParticleInfluencer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java b/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java index d6d2c5ecf2..c3d69dd83c 100644 --- a/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java +++ b/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java @@ -104,6 +104,7 @@ public DefaultParticleInfluencer clone() { try { DefaultParticleInfluencer clone = (DefaultParticleInfluencer) super.clone(); clone.initialVelocity = initialVelocity.clone(); + clone.temp = temp.clone(); return clone; } catch (CloneNotSupportedException e) { throw new AssertionError(); From 78e1090653275d04c49afbbc3f0c83cfd0420dd2 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 22 Apr 2025 16:11:06 +0200 Subject: [PATCH 4/8] ParticleInfluencerTest: assertNotSame temp Vector3f --- .../com/jme3/effect/influencers/ParticleInfluencerTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java b/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java index 48b7df0e82..024878eb6b 100644 --- a/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java +++ b/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java @@ -30,6 +30,7 @@ public void testNewtonianParticleInfluencer() { NewtonianParticleInfluencer clone = (NewtonianParticleInfluencer) inf.clone(); assertEquals(inf, clone); + Assert.assertNotSame(inf.temp, clone.temp); NewtonianParticleInfluencer copy = BinaryExporter.saveAndLoad(assetManager, inf); assertEquals(inf, copy); @@ -59,6 +60,7 @@ public void testRadialParticleInfluencer() { RadialParticleInfluencer clone = (RadialParticleInfluencer) inf.clone(); assertEquals(inf, clone); + Assert.assertNotSame(inf.temp, clone.temp); RadialParticleInfluencer copy = BinaryExporter.saveAndLoad(assetManager, inf); assertEquals(inf, copy); From fb38a4dfb2b446e53ccdc7c9be05817ee5d053bf Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 22 Apr 2025 16:22:16 +0200 Subject: [PATCH 5/8] DefaultParticleInfluencer: use Cloner --- .../influencers/DefaultParticleInfluencer.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java b/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java index c3d69dd83c..70b9cfb7ba 100644 --- a/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java +++ b/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java @@ -40,6 +40,7 @@ import com.jme3.math.FastMath; import com.jme3.math.Vector3f; import com.jme3.util.clone.Cloner; + import java.io.IOException; /** @@ -101,14 +102,10 @@ public void read(JmeImporter im) throws IOException { @Override public DefaultParticleInfluencer clone() { - try { - DefaultParticleInfluencer clone = (DefaultParticleInfluencer) super.clone(); - clone.initialVelocity = initialVelocity.clone(); - clone.temp = temp.clone(); - return clone; - } catch (CloneNotSupportedException e) { - throw new AssertionError(); - } + // Set up the cloner for the type of cloning we want to do. + Cloner cloner = new Cloner(); + DefaultParticleInfluencer clone = cloner.clone(this); + return clone; } /** From f6a02e9f0386c0f113a2d1aff341582f25ccf487 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 22 Apr 2025 16:23:28 +0200 Subject: [PATCH 6/8] DefaultParticleInfluencer: updated license year --- .../com/jme3/effect/influencers/DefaultParticleInfluencer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java b/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java index 70b9cfb7ba..ba12a90e44 100644 --- a/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java +++ b/jme3-core/src/main/java/com/jme3/effect/influencers/DefaultParticleInfluencer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2021 jMonkeyEngine + * Copyright (c) 2009-2025 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without From 5d3bdfff00b658c0fc5936954c1ea465084b62a4 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 22 Apr 2025 16:24:22 +0200 Subject: [PATCH 7/8] Update ParticleInfluencerTest --- .../java/com/jme3/effect/influencers/ParticleInfluencerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java b/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java index 024878eb6b..1e98da6e57 100644 --- a/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java +++ b/jme3-core/src/test/java/com/jme3/effect/influencers/ParticleInfluencerTest.java @@ -61,6 +61,7 @@ public void testRadialParticleInfluencer() { RadialParticleInfluencer clone = (RadialParticleInfluencer) inf.clone(); assertEquals(inf, clone); Assert.assertNotSame(inf.temp, clone.temp); + Assert.assertNotSame(inf.getOrigin(), clone.getOrigin()); RadialParticleInfluencer copy = BinaryExporter.saveAndLoad(assetManager, inf); assertEquals(inf, copy); From cd0eb246e3ed6610562fe1e08729449b7ba55ca7 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 22 Apr 2025 16:54:01 +0200 Subject: [PATCH 8/8] ParticleInfluencer: removed redundant clonable interface JmeCloneable already extends the Cloneable interface so you can remove it --- .../com/jme3/effect/influencers/ParticleInfluencer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/effect/influencers/ParticleInfluencer.java b/jme3-core/src/main/java/com/jme3/effect/influencers/ParticleInfluencer.java index 1350463196..9fc273a121 100644 --- a/jme3-core/src/main/java/com/jme3/effect/influencers/ParticleInfluencer.java +++ b/jme3-core/src/main/java/com/jme3/effect/influencers/ParticleInfluencer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 jMonkeyEngine + * Copyright (c) 2009-2025 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,7 @@ * An interface that defines the methods to affect initial velocity of the particles. * @author Marcin Roguski (Kaelthas) */ -public interface ParticleInfluencer extends Savable, Cloneable, JmeCloneable { +public interface ParticleInfluencer extends Savable, JmeCloneable { /** * This method influences the particle. @@ -57,7 +57,7 @@ public interface ParticleInfluencer extends Savable, Cloneable, JmeCloneable { * This method clones the influencer instance. * @return cloned instance */ - public ParticleInfluencer clone(); + ParticleInfluencer clone(); /** * @param initialVelocity