Skip to content

Commit

Permalink
chore: some lintings and suggested simplifications (#4870)
Browse files Browse the repository at this point in the history
  • Loading branch information
keturn authored Aug 28, 2021
1 parent 80d0983 commit a7dacdc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/kevint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.joml.Vector2fc;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL30;
import org.terasology.engine.rendering.assets.material.Material;
import org.terasology.engine.rendering.assets.mesh.resource.GLAttributes;
Expand All @@ -25,7 +24,6 @@
/**
* Chunk meshes store, manipulate and render the vertex data of tessellated chunks.
*/
@SuppressWarnings("PointlessArithmeticExpression")
public class ChunkMesh {

/**
Expand All @@ -38,7 +36,7 @@ public enum RenderType {
BILLBOARD(2),
WATER_AND_ICE(3);

private int meshIndex;
private final int meshIndex;

RenderType(int index) {
meshIndex = index;
Expand Down Expand Up @@ -71,7 +69,7 @@ public enum RenderPhase {
private boolean disposed;

/* CONCURRENCY */
private ReentrantLock lock = new ReentrantLock();
private final ReentrantLock lock = new ReentrantLock();

/* MEASUREMENTS */
private int timeToGenerateBlockVertices;
Expand Down Expand Up @@ -128,16 +126,14 @@ private void generateVBO(RenderType type) {
VertexElements elements = vertexElements[type.ordinal()];
int id = type.getIndex();
if (!disposed && elements.buffer.elements() > 0) {
vertexBuffers[id] = GL15.glGenBuffers();
idxBuffers[id] = GL15.glGenBuffers();
vertexBuffers[id] = GL30.glGenBuffers();
idxBuffers[id] = GL30.glGenBuffers();
vaoCount[id] = GL30.glGenVertexArrays();

GL30.glBindVertexArray(vaoCount[id]);

GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBuffers[id]);
elements.buffer.writeBuffer(buffer -> {
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL30.GL_STATIC_DRAW);
});
GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, vertexBuffers[id]);
elements.buffer.writeBuffer(buffer -> GL30.glBufferData(GL30.GL_ARRAY_BUFFER, buffer, GL30.GL_STATIC_DRAW));

for (VertexResource.VertexDefinition definition : elements.buffer.definitions()) {
GL30.glEnableVertexAttribArray(definition.location);
Expand Down Expand Up @@ -231,13 +227,13 @@ public void dispose() {
for (int i = 0; i < vertexBuffers.length; i++) {
int id = vertexBuffers[i];
if (id != 0) {
GL15.glDeleteBuffers(id);
GL30.glDeleteBuffers(id);
vertexBuffers[i] = 0;
}

id = idxBuffers[i];
if (id != 0) {
GL15.glDeleteBuffers(id);
GL30.glDeleteBuffers(id);
idxBuffers[i] = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.terasology.math.TeraMath;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
Expand All @@ -44,34 +43,33 @@
* TODO: write javadoc unless this class gets slated for removal, which might be.
*/
class RenderableWorldImpl implements RenderableWorld {
private static final Logger logger = LoggerFactory.getLogger(RenderableWorldImpl.class);

private static final int MAX_ANIMATED_CHUNKS = 64;
private static final int MAX_LOADABLE_CHUNKS =
ViewDistance.MEGA.getChunkDistance().x() * ViewDistance.MEGA.getChunkDistance().y() * ViewDistance.MEGA.getChunkDistance().z();
private static final Vector3fc CHUNK_CENTER_OFFSET = new Vector3f(Chunks.CHUNK_SIZE).div(2);

private static final Logger logger = LoggerFactory.getLogger(RenderableWorldImpl.class);

private final int maxChunksForShadows =
TeraMath.clamp(CoreRegistry.get(Config.class).getRendering().getMaxChunksUsedForShadowMapping(), 64, 1024);

private final WorldProvider worldProvider;
private ChunkProvider chunkProvider;
private LodChunkProvider lodChunkProvider;
private final ChunkProvider chunkProvider;
private final LodChunkProvider lodChunkProvider;

private ChunkTessellator chunkTessellator;
private final ChunkTessellator chunkTessellator;
private final ChunkMeshUpdateManager chunkMeshUpdateManager;
private final List<Chunk> chunksInProximityOfCamera = Lists.newArrayListWithCapacity(MAX_LOADABLE_CHUNKS);
private BlockRegion renderableRegion = new BlockRegion(BlockRegion.INVALID);
private ViewDistance currentViewDistance;
private RenderQueuesHelper renderQueues;
private final RenderQueuesHelper renderQueues;
private ChunkMeshRenderer chunkMeshRenderer;

private Camera playerCamera;
private final Camera playerCamera;
private Camera shadowMapCamera;

private Config config = CoreRegistry.get(Config.class);
private RenderingConfig renderingConfig = config.getRendering();
private final Config config = CoreRegistry.get(Config.class);
private final RenderingConfig renderingConfig = config.getRendering();

private int statDirtyChunks;
private int statVisibleChunks;
Expand Down Expand Up @@ -109,7 +107,7 @@ public void onChunkLoaded(Vector3ic chunkCoordinates) {
Chunk chunk = chunkProvider.getChunk(chunkCoordinates);
if (chunk != null) {
chunksInProximityOfCamera.add(chunk);
Collections.sort(chunksInProximityOfCamera, new ChunkFrontToBackComparator());
chunksInProximityOfCamera.sort(new ChunkFrontToBackComparator());
if (lodChunkProvider != null) {
lodChunkProvider.onRealChunkLoaded(chunkCoordinates);
}
Expand All @@ -132,7 +130,7 @@ public void onChunkUnloaded(Vector3ic chunkCoordinates) {
Iterator<Chunk> iterator = chunksInProximityOfCamera.iterator();
while (iterator.hasNext()) {
chunk = iterator.next();
if (chunk.getPosition(new org.joml.Vector3i()).equals(chunkCoordinates)) {
if (chunk.getPosition().equals(chunkCoordinates)) {
chunk.disposeMesh();
iterator.remove();
break;
Expand Down Expand Up @@ -240,7 +238,7 @@ public boolean updateChunksInProximity(BlockRegion newRenderableRegion) {
}

if (chunksHaveBeenAdded) {
Collections.sort(chunksInProximityOfCamera, new ChunkFrontToBackComparator());
chunksInProximityOfCamera.sort(new ChunkFrontToBackComparator());
}
renderableRegion = newRenderableRegion;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.engine.world.chunks;


import org.joml.Vector3f;
import org.joml.Vector3i;
import org.joml.Vector3ic;
import org.terasology.engine.rendering.primitives.ChunkMesh;
import org.terasology.engine.world.block.Block;
import org.terasology.engine.world.block.BlockRegionc;
import org.terasology.protobuf.EntityData;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.protobuf.EntityData;

/**
* Chunks are a box-shaped logical grouping of Terasology's blocks, for performance reasons.
*
* Chunks are a box-shaped logical grouping of Terasology's blocks, for performance reasons.
* <p>
* For example the renderer renders a single mesh for all opaque blocks in a chunk rather
* than rendering each block as a separate mesh.
*
* <p>
* For details on dimensions and other chunks characteristics see {@link Chunks}.
*/
@API
Expand Down

0 comments on commit a7dacdc

Please sign in to comment.