Search in sources :

Example 31 with Vector3ic

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

the class Diamond3iIteratorTest method testThreeDistanceOnlyIteration.

@Test
public void testThreeDistanceOnlyIteration() {
    int cc = 0;
    for (Vector3ic next : Diamond3iIterable.shell(new Vector3i(), 3).build()) {
        assertEquals(3, next.gridDistance(new Vector3i()));
        cc++;
    }
    assertEquals(38, cc);
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) Test(org.junit.jupiter.api.Test)

Example 32 with Vector3ic

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

the class BlockSelectionRenderSystem method renderOverlayForOneBlockSelection.

private void renderOverlayForOneBlockSelection(BlockSelectionComponent blockSelectionComponent, BlockSelectionRenderer selectionRenderer) {
    selectionRenderer.beginRenderOverlay();
    if (blockSelectionComponent.currentSelection == null) {
        if (blockSelectionComponent.startPosition != null) {
            selectionRenderer.renderMark(blockSelectionComponent.startPosition);
        }
    } else {
        for (Vector3ic pos : blockSelectionComponent.currentSelection) {
            selectionRenderer.renderMark(pos);
        }
    }
    selectionRenderer.endRenderOverlay();
}
Also used : Vector3ic(org.joml.Vector3ic)

Example 33 with Vector3ic

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

the class RenderableWorldImpl method onChunkLoaded.

@Override
public void onChunkLoaded(Vector3ic chunkCoordinates) {
    if (renderableRegion.contains(chunkCoordinates)) {
        Chunk chunk = chunkProvider.getChunk(chunkCoordinates);
        if (chunk != null) {
            chunksInProximityOfCamera.add(chunk);
            chunksInProximityOfCamera.sort(new ChunkFrontToBackComparator());
            if (lodChunkProvider != null) {
                lodChunkProvider.onRealChunkLoaded(chunkCoordinates);
            }
        } else {
            logger.warn("Warning: onChunkLoaded called for a null chunk!");
        }
    }
    for (Vector3ic pos : new BlockRegion(chunkCoordinates).expand(1, 1, 1)) {
        Chunk chunk = chunkProvider.getChunk(pos);
        if (chunk != null) {
            chunk.setDirty(true);
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) RenderableChunk(org.terasology.engine.world.chunks.RenderableChunk) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 34 with Vector3ic

use of org.joml.Vector3ic 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 35 with Vector3ic

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

the class HeadlessWorldRenderer method updateChunksInProximity.

/**
 * Updates the list of chunks around the player.
 *
 * @param force Forces the update
 * @return True if the list was changed
 */
public boolean updateChunksInProximity(boolean force) {
    Vector3i newChunkPos = calcCamChunkOffset();
    // TODO: This should actually be done based on events from the ChunkProvider on new chunk availability/old chunk removal
    boolean chunksCurrentlyPending = false;
    if (!newChunkPos.equals(chunkPos) || force || pendingChunks) {
        Vector3ic viewingDistance = config.getRendering().getViewDistance().getChunkDistance();
        BlockRegion viewRegion = new BlockRegion(newChunkPos).expand(new Vector3i(viewingDistance.x() / 2, viewingDistance.y() / 2, viewingDistance.z() / 2));
        if (chunksInProximity.size() == 0 || force || pendingChunks) {
            // just add all visible chunks
            chunksInProximity.clear();
            for (Vector3ic chunkPosition : viewRegion) {
                Chunk c = chunkProvider.getChunk(chunkPosition);
                if (c != null && worldProvider.getLocalView(c.getPosition(new Vector3i())) != null) {
                    chunksInProximity.add(c);
                } else {
                    chunksCurrentlyPending = true;
                }
            }
        } else {
            BlockRegion oldRegion = new BlockRegion(chunkPos).expand(new Vector3i(viewingDistance.x() / 2, viewingDistance.y() / 2, viewingDistance.z() / 2));
            // remove
            for (Vector3ic candidateForRemove : viewRegion) {
                if (!oldRegion.contains(candidateForRemove)) {
                    Chunk c = chunkProvider.getChunk(candidateForRemove);
                    if (c != null) {
                        chunksInProximity.remove(c);
                        c.disposeMesh();
                    }
                }
            }
            // add
            for (Vector3ic chunkPosition : viewRegion) {
                Chunk c = chunkProvider.getChunk(chunkPosition);
                if (c != null && worldProvider.getLocalView(c.getPosition(new Vector3i())) != null) {
                    chunksInProximity.add(c);
                } else {
                    chunksCurrentlyPending = true;
                }
            }
        }
        chunkPos.set(newChunkPos);
        pendingChunks = chunksCurrentlyPending;
        Collections.sort(chunksInProximity, new ChunkFrontToBackComparator());
        return true;
    }
    return false;
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) RenderableChunk(org.terasology.engine.world.chunks.RenderableChunk) Chunk(org.terasology.engine.world.chunks.Chunk)

Aggregations

Vector3ic (org.joml.Vector3ic)87 Vector3i (org.joml.Vector3i)52 Test (org.junit.jupiter.api.Test)35 BlockRegion (org.terasology.engine.world.block.BlockRegion)28 Chunk (org.terasology.engine.world.chunks.Chunk)28 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)16 Block (org.terasology.engine.world.block.Block)12 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)11 Map (java.util.Map)8 Lists (com.google.common.collect.Lists)5 List (java.util.List)5 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)5 LocationComponent (org.terasology.engine.logic.location.LocationComponent)5 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)5 Maps (com.google.common.collect.Maps)4 Sets (com.google.common.collect.Sets)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 Set (java.util.Set)4 Vector3f (org.joml.Vector3f)4