浏览代码

Codequality Pass 1 (#1426)

* RendererUtil: Remove unreachable switch case.

* PhysicsCharacter#setUpAxis (deprecated): Behavior change: Throw an exception instead of clamping when invalid values are passed.

* ALUtil: unnecessary String.valueOf call and missing break.

* OrientedBoxProbeArea: Some Simplifications and Switch improvements

* LwjglContext: Switch improvements

* PBRMaterialAdapter: Switch improvement and comment clarifications

* DOMSerializer: Add break on the default statement, just in case.

* MikktSpaceTangentGenerator: simplify condition

* DOMSerializer: Use StandardCharsets instead of Charset.forName

* TestBatchNode: Simplify the code a lot

* TestIssue928: Do not exit the JVM but exit the Application - This allows us to unit test this.
MeFisto94 4 年之前
父节点
当前提交
5d00bb3fff

+ 0 - 2
jme3-android/src/main/java/com/jme3/renderer/android/RendererUtil.java

@@ -77,8 +77,6 @@ public class RendererUtil {
         if (error != EGL10.EGL_SUCCESS) {
             String errorMessage;
             switch (error) {
-                case EGL10.EGL_SUCCESS:
-                    return;
                 case EGL10.EGL_NOT_INITIALIZED:
                     errorMessage = "EGL is not initialized, or could not be "
                             + "initialized, for the specified EGL display connection. ";

+ 14 - 13
jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java

@@ -40,6 +40,7 @@ import com.jme3.export.JmeImporter;
 import com.jme3.export.OutputCapsule;
 import com.jme3.math.Quaternion;
 import com.jme3.math.Vector3f;
+
 import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -161,18 +162,19 @@ public class PhysicsCharacter extends PhysicsCollisionObject {
      */
     @Deprecated
 	public void setUpAxis(int axis) {
-		if(axis<0) axis=0;
-		else if(axis>2) axis=2;
-		switch(axis){
-			case 0:
-				setUp(Vector3f.UNIT_X);
-				break;
-			case 1:
-				setUp(Vector3f.UNIT_Y);
-				break;
-			case 2:
-				setUp(Vector3f.UNIT_Z);
-		}
+        switch (axis) {
+            case 0:
+                setUp(Vector3f.UNIT_X);
+                break;
+            case 1:
+                setUp(Vector3f.UNIT_Y);
+                break;
+            case 2:
+                setUp(Vector3f.UNIT_Z);
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid axis, not in range [0, 2]");
+        }
 	}
     
     /**
@@ -184,7 +186,6 @@ public class PhysicsCharacter extends PhysicsCollisionObject {
         setUp(characterId, axis);
     }
 
-
     private native void setUp(long characterId, Vector3f axis);
 
     /**

+ 2 - 1
jme3-core/src/main/java/com/jme3/audio/openal/ALUtil.java

@@ -29,7 +29,8 @@ public final class ALUtil {
                 errorText = "Out of Memory";
                 break;
             default:
-                errorText = "Unknown Error Code: " + String.valueOf(errorCode);
+                errorText = "Unknown Error Code: " + errorCode;
+                break;
         }
         return errorText;
     }

+ 8 - 17
jme3-core/src/main/java/com/jme3/light/OrientedBoxProbeArea.java

@@ -17,7 +17,7 @@ public class OrientedBoxProbeArea implements ProbeArea {
      * for this Area type, the matrix is updated when the probe is transformed,
      * and its data is used for bound checks in the light culling process.
      */
-    private Matrix4f uniformMatrix = new Matrix4f();
+    private final Matrix4f uniformMatrix = new Matrix4f();
 
     public OrientedBoxProbeArea() {
     }
@@ -61,9 +61,7 @@ public class OrientedBoxProbeArea implements ProbeArea {
 
         p.setNormal(1, 0, 0);
         p.setConstant(c.x - box.getXExtent());
-        if (!insidePlane(p, axis1, axis2, axis3, tn)) return false;
-
-        return true;
+        return insidePlane(p, axis1, axis2, axis3, tn);
 
     }
 
@@ -79,18 +77,13 @@ public class OrientedBoxProbeArea implements ProbeArea {
 
     @Override
     public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) {
-
         Vector3f closestPoint = getClosestPoint(vars, sphere.getCenter());
         // check if the point intersects with the sphere bound
-        if (sphere.intersects(closestPoint)) {
-            return true;
-        }
-        return false;
+        return sphere.intersects(closestPoint);
     }
 
     @Override
     public boolean intersectsFrustum(Camera camera, TempVars vars) {
-
         // extract the scaled axis
         // this allows a small optimization.
         Vector3f axis1 = getScaledAxis(0, vars.vect1);
@@ -108,7 +101,7 @@ public class OrientedBoxProbeArea implements ProbeArea {
 
     private Vector3f getScaledAxis(int index, Vector3f store) {
         Matrix4f u = uniformMatrix;
-        float x = 0, y = 0, z = 0, s = 1;
+        float x, y, z, s;
         switch (index) {
             case 0:
                 x = u.m00;
@@ -127,6 +120,9 @@ public class OrientedBoxProbeArea implements ProbeArea {
                 y = u.m12;
                 z = u.m22;
                 s = u.m32;
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid axis, not in range [0, 2]");
         }
         return store.set(x, y, z).multLocal(s);
     }
@@ -141,11 +137,7 @@ public class OrientedBoxProbeArea implements ProbeArea {
                 FastMath.abs(tn.z);
 
         float distance = p.pseudoDistance(transform.getTranslation());
-
-        if (distance < -radius) {
-            return false;
-        }
-        return true;
+        return distance >= -radius;
     }
 
     private Vector3f getClosestPoint(TempVars vars, Vector3f point) {
@@ -252,5 +244,4 @@ public class OrientedBoxProbeArea implements ProbeArea {
         transform = (Transform) ic.readSavable("transform", new Transform());
         updateMatrix();
     }
-
 }

+ 1 - 1
jme3-core/src/main/java/com/jme3/util/mikktspace/MikktspaceTangentGenerator.java

@@ -434,7 +434,7 @@ public class MikktspaceTangentGenerator {
                 boolean bReadyLeftSwap = false, bReadyRightSwap = false;
                 while ((!bReadyLeftSwap) && iL < iR) {
                     assert (iL >= iL_in && iL <= iR_in);
-                    bReadyLeftSwap = !(pTmpVert[iL].vert[channel] < fSep);
+                    bReadyLeftSwap = pTmpVert[iL].vert[channel] >= fSep;
                     if (!bReadyLeftSwap) {
                         ++iL;
                     }

+ 21 - 33
jme3-examples/src/main/java/jme3test/batching/TestBatchNode.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 jMonkeyEngine
+ * Copyright (c) 2009-2020 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -49,22 +49,24 @@ import com.jme3.system.NanoTimer;
 import com.jme3.util.TangentBinormalGenerator;
 
 /**
- *
+ * A test to demonstrate the usage and functionality of the {@link BatchNode}
  * @author Nehon
  */
 public class TestBatchNode extends SimpleApplication {
+    private BatchNode batch;
+    private WireFrustum frustum;
+    private final Vector3f[] points;
+    private Geometry cube2;
+    private float time = 0;
+    private DirectionalLight dl;
+    private boolean done = false;
 
     public static void main(String[] args) {
-
         TestBatchNode app = new TestBatchNode();
         app.start();
     }
-    BatchNode batch;
-    WireFrustum frustum;
-    Geometry frustumMdl;
-    private Vector3f[] points;
 
-    {
+    public TestBatchNode() {
         points = new Vector3f[8];
         for (int i = 0; i < points.length; i++) {
             points[i] = new Vector3f();
@@ -76,20 +78,18 @@ public class TestBatchNode extends SimpleApplication {
         timer = new NanoTimer();
         batch = new BatchNode("theBatchNode");
 
-
-
-        /**
+        /*
          * A cube with a color "bleeding" through transparent texture. Uses
          * Texture from jme3-test-data library!
          */
         Box boxshape4 = new Box(1f, 1f, 1f);
-        cube = new Geometry("cube1", boxshape4);
+        Geometry cube = new Geometry("cube1", boxshape4);
         Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
         cube.setMaterial(mat);
-//        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");        
-//        mat.setColor("Diffuse", ColorRGBA.Blue);
-//        mat.setBoolean("UseMaterialColors", true);
-        /**
+        //Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
+        //mat.setColor("Diffuse", ColorRGBA.Blue);
+        //mat.setBoolean("UseMaterialColors", true);
+        /*
          * A cube with a color "bleeding" through transparent texture. Uses
          * Texture from jme3-test-data library!
          */
@@ -100,9 +100,6 @@ public class TestBatchNode extends SimpleApplication {
         TangentBinormalGenerator.generate(cube);
         TangentBinormalGenerator.generate(cube2);
 
-
-        n = new Node("aNode");
-        // n.attachChild(cube2);
         batch.attachChild(cube);
         //  batch.attachChild(cube2);
         //  batch.setMaterial(mat);
@@ -111,10 +108,9 @@ public class TestBatchNode extends SimpleApplication {
         cube.setLocalTranslation(3, 0, 0);
         cube2.setLocalTranslation(0, 20, 0);
 
-
-        updateBoindPoints(points);
+        updateBoundingPoints(points);
         frustum = new WireFrustum(points);
-        frustumMdl = new Geometry("f", frustum);
+        Geometry frustumMdl = new Geometry("f", frustum);
         frustumMdl.setCullHint(Spatial.CullHint.Never);
         frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
         frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
@@ -126,12 +122,6 @@ public class TestBatchNode extends SimpleApplication {
         rootNode.addLight(dl);
         flyCam.setMoveSpeed(10);
     }
-    Node n;
-    Geometry cube;
-    Geometry cube2;
-    float time = 0;
-    DirectionalLight dl;
-    boolean done = false;
 
     @Override
     public void simpleUpdate(float tpf) {
@@ -140,7 +130,7 @@ public class TestBatchNode extends SimpleApplication {
             batch.attachChild(cube2);
             batch.batch();
         }
-        updateBoindPoints(points);
+        updateBoundingPoints(points);
         frustum.update(points);
         time += tpf;
         dl.setDirection(cam.getDirection());
@@ -148,12 +138,10 @@ public class TestBatchNode extends SimpleApplication {
         cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
         cube2.setLocalScale(Math.max(FastMath.sin(time), 0.5f));
 
-//        batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
-
+        // batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
     }
-//    
 
-    public void updateBoindPoints(Vector3f[] points) {
+    public void updateBoundingPoints(Vector3f[] points) {
         BoundingBox bb = (BoundingBox) batch.getWorldBound();
         float xe = bb.getXExtent();
         float ye = bb.getYExtent();

+ 5 - 4
jme3-examples/src/main/java/jme3test/bullet/TestIssue928.java

@@ -43,6 +43,10 @@ import com.jme3.bullet.BulletAppState.ThreadingType;
  * If successful, no crash will occur.
  */
 public class TestIssue928 extends SimpleApplication {
+    private int count = 0;
+    private int frame = 0;
+    private BulletAppState bulletAppState;
+
     // *************************************************************************
     // new methods exposed
 
@@ -51,9 +55,6 @@ public class TestIssue928 extends SimpleApplication {
         app.start();
     }
 
-    int count = 0;
-    int frame = 0;
-    BulletAppState bulletAppState;
     // *************************************************************************
     // SimpleApplication methods
 
@@ -74,7 +75,7 @@ public class TestIssue928 extends SimpleApplication {
 
         frame++;
         if (count == 70) {
-            System.exit(0);
+            stop();
         }
     }
 }

+ 3 - 0
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java

@@ -431,6 +431,9 @@ public abstract class LwjglContext implements JmeContext {
                 case MACOSX:
                     properties.put(APPLEGLSharing.CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE)
                             .put(org.lwjgl.opengl.CGL.CGLGetShareGroup(org.lwjgl.opengl.CGL.CGLGetCurrentContext()));
+                    break;
+                default:
+                    break; // Unknown Platform, do nothing.
             }
 
             properties.put(CL_CONTEXT_PLATFORM).put(platform);

+ 4 - 5
jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRMaterialAdapter.java

@@ -38,7 +38,6 @@ import com.jme3.material.*;
  */
 public abstract class PBRMaterialAdapter extends MaterialAdapter {
 
-
     public PBRMaterialAdapter() {
         addParamMapping("normalTexture", "NormalMap");
         addParamMapping("occlusionTexture", "LightMap");
@@ -59,10 +58,12 @@ public abstract class PBRMaterialAdapter extends MaterialAdapter {
         if (param.getName().equals("alpha")) {
             String alphaMode = (String) param.getValue();
             switch (alphaMode) {
-                case "MASK":
+                case "MASK": // fallthrough
                 case "BLEND":
                     getMaterial().getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
+                    break;
             }
+            // Alpha is a RenderState not a Material Parameter, so return null
             return null;
         }
         if (param.getName().equals("doubleSided")) {
@@ -71,6 +72,7 @@ public abstract class PBRMaterialAdapter extends MaterialAdapter {
                 //Note that this is not completely right as normals on the back side will be in the wrong direction.
                 getMaterial().getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
             }
+            // FaceCulling is a RenderState not a Material Parameter, so return null
             return null;
         }
         if (param.getName().equals("NormalMap")) {
@@ -82,9 +84,6 @@ public abstract class PBRMaterialAdapter extends MaterialAdapter {
             getMaterial().setBoolean("LightMapAsAOMap", true);
         }
 
-
-
-
         return param;
     }
 }

+ 4 - 1
jme3-plugins/src/xml/java/com/jme3/export/xml/DOMSerializer.java

@@ -34,6 +34,8 @@ package com.jme3.export.xml;
 
 import java.io.*;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
 import org.w3c.dom.*;
 
 /**
@@ -48,7 +50,7 @@ import org.w3c.dom.*;
 public class DOMSerializer {
 
     /** The encoding to use for output (default is UTF-8) */
-    private Charset encoding = Charset.forName("utf-8");
+    private Charset encoding = StandardCharsets.UTF_8;
 
     /** The amount of indentation to use (default is 4 spaces). */
     private int indent = 4;
@@ -75,6 +77,7 @@ public class DOMSerializer {
                 break;
             default:
                 writer.write(c);
+                break;
             }
         }
     }