Info: make tile existence map mor efficient for sparse worlds

Explicitly list the coordinates where tiles exist instead of including a
full array with the size of the bounding box.
This commit is contained in:
Matthias Schiffer 2021-02-12 23:40:24 +01:00
parent 0ebc895ec0
commit d2802b73f5
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
3 changed files with 50 additions and 19 deletions

View file

@ -1,3 +1,22 @@
// bsearch-based array element check
function contains(array, elem) {
var min = 0, max = array.length, i, cur;
while (min < max) {
i = min + Math.floor((max-min)/2);
cur = array[i];
if (cur === elem)
return true;
else if (cur < elem)
min = i + 1;
else
max = i;
}
return false;
}
var MinedMapLayer = L.GridLayer.extend({
initialize: function (mipmaps, layer) {
this.mipmaps = mipmaps;
@ -43,7 +62,7 @@ var MinedMapLayer = L.GridLayer.extend({
if (coords.x >= mipmap.info.minX && coords.x <= mipmap.info.maxX &&
coords.y >= mipmap.info.minZ && coords.y <= mipmap.info.maxZ &&
mipmap.regions[coords.y-mipmap.info.minZ][coords.x-mipmap.info.minX])
contains(mipmap.regions[coords.y] || [], coords.x))
tile.src = 'data/'+this.layer+'/'+z+'/r.'+coords.x+'.'+coords.y+'.png';
if (z === 0)