From 8344994328d490967754f3027610aa4e19b0c087 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Tue, 8 Mar 2016 15:15:53 -0500 Subject: [PATCH] MPO: use List instead of ArrayList Also rename get*Overrides to get*MatParamOverrides to be more specific. --- .../main/java/com/jme3/material/Material.java | 6 +- .../java/com/jme3/material/Technique.java | 3 +- .../src/main/java/com/jme3/scene/Spatial.java | 8 +-- .../java/com/jme3/scene/MPOTestUtils.java | 6 +- .../jme3/scene/SceneMatParamOverrideTest.java | 58 +++++++++---------- .../material/TestMatParamOverride.java | 4 +- 6 files changed, 43 insertions(+), 42 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java index efb9fcd09..4be24fd29 100644 --- a/jme3-core/src/main/java/com/jme3/material/Material.java +++ b/jme3-core/src/main/java/com/jme3/material/Material.java @@ -785,7 +785,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { sortingId = -1; } - private void updateShaderMaterialParameters(Renderer renderer, Shader shader, ArrayList overrides) { + private void updateShaderMaterialParameters(Renderer renderer, Shader shader, List overrides) { int unit = 0; for (MatParamOverride override : overrides) { @@ -964,7 +964,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { updateRenderState(renderManager, renderer, techniqueDef); // Get world overrides - ArrayList overrides = geometry.getWorldOverrides(); + List overrides = geometry.getWorldMatParamOverrides(); // Select shader to use Shader shader = technique.makeCurrent(renderManager, overrides, lights, rendererCaps); @@ -976,7 +976,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { renderManager.updateUniformBindings(shader); // Set material parameters - updateShaderMaterialParameters(renderer, shader, geometry.getWorldOverrides()); + updateShaderMaterialParameters(renderer, shader, geometry.getWorldMatParamOverrides()); // Clear any uniforms not changed by material. resetUniformsNotSetByCurrent(shader); diff --git a/jme3-core/src/main/java/com/jme3/material/Technique.java b/jme3-core/src/main/java/com/jme3/material/Technique.java index fcadef9ab..3c6de557c 100644 --- a/jme3-core/src/main/java/com/jme3/material/Technique.java +++ b/jme3-core/src/main/java/com/jme3/material/Technique.java @@ -44,6 +44,7 @@ import com.jme3.shader.VarType; import com.jme3.util.ListMap; import java.util.ArrayList; import java.util.EnumSet; +import java.util.List; /** * Represents a technique instance. @@ -119,7 +120,7 @@ public final class Technique { * @param rendererCaps The renderer capabilities which the shader should support. * @return A compatible shader. */ - Shader makeCurrent(RenderManager renderManager, ArrayList overrides, + Shader makeCurrent(RenderManager renderManager, List overrides, LightList lights, EnumSet rendererCaps) { TechniqueDefLogic logic = def.getLogic(); AssetManager assetManager = owner.getMaterialDef().getAssetManager(); diff --git a/jme3-core/src/main/java/com/jme3/scene/Spatial.java b/jme3-core/src/main/java/com/jme3/scene/Spatial.java index 016e8e969..ce637b5fc 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Spatial.java +++ b/jme3-core/src/main/java/com/jme3/scene/Spatial.java @@ -430,7 +430,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab * * @return The list of local material parameter overrides. */ - public ArrayList getLocalOverrides() { + public List getLocalMatParamOverrides() { return localOverrides; } @@ -440,11 +440,11 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab * Note that this list is only updated on a call to * {@link #updateGeometricState()}. After update, the world overrides list * will contain the {@link #getParent() parent's} world overrides combined - * with this spatial's {@link #getLocalOverrides() local overrides}. + * with this spatial's {@link #getLocalMatParamOverrides() local overrides}. * * @return The list of world material parameter overrides. */ - public ArrayList getWorldOverrides() { + public List getWorldMatParamOverrides() { return worldOverrides; } @@ -600,7 +600,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab * Adds a local material parameter override. * * @param override The override to add. - * @see #getLocalOverrides() + * @see MatParamOverride */ public void addMatParamOverride(MatParamOverride override) { localOverrides.add(override); diff --git a/jme3-core/src/test/java/com/jme3/scene/MPOTestUtils.java b/jme3-core/src/test/java/com/jme3/scene/MPOTestUtils.java index 2eb87fbde..349789e90 100644 --- a/jme3-core/src/test/java/com/jme3/scene/MPOTestUtils.java +++ b/jme3-core/src/test/java/com/jme3/scene/MPOTestUtils.java @@ -57,14 +57,14 @@ public class MPOTestUtils { scene.checkCulling(DUMMY_CAM); Set actualOverrides = new HashSet(); - for (MatParamOverride override : scene.getWorldOverrides()) { + for (MatParamOverride override : scene.getWorldMatParamOverrides()) { actualOverrides.add(override); } Set expectedOverrides = new HashSet(); Spatial current = scene; while (current != null) { - for (MatParamOverride override : current.getLocalOverrides()) { + for (MatParamOverride override : current.getLocalMatParamOverrides()) { expectedOverrides.add(override); } current = current.getParent(); @@ -151,7 +151,7 @@ public class MPOTestUtils { sb.append(")"); } - if (!scene.getLocalOverrides().isEmpty()) { + if (!scene.getLocalMatParamOverrides().isEmpty()) { sb.append(" [MPO]"); } diff --git a/jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java b/jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java index 739ca6eee..e3f47a110 100644 --- a/jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java +++ b/jme3-core/src/test/java/com/jme3/scene/SceneMatParamOverrideTest.java @@ -41,11 +41,11 @@ import static org.junit.Assert.*; import com.jme3.system.TestUtil; import java.util.ArrayList; +import java.util.List; public class SceneMatParamOverrideTest { - private static Node createDummyScene() { Node scene = new Node("Scene Node"); @@ -81,12 +81,12 @@ public class SceneMatParamOverrideTest { @Test public void testOverrides_Empty() { Node n = new Node("Node"); - assertTrue(n.getLocalOverrides().isEmpty()); - assertTrue(n.getWorldOverrides().isEmpty()); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertTrue(n.getWorldMatParamOverrides().isEmpty()); n.updateGeometricState(); - assertTrue(n.getLocalOverrides().isEmpty()); - assertTrue(n.getWorldOverrides().isEmpty()); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertTrue(n.getWorldMatParamOverrides().isEmpty()); } @Test @@ -95,25 +95,25 @@ public class SceneMatParamOverrideTest { Node n = new Node("Node"); n.removeMatParamOverride(override); - assertTrue(n.getLocalOverrides().isEmpty()); - assertTrue(n.getWorldOverrides().isEmpty()); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertTrue(n.getWorldMatParamOverrides().isEmpty()); n.addMatParamOverride(override); - assertSame(n.getLocalOverrides().get(0), override); - assertTrue(n.getWorldOverrides().isEmpty()); + assertSame(n.getLocalMatParamOverrides().get(0), override); + assertTrue(n.getWorldMatParamOverrides().isEmpty()); n.updateGeometricState(); - assertSame(n.getLocalOverrides().get(0), override); - assertSame(n.getWorldOverrides().get(0), override); + assertSame(n.getLocalMatParamOverrides().get(0), override); + assertSame(n.getWorldMatParamOverrides().get(0), override); n.removeMatParamOverride(override); - assertTrue(n.getLocalOverrides().isEmpty()); - assertSame(n.getWorldOverrides().get(0), override); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertSame(n.getWorldMatParamOverrides().get(0), override); n.updateGeometricState(); - assertTrue(n.getLocalOverrides().isEmpty()); - assertTrue(n.getWorldOverrides().isEmpty()); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertTrue(n.getWorldMatParamOverrides().isEmpty()); } @Test @@ -122,29 +122,29 @@ public class SceneMatParamOverrideTest { Node n = new Node("Node"); n.clearMatParamOverrides(); - assertTrue(n.getLocalOverrides().isEmpty()); - assertTrue(n.getWorldOverrides().isEmpty()); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertTrue(n.getWorldMatParamOverrides().isEmpty()); n.addMatParamOverride(override); n.clearMatParamOverrides(); - assertTrue(n.getLocalOverrides().isEmpty()); - assertTrue(n.getWorldOverrides().isEmpty()); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertTrue(n.getWorldMatParamOverrides().isEmpty()); n.addMatParamOverride(override); n.updateGeometricState(); n.clearMatParamOverrides(); - assertTrue(n.getLocalOverrides().isEmpty()); - assertSame(n.getWorldOverrides().get(0), override); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertSame(n.getWorldMatParamOverrides().get(0), override); n.updateGeometricState(); - assertTrue(n.getLocalOverrides().isEmpty()); - assertTrue(n.getWorldOverrides().isEmpty()); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertTrue(n.getWorldMatParamOverrides().isEmpty()); n.addMatParamOverride(override); n.clearMatParamOverrides(); n.updateGeometricState(); - assertTrue(n.getLocalOverrides().isEmpty()); - assertTrue(n.getWorldOverrides().isEmpty()); + assertTrue(n.getLocalMatParamOverrides().isEmpty()); + assertTrue(n.getWorldMatParamOverrides().isEmpty()); } @Test @@ -233,8 +233,8 @@ public class SceneMatParamOverrideTest { validateScene(clonedScene); validateScene(originalScene); - ArrayList clonedOverrides = clonedScene.getChild("A").getLocalOverrides(); - ArrayList originalOverrides = originalScene.getChild("A").getLocalOverrides(); + List clonedOverrides = clonedScene.getChild("A").getLocalMatParamOverrides(); + List originalOverrides = originalScene.getChild("A").getLocalMatParamOverrides(); assertNotSame(clonedOverrides, originalOverrides); assertEquals(clonedOverrides, originalOverrides); @@ -258,8 +258,8 @@ public class SceneMatParamOverrideTest { validateScene(root); validateScene(scene); - assertNotSame(override, loadedScene.getChild("A").getLocalOverrides().get(0)); - assertEquals(override, loadedScene.getChild("A").getLocalOverrides().get(0)); + assertNotSame(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0)); + assertEquals(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0)); } @Test diff --git a/jme3-examples/src/main/java/jme3test/material/TestMatParamOverride.java b/jme3-examples/src/main/java/jme3test/material/TestMatParamOverride.java index 2e62f9705..224290f25 100644 --- a/jme3-examples/src/main/java/jme3test/material/TestMatParamOverride.java +++ b/jme3-examples/src/main/java/jme3test/material/TestMatParamOverride.java @@ -79,12 +79,12 @@ public class TestMatParamOverride extends SimpleApplication { @Override public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("override") && isPressed) { - if (!rootNode.getLocalOverrides().isEmpty()) { + if (!rootNode.getLocalMatParamOverrides().isEmpty()) { rootNode.clearMatParamOverrides(); } else { rootNode.addMatParamOverride(override); } - System.out.println(rootNode.getLocalOverrides()); + System.out.println(rootNode.getLocalMatParamOverrides()); } } }, "override");