Search in sources :

Example 6 with Region3i

use of org.terasology.math.Region3i in project Terasology by MovingBlocks.

the class FloraFacetLayer method getWorldText.

@Override
public String getWorldText(Region region, int wx, int wy) {
    FloraFacet floraFacet = region.getFacet(FloraFacet.class);
    Region3i worldRegion = floraFacet.getWorldRegion();
    Region3i relativeRegion = floraFacet.getRelativeRegion();
    int rx = wx - worldRegion.minX() + relativeRegion.minX();
    int rz = wy - worldRegion.minZ() + relativeRegion.minZ();
    for (Entry<BaseVector3i, FloraType> entry : floraFacet.getRelativeEntries().entrySet()) {
        BaseVector3i treePos = entry.getKey();
        if (treePos.getX() == rx && treePos.getZ() == rz) {
            FloraType flora = entry.getValue();
            return labelFunc.apply(flora);
        }
    }
    return "-no vegetation-";
}
Also used : FloraType(org.terasology.core.world.generator.rasterizers.FloraType) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) BaseVector3i(org.terasology.math.geom.BaseVector3i) Region3i(org.terasology.math.Region3i)

Example 7 with Region3i

use of org.terasology.math.Region3i in project Terasology by MovingBlocks.

the class TreeFacetLayer method getWorldText.

@Override
public String getWorldText(Region region, int wx, int wy) {
    TreeFacet treeFacet = region.getFacet(TreeFacet.class);
    Region3i worldRegion = treeFacet.getWorldRegion();
    Region3i relativeRegion = treeFacet.getRelativeRegion();
    int rx = wx - worldRegion.minX() + relativeRegion.minX();
    int rz = wy - worldRegion.minZ() + relativeRegion.minZ();
    Vector2f relCursor = new Vector2f(rx, rz);
    CirclePicker<TreeGenerator> picker = new CirclePickerAll<>(relCursor, radiusFunc);
    for (Entry<BaseVector3i, TreeGenerator> entry : treeFacet.getRelativeEntries().entrySet()) {
        TreeGenerator treeGen = entry.getValue();
        BaseVector3i treePos = entry.getKey();
        picker.offer(treePos.getX(), treePos.getZ(), treeGen);
    }
    Set<TreeGenerator> picked = picker.getAll();
    // try to exit early first
    if (picked.isEmpty()) {
        return null;
    }
    if (picked.size() == 1) {
        TreeGenerator first = picked.iterator().next();
        return labelFunc.apply(first);
    }
    // convert to a stream of labels
    Stream<String> labels = picked.stream().map(labelFunc);
    // collect identical String elements and collect the count in a map
    Map<String, Long> counters = labels.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    // define a mapping from a map entry to a String representation
    // TODO: treat 1x occurrences like above (e.g. Tree instead of 1x Tree)
    Function<Entry<String, Long>, String> toStringFunc = e -> String.format("%dx %s", e.getValue(), e.getKey());
    // apply that mapping and join the Strings with a comma
    return counters.entrySet().stream().map(toStringFunc).collect(Collectors.joining(", "));
}
Also used : Color(java.awt.Color) Region(org.terasology.world.generation.Region) Region3i(org.terasology.math.Region3i) BufferedImage(java.awt.image.BufferedImage) TreeGenerator(org.terasology.core.world.generator.trees.TreeGenerator) Set(java.util.Set) RenderingHints(java.awt.RenderingHints) Vector2f(org.terasology.math.geom.Vector2f) CirclePickerAll(org.terasology.world.viewer.picker.CirclePickerAll) Renders(org.terasology.world.viewer.layers.Renders) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) AbstractFacetLayer(org.terasology.world.viewer.layers.AbstractFacetLayer) Stream(java.util.stream.Stream) TreeFacet(org.terasology.core.world.generator.facets.TreeFacet) BaseVector3i(org.terasology.math.geom.BaseVector3i) Graphics2D(java.awt.Graphics2D) Map(java.util.Map) Entry(java.util.Map.Entry) CirclePicker(org.terasology.world.viewer.picker.CirclePicker) ZOrder(org.terasology.world.viewer.layers.ZOrder) CirclePickerAll(org.terasology.world.viewer.picker.CirclePickerAll) TreeFacet(org.terasology.core.world.generator.facets.TreeFacet) TreeGenerator(org.terasology.core.world.generator.trees.TreeGenerator) Entry(java.util.Map.Entry) Vector2f(org.terasology.math.geom.Vector2f) BaseVector3i(org.terasology.math.geom.BaseVector3i) Region3i(org.terasology.math.Region3i)

Example 8 with Region3i

use of org.terasology.math.Region3i in project Terasology by MovingBlocks.

