add function to get visible tiles only

This commit is contained in:
Hannes Janetzek 2013-02-04 01:02:54 +01:00
parent f3f1c4ae54
commit 0d87aabd3d

View File

@ -320,6 +320,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
} }
} }
private static Object tilelock = new Object();
static void draw() { static void draw() {
long start = 0; long start = 0;
@ -372,6 +374,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
MapTile[] tiles = mDrawTiles.tiles; MapTile[] tiles = mDrawTiles.tiles;
if (changed) { if (changed) {
synchronized (GLRenderer.tilelock) {
// get visible tiles // get visible tiles
for (int i = 0; i < tileCnt; i++) for (int i = 0; i < tileCnt; i++)
tiles[i].isVisible = false; tiles[i].isVisible = false;
@ -380,7 +384,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
// zoom-level changed. // zoom-level changed.
byte z = tiles[0].zoomLevel; byte z = tiles[0].zoomLevel;
float div = FastMath.pow(z - pos.zoomLevel); float div = FastMath.pow(z - pos.zoomLevel);
if (div != 1)
Log.d(TAG, "tiles not from current zoom level");
// transform screen coordinates to tile coordinates // transform screen coordinates to tile coordinates
float scale = pos.scale / div; float scale = pos.scale / div;
float px = (float) pos.x * div; float px = (float) pos.x * div;
@ -394,6 +399,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
mHolderCount = 0; mHolderCount = 0;
mScanBox.scan(coords, z); mScanBox.scan(coords, z);
} }
}
tileCnt += mHolderCount; tileCnt += mHolderCount;
@ -506,6 +512,40 @@ public class GLRenderer implements GLSurfaceView.Renderer {
return ((t.tileX % 4) + (t.tileY % 4 * 4) + 1); return ((t.tileX % 4) + (t.tileY % 4 * 4) + 1);
} }
public static TileSet getVisibleTiles(TileSet td) {
if (mDrawTiles == null)
return td;
MapTile[] newTiles = mDrawTiles.tiles;
int cnt = mDrawTiles.cnt;
MapTile[] nextTiles;
synchronized (TileManager.tilelock) {
// lock tiles (and their proxies) to not be removed from cache
for (int i = 0; i < cnt; i++)
if (newTiles[i].isVisible)
newTiles[i].lock();
if (td == null)
td = new TileSet(newTiles.length);
nextTiles = td.tiles;
// unlock previously active tiles
for (int i = 0, n = td.cnt; i < n; i++)
nextTiles[i].unlock();
}
synchronized (GLRenderer.tilelock) {
// copy newTiles to nextTiles
td.cnt = 0;
for (int i = 0; i < cnt; i++)
if (newTiles[i].isVisible)
nextTiles[td.cnt++] = newTiles[i];
}
return td;
}
@Override @Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) { public void onSurfaceChanged(GL10 glUnused, int width, int height) {
Log.d(TAG, "SurfaceChanged:" + mNewSurface + " " + width + " " + height); Log.d(TAG, "SurfaceChanged:" + mNewSurface + " " + width + " " + height);