Also found in the block structure
public void generateFaces(byte[] data, int vertexIndexOffset) {
// initialize face instances
for (int face = 0; face < faceCount; face++) {
addFace(new Face(face));
}
// find vertex indices of the face instances
for (Face face : faces) {
face.findVertexIndices(
data,
offset + face.getId() * FACE_BYTES,
vertexIndexOffset
);
}
}
public void generateVertices(byte[] data, int segmentX, int segmentZ) {
// initialize vertex instances
for (int vertex = 0; vertex < vertexCount; vertex++) {
addVertex(new Vertex(vertex));
}
// find vertex coordinates of the vertex instances
for (Vertex vertex : vertices) {
vertex.findCoordinates(
data,
offset + faceCount * FACE_BYTES
+ vertex.getId() * VERTEX_BYTES,
offsetX,
offsetZ,
segmentX,
segmentZ
);
}
}
in C++ containers similar to ArrayList in java allows
public void generateFaces(byte[] data, int vertexIndexOffset) {
// find vertex indices of the face instances
for (int face = 0; face < faceCount; face++) {
Face ref=faces.add(new Face(face));
ref.findVertexIndices(
data,
offset + ref.getId() * FACE_BYTES,
vertexIndexOffset
);
}
}
public void generateVertices(byte[] data, int segmentX, int segmentZ) {
// initialize vertex instances
// find vertex coordinates of the vertex instances
for (Vertex vertex : vertices) {
Vertex ref=vertices.add(new Vertex(vertex));
ref.findCoordinates(
data,
offset + faceCount * FACE_BYTES
+ ref.getId() * VERTEX_BYTES,
offsetX,
offsetZ,
segmentX,
segmentZ
);
}
}
Is something like this not possible in Java?
if it is, it would save alot of additional loop complexity.
it would still be possible to just access it straight after inserting it(as add(object) is put into the end) by doing
Face ref=faces.get(face);
I'd still say the addVertex and addFace amongst other functions
does not need their
public void addFace(Face face) {
if (faces.size() < faceCount) {
faces.add(face);
}
}
public void addVertex(Vertex vertex) {
if (vertices.size() < vertexCount) {
vertices.add(vertex);
}
}
ArrayList size checks, as the faceCount and vertexCount loop is always the same, meaning these branching if statements are just wasting CPU cycles.