mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-07-01 13:29:06 +02:00
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:
parent
0ebc895ec0
commit
d2802b73f5
3 changed files with 50 additions and 19 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue