Search in sources :

Example 11 with Vector3ic

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

the class SparseBooleanFieldFacet3D method getWorldEntries.

/**
 * @return a <b>new</b> map with world-based position entries
 */
public Map<Vector3i, Boolean> getWorldEntries() {
    Map<Vector3i, Boolean> result = Maps.newLinkedHashMap();
    for (Entry<Vector3ic, Boolean> entry : relData.entrySet()) {
        Vector3ic relPos = entry.getKey();
        Vector3i worldPos = relativeToWorld(relPos.x(), relPos.y(), relPos.z());
        result.put(worldPos, entry.getValue());
    }
    return result;
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i)

Example 12 with Vector3ic

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

the class ChunkViewCoreImpl method setDirtyAround.

@Override
public void setDirtyAround(BlockRegionc region) {
    BlockRegion tmp = new BlockRegion(region).expand(1, 1, 1);
    for (Vector3ic pos : Chunks.toChunkRegion(tmp, tmp)) {
        int px = pos.x() + offset.x;
        int py = pos.y() + offset.y;
        int pz = pos.z() + offset.z;
        Chunk chunk = chunks[px + chunkRegion.getSizeX() * (pz + chunkRegion.getSizeZ() * py)];
        if (chunk != null) {
            chunk.setDirty(true);
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 13 with Vector3ic

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

the class WorldProviderCoreImpl method setBlocks.

@Override
public Map<Vector3ic, Block> setBlocks(Map<? extends Vector3ic, Block> blocks) {
    /*
         * Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
         * command "showSCreen BenchmarkScreen".
         */
    Set<BlockChange> changedBlocks = new HashSet<>();
    Map<Vector3ic, Block> result = new HashMap<>(blocks.size());
    Vector3i chunkPos = new Vector3i();
    Vector3i relativePos = new Vector3i();
    for (Map.Entry<? extends Vector3ic, Block> entry : blocks.entrySet()) {
        Vector3ic worldPos = entry.getKey();
        Chunks.toChunkPos(worldPos, chunkPos);
        Chunk chunk = chunkProvider.getChunk(chunkPos);
        if (chunk != null) {
            Block type = entry.getValue();
            Chunks.toRelative(worldPos, relativePos);
            Block oldBlockType = chunk.setBlock(relativePos, type);
            if (oldBlockType != type) {
                BlockChange oldChange = blockChanges.get(worldPos);
                if (oldChange == null) {
                    blockChanges.put(new Vector3i(worldPos), new BlockChange(worldPos, oldBlockType, type));
                } else {
                    oldChange.setTo(type);
                }
                setDirtyChunksNear(worldPos);
                changedBlocks.add(new BlockChange(worldPos, oldBlockType, type));
            }
            result.put(worldPos, oldBlockType);
        } else {
            result.put(worldPos, null);
        }
    }
    for (BlockChange change : changedBlocks) {
        notifyBlockChanged(change.getPosition(), change.getTo(), change.getFrom());
    }
    return result;
}
Also used : BlockChange(org.terasology.engine.world.propagation.BlockChange) Vector3ic(org.joml.Vector3ic) HashMap(java.util.HashMap) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) Chunk(org.terasology.engine.world.chunks.Chunk) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 14 with Vector3ic

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

use of org.joml.Vector3ic 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

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