Search in sources :

Example 1 with ChunkView

use of org.terasology.engine.world.ChunkView in project Terasology by MovingBlocks.

the class RenderableWorldImpl method pregenerateChunks.

/**
 * @return true if pregeneration is complete
 */
@Override
public boolean pregenerateChunks() {
    boolean pregenerationIsComplete = true;
    chunkProvider.update();
    Chunk chunk;
    ChunkMesh newMesh;
    ChunkView localView;
    for (Vector3ic chunkCoordinates : calculateRenderableRegion(renderingConfig.getViewDistance())) {
        chunk = chunkProvider.getChunk(chunkCoordinates);
        if (chunk == null) {
            pregenerationIsComplete = false;
        } else if (chunk.isDirty()) {
            localView = worldProvider.getLocalView(chunkCoordinates);
            if (localView == null) {
                continue;
            }
            chunk.setDirty(false);
            newMesh = chunkTessellator.generateMesh(localView);
            newMesh.updateMesh();
            newMesh.discardData();
            if (chunk.hasMesh()) {
                chunk.getMesh().dispose();
            }
            chunk.setMesh(newMesh);
            pregenerationIsComplete = false;
            break;
        }
    }
    return pregenerationIsComplete;
}
Also used : ChunkMesh(org.terasology.engine.rendering.primitives.ChunkMesh) Vector3ic(org.joml.Vector3ic) RenderableChunk(org.terasology.engine.world.chunks.RenderableChunk) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkView(org.terasology.engine.world.ChunkView)

Example 2 with ChunkView

use of org.terasology.engine.world.ChunkView in project Terasology by MovingBlocks.

the class LodChunkProvider method createChunks.

private void createChunks() {
    Block unloaded = blockManager.getBlock(BlockManager.UNLOADED_ID);
    try {
        while (true) {
            Vector3ic pos = neededChunks.take();
            // Actually the log scale
            Integer scale = requiredChunks.get(pos);
            if (scale == null) {
                // This chunk is being removed in the main thread.
                continue;
            }
            Chunk chunk = new PreLodChunk(scaleDown(pos, scale), blockManager, extraDataManager);
            generator.createChunk(chunk, (1 << scale) * (2f / (Chunks.SIZE_X - 2) + 1));
            InternalLightProcessor.generateInternalLighting(chunk, 1 << scale);
            // tintChunk(chunk);
            ChunkView view = new ChunkViewCoreImpl(new Chunk[] { chunk }, new BlockRegion(chunk.getPosition(new Vector3i())), new Vector3i(), unloaded);
            ChunkMesh mesh = tessellator.generateMesh(view, 1 << scale, 1);
            readyChunks.add(new LodChunk(pos, mesh, scale));
        }
    } catch (InterruptedException ignored) {
    }
}
Also used : PreLodChunk(org.terasology.engine.world.chunks.internal.PreLodChunk) ChunkViewCoreImpl(org.terasology.engine.world.internal.ChunkViewCoreImpl) ChunkMesh(org.terasology.engine.rendering.primitives.ChunkMesh) Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) BlockRegion(org.terasology.engine.world.block.BlockRegion) PreLodChunk(org.terasology.engine.world.chunks.internal.PreLodChunk) PreLodChunk(org.terasology.engine.world.chunks.internal.PreLodChunk) ChunkView(org.terasology.engine.world.ChunkView)

Aggregations

Vector3ic (org.joml.Vector3ic)2 ChunkMesh (org.terasology.engine.rendering.primitives.ChunkMesh)2 ChunkView (org.terasology.engine.world.ChunkView)2 Vector3i (org.joml.Vector3i)1 Block (org.terasology.engine.world.block.Block)1 BlockRegion (org.terasology.engine.world.block.BlockRegion)1 Chunk (org.terasology.engine.world.chunks.Chunk)1 RenderableChunk (org.terasology.engine.world.chunks.RenderableChunk)1 PreLodChunk (org.terasology.engine.world.chunks.internal.PreLodChunk)1 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)1