the class ChunkRelevanceRegion method reviewRelevantChunks.

private void reviewRelevantChunks(Vector3i distance) {
    Vector3i extents = new Vector3i(distance.x / 2, distance.y / 2, distance.z / 2);
    Region3i retainRegion = Region3i.createFromCenterExtents(center, extents);
    Iterator<Vector3i> iter = relevantChunks.iterator();
    while (iter.hasNext()) {
        Vector3i pos = iter.next();
        if (!retainRegion.encompasses(pos)) {
            sendChunkIrrelevant(pos);
            iter.remove();
        }
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Region3i(org.terasology.math.Region3i)

Example 9 with Region3i

use of org.terasology.math.Region3i in project Terasology by MovingBlocks.

the class SubSampledNoise3D method noise.

public float[] noise(Region3i region) {
    Region3i fullRegion = determineRequiredRegion(region);
    float[] keyData = getKeyValues(fullRegion);
    float[] fullData = mapExpand(keyData, fullRegion);
    return getSubset(fullData, fullRegion, region);
}
Also used : Region3i(org.terasology.math.Region3i)

Example 10 with Region3i

use of org.terasology.math.Region3i in project Terasology by MovingBlocks.

the class HeadlessWorldRenderer method updateChunksInProximity.

/**
 * Updates the list of chunks around the player.
 *
 * @param force Forces the update
 * @return True if the list was changed
 */
public boolean updateChunksInProximity(boolean force) {
    Vector3i newChunkPos = calcCamChunkOffset();
    // TODO: This should actually be done based on events from the ChunkProvider on new chunk availability/old chunk removal
    boolean chunksCurrentlyPending = false;
    if (!newChunkPos.equals(chunkPos) || force || pendingChunks) {
        Vector3i viewingDistance = config.getRendering().getViewDistance().getChunkDistance();
        Region3i viewRegion = Region3i.createFromCenterExtents(newChunkPos, new Vector3i(viewingDistance.x / 2, viewingDistance.y / 2, viewingDistance.z / 2));
        if (chunksInProximity.size() == 0 || force || pendingChunks) {
            // just add all visible chunks
            chunksInProximity.clear();
            for (Vector3i chunkPosition : viewRegion) {
                RenderableChunk c = chunkProvider.getChunk(chunkPosition);
                if (c != null && worldProvider.getLocalView(c.getPosition()) != null) {
                    chunksInProximity.add(c);
                } else {
                    chunksCurrentlyPending = true;
                }
            }
        } else {
            Region3i oldRegion = Region3i.createFromCenterExtents(chunkPos, new Vector3i(viewingDistance.x / 2, viewingDistance.y / 2, viewingDistance.z / 2));
            Iterator<Vector3i> chunksForRemove = oldRegion.subtract(viewRegion);
            // remove
            while (chunksForRemove.hasNext()) {
                Vector3i r = chunksForRemove.next();
                RenderableChunk c = chunkProvider.getChunk(r);
                if (c != null) {
                    chunksInProximity.remove(c);
                    c.disposeMesh();
                }
            }
            // add
            for (Vector3i chunkPosition : viewRegion) {
                RenderableChunk c = chunkProvider.getChunk(chunkPosition);
                if (c != null && worldProvider.getLocalView(c.getPosition()) != null) {
                    chunksInProximity.add(c);
                } else {
                    chunksCurrentlyPending = true;
                }
            }
        }
        chunkPos.set(newChunkPos);
        pendingChunks = chunksCurrentlyPending;
        Collections.sort(chunksInProximity, new ChunkFrontToBackComparator());
        return true;
    }
    return false;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) RenderableChunk(org.terasology.world.chunks.RenderableChunk) Region3i(org.terasology.math.Region3i)

Aggregations

Region3i (org.terasology.math.Region3i)23 Vector3i (org.terasology.math.geom.Vector3i)15 Test (org.junit.Test)4 WorldGeneratorPluginLibrary (org.terasology.world.generator.plugin.WorldGeneratorPluginLibrary)4 Before (org.junit.Before)3 BaseVector2i (org.terasology.math.geom.BaseVector2i)3 BaseVector3i (org.terasology.math.geom.BaseVector3i)3 Border3D (org.terasology.world.generation.Border3D)3 Region (org.terasology.world.generation.Region)3 SurfaceHeightFacet (org.terasology.world.generation.facets.SurfaceHeightFacet)3 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 Rect2i (org.terasology.math.geom.Rect2i)2 Vector3f (org.terasology.math.geom.Vector3f)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 RenderingHints (java.awt.RenderingHints)1 BufferedImage (java.awt.image.BufferedImage)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1