use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class LocalChunkProvider method getSubview.
@Override
public ChunkViewCore getSubview(BlockRegionc region, Vector3ic offset) {
Chunk[] chunks = new Chunk[region.volume()];
for (Vector3ic chunkPos : region) {
Chunk chunk = chunkCache.get(chunkPos);
int index = (chunkPos.x() - region.minX()) + region.getSizeX() * ((chunkPos.z() - region.minZ()) + region.getSizeZ() * (chunkPos.y() - region.minY()));
chunks[index] = chunk;
}
return new ChunkViewCoreImpl(chunks, region, offset, blockManager.getBlock(BlockManager.AIR_ID));
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class LodChunkProvider method createChunks.
private void createChunks() {
Block unloaded = blockManager.getBlock(BlockManager.UNLOADED_ID);
try {
while (true) {
Vector3ic pos = neededChunks.take();
// Actually the log scale
Integer scale = requiredChunks.get(pos);
if (scale == null) {
// This chunk is being removed in the main thread.
continue;
}
Chunk chunk = new PreLodChunk(scaleDown(pos, scale), blockManager, extraDataManager);
generator.createChunk(chunk, (1 << scale) * (2f / (Chunks.SIZE_X - 2) + 1));
InternalLightProcessor.generateInternalLighting(chunk, 1 << scale);
// tintChunk(chunk);
ChunkView view = new ChunkViewCoreImpl(new Chunk[] { chunk }, new BlockRegion(chunk.getPosition(new Vector3i())), new Vector3i(), unloaded);
ChunkMesh mesh = tessellator.generateMesh(view, 1 << scale, 1);
readyChunks.add(new LodChunk(pos, mesh, scale));
}
} catch (InterruptedException ignored) {
}
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class LodChunkProvider method updateRenderableRegion.
public void updateRenderableRegion(ViewDistance newViewDistance, int newChunkLods, Vector3i newCenter) {
viewDistanceSetting = newViewDistance;
center = new Vector3i(delay(center.x, newCenter.x), delay(center.y, newCenter.y), delay(center.z, newCenter.z));
chunkLods = newChunkLods;
nearby.pos = center;
Vector3i viewDistance = new Vector3i(newViewDistance.getChunkDistance()).div(2);
Vector3i altViewDistance = viewDistance.add(1 - Math.abs(viewDistance.x % 2), 1 - Math.abs(viewDistance.y % 2), 1 - Math.abs(viewDistance.z % 2), new Vector3i());
BlockRegion newPossiblyLoadedRegion = new BlockRegion(newCenter).expand(viewDistance);
BlockRegion newProbablyLoadedRegion = new BlockRegion(newPossiblyLoadedRegion).expand(-1, -1, -1);
BlockRegion[] newLodRegions = new BlockRegion[newChunkLods == 0 ? 0 : 1 + newChunkLods];
while (chunks.size() < newLodRegions.length) {
chunks.add(new ConcurrentHashMap<>());
}
while (chunks.size() > newLodRegions.length) {
for (LodChunk chunk : chunks.remove(chunks.size() - 1).values()) {
chunk.disposeMesh();
}
}
boolean lodRegionChange = newLodRegions.length != lodRegions.length;
for (int i = 0; i < newLodRegions.length; i++) {
if (i == 0) {
newLodRegions[i] = new BlockRegion(newPossiblyLoadedRegion);
} else {
// By making viewDistance odd, we ensure that every time a chunk boundary is crossed, at most a single
// lodRegion changes (except possibly for lodRegions[0], which is more closely tied to the renderable
// region).
newLodRegions[i] = new BlockRegion(scaleDown(center, i)).expand(altViewDistance);
}
Vector3i min = newLodRegions[i].getMin(new Vector3i());
Vector3i max = newLodRegions[i].getMax(new Vector3i());
newLodRegions[i].addToMin(-Math.abs(min.x % 2), -Math.abs(min.y % 2), -Math.abs(min.z % 2));
newLodRegions[i].addToMax(1 - Math.abs(max.x % 2), 1 - Math.abs(max.y % 2), 1 - Math.abs(max.z % 2));
if (!lodRegionChange && !newLodRegions[i].equals(lodRegions[i])) {
lodRegionChange = true;
}
}
if (lodRegionChange || !newProbablyLoadedRegion.equals(probablyLoadedRegion) || !newPossiblyLoadedRegion.equals(possiblyLoadedRegion)) {
// Remove previously present chunks.
Set<Vector3ic> previouslyRequiredChunks = new HashSet<>(requiredChunks.keySet());
for (Vector3ic pos : previouslyRequiredChunks) {
int scale = requiredChunks.get(pos);
// Whether this entry in requiredChunks should be removed entirely (i.e. the chunk at the actually
// required scale is not at this position).
boolean gone = false;
boolean increased = false;
while (scale < newLodRegions.length && !gone && !newLodRegions[scale].contains(scaleDown(pos, scale))) {
LodChunk chunk = chunks.get(scale).get(new Vector3i(pos));
if (chunk != null) {
chunk.disposeMesh();
chunks.get(scale).remove(new Vector3i(pos));
}
gone = ((pos.x() | pos.y() | pos.z()) & (1 << scale)) != 0;
scale++;
increased = true;
}
if (gone || scale >= newLodRegions.length) {
neededChunks.remove(pos);
requiredChunks.remove(pos);
} else if (increased) {
LodChunk chunk = chunks.get(scale).get(new Vector3i(pos));
if (chunk != null) {
requiredChunks.put(new Vector3i(pos), scale);
chunk.hiddenness = 0;
} else {
requiredChunks.remove(pos);
}
}
}
// Add new chunks.
for (int scale = 0; scale < newLodRegions.length; scale++) {
for (Vector3ic pos : newLodRegions[scale]) {
if (scale == 0 && newProbablyLoadedRegion.contains(pos) || scale == 0 && newPossiblyLoadedRegion.contains(pos) && chunkProvider.isChunkReady(pos) || scale > 0 && newLodRegions[scale - 1].contains(pos.mul(2, new Vector3i()))) {
continue;
}
Vector3i globalPos = pos.mul(1 << scale, new Vector3i());
Integer previousScale = requiredChunks.get(globalPos);
if (previousScale == null || previousScale > scale) {
addChunk(globalPos, scale);
}
}
}
}
lodRegions = newLodRegions;
probablyLoadedRegion = newProbablyLoadedRegion;
possiblyLoadedRegion = newPossiblyLoadedRegion;
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class VoxelBlockFluidWorld method loadChunk.
@Override
public void loadChunk(Chunk chunk, ShortBuffer buffer) {
Vector3ic chunkPos = chunk.getPosition();
wrapper.setRegion(chunkPos.x(), chunkPos.y(), chunkPos.z(), buffer);
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class VoxelBlockWorld method loadChunk.
@Override
public void loadChunk(Chunk chunk, ShortBuffer buffer) {
Vector3ic chunkPos = chunk.getPosition();
wrapper.setRegion(chunkPos.x(), chunkPos.y(), chunkPos.z(), buffer);
}
Aggregations