diff --git a/index.js b/index.js index e5c6aeb..8d9e78d 100644 --- a/index.js +++ b/index.js @@ -445,25 +445,28 @@ function updateWorldGeometry(gl, world, z, x, timeLimit = 10000) { const start = performance.now(); // k. Now, generate buffers for all chunks - for (let i = ic - 8; i < ic + 8; i++) { - for (let j = jc - 8; j < jc + 8; j++) { - const chunk = world.chunkMap.get(i, j); + for (let radius = 0; radius < 8; radius++) { + for (let i = ic - radius; i < ic + radius; i++) { + for (let j = jc - radius; j < jc + radius; j++) { + const chunk = world.chunkMap.get(i, j); - if (chunk.buffer !== undefined) { - continue; - } + if (chunk.buffer !== undefined) { + continue; + } - const chunkz = 16 * i; - const chunkx = 16 * j; - const lookup = (i, j, k) => blockLookup(world, j + chunkx, k, i + chunkz); + const chunkz = 16 * i; + const chunkx = 16 * j; + const lookup = (i, j, k) => blockLookup(world, j + chunkx, k, i + chunkz); - chunk.buffer = makeChunkBuffer(gl, chunk.data, chunk.position.z, chunk.position.x, lookup); + chunk.buffer = makeChunkBuffer(gl, chunk.data, chunk.position.z, chunk.position.x, lookup); - // throttle this for fluidity - if (performance.now() - start > timeLimit) { - throw 'timesup'; + // throttle this for fluidity + if (performance.now() - start > timeLimit) { + throw 'timesup'; + } } } + } }