use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class RenderableWorldImpl method pregenerateChunks.
/**
* @return true if pregeneration is complete
*/
@Override
public boolean pregenerateChunks() {
boolean pregenerationIsComplete = true;
chunkProvider.completeUpdate();
chunkProvider.beginUpdate();
RenderableChunk chunk;
ChunkMesh newMesh;
ChunkView localView;
for (Vector3i chunkCoordinates : calculateRenderableRegion(renderingConfig.getViewDistance())) {
chunk = chunkProvider.getChunk(chunkCoordinates);
if (chunk == null) {
pregenerationIsComplete = false;
} else if (chunk.isDirty()) {
localView = worldProvider.getLocalView(chunkCoordinates);
if (localView == null) {
continue;
}
chunk.setDirty(false);
newMesh = chunkTessellator.generateMesh(localView, ChunkConstants.SIZE_Y, 0);
newMesh.generateVBOs();
if (chunk.hasMesh()) {
chunk.getMesh().dispose();
}
chunk.setMesh(newMesh);
pregenerationIsComplete = false;
break;
}
}
return pregenerationIsComplete;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class RenderableWorldImpl method calculateRenderableRegion.
private Region3i calculateRenderableRegion(ViewDistance newViewDistance) {
Vector3i cameraCoordinates = calcCameraCoordinatesInChunkUnits();
Vector3i renderableRegionSize = newViewDistance.getChunkDistance();
Vector3i renderableRegionExtents = new Vector3i(renderableRegionSize.x / 2, renderableRegionSize.y / 2, renderableRegionSize.z / 2);
return Region3i.createFromCenterExtents(cameraCoordinates, renderableRegionExtents);
}
use of org.terasology.math.geom.Vector3i 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. Bz iterating we can make sure that all entires removed
* from unloadedAndUnsavedChunkMap get added to unloadedAndSavingChunkMap.
*/
Iterator<Map.Entry<Vector3i, CompressedChunkBuilder>> unsavedEntryIterator = unloadedAndUnsavedChunkMap.entrySet().iterator();
while (unsavedEntryIterator.hasNext()) {
Map.Entry<Vector3i, CompressedChunkBuilder> entry = unsavedEntryIterator.next();
unloadedAndSavingChunkMap.put(entry.getKey(), entry.getValue());
unsavedEntryIterator.remove();
}
chunkProvider.getAllChunks().stream().filter(ManagedChunk::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());
// this storage manager can only work with ChunkImpls
ChunkImpl chunkImpl = (ChunkImpl) chunk;
saveTransactionBuilder.addLoadedChunk(chunk.getPosition(), chunkImpl);
});
for (Map.Entry<Vector3i, CompressedChunkBuilder> entry : unloadedAndSavingChunkMap.entrySet()) {
saveTransactionBuilder.addUnloadedChunk(entry.getKey(), entry.getValue());
}
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class SaveTransaction method createChunkPosToUnsavedOwnerLessEntitiesMap.
private Map<Vector3i, Collection<EntityRef>> createChunkPosToUnsavedOwnerLessEntitiesMap() {
Map<Vector3i, Collection<EntityRef>> chunkPosToEntitiesMap = Maps.newHashMap();
for (EntityRef entity : privateEntityManager.getEntitiesWith(LocationComponent.class)) {
/*
* Note: Entities with owners get saved with the owner. Entities that are always relevant don't get stored
* in chunk as the chunk is not always loaded
*/
if (entity.isPersistent() && !entity.getOwner().exists() && !entity.hasComponent(ClientComponent.class) && !entity.isAlwaysRelevant()) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (locationComponent != null) {
Vector3f loc = locationComponent.getWorldPosition();
Vector3i chunkPos = ChunkMath.calcChunkPos((int) loc.x, (int) loc.y, (int) loc.z);
Collection<EntityRef> collection = chunkPosToEntitiesMap.get(chunkPos);
if (collection == null) {
collection = Lists.newArrayList();
chunkPosToEntitiesMap.put(chunkPos, collection);
}
collection.add(entity);
}
}
}
return chunkPosToEntitiesMap;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class StoragePathProvider method getChunkZipPosition.
public Vector3i getChunkZipPosition(Vector3i chunkPos) {
Vector3i result = new Vector3i(chunkPos);
result.div(CHUNK_ZIP_DIM);
if (chunkPos.x < 0) {
result.x -= 1;
}
if (chunkPos.y < 0) {
result.y -= 1;
}
if (chunkPos.z < 0) {
result.z -= 1;
}
return result;
}
Aggregations