fix regression, make sure not to upload a tile that will be cleared

This commit is contained in:
Hannes Janetzek 2012-08-28 10:10:30 +02:00
parent 14fe4a6892
commit ba90664ee2
2 changed files with 36 additions and 40 deletions

View File

@ -538,9 +538,6 @@ public class MapGenerator implements IMapGenerator, IRenderCallback, IMapDatabas
mCurPolyLayer = null; mCurPolyLayer = null;
mCurLineLayer = null; mCurLineLayer = null;
tile.newData = true;
tile.isLoading = false;
return true; return true;
} }

View File

@ -208,7 +208,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
if (diff == 0) { if (diff == 0) {
dx = (t.pixelX + h) - x; dx = (t.pixelX + h) - x;
dy = (t.pixelY + h) - y; dy = (t.pixelY + h) - y;
t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)) * 0.5f; t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)) * 0.25f;
// t.distance = FloatMath.sqrt((dx * dx + dy * dy)) * 0.25f; // t.distance = FloatMath.sqrt((dx * dx + dy * dy)) * 0.25f;
} else if (diff > 0) { } else if (diff > 0) {
// tile zoom level is child of current // tile zoom level is child of current
@ -225,7 +225,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
dy = ((t.pixelY + h) << -diff) - y; dy = ((t.pixelY + h) << -diff) - y;
t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)) t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy))
* (-diff * 0.25f); * (-diff * 0.5f);
// t.distance = FloatMath.sqrt((dx * dx + dy * dy)) * (-diff * 0.5f); // t.distance = FloatMath.sqrt((dx * dx + dy * dy)) * (-diff * 0.5f);
} }
@ -493,11 +493,10 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
mUpdateTiles = true; mUpdateTiles = true;
} }
int active = 0;
// see FIXME in passTile // see FIXME in passTile
synchronized (mTiles) { // synchronized (mTiles) {
active = updateTileDistances(); updateTileDistances();
} // }
if (mJobList.size() > 0) if (mJobList.size() > 0)
mMapView.addJobs(mJobList); mMapView.addJobs(mJobList);
@ -505,9 +504,8 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
int removes = mTiles.size() - CACHE_TILES; int removes = mTiles.size() - CACHE_TILES;
if (removes > 20) { if (removes > 20) {
// Log.d(TAG, "---- remove " + removes + " on " + zoomLevel + " active:"
Log.d(TAG, "---- remove " + removes + " on " + zoomLevel + " active:" // + active + "------");
+ active + "------");
Collections.sort(mTileList, mTileDistanceSort); Collections.sort(mTileList, mTileDistanceSort);
limitCache(removes); limitCache(removes);
} }
@ -611,8 +609,8 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
mTileY = tileY; mTileY = tileY;
mLastZoom = zoomLevel; mLastZoom = zoomLevel;
if (zdir > 0) // if (zdir > 0)
Log.d(TAG, "prefetch parent"); // Log.d(TAG, "prefetch parent");
if (changedZoom) { if (changedZoom) {
// need to update visible list first when zoom level changes // need to update visible list first when zoom level changes
@ -651,9 +649,6 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
return true; return true;
} }
if (!timing && tile.isVisible)
mMapView.requestRender();
int size = mTilesLoaded.size(); int size = mTilesLoaded.size();
if (size > MAX_TILES_IN_QUEUE) { if (size > MAX_TILES_IN_QUEUE) {
// remove uploaded tiles // remove uploaded tiles
@ -670,21 +665,19 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
if (size > MAX_TILES_IN_QUEUE) { if (size > MAX_TILES_IN_QUEUE) {
// FIXME pass tile via queue back to mainloop instead... // FIXME pass tile via queue back to mainloop instead...
synchronized (mTiles) { // synchronized (mTiles) {
Collections.sort(mTilesLoaded, mTileDistanceSort); // Collections.sort(mTilesLoaded, mTileDistanceSort);
} // }
// clear loaded but not used tiles // clear loaded but not used tiles
while (size-- > MAX_TILES_IN_QUEUE) { while (size-- > MAX_TILES_IN_QUEUE) {
GLMapTile t = mTilesLoaded.get(size); GLMapTile t = mTilesLoaded.get(size);
// FIXME race condition: tile could be uploaded as proxy // FIXME race condition: tile could be uploaded as proxy
// therefore sync with upload tile data // therefore sync with upload tile data
synchronized (t) { // synchronized (t) {
// dont remove tile if currently used or is direct parent // dont remove tile if currently used or is direct parent
// or child of currently active tile // or child of currently active tile
if (t.isActive || childIsActive(t)) if (t.isActive || childIsActive(t) ||
// (t.parent != null && t.parent.isActive)) (tile.parent != null && tile.parent.isActive)) {
{
// Log.d(TAG, "keep unused tile data: " + t + " " + t.isActive); // Log.d(TAG, "keep unused tile data: " + t + " " + t.isActive);
continue; continue;
} }
@ -692,12 +685,18 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
// Log.d(TAG, "remove unused tile data: " + t); // Log.d(TAG, "remove unused tile data: " + t);
clearTile(t); clearTile(t);
// TODO could also remove from mTileHash/List ? // TODO could also remove from mTileHash/List ?
// }
} }
} }
} }
} tile.newData = true;
tile.isLoading = false;
mTilesLoaded.add(0, tile); mTilesLoaded.add(0, tile);
if (!timing)
mMapView.requestRender();
return true; return true;
} }
@ -767,13 +766,13 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
} }
} }
synchronized (tile) { // synchronized (tile) {
if (!tile.newData) if (!tile.newData)
return false; return false;
tile.isReady = true; tile.isReady = true;
tile.newData = false; tile.newData = false;
} // }
int lineSize = LineLayers.sizeOf(tile.lineLayers); int lineSize = LineLayers.sizeOf(tile.lineLayers);
int polySize = PolygonLayers.sizeOf(tile.polygonLayers); int polySize = PolygonLayers.sizeOf(tile.polygonLayers);