better tile distance + comments

This commit is contained in:
Hannes Janetzek 2013-02-10 12:15:18 +01:00
parent bdbdbb5905
commit 429b8a98d7

View File

@ -415,26 +415,43 @@ public class TileManager {
continue;
int diff = (t.zoomLevel - zoom);
double dx, dy, dz;
double dx, dy, dz, scale;
dz = 0;
if (diff == 0) {
dx = (t.pixelX + h) - x;
dy = (t.pixelY + h) - y;
dz = 0.5f;
scale = 0.5f;
} else if (diff > 0) {
// tile zoom level is greater than current
// NB: distance increase by the factor 2
// with each zoom-level, so that children
// will be kept less likely than parent tiles.
dx = (t.pixelX + h) - x * (1 << diff);
dy = (t.pixelY + h) - y * (1 << diff);
dz = 0.25f * (1 << (diff - 1));
// add tilesize/2 with each zoom-level
// so that children near the current
// map position but a few levels above
// will also be removed
dz = diff * h;
scale = 0.25f * (1 << diff);
} else {
diff = -diff;
// tile zoom level is smaller than current
dx = (t.pixelX + h) - x / (1 << -diff);
dy = (t.pixelY + h) - y / (1 << -diff);
dz = 0.5f * (1 << -diff);
dx = (t.pixelX + h) - x / (1 << diff);
dy = (t.pixelY + h) - y / (1 << diff);
dz = diff * h;
scale = 0.5f * (1 << diff);
}
if (dx < 0)
dx = -dx;
if (dy < 0)
dy = -dy;
dx %= center;
dy %= center;
t.distance = (float) ((dx * dx + dy * dy) * dz);
t.distance = (float) ((dx + dy + dz) * scale);
}
}
@ -483,7 +500,7 @@ public class TileManager {
Log.d(TAG, "limitCache: tile still locked " + t + " " + t.distance);
// try again in next run.
//locked = true;
break;
//break;
} else if (t.state == STATE_LOADING) {
// NOTE: when set loading to false the tile could be
// added to load queue again while still processed in