diff --git a/engine/src/main/java/org/terasology/engine/physics/bullet/shapes/BulletConvexHullShape.java b/engine/src/main/java/org/terasology/engine/physics/bullet/shapes/BulletConvexHullShape.java index 84c3b757e03..6a2435cca3b 100644 --- a/engine/src/main/java/org/terasology/engine/physics/bullet/shapes/BulletConvexHullShape.java +++ b/engine/src/main/java/org/terasology/engine/physics/bullet/shapes/BulletConvexHullShape.java @@ -20,8 +20,7 @@ public class BulletConvexHullShape extends BulletCollisionShape implements Conve public BulletConvexHullShape(List vertices) { FloatBuffer buffer = BufferUtils.createFloatBuffer(vertices.size() * 3); - for (int i = 0; i < vertices.size(); i++) { - Vector3f vertex = vertices.get(i); + for (Vector3f vertex : vertices) { buffer.put(vertex.x); buffer.put(vertex.y); buffer.put(vertex.z); diff --git a/engine/src/main/java/org/terasology/engine/rendering/assets/mesh/ObjMeshFormat.java b/engine/src/main/java/org/terasology/engine/rendering/assets/mesh/ObjMeshFormat.java index fe677dcc2d8..885febc5e05 100644 --- a/engine/src/main/java/org/terasology/engine/rendering/assets/mesh/ObjMeshFormat.java +++ b/engine/src/main/java/org/terasology/engine/rendering/assets/mesh/ObjMeshFormat.java @@ -56,9 +56,9 @@ private StandardMeshData processData(List rawVertices, List List rawTexCoords, List rawIndices) throws IOException { int numIndices = 0; int numVerts = 0; - for (int x = 0; x < rawIndices.size(); x++) { - numIndices += (rawIndices.get(x).length - 2) * 3; - numVerts += rawIndices.get(x).length; + for (Vector3i[] rawIndex : rawIndices) { + numIndices += (rawIndex.length - 2) * 3; + numVerts += rawIndex.length; } StandardMeshData result = new StandardMeshData(); diff --git a/engine/src/main/java/org/terasology/engine/rendering/assets/skeletalmesh/SkeletalMeshData.java b/engine/src/main/java/org/terasology/engine/rendering/assets/skeletalmesh/SkeletalMeshData.java index f8dbb2c7463..1a51285e136 100644 --- a/engine/src/main/java/org/terasology/engine/rendering/assets/skeletalmesh/SkeletalMeshData.java +++ b/engine/src/main/java/org/terasology/engine/rendering/assets/skeletalmesh/SkeletalMeshData.java @@ -17,6 +17,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.IntStream; public class SkeletalMeshData implements AssetData { @@ -172,10 +174,8 @@ public AABBf getStaticAABB() { private void calculateNormals() { // TODO: Better algorithm (take into account triangle size and angles List vertices = getBindPoseVertexPositions(); - List normals = Lists.newArrayListWithCapacity(vertices.size()); - for (int i = 0; i < vertices.size(); ++i) { - normals.add(new Vector3f()); - } + List normals = IntStream.range(0, vertices.size()).mapToObj(i -> new Vector3f()).collect(Collectors.toCollection(() -> + Lists.newArrayListWithCapacity(vertices.size()))); Vector3f v1 = new Vector3f(); Vector3f v2 = new Vector3f(); Vector3f norm = new Vector3f(); diff --git a/engine/src/main/java/org/terasology/engine/rendering/assets/texture/AWTTextureFormat.java b/engine/src/main/java/org/terasology/engine/rendering/assets/texture/AWTTextureFormat.java index 4e59beda55f..47a2c05b3aa 100644 --- a/engine/src/main/java/org/terasology/engine/rendering/assets/texture/AWTTextureFormat.java +++ b/engine/src/main/java/org/terasology/engine/rendering/assets/texture/AWTTextureFormat.java @@ -19,6 +19,7 @@ import java.nio.ByteBuffer; import java.util.List; import java.util.function.Predicate; +import java.util.stream.IntStream; import static org.terasology.gestalt.assets.module.ModuleAssetScanner.OVERRIDE_FOLDER; @@ -79,34 +80,34 @@ public static TextureData convertToTextureData(final BufferedImage image, Textur // Convert AWT image to proper internal format if (image.getType() == BufferedImage.TYPE_3BYTE_BGR) { - for (int i = 0; i < data.length; i += stride) { + IntStream.iterate(0, i -> i < data.length, i -> i + stride).forEach(i -> { buf.put(data, i + 2, 1); // R buf.put(data, i + 1, 1); // G buf.put(data, i + 0, 1); // B buf.put((byte) 255); // A - } + }); } else if (image.getType() == BufferedImage.TYPE_4BYTE_ABGR) { - for (int i = 0; i < data.length; i += stride) { + IntStream.iterate(0, i -> i < data.length, i -> i + stride).forEach(i -> { buf.put(data, i + 3, 1); // R buf.put(data, i + 2, 1); // G buf.put(data, i + 1, 1); // B buf.put(data, i + 0, 1); // A - } + }); } else if (image.getType() == BufferedImage.TYPE_INT_ARGB) { - for (int i = 0; i < data.length; i += stride) { + IntStream.iterate(0, i -> i < data.length, i -> i + stride).forEach(i -> { buf.put(data, i + 1, 1); // R buf.put(data, i + 2, 1); // G buf.put(data, i + 3, 1); // B buf.put(data, i + 0, 1); // A - } + }); } else if (image.getType() == BufferedImage.TYPE_BYTE_INDEXED) { final ColorModel cm = image.getColorModel(); - for (int i = 0; i < data.length; i += stride) { + IntStream.iterate(0, i -> i < data.length, i -> i + stride).forEach(i -> { buf.put((byte) cm.getRed(data[i])); // R buf.put((byte) cm.getGreen(data[i])); // G buf.put((byte) cm.getBlue(data[i])); // B buf.put((byte) cm.getAlpha(data[i])); // A - } + }); } else { throw new IOException("Unsupported AWT format: " + image.getType()); } diff --git a/engine/src/main/java/org/terasology/engine/rendering/opengl/OpenGLMeshBase.java b/engine/src/main/java/org/terasology/engine/rendering/opengl/OpenGLMeshBase.java index 97585ad50d0..408b4dd964d 100644 --- a/engine/src/main/java/org/terasology/engine/rendering/opengl/OpenGLMeshBase.java +++ b/engine/src/main/java/org/terasology/engine/rendering/opengl/OpenGLMeshBase.java @@ -11,13 +11,13 @@ public interface OpenGLMeshBase { default boolean updateState(VBOContext state) { GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, state.vbo); - for (int x = 0; x < state.entries.length; x++) { - if (state.entries[x].version != state.entries[x].resource.getVersion()) { - if (state.entries[x].size != state.entries[x].resource.inSize()) { + for (VBOContext.VBOSubBuffer subBuffer : state.entries) { + if (subBuffer.version != subBuffer.resource.getVersion()) { + if (subBuffer.size != subBuffer.resource.inSize()) { return false; } - VertexResource resource = state.entries[x].resource; - int offset = state.entries[x].offset; + VertexResource resource = subBuffer.resource; + int offset = subBuffer.offset; resource.writeBuffer((buffer) -> { GL30.glBufferSubData(GL30.GL_ARRAY_BUFFER, offset, buffer); });