for (int y = -distanceChunksRange; y <= distanceChunksRange; y++) {
for (int z = -distanceChunksRange; z <= distanceChunksRange; z++) {
int ncx = cx + x;
int ncy = cy + y;
int ncz = cz + z;
Vector3i cpos = new Vector3i(ncx, ncy, ncz);
boolean pInRenderRange = false;
if (x >= -renderedChunksRange && x <= renderedChunksRange){
if (y >= -renderedChunksRange && y <= renderedChunksRange){
if (z >= -renderedChunksRange && z <= renderedChunksRange){
pInRenderRange = true;
inRenderRange.add(cpos);
Chunk chunk = this.chunks.getChunk(cpos);
if (!chunk.needFirstSim && !chunk.fastMode){
if (!this.renderedChunks.contains(cpos)) {
points.add(cpos);
chunk.setDirty(false);
} else {
if (resetLights || chunk.isDirty()) {
chunk.setDirty(false);
points.add(cpos);
}
}
}
if (points.size() > 10) {
this.renderer.loadChunks(points);
this.renderedChunks.addAll(points);
points = new ArrayList<Vector3i>();
}
if (x >= -simulatedChunksRange && x <= simulatedChunksRange){
if (y >= -simulatedChunksRange && y <= simulatedChunksRange){
if (z >= -simulatedChunksRange && z <= simulatedChunksRange){
inSimRange.add(cpos);
this.simulatedChunks.add(cpos);
}
}
}
}
}
if (!pInRenderRange){
inDistRange.add(cpos);
}
}
}
}
}
this.renderer.loadChunks(points);
this.renderedChunks.addAll(points);
lastLightLevel = lightLevel;
HashMap<Vector3i, GLChunk> glChunkTable = this.renderer.getGLChunkTable();
for (Vector3i p : new HashSet<Vector3i>(glChunkTable.keySet())) {
if (!inRenderRange.contains(p)) {
this.renderer.unloadGLChunk(p);
}
}
Iterator<Vector3i> iter = this.renderedChunks.iterator();
ArrayList<Vector3i> toRemove = new ArrayList<Vector3i>();
while (iter.hasNext()) {
Vector3i position = iter.next();
if (!inRenderRange.contains(position) && !points.contains(position)) {
toRemove.add(position);
}
}
this.renderedChunks.removeAll(toRemove);
iter = this.simulatedChunks.iterator();
toRemove = new ArrayList<Vector3i>();
while (iter.hasNext()) {
Vector3i position = iter.next();
if (!inSimRange.contains(position)) {
toRemove.add(position);
}
}
this.simulatedChunks.removeAll(toRemove);
iter = this.distanceChunks.iterator();
toRemove = new ArrayList<Vector3i>();
while (iter.hasNext()) {
Vector3i position = iter.next();
if (!inDistRange.contains(position)) {
toRemove.add(position);
}
}
this.distanceChunks.removeAll(toRemove);