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();
// 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';
}
}
}
}
}