Search in sources :

Example 51 with Vector3ic

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

the class BulkLightPropagationTest method testRemoveAdjacentLights.

@Test
public void testRemoveAdjacentLights() {
    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));
    worldView.setBlockAt(new Vector3i(1, 0, 0), air);
    worldView.setBlockAt(new Vector3i(0, 0, 0), air);
    propagator.process(new BlockChange(new Vector3i(1, 0, 0), mediumLight, air), new BlockChange(ZERO_VECTOR, mediumLight, air));
    for (int i = 0; i < fullLight.getLuminance() + 1; ++i) {
        byte expectedLuminance = (byte) 0;
        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)

Example 52 with Vector3ic

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

the class BulkLightPropagationTest method testRemoveLightOverlappingAtEdge.

@Test
public void testRemoveLightOverlappingAtEdge() {
    Vector3i lightPos = new Vector3i(2, 0, 0);
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    worldView.setBlockAt(new Vector3i(0, 0, 0), weakLight);
    worldView.setBlockAt(lightPos, weakLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(ZERO_VECTOR, air, weakLight), new BlockChange(lightPos, air, weakLight));
    worldView.setBlockAt(lightPos, air);
    propagator.process(new BlockChange(lightPos, weakLight, air));
    for (int i = 0; i < weakLight.getLuminance() + 1; ++i) {
        byte expectedLuminance = (byte) Math.max(0, weakLight.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)

Example 53 with Vector3ic

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

the class BulkLightPropagationTest method testRemoveSolidAndLight.

@Test
public void testRemoveSolidAndLight() {
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    for (Vector3ic pos : new BlockRegion(1, 0, 0).expand(0, 30, 30)) {
        worldView.setBlockAt(new Vector3i(pos), solid);
    }
    worldView.setBlockAt(new Vector3i(0, 0, 0), fullLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(ZERO_VECTOR, air, fullLight));
    assertEquals(0, worldView.getValueAt(new Vector3i(1, 0, 0)));
    worldView.setBlockAt(new Vector3i(1, 0, 0), air);
    worldView.setBlockAt(new Vector3i(0, 0, 0), air);
    propagator.process(new BlockChange(new Vector3i(1, 0, 0), solid, air), new BlockChange(ZERO_VECTOR, fullLight, air));
    for (int i = 0; i < fullLight.getLuminance() + 1; ++i) {
        byte expectedLuminance = (byte) 0;
        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) BlockRegion(org.terasology.engine.world.block.BlockRegion) Test(org.junit.jupiter.api.Test)

Example 54 with Vector3ic

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

the class BetweenChunkPropagationTest method testBetweenChunksSimpleSunlightRegenOnly.

@Test
public void testBetweenChunksSimpleSunlightRegenOnly() {
    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);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, true);
    propagator.process();
    for (Vector3ic pos : Chunks.CHUNK_REGION) {
        assertEquals(Chunks.MAX_SUNLIGHT_REGEN, bottomChunk.getSunlightRegen(pos), () -> "Incorrect at position " + pos);
    }
}
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 55 with Vector3ic

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

the class BulkSunlightPropagationTest method setup.

@BeforeEach
public void setup() throws Exception {
    super.setup();
    regenRules = new SunlightRegenPropagationRules();
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager, true);
    CoreRegistry.put(BlockManager.class, blockManager);
    BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
    solidData.getBaseSection().setDisplayName("Stone");
    solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    solidData.getBaseSection().setTranslucent(false);
    solidData.setBlockFamily(SymmetricFamily.class);
    assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
    solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
    air = blockManager.getBlock(BlockManager.AIR_ID);
    Map<Vector3ic, Block> blockData = Maps.newHashMap();
    regenWorldView = new StubPropagatorWorldView(Chunks.CHUNK_REGION, air, blockData);
    lightWorldView = new StubPropagatorWorldView(Chunks.CHUNK_REGION, air, blockData);
    lightRules = new SunlightPropagationRules(regenWorldView);
    sunlightPropagator = new StandardBatchPropagator(lightRules, lightWorldView);
    propagator = new SunlightRegenBatchPropagator(regenRules, regenWorldView, sunlightPropagator, lightWorldView);
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) AssetManager(org.terasology.gestalt.assets.management.AssetManager) SunlightPropagationRules(org.terasology.engine.world.propagation.light.SunlightPropagationRules) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) Vector3ic(org.joml.Vector3ic) Block(org.terasology.engine.world.block.Block) NullWorldAtlas(org.terasology.engine.world.block.tiles.NullWorldAtlas) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) SunlightRegenPropagationRules(org.terasology.engine.world.propagation.light.SunlightRegenPropagationRules) BlockManagerImpl(org.terasology.engine.world.block.internal.BlockManagerImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

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