Search in sources :

Example 6 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class RenderableWorldImpl method pregenerateChunks.

/**
 * @return true if pregeneration is complete
 */
@Override
public boolean pregenerateChunks() {
    boolean pregenerationIsComplete = true;
    chunkProvider.completeUpdate();
    chunkProvider.beginUpdate();
    RenderableChunk chunk;
    ChunkMesh newMesh;
    ChunkView localView;
    for (Vector3i 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, ChunkConstants.SIZE_Y, 0);
            newMesh.generateVBOs();
            if (chunk.hasMesh()) {
                chunk.getMesh().dispose();
            }
            chunk.setMesh(newMesh);
            pregenerationIsComplete = false;
            break;
        }
    }
    return pregenerationIsComplete;
}
Also used : ChunkMesh(org.terasology.rendering.primitives.ChunkMesh) RenderableChunk(org.terasology.world.chunks.RenderableChunk) Vector3i(org.terasology.math.geom.Vector3i) ChunkView(org.terasology.world.ChunkView)

Example 7 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class RenderableWorldImpl method calculateRenderableRegion.

private Region3i calculateRenderableRegion(ViewDistance newViewDistance) {
    Vector3i cameraCoordinates = calcCameraCoordinatesInChunkUnits();
    Vector3i renderableRegionSize = newViewDistance.getChunkDistance();
    Vector3i renderableRegionExtents = new Vector3i(renderableRegionSize.x / 2, renderableRegionSize.y / 2, renderableRegionSize.z / 2);
    return Region3i.createFromCenterExtents(cameraCoordinates, renderableRegionExtents);
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 8 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method addChunksToSaveTransaction.

private void addChunksToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder, ChunkProvider chunkProvider) {
    unloadedAndSavingChunkMap.clear();
    /**
     * New entries might be added concurrently. By using putAll + clear to transfer entries we might loose new
     * ones added in between putAll and clear. Bz iterating we can make sure that all entires removed
     * from unloadedAndUnsavedChunkMap get added to unloadedAndSavingChunkMap.
     */
    Iterator<Map.Entry<Vector3i, CompressedChunkBuilder>> unsavedEntryIterator = unloadedAndUnsavedChunkMap.entrySet().iterator();
    while (unsavedEntryIterator.hasNext()) {
        Map.Entry<Vector3i, CompressedChunkBuilder> entry = unsavedEntryIterator.next();
        unloadedAndSavingChunkMap.put(entry.getKey(), entry.getValue());
        unsavedEntryIterator.remove();
    }
    chunkProvider.getAllChunks().stream().filter(ManagedChunk::isReady).forEach(chunk -> {
        // If there is a newer undisposed version of the chunk,we don't need to save the disposed version:
        unloadedAndSavingChunkMap.remove(chunk.getPosition());
        // this storage manager can only work with ChunkImpls
        ChunkImpl chunkImpl = (ChunkImpl) chunk;
        saveTransactionBuilder.addLoadedChunk(chunk.getPosition(), chunkImpl);
    });
    for (Map.Entry<Vector3i, CompressedChunkBuilder> entry : unloadedAndSavingChunkMap.entrySet()) {
        saveTransactionBuilder.addUnloadedChunk(entry.getKey(), entry.getValue());
    }
}
Also used : ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 9 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class SaveTransaction method createChunkPosToUnsavedOwnerLessEntitiesMap.

private Map<Vector3i, Collection<EntityRef>> createChunkPosToUnsavedOwnerLessEntitiesMap() {
    Map<Vector3i, Collection<EntityRef>> chunkPosToEntitiesMap = Maps.newHashMap();
    for (EntityRef entity : privateEntityManager.getEntitiesWith(LocationComponent.class)) {
        /*
             * Note: Entities with owners get saved with the owner. Entities that are always relevant don't get stored
             * in chunk as the chunk is not always loaded
             */
        if (entity.isPersistent() && !entity.getOwner().exists() && !entity.hasComponent(ClientComponent.class) && !entity.isAlwaysRelevant()) {
            LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
            if (locationComponent != null) {
                Vector3f loc = locationComponent.getWorldPosition();
                Vector3i chunkPos = ChunkMath.calcChunkPos((int) loc.x, (int) loc.y, (int) loc.z);
                Collection<EntityRef> collection = chunkPosToEntitiesMap.get(chunkPos);
                if (collection == null) {
                    collection = Lists.newArrayList();
                    chunkPosToEntitiesMap.put(chunkPos, collection);
                }
                collection.add(entity);
            }
        }
    }
    return chunkPosToEntitiesMap;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Collection(java.util.Collection) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 10 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class StoragePathProvider method getChunkZipPosition.

public Vector3i getChunkZipPosition(Vector3i chunkPos) {
    Vector3i result = new Vector3i(chunkPos);
    result.div(CHUNK_ZIP_DIM);
    if (chunkPos.x < 0) {
        result.x -= 1;
    }
    if (chunkPos.y < 0) {
        result.y -= 1;
    }
    if (chunkPos.z < 0) {
        result.z -= 1;
    }
    return result;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)249 Test (org.junit.Test)94 EntityRef (org.terasology.entitySystem.entity.EntityRef)34 Block (org.terasology.world.block.Block)32 Chunk (org.terasology.world.chunks.Chunk)30 Vector3f (org.terasology.math.geom.Vector3f)21 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)17 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)17 Region3i (org.terasology.math.Region3i)15 BaseVector3i (org.terasology.math.geom.BaseVector3i)15 LocationComponent (org.terasology.logic.location.LocationComponent)14 BlockComponent (org.terasology.world.block.BlockComponent)10 Side (org.terasology.math.Side)9 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Before (org.junit.Before)7 Biome (org.terasology.world.biomes.Biome)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CoreChunk (org.terasology.world.chunks.CoreChunk)6 RenderableChunk (org.terasology.world.chunks.RenderableChunk)6