use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class ReadWriteStorageManager method addChunksToSaveTransaction.
private void addChunksToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder, ChunkProvider chunkProvider) {
unloadedAndSavingChunkMap.clear();
/*
* New entries might be added concurrently. By using putAll + clear to transfer entries we might loose new
* ones added in between putAll and clear. By iterating we can make sure that all entries removed
* from unloadedAndUnsavedChunkMap get added to unloadedAndSavingChunkMap.
*/
Iterator<Map.Entry<Vector3ic, CompressedChunkBuilder>> unsavedEntryIterator = unloadedAndUnsavedChunkMap.entrySet().iterator();
while (unsavedEntryIterator.hasNext()) {
Map.Entry<Vector3ic, CompressedChunkBuilder> entry = unsavedEntryIterator.next();
unloadedAndSavingChunkMap.put(entry.getKey(), entry.getValue());
unsavedEntryIterator.remove();
}
chunkProvider.getAllChunks().stream().filter(Chunk::isReady).forEach(chunk -> {
// If there is a newer undisposed version of the chunk,we don't need to save the disposed version:
unloadedAndSavingChunkMap.remove(chunk.getPosition(new Vector3i()));
// this storage manager can only work with ChunkImpls
ChunkImpl chunkImpl = (ChunkImpl) chunk;
saveTransactionBuilder.addLoadedChunk(chunk.getPosition(), chunkImpl);
});
for (Map.Entry<Vector3ic, CompressedChunkBuilder> entry : unloadedAndSavingChunkMap.entrySet()) {
saveTransactionBuilder.addUnloadedChunk(entry.getKey(), entry.getValue());
}
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class VoxelWorldSystem method onNewChunk.
/**
* new chunks that are loaded need to update pass the data to bullet
*
* @param chunkAvailable the chunk
* @param worldEntity world entity
*/
@ReceiveEvent(components = WorldComponent.class)
public void onNewChunk(OnChunkLoaded chunkAvailable, EntityRef worldEntity) {
Vector3ic chunkPos = chunkAvailable.getChunkPos();
Chunk chunk = chunkProvider.getChunk(chunkPos);
ByteBuffer buffer = ByteBuffer.allocateDirect(2 * (Chunks.SIZE_X * Chunks.SIZE_Y * Chunks.SIZE_Z));
buffer.order(ByteOrder.nativeOrder());
for (int z = 0; z < Chunks.SIZE_Z; z++) {
for (int x = 0; x < Chunks.SIZE_X; x++) {
for (int y = 0; y < Chunks.SIZE_Y; y++) {
Block block = chunk.getBlock(x, y, z);
colliders.forEach(k -> k.registerBlock(block));
buffer.putShort(block.getId());
}
}
}
buffer.rewind();
colliders.forEach(k -> k.loadChunk(chunk, buffer.duplicate().asShortBuffer()));
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class VoxelWorldSystem method onBlockChange.
@ReceiveEvent(components = BlockComponent.class)
public void onBlockChange(OnChangedBlock event, EntityRef entity) {
Vector3ic p = event.getBlockPosition();
colliders.forEach(k -> k.setBlock(p.x(), p.y(), p.z(), event.getNewType()));
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class RenderableWorldImpl method calculateRenderableRegion.
private BlockRegion calculateRenderableRegion(ViewDistance newViewDistance) {
Vector3i cameraCoordinates = calcCameraCoordinatesInChunkUnits();
Vector3ic renderableRegionSize = newViewDistance.getChunkDistance();
Vector3i renderableRegionExtents = new Vector3i(renderableRegionSize.x() / 2, renderableRegionSize.y() / 2, renderableRegionSize.z() / 2);
return new BlockRegion(cameraCoordinates).expand(renderableRegionExtents);
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class RenderableWorldImpl method updateChunksInProximity.
/**
* Updates the list of chunks around the player.
*
* @return True if the list was changed
*/
@Override
public boolean updateChunksInProximity(BlockRegion newRenderableRegion) {
if (!newRenderableRegion.equals(renderableRegion)) {
Chunk chunk;
for (Vector3ic chunkPositionToRemove : renderableRegion) {
if (!newRenderableRegion.contains(chunkPositionToRemove)) {
Iterator<Chunk> nearbyChunks = chunksInProximityOfCamera.iterator();
while (nearbyChunks.hasNext()) {
chunk = nearbyChunks.next();
if (chunk.getPosition().equals(chunkPositionToRemove)) {
chunk.disposeMesh();
nearbyChunks.remove();
break;
}
}
}
}
boolean chunksHaveBeenAdded = false;
for (Vector3ic chunkPositionToAdd : newRenderableRegion) {
if (!renderableRegion.contains(chunkPositionToAdd)) {
chunk = chunkProvider.getChunk(chunkPositionToAdd);
if (chunk != null) {
chunksInProximityOfCamera.add(chunk);
chunksHaveBeenAdded = true;
}
}
}
if (chunksHaveBeenAdded) {
chunksInProximityOfCamera.sort(new ChunkFrontToBackComparator());
}
renderableRegion = newRenderableRegion;
return true;
}
return false;
}
Aggregations