make gc care better about other zoomlevles of the same area

closes #43
This commit is contained in:
HF 2023-03-13 01:06:15 +01:00
parent a7e6a49a79
commit f668c025f2
2 changed files with 20 additions and 9 deletions

View File

@ -123,8 +123,8 @@ class ChunkLoader {
}
});
this.bcRemoveChunks(remChunks);
// eslint-disable-next-line no-console
console.log(`GC cleaned ${remChunks.length} chunks.`);
// eslint-disable-next-line no-console,max-len
console.log(`GC cleaned ${remChunks.length} / ${chunks.size + remChunks.length} chunks`);
}
}

View File

@ -272,20 +272,31 @@ class Renderer2D extends Renderer {
cx,
cy,
) {
if (cz !== this.tiledZoom) {
const { tiledZoom } = this;
if (cz > tiledZoom + 1) {
return false;
}
let [xc, yc] = this.centerChunk;
let { relScale } = this;
// adjust for tiledZoom differences
if (cz !== tiledZoom) {
const zFac = TILE_ZOOM_LEVEL ** (cz - tiledZoom);
xc = Math.floor(xc * zFac);
yc = Math.floor(yc * zFac);
relScale *= zFac;
}
const { width, height } = this.viewport;
const CHUNK_RENDER_RADIUS_X = Math.ceil(
width / TILE_SIZE / 2 / this.relScale,
width / TILE_SIZE / 2 / relScale,
);
const CHUNK_RENDER_RADIUS_Y = Math.ceil(
height / TILE_SIZE / 2 / this.relScale,
height / TILE_SIZE / 2 / relScale,
);
const [xc, yc] = this.centerChunk;
if (Math.abs(cx - xc)
<= CHUNK_RENDER_RADIUS_X && Math.abs(cy - yc)
<= CHUNK_RENDER_RADIUS_Y
if (Math.abs(cx - xc) <= CHUNK_RENDER_RADIUS_X
&& Math.abs(cy - yc) <= CHUNK_RENDER_RADIUS_Y
) {
return true;
}