load near chunks first

This commit is contained in:
Paul Mathieu 2021-12-12 01:09:47 -08:00
parent 6e47e9cd0a
commit 5175232b6d

View File

@ -445,25 +445,28 @@ function updateWorldGeometry(gl, world, z, x, timeLimit = 10000) {
const start = performance.now(); const start = performance.now();
// k. Now, generate buffers for all chunks // k. Now, generate buffers for all chunks
for (let i = ic - 8; i < ic + 8; i++) { for (let radius = 0; radius < 8; radius++) {
for (let j = jc - 8; j < jc + 8; j++) { for (let i = ic - radius; i < ic + radius; i++) {
const chunk = world.chunkMap.get(i, j); for (let j = jc - radius; j < jc + radius; j++) {
const chunk = world.chunkMap.get(i, j);
if (chunk.buffer !== undefined) { if (chunk.buffer !== undefined) {
continue; continue;
} }
const chunkz = 16 * i; const chunkz = 16 * i;
const chunkx = 16 * j; const chunkx = 16 * j;
const lookup = (i, j, k) => blockLookup(world, j + chunkx, k, i + chunkz); 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 // throttle this for fluidity
if (performance.now() - start > timeLimit) { if (performance.now() - start > timeLimit) {
throw 'timesup'; throw 'timesup';
}
} }
} }
} }
} }