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-";
}
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(", "));
}
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();
}
}
}
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);
}
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;
}
Aggregations