use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class BlockLifecycleEvent method iterator.
@Override
public Iterator<Vector3ic> iterator() {
if (positions.size() < 3) {
return Collections.emptyIterator();
}
return new Iterator<Vector3ic>() {
private Vector3i next = new Vector3i(positions.get(0), positions.get(1), positions.get(2));
private final Vector3i current = new Vector3i();
private int index = 3;
@Override
public boolean hasNext() {
return next != null;
}
@Override
public Vector3ic next() {
if (next == null) {
throw new NoSuchElementException();
}
current.set(next);
fetchNext();
return current;
}
private void fetchNext() {
while (index < positions.size() - 2) {
next.x = positions.get(index++);
next.y = positions.get(index++);
next.z = positions.get(index++);
if (!registry.hasPermanentBlockEntity(next)) {
return;
}
}
next = null;
}
};
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class ChunkRelevanceRegion method checkIfChunkIsRelevant.
/**
* Checks if the chunk belongs to this relevance region and adds it to it if it is relevant.
*
* This method does explictly not care for the readyness of the chunk (light calcualted) or not: The light
* calculation gets only performed once the adjacent chunks got loaded. So if wait for the light calculation
* before we mark a chunk as relevant for a client then we would transfer less chunks to the client then the
* relevance region is large. the client would then again perform the light calculation too based on that
* reduced chunk count and would reduce the view distance again. That is why it makes sense to detect
* chunks as relevant even when no light calculation has been performed yet.
*/
public void checkIfChunkIsRelevant(Chunk chunk) {
if (currentRegion.contains(chunk.getPosition(new Vector3i())) && !relevantChunks.contains(chunk.getPosition(new Vector3i()))) {
relevantChunks.add(chunk.getPosition(new Vector3i()));
sendChunkRelevant(chunk);
}
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class LocalChunkProvider method createOrLoadChunk.
protected ListenableFuture<Chunk> createOrLoadChunk(Vector3ic chunkPos) {
Vector3i pos = new Vector3i(chunkPos);
return loadingPipeline.invokeGeneratorTask(pos, () -> {
ChunkStore chunkStore = storageManager.loadChunkStore(pos);
Chunk chunk;
EntityBufferImpl buffer = new EntityBufferImpl();
if (chunkStore == null) {
chunk = new ChunkImpl(pos, blockManager, extraDataManager);
generator.createChunk(chunk, buffer);
generateQueuedEntities.put(chunk.getPosition(new Vector3i()), buffer.getAll());
} else {
chunk = chunkStore.getChunk();
}
return chunk;
});
}
use of org.joml.Vector3i 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.Vector3i in project Terasology by MovingBlocks.
the class LodChunkProvider method addChunk.
private void addChunk(Vector3ic pos, int scale) {
requiredChunks.put(new Vector3i(pos), scale);
neededChunks.add(pos);
}
Aggregations