Package org.terasology.world.chunks

Examples of org.terasology.world.chunks.Chunk


            }
        });
    }

    public void invalidateChunks(Vector3i pos) {
        Chunk removed = chunkCache.remove(pos);
        if (removed != null && !removed.isReady()) {
            sortedReadyChunks.remove(removed);
        }

    }
View Full Code Here


            readyChunks.drainTo(newReadyChunks);
            if (!newReadyChunks.isEmpty()) {
                sortedReadyChunks.addAll(newReadyChunks);
                Collections.sort(sortedReadyChunks, new ReadyChunkRelevanceComparator());
                for (Chunk chunk : newReadyChunks) {
                    Chunk oldChunk = chunkCache.put(chunk.getPosition(), chunk);
                    if (oldChunk != null) {
                        oldChunk.dispose();
                    }
                }
            }
            if (!sortedReadyChunks.isEmpty()) {
                int loaded = 0;
                for (int i = sortedReadyChunks.size() - 1; i >= 0 && loaded < LOAD_PER_FRAME; i--) {
                    Chunk chunkInfo = sortedReadyChunks.get(i);
                    PerformanceMonitor.startActivity("Make Chunk Available");
                    if (makeChunkAvailable(chunkInfo)) {
                        sortedReadyChunks.remove(i);
                        loaded++;
                    }
View Full Code Here

        return getChunk(new Vector3i(x, y, z));
    }

    @Override
    public Chunk getChunk(Vector3i chunkPos) {
        Chunk chunk = chunkCache.get(chunkPos);
        if (chunk != null && chunk.isReady()) {
            return chunk;
        }
        return null;
    }
View Full Code Here

        return null;
    }

    @Override
    public boolean isChunkReady(Vector3i pos) {
        Chunk chunk = chunkCache.get(pos);
        return chunk != null && chunk.isReady();
    }
View Full Code Here

    }

    private ChunkViewCore createWorldView(Region3i region, Vector3i offset) {
        Chunk[] chunks = new Chunk[region.size().x * region.size().y * region.size().z];
        for (Vector3i chunkPos : region) {
            Chunk chunk = chunkCache.get(chunkPos);
            if (chunk == null || !chunk.isReady()) {
                return null;
            }
            chunkPos.sub(region.min());
            int index = TeraMath.calculate3DArrayIndex(chunkPos, region.size());
            chunks[index] = chunk;
View Full Code Here

    public void removeRelevanceEntity(EntityRef entity) {
    }

    @Override
    public void completeUpdate() {
        Chunk chunk = lightMerger.completeMerge();
        if (chunk != null) {
            chunk.markReady();
            listener.onChunkReady(chunk.getPosition());
            worldEntity.send(new OnChunkLoaded(chunk.getPosition()));
        }
    }
View Full Code Here

        }
    }

    private void processReceivedChunks(NetData.NetMessage message) {
        for (EntityData.ChunkStore chunkInfo : message.getChunkInfoList()) {
            Chunk chunk = ChunkSerializer.decode(chunkInfo);
            chunkQueue.offer(chunk);
        }
    }
View Full Code Here

        esm.loadChunkStore(CHUNK_POS);
    }

    @Test
    public void storeAndRestoreChunkStore() {
        Chunk chunk = new ChunkImpl(CHUNK_POS);
        chunk.setBlock(0, 0, 0, testBlock);
        ChunkProvider chunkProvider = mock(ChunkProvider.class);
        when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
        CoreRegistry.put(ChunkProvider.class, chunkProvider);

        esm.waitForCompletionOfPreviousSaveAndStartSaving();
View Full Code Here

        assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0));
    }

    @Test
    public void chunkSurvivesStorageSaveAndRestore() throws Exception {
        Chunk chunk = new ChunkImpl(CHUNK_POS);
        chunk.setBlock(0, 0, 0, testBlock);
        chunk.setBlock(0, 4, 2, testBlock2);
        ChunkProvider chunkProvider = mock(ChunkProvider.class);
        when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
        when(chunkProvider.getChunk(Mockito.any(Vector3i.class))).thenReturn(chunk);
        CoreRegistry.put(ChunkProvider.class, chunkProvider);
        boolean storeChunkInZips = true;
View Full Code Here

        assertEquals(testBlock2, restored.getChunk().getBlock(0, 4, 2));
    }

    @Test
    public void entitySurvivesStorageInChunkStore() throws Exception {
        Chunk chunk = new ChunkImpl(CHUNK_POS);
        chunk.setBlock(0, 0, 0, testBlock);
        ChunkProvider chunkProvider = mock(ChunkProvider.class);
        when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
        CoreRegistry.put(ChunkProvider.class, chunkProvider);
        EntityRef entity = entityManager.create();
        int id = entity.getId();
        LocationComponent locationComponent = new LocationComponent();
        Vector3f positionInChunk = new Vector3f(chunk.getAABB().getMin());
        positionInChunk.x += 1;
        positionInChunk.y += 1;
        positionInChunk.z += 1;
        locationComponent.setWorldPosition(positionInChunk);
        entity.addComponent(locationComponent);
View Full Code Here

TOP

Related Classes of org.terasology.world.chunks.Chunk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.