Search in sources :

Example 11 with Vector3i

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

the class ChunkViewTest method testLocalToWorld.

@Test
public void testLocalToWorld() {
    Chunk chunk = createChunk(1, 0, 1);
    chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
    Chunk[] chunks = new Chunk[] { createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(2, 0, 0), createChunk(0, 0, 1), chunk, createChunk(2, 0, 1), createChunk(0, 0, 2), createChunk(1, 0, 2), createChunk(2, 0, 2) };
    ChunkViewCoreImpl chunkView = new ChunkViewCoreImpl(chunks, new BlockRegion(1, 0, 1).expand(1, 0, 1), new Vector3i(1, 1, 1), airBlock);
    assertEquals(new Vector3i(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z), chunkView.toWorldPos(new Vector3i()));
}
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) Test(org.junit.jupiter.api.Test)

Example 12 with Vector3i

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

the class ChunkViewTest method testOffsetChunksWorldView.

@Test
public void testOffsetChunksWorldView() {
    Chunk chunk = createChunk(1, 0, 1);
    chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
    Chunk[] chunks = new Chunk[] { createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(2, 0, 0), createChunk(0, 0, 1), chunk, createChunk(2, 0, 1), createChunk(0, 0, 2), createChunk(1, 0, 2), createChunk(2, 0, 2) };
    ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, new BlockRegion(1, 0, 1).expand(1, 0, 1), new Vector3i(1, 0, 1), 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)

Example 13 with Vector3i

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

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

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

the class BulkLightPropagationTest method testAddAdjacentLights.

@Test
public void testAddAdjacentLights() {
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    worldView.setBlockAt(new Vector3i(1, 0, 0), mediumLight);
    worldView.setBlockAt(new Vector3i(0, 0, 0), mediumLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(new Vector3i(1, 0, 0), air, mediumLight), new BlockChange(ZERO_VECTOR, air, mediumLight));
    for (int i = 0; i < fullLight.getLuminance() + 1; ++i) {
        for (Vector3ic pos : Diamond3iIterable.shell(new Vector3i(0, 0, 0), i).build()) {
            long dist = Math.min(new Vector3i(0, 0, 0).gridDistance(pos), new Vector3i(1, 0, 0).gridDistance(pos));
            byte expectedLuminance = (byte) Math.max(mediumLight.getLuminance() - dist, 0);
            assertEquals(expectedLuminance, worldView.getValueAt(pos));
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) Test(org.junit.jupiter.api.Test)

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