Search in sources :

Example 46 with Vector3ic

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

the class InternalLightGeneratorTest method testUnblockedSunlightPropagationAfterHittingMaxRegen.

@Test
public void testUnblockedSunlightPropagationAfterHittingMaxRegen() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
    InternalLightProcessor.generateInternalLighting(chunk);
    for (Vector3ic pos : new BlockRegion(0, 15, 0).setSize(Chunks.SIZE_X, Chunks.SIZE_Y - 15, Chunks.SIZE_Z)) {
        assertEquals(0, chunk.getSunlight(pos));
    }
    for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, Chunks.SIZE_Y - Chunks.MAX_SUNLIGHT_REGEN, Chunks.SIZE_Z)) {
        byte expectedSunlight = (byte) Math.min(Chunks.SIZE_Y - Chunks.SUNLIGHT_REGEN_THRESHOLD - pos.y() - 1, Chunks.MAX_SUNLIGHT);
        assertEquals(expectedSunlight, chunk.getSunlight(pos), () -> "Incorrect lighting at " + pos);
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Example 47 with Vector3ic

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

the class BetweenChunkPropagationTest method testPropagateSunlightAppearingMidChunk.

@Test
public void testPropagateSunlightAppearingMidChunk() {
    Chunk topChunk = new ChunkImpl(new Vector3i(0, 1, 0), blockManager, extraDataManager);
    Chunk bottomChunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, extraDataManager);
    provider.addChunk(topChunk);
    provider.addChunk(bottomChunk);
    for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
        topChunk.setSunlight(pos, (byte) 0);
        topChunk.setSunlightRegen(pos, (byte) 0);
    }
    for (Vector3ic pos : new BlockRegion(8, 0, 8).setSize(Chunks.SIZE_X - 16, 1, Chunks.SIZE_Z - 16)) {
        topChunk.setSunlight(pos, (byte) 0);
        topChunk.setSunlightRegen(pos, (byte) 32);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, false);
    propagator.process();
    sunlightPropagator.process();
    for (int i = 0; i < 15; ++i) {
        assertEquals(14 - i, bottomChunk.getSunlight(7, 33 + i, 16), "Incorrect value at " + (33 + i));
    }
    for (int i = 2; i < 33; ++i) {
        assertEquals(14, bottomChunk.getSunlight(7, i, 16), "Incorrect value at " + i);
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) 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 48 with Vector3ic

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

the class BetweenChunkPropagationTest method testBetweenChunksWithOverhang.

@Test
public void testBetweenChunksWithOverhang() {
    Chunk topChunk = new ChunkImpl(new Vector3i(0, 1, 0), blockManager, extraDataManager);
    Chunk bottomChunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, extraDataManager);
    provider.addChunk(topChunk);
    provider.addChunk(bottomChunk);
    for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
        topChunk.setSunlight(pos, Chunks.MAX_SUNLIGHT);
        topChunk.setSunlightRegen(pos, Chunks.MAX_SUNLIGHT_REGEN);
    }
    for (Vector3ic pos : new BlockRegion(16, 48, 0, 31, 48, 31)) {
        bottomChunk.setBlock(pos, solid);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, false);
    propagator.process();
    sunlightPropagator.process();
    for (int z = 0; z < Chunks.SIZE_Z; ++z) {
        assertEquals(14, bottomChunk.getSunlight(16, 47, z));
    }
    for (int z = 0; z < Chunks.SIZE_Z; ++z) {
        assertEquals(13, bottomChunk.getSunlight(17, 47, z));
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) 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 49 with Vector3ic

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

the class BulkLightPropagationTest method testAddLightInVacuum.

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

Example 50 with Vector3ic

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

the class BulkLightPropagationTest method testRemoveOverlappingLight.

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

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