Search in sources :

Example 1 with ChunkViewCoreImpl

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

the class ChunkViewTest method testSimpleWorldView.

@Test
public void testSimpleWorldView() {
    Chunk chunk = createChunk(0, 0, 0);
    chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
    ChunkViewCore chunkView = new ChunkViewCoreImpl(new Chunk[] { chunk }, new BlockRegion(0, 0, 0), new Vector3i(), airBlock);
    assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
}
Also used : ChunkViewCoreImpl(org.terasology.engine.world.internal.ChunkViewCoreImpl) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkViewCore(org.terasology.engine.world.internal.ChunkViewCore) Test(org.junit.jupiter.api.Test)

Example 2 with ChunkViewCoreImpl

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

the class ChunkViewTest method testLocalToWorld.

@Test
public void testLocalToWorld() {
    Chunk chunk = createChunk(1, 0, 1);
    chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
    Chunk[] chunks = new Chunk[] { createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(2, 0, 0), createChunk(0, 0, 1), chunk, createChunk(2, 0, 1), createChunk(0, 0, 2), createChunk(1, 0, 2), createChunk(2, 0, 2) };
    ChunkViewCoreImpl chunkView = new ChunkViewCoreImpl(chunks, new BlockRegion(1, 0, 1).expand(1, 0, 1), new Vector3i(1, 1, 1), airBlock);
    assertEquals(new Vector3i(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z), chunkView.toWorldPos(new Vector3i()));
}
Also used : ChunkViewCoreImpl(org.terasology.engine.world.internal.ChunkViewCoreImpl) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Example 3 with ChunkViewCoreImpl

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

the class ChunkViewTest method testOffsetChunksWorldView.

@Test
public void testOffsetChunksWorldView() {
    Chunk chunk = createChunk(1, 0, 1);
    chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
    Chunk[] chunks = new Chunk[] { createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(2, 0, 0), createChunk(0, 0, 1), chunk, createChunk(2, 0, 1), createChunk(0, 0, 2), createChunk(1, 0, 2), createChunk(2, 0, 2) };
    ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, new BlockRegion(1, 0, 1).expand(1, 0, 1), new Vector3i(1, 0, 1), airBlock);
    assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
}
Also used : ChunkViewCoreImpl(org.terasology.engine.world.internal.ChunkViewCoreImpl) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkViewCore(org.terasology.engine.world.internal.ChunkViewCore) Test(org.junit.jupiter.api.Test)

Example 4 with ChunkViewCoreImpl

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

the class LocalChunkProvider method getSubview.

@Override
public ChunkViewCore getSubview(BlockRegionc region, Vector3ic offset) {
    Chunk[] chunks = new Chunk[region.volume()];
    for (Vector3ic chunkPos : region) {
        Chunk chunk = chunkCache.get(chunkPos);
        int index = (chunkPos.x() - region.minX()) + region.getSizeX() * ((chunkPos.z() - region.minZ()) + region.getSizeZ() * (chunkPos.y() - region.minY()));
        chunks[index] = chunk;
    }
    return new ChunkViewCoreImpl(chunks, region, offset, blockManager.getBlock(BlockManager.AIR_ID));
}
Also used : ChunkViewCoreImpl(org.terasology.engine.world.internal.ChunkViewCoreImpl) Vector3ic(org.joml.Vector3ic) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 5 with ChunkViewCoreImpl

use of org.terasology.engine.world.internal.ChunkViewCoreImpl 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

ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)9 Chunk (org.terasology.engine.world.chunks.Chunk)8 Vector3i (org.joml.Vector3i)7 BlockRegion (org.terasology.engine.world.block.BlockRegion)7 Test (org.junit.jupiter.api.Test)6 ChunkViewCore (org.terasology.engine.world.internal.ChunkViewCore)5 Vector3ic (org.joml.Vector3ic)3 ChunkMesh (org.terasology.engine.rendering.primitives.ChunkMesh)1 ChunkView (org.terasology.engine.world.ChunkView)1 Block (org.terasology.engine.world.block.Block)1 PreLodChunk (org.terasology.engine.world.chunks.internal.PreLodChunk)1