Skip to content

Commit

Permalink
qa: address PMD ForLoopCanBeForeach findings
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrueckert committed Aug 18, 2024
1 parent 6fcb9bd commit 7e05b9e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public class BulletConvexHullShape extends BulletCollisionShape implements Conve

public BulletConvexHullShape(List<Vector3f> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ private StandardMeshData processData(List<Vector3f> rawVertices, List<Vector3f>
List<Vector2f> rawTexCoords, List<Vector3i[]> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -172,10 +174,8 @@ public AABBf getStaticAABB() {
private void calculateNormals() {
// TODO: Better algorithm (take into account triangle size and angles
List<Vector3f> vertices = getBindPoseVertexPositions();
List<Vector3f> normals = Lists.newArrayListWithCapacity(vertices.size());
for (int i = 0; i < vertices.size(); ++i) {
normals.add(new Vector3f());
}
List<Vector3f> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 7e05b9e

Please sign in to comment.