Search in sources :

Example 96 with Vector3i

use of org.joml.Vector3i in project Terasology by MovingBlocks.

the class BlockLifecycleEvent method iterator.

@Override
public Iterator<Vector3ic> iterator() {
    if (positions.size() < 3) {
        return Collections.emptyIterator();
    }
    return new Iterator<Vector3ic>() {

        private Vector3i next = new Vector3i(positions.get(0), positions.get(1), positions.get(2));

        private final Vector3i current = new Vector3i();

        private int index = 3;

        @Override
        public boolean hasNext() {
            return next != null;
        }

        @Override
        public Vector3ic next() {
            if (next == null) {
                throw new NoSuchElementException();
            }
            current.set(next);
            fetchNext();
            return current;
        }

        private void fetchNext() {
            while (index < positions.size() - 2) {
                next.x = positions.get(index++);
                next.y = positions.get(index++);
                next.z = positions.get(index++);
                if (!registry.hasPermanentBlockEntity(next)) {
                    return;
                }
            }
            next = null;
        }
    };
}
Also used : Iterator(java.util.Iterator) Vector3i(org.joml.Vector3i) NoSuchElementException(java.util.NoSuchElementException)

Example 97 with Vector3i

use of org.joml.Vector3i in project Terasology by MovingBlocks.

the class ChunkRelevanceRegion method checkIfChunkIsRelevant.

/**
 * Checks if the chunk belongs to this relevance region and adds it to it if it is relevant.
 *
 * This method does explictly not care for the readyness of the chunk (light calcualted) or not: The light
 * calculation gets only performed once the adjacent chunks got loaded. So if wait for the light calculation
 * before we mark a chunk as relevant for a client then we would transfer less chunks to the client then the
 * relevance region is large. the client would then again perform the light calculation too based on that
 * reduced chunk count and would reduce the view distance again. That is why it makes sense to detect
 * chunks as relevant even when no light calculation has been performed yet.
 */
public void checkIfChunkIsRelevant(Chunk chunk) {
    if (currentRegion.contains(chunk.getPosition(new Vector3i())) && !relevantChunks.contains(chunk.getPosition(new Vector3i()))) {
        relevantChunks.add(chunk.getPosition(new Vector3i()));
        sendChunkRelevant(chunk);
    }
}
Also used : Vector3i(org.joml.Vector3i)

Example 98 with Vector3i

use of org.joml.Vector3i in project Terasology by MovingBlocks.

the class LocalChunkProvider method createOrLoadChunk.

protected ListenableFuture<Chunk> createOrLoadChunk(Vector3ic chunkPos) {
    Vector3i pos = new Vector3i(chunkPos);
    return loadingPipeline.invokeGeneratorTask(pos, () -> {
        ChunkStore chunkStore = storageManager.loadChunkStore(pos);
        Chunk chunk;
        EntityBufferImpl buffer = new EntityBufferImpl();
        if (chunkStore == null) {
            chunk = new ChunkImpl(pos, blockManager, extraDataManager);
            generator.createChunk(chunk, buffer);
            generateQueuedEntities.put(chunk.getPosition(new Vector3i()), buffer.getAll());
        } else {
            chunk = chunkStore.getChunk();
        }
        return chunk;
    });
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) EntityBufferImpl(org.terasology.engine.world.generation.impl.EntityBufferImpl) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkStore(org.terasology.engine.persistence.ChunkStore)

Example 99 with Vector3i

use of org.joml.Vector3i 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)

Example 100 with Vector3i

use of org.joml.Vector3i in project Terasology by MovingBlocks.

the class LodChunkProvider method addChunk.

private void addChunk(Vector3ic pos, int scale) {
    requiredChunks.put(new Vector3i(pos), scale);
    neededChunks.add(pos);
}
Also used : Vector3i(org.joml.Vector3i)

Aggregations

Vector3i (org.joml.Vector3i)203 Test (org.junit.jupiter.api.Test)87 Vector3ic (org.joml.Vector3ic)54 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)38 Chunk (org.terasology.engine.world.chunks.Chunk)36 BlockRegion (org.terasology.engine.world.block.BlockRegion)30 Block (org.terasology.engine.world.block.Block)22 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)21 Vector3f (org.joml.Vector3f)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Map (java.util.Map)11 BeforeEach (org.junit.jupiter.api.BeforeEach)10 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)10 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)8 OnChunkLoaded (org.terasology.engine.world.chunks.event.OnChunkLoaded)7 Lists (com.google.common.collect.Lists)6 Maps (com.google.common.collect.Maps)6 List (java.util.List)6 ExecutionException (java.util.concurrent.ExecutionException)6 Future (java.util.concurrent.Future)6