Search in sources :

Example 6 with Chunk

use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method getTotalLight.

@Override
public byte getTotalLight(int x, int y, int z) {
    Vector3i chunkPos = Chunks.toChunkPos(x, y, z, new Vector3i());
    Chunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = Chunks.toRelative(x, y, z, new Vector3i());
        return (byte) Math.max(chunk.getSunlight(blockPos), chunk.getLight(blockPos));
    }
    return 0;
}
Also used : Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 7 with Chunk

use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.

the class LocalChunkProviderTest method requestCreatingOrLoadingArea.

private Future<Chunk> requestCreatingOrLoadingArea(Vector3ic chunkPosition, int radius) {
    Future<Chunk> chunkFuture = chunkProvider.createOrLoadChunk(chunkPosition);
    BlockRegion extentsRegion = new BlockRegion(chunkPosition.x() - radius, chunkPosition.y() - radius, chunkPosition.z() - radius, chunkPosition.x() + radius, chunkPosition.y() + radius, chunkPosition.z() + radius);
    extentsRegion.iterator().forEachRemaining(pos -> {
        if (!pos.equals(chunkPosition)) {
            // remove center. we takes future for it already.
            chunkProvider.createOrLoadChunk(pos);
        }
    });
    return chunkFuture;
}
Also used : BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 8 with Chunk

use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.

the class ChunkProcessingPipelineTest method multiRequirementsChunksExistsSuccess.

/**
 * Imagine that we have task, which requires neighbors with same Z level. neighbors chunk already in chunk cache.
 */
@Test
void multiRequirementsChunksExistsSuccess() throws ExecutionException, InterruptedException, TimeoutException {
    Vector3i positionToGenerate = new Vector3i(0, 0, 0);
    Map<Vector3ic, Chunk> chunkCache = getNearChunkPositions(positionToGenerate).stream().filter(// remove central chunk.
    (p) -> !p.equals(positionToGenerate)).map(this::createChunkAt).collect(Collectors.toMap((chunk) -> chunk.getPosition(new Vector3i()), Function.identity()));
    pipeline = new ChunkProcessingPipeline(chunkCache::get, (o1, o2) -> 0);
    pipeline.addStage(ChunkTaskProvider.createMulti("flat merging task", (chunks) -> chunks.stream().filter((c) -> c.getPosition().equals(positionToGenerate)).findFirst().get(), this::getNearChunkPositions));
    Chunk chunk = createChunkAt(positionToGenerate);
    Future<Chunk> chunkFuture = pipeline.invokeGeneratorTask(new Vector3i(0, 0, 0), () -> chunk);
    Chunk chunkAfterProcessing = chunkFuture.get(1, TimeUnit.SECONDS);
    Assertions.assertEquals(chunkAfterProcessing.getPosition(new Vector3i()), chunk.getPosition(new Vector3i()), "Chunk after processing must have equals position, probably pipeline lost you chunk");
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) BeforeEach(org.junit.jupiter.api.BeforeEach) TimeoutException(java.util.concurrent.TimeoutException) Random(java.util.Random) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Future(java.util.concurrent.Future) Lists(com.google.common.collect.Lists) Vector3ic(org.joml.Vector3ic) TestInstance(org.junit.jupiter.api.TestInstance) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) AssetManager(org.terasology.gestalt.assets.management.AssetManager) ChunkTaskProvider(org.terasology.engine.world.chunks.pipeline.stages.ChunkTaskProvider) CancellationException(java.util.concurrent.CancellationException) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) BlockManagerImpl(org.terasology.engine.world.block.internal.BlockManagerImpl) List(java.util.List) Stream(java.util.stream.Stream) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) BlockManager(org.terasology.engine.world.block.BlockManager) TerasologyTestingEnvironment(org.terasology.engine.TerasologyTestingEnvironment) NullWorldAtlas(org.terasology.engine.world.block.tiles.NullWorldAtlas) Assertions(org.junit.jupiter.api.Assertions) Comparator(java.util.Comparator) CoreRegistry(org.terasology.engine.registry.CoreRegistry) Collections(java.util.Collections) Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Example 9 with Chunk

use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.

the class ChunkProcessingPipelineTest method simpleStopProcessingSuccess.

@Test
void simpleStopProcessingSuccess() {
    pipeline = new ChunkProcessingPipeline((p) -> null, (o1, o2) -> 0);
    Vector3i position = new Vector3i(0, 0, 0);
    Chunk chunk = createChunkAt(position);
    pipeline.addStage(ChunkTaskProvider.create("dummy long executing task", (c) -> {
        try {
            Thread.sleep(1_000);
        } catch (InterruptedException e) {
        }
        return c;
    }));
    Future<Chunk> chunkFuture = pipeline.invokeGeneratorTask(position, () -> chunk);
    pipeline.stopProcessingAt(position);
    Assertions.assertThrows(CancellationException.class, () -> chunkFuture.get(1, TimeUnit.SECONDS), "chunkFuture must be cancelled, when processing stopped");
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) BeforeEach(org.junit.jupiter.api.BeforeEach) TimeoutException(java.util.concurrent.TimeoutException) Random(java.util.Random) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Future(java.util.concurrent.Future) Lists(com.google.common.collect.Lists) Vector3ic(org.joml.Vector3ic) TestInstance(org.junit.jupiter.api.TestInstance) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) AssetManager(org.terasology.gestalt.assets.management.AssetManager) ChunkTaskProvider(org.terasology.engine.world.chunks.pipeline.stages.ChunkTaskProvider) CancellationException(java.util.concurrent.CancellationException) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) BlockManagerImpl(org.terasology.engine.world.block.internal.BlockManagerImpl) List(java.util.List) Stream(java.util.stream.Stream) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) BlockManager(org.terasology.engine.world.block.BlockManager) TerasologyTestingEnvironment(org.terasology.engine.TerasologyTestingEnvironment) NullWorldAtlas(org.terasology.engine.world.block.tiles.NullWorldAtlas) Assertions(org.junit.jupiter.api.Assertions) Comparator(java.util.Comparator) CoreRegistry(org.terasology.engine.registry.CoreRegistry) Collections(java.util.Collections) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Example 10 with Chunk

use of org.terasology.engine.world.chunks.Chunk 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)

Aggregations

Chunk (org.terasology.engine.world.chunks.Chunk)67 Vector3i (org.joml.Vector3i)36 Vector3ic (org.joml.Vector3ic)33 Test (org.junit.jupiter.api.Test)29 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)25 BlockRegion (org.terasology.engine.world.block.BlockRegion)24 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)8 Map (java.util.Map)7 RenderableChunk (org.terasology.engine.world.chunks.RenderableChunk)7 Lists (com.google.common.collect.Lists)6 Maps (com.google.common.collect.Maps)6 Comparator (java.util.Comparator)6 List (java.util.List)6 ExecutionException (java.util.concurrent.ExecutionException)6 Future (java.util.concurrent.Future)6 TimeUnit (java.util.concurrent.TimeUnit)6 TimeoutException (java.util.concurrent.TimeoutException)6 Assertions (org.junit.jupiter.api.Assertions)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 BlockManager (org.terasology.engine.world.block.BlockManager)6