Skip to content

Commit 5d00bb3

Browse files
authored
Codequality Pass 1 (jMonkeyEngine#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.
1 parent 02dac1c commit 5d00bb3

File tree

10 files changed

+62
-77
lines changed

10 files changed

+62
-77
lines changed

jme3-android/src/main/java/com/jme3/renderer/android/RendererUtil.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ public static void checkEGLError(EGL10 egl) {
7777
if (error != EGL10.EGL_SUCCESS) {
7878
String errorMessage;
7979
switch (error) {
80-
case EGL10.EGL_SUCCESS:
81-
return;
8280
case EGL10.EGL_NOT_INITIALIZED:
8381
errorMessage = "EGL is not initialized, or could not be "
8482
+ "initialized, for the specified EGL display connection. ";

jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.jme3.export.OutputCapsule;
4141
import com.jme3.math.Quaternion;
4242
import com.jme3.math.Vector3f;
43+
4344
import java.io.IOException;
4445
import java.util.logging.Level;
4546
import java.util.logging.Logger;
@@ -161,18 +162,19 @@ public Vector3f getWalkDirection() {
161162
*/
162163
@Deprecated
163164
public void setUpAxis(int axis) {
164-
if(axis<0) axis=0;
165-
else if(axis>2) axis=2;
166-
switch(axis){
167-
case 0:
168-
setUp(Vector3f.UNIT_X);
169-
break;
170-
case 1:
171-
setUp(Vector3f.UNIT_Y);
172-
break;
173-
case 2:
174-
setUp(Vector3f.UNIT_Z);
175-
}
165+
switch (axis) {
166+
case 0:
167+
setUp(Vector3f.UNIT_X);
168+
break;
169+
case 1:
170+
setUp(Vector3f.UNIT_Y);
171+
break;
172+
case 2:
173+
setUp(Vector3f.UNIT_Z);
174+
break;
175+
default:
176+
throw new IllegalArgumentException("Invalid axis, not in range [0, 2]");
177+
}
176178
}
177179

178180
/**
@@ -184,7 +186,6 @@ public void setUp(Vector3f axis) {
184186
setUp(characterId, axis);
185187
}
186188

187-
188189
private native void setUp(long characterId, Vector3f axis);
189190

190191
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public static String getALErrorMessage(int errorCode) {
2929
errorText = "Out of Memory";
3030
break;
3131
default:
32-
errorText = "Unknown Error Code: " + String.valueOf(errorCode);
32+
errorText = "Unknown Error Code: " + errorCode;
33+
break;
3334
}
3435
return errorText;
3536
}

jme3-core/src/main/java/com/jme3/light/OrientedBoxProbeArea.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class OrientedBoxProbeArea implements ProbeArea {
1717
* for this Area type, the matrix is updated when the probe is transformed,
1818
* and its data is used for bound checks in the light culling process.
1919
*/
20-
private Matrix4f uniformMatrix = new Matrix4f();
20+
private final Matrix4f uniformMatrix = new Matrix4f();
2121

2222
public OrientedBoxProbeArea() {
2323
}
@@ -61,9 +61,7 @@ public boolean intersectsBox(BoundingBox box, TempVars vars) {
6161

6262
p.setNormal(1, 0, 0);
6363
p.setConstant(c.x - box.getXExtent());
64-
if (!insidePlane(p, axis1, axis2, axis3, tn)) return false;
65-
66-
return true;
64+
return insidePlane(p, axis1, axis2, axis3, tn);
6765

6866
}
6967

@@ -79,18 +77,13 @@ public void setRadius(float radius) {
7977

8078
@Override
8179
public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) {
82-
8380
Vector3f closestPoint = getClosestPoint(vars, sphere.getCenter());
8481
// check if the point intersects with the sphere bound
85-
if (sphere.intersects(closestPoint)) {
86-
return true;
87-
}
88-
return false;
82+
return sphere.intersects(closestPoint);
8983
}
9084

9185
@Override
9286
public boolean intersectsFrustum(Camera camera, TempVars vars) {
93-
9487
// extract the scaled axis
9588
// this allows a small optimization.
9689
Vector3f axis1 = getScaledAxis(0, vars.vect1);
@@ -108,7 +101,7 @@ public boolean intersectsFrustum(Camera camera, TempVars vars) {
108101

109102
private Vector3f getScaledAxis(int index, Vector3f store) {
110103
Matrix4f u = uniformMatrix;
111-
float x = 0, y = 0, z = 0, s = 1;
104+
float x, y, z, s;
112105
switch (index) {
113106
case 0:
114107
x = u.m00;
@@ -127,6 +120,9 @@ private Vector3f getScaledAxis(int index, Vector3f store) {
127120
y = u.m12;
128121
z = u.m22;
129122
s = u.m32;
123+
break;
124+
default:
125+
throw new IllegalArgumentException("Invalid axis, not in range [0, 2]");
130126
}
131127
return store.set(x, y, z).multLocal(s);
132128
}
@@ -141,11 +137,7 @@ private boolean insidePlane(Plane p, Vector3f axis1, Vector3f axis2, Vector3f ax
141137
FastMath.abs(tn.z);
142138

143139
float distance = p.pseudoDistance(transform.getTranslation());
144-
145-
if (distance < -radius) {
146-
return false;
147-
}
148-
return true;
140+
return distance >= -radius;
149141
}
150142

151143
private Vector3f getClosestPoint(TempVars vars, Vector3f point) {
@@ -252,5 +244,4 @@ public void read(JmeImporter i) throws IOException {
252244
transform = (Transform) ic.readSavable("transform", new Transform());
253245
updateMatrix();
254246
}
255-
256247
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static void MergeVertsFast(int piTriList_in_and_out[], TmpVert pTmpVert[], final
434434
boolean bReadyLeftSwap = false, bReadyRightSwap = false;
435435
while ((!bReadyLeftSwap) && iL < iR) {
436436
assert (iL >= iL_in && iL <= iR_in);
437-
bReadyLeftSwap = !(pTmpVert[iL].vert[channel] < fSep);
437+
bReadyLeftSwap = pTmpVert[iL].vert[channel] >= fSep;
438438
if (!bReadyLeftSwap) {
439439
++iL;
440440
}

jme3-examples/src/main/java/jme3test/batching/TestBatchNode.java

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2012 jMonkeyEngine
2+
* Copyright (c) 2009-2020 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -49,22 +49,24 @@
4949
import com.jme3.util.TangentBinormalGenerator;
5050

5151
/**
52-
*
52+
* A test to demonstrate the usage and functionality of the {@link BatchNode}
5353
* @author Nehon
5454
*/
5555
public class TestBatchNode extends SimpleApplication {
56+
private BatchNode batch;
57+
private WireFrustum frustum;
58+
private final Vector3f[] points;
59+
private Geometry cube2;
60+
private float time = 0;
61+
private DirectionalLight dl;
62+
private boolean done = false;
5663

5764
public static void main(String[] args) {
58-
5965
TestBatchNode app = new TestBatchNode();
6066
app.start();
6167
}
62-
BatchNode batch;
63-
WireFrustum frustum;
64-
Geometry frustumMdl;
65-
private Vector3f[] points;
6668

67-
{
69+
public TestBatchNode() {
6870
points = new Vector3f[8];
6971
for (int i = 0; i < points.length; i++) {
7072
points[i] = new Vector3f();
@@ -76,20 +78,18 @@ public void simpleInitApp() {
7678
timer = new NanoTimer();
7779
batch = new BatchNode("theBatchNode");
7880

79-
80-
81-
/**
81+
/*
8282
* A cube with a color "bleeding" through transparent texture. Uses
8383
* Texture from jme3-test-data library!
8484
*/
8585
Box boxshape4 = new Box(1f, 1f, 1f);
86-
cube = new Geometry("cube1", boxshape4);
86+
Geometry cube = new Geometry("cube1", boxshape4);
8787
Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
8888
cube.setMaterial(mat);
89-
// Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
90-
// mat.setColor("Diffuse", ColorRGBA.Blue);
91-
// mat.setBoolean("UseMaterialColors", true);
92-
/**
89+
//Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
90+
//mat.setColor("Diffuse", ColorRGBA.Blue);
91+
//mat.setBoolean("UseMaterialColors", true);
92+
/*
9393
* A cube with a color "bleeding" through transparent texture. Uses
9494
* Texture from jme3-test-data library!
9595
*/
@@ -100,9 +100,6 @@ public void simpleInitApp() {
100100
TangentBinormalGenerator.generate(cube);
101101
TangentBinormalGenerator.generate(cube2);
102102

103-
104-
n = new Node("aNode");
105-
// n.attachChild(cube2);
106103
batch.attachChild(cube);
107104
// batch.attachChild(cube2);
108105
// batch.setMaterial(mat);
@@ -111,10 +108,9 @@ public void simpleInitApp() {
111108
cube.setLocalTranslation(3, 0, 0);
112109
cube2.setLocalTranslation(0, 20, 0);
113110

114-
115-
updateBoindPoints(points);
111+
updateBoundingPoints(points);
116112
frustum = new WireFrustum(points);
117-
frustumMdl = new Geometry("f", frustum);
113+
Geometry frustumMdl = new Geometry("f", frustum);
118114
frustumMdl.setCullHint(Spatial.CullHint.Never);
119115
frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
120116
frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
@@ -126,12 +122,6 @@ public void simpleInitApp() {
126122
rootNode.addLight(dl);
127123
flyCam.setMoveSpeed(10);
128124
}
129-
Node n;
130-
Geometry cube;
131-
Geometry cube2;
132-
float time = 0;
133-
DirectionalLight dl;
134-
boolean done = false;
135125

136126
@Override
137127
public void simpleUpdate(float tpf) {
@@ -140,20 +130,18 @@ public void simpleUpdate(float tpf) {
140130
batch.attachChild(cube2);
141131
batch.batch();
142132
}
143-
updateBoindPoints(points);
133+
updateBoundingPoints(points);
144134
frustum.update(points);
145135
time += tpf;
146136
dl.setDirection(cam.getDirection());
147137
cube2.setLocalTranslation(FastMath.sin(-time) * 3, FastMath.cos(time) * 3, 0);
148138
cube2.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
149139
cube2.setLocalScale(Math.max(FastMath.sin(time), 0.5f));
150140

151-
// batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
152-
141+
// batch.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Z));
153142
}
154-
//
155143

156-
public void updateBoindPoints(Vector3f[] points) {
144+
public void updateBoundingPoints(Vector3f[] points) {
157145
BoundingBox bb = (BoundingBox) batch.getWorldBound();
158146
float xe = bb.getXExtent();
159147
float ye = bb.getYExtent();

jme3-examples/src/main/java/jme3test/bullet/TestIssue928.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
* If successful, no crash will occur.
4444
*/
4545
public class TestIssue928 extends SimpleApplication {
46+
private int count = 0;
47+
private int frame = 0;
48+
private BulletAppState bulletAppState;
49+
4650
// *************************************************************************
4751
// new methods exposed
4852

@@ -51,9 +55,6 @@ public static void main(String[] args) {
5155
app.start();
5256
}
5357

54-
int count = 0;
55-
int frame = 0;
56-
BulletAppState bulletAppState;
5758
// *************************************************************************
5859
// SimpleApplication methods
5960

@@ -74,7 +75,7 @@ public void simpleUpdate(float tpf) {
7475

7576
frame++;
7677
if (count == 70) {
77-
System.exit(0);
78+
stop();
7879
}
7980
}
8081
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ private long createContext(final long platform, final long[] devices, long windo
431431
case MACOSX:
432432
properties.put(APPLEGLSharing.CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE)
433433
.put(org.lwjgl.opengl.CGL.CGLGetShareGroup(org.lwjgl.opengl.CGL.CGLGetCurrentContext()));
434+
break;
435+
default:
436+
break; // Unknown Platform, do nothing.
434437
}
435438

436439
properties.put(CL_CONTEXT_PLATFORM).put(platform);

jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/PBRMaterialAdapter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
*/
3939
public abstract class PBRMaterialAdapter extends MaterialAdapter {
4040

41-
4241
public PBRMaterialAdapter() {
4342
addParamMapping("normalTexture", "NormalMap");
4443
addParamMapping("occlusionTexture", "LightMap");
@@ -59,10 +58,12 @@ protected MatParam adaptMatParam(MatParam param) {
5958
if (param.getName().equals("alpha")) {
6059
String alphaMode = (String) param.getValue();
6160
switch (alphaMode) {
62-
case "MASK":
61+
case "MASK": // fallthrough
6362
case "BLEND":
6463
getMaterial().getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
64+
break;
6565
}
66+
// Alpha is a RenderState not a Material Parameter, so return null
6667
return null;
6768
}
6869
if (param.getName().equals("doubleSided")) {
@@ -71,6 +72,7 @@ protected MatParam adaptMatParam(MatParam param) {
7172
//Note that this is not completely right as normals on the back side will be in the wrong direction.
7273
getMaterial().getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
7374
}
75+
// FaceCulling is a RenderState not a Material Parameter, so return null
7476
return null;
7577
}
7678
if (param.getName().equals("NormalMap")) {
@@ -82,9 +84,6 @@ protected MatParam adaptMatParam(MatParam param) {
8284
getMaterial().setBoolean("LightMapAsAOMap", true);
8385
}
8486

85-
86-
87-
8887
return param;
8988
}
9089
}

jme3-plugins/src/xml/java/com/jme3/export/xml/DOMSerializer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
import java.io.*;
3636
import java.nio.charset.Charset;
37+
import java.nio.charset.StandardCharsets;
38+
3739
import org.w3c.dom.*;
3840

3941
/**
@@ -48,7 +50,7 @@
4850
public class DOMSerializer {
4951

5052
/** The encoding to use for output (default is UTF-8) */
51-
private Charset encoding = Charset.forName("utf-8");
53+
private Charset encoding = StandardCharsets.UTF_8;
5254

5355
/** The amount of indentation to use (default is 4 spaces). */
5456
private int indent = 4;
@@ -75,6 +77,7 @@ private void escape(Writer writer, String s) throws IOException {
7577
break;
7678
default:
7779
writer.write(c);
80+
break;
7881
}
7982
}
8083
}

0 commit comments

Comments
 (0)