API: add TileSet.{lockTiles,releaseTiles,setTiles}
This commit is contained in:
parent
e5761ef601
commit
f6bb944907
@ -664,7 +664,7 @@ class TextRenderer extends ElementRenderer {
|
||||
/* private */void cleanup() {
|
||||
mPool.releaseAll(mLabels);
|
||||
mLabels = null;
|
||||
mTileSet.clear();
|
||||
mTileSet.releaseTiles();
|
||||
mLabelTask = null;
|
||||
}
|
||||
|
||||
|
||||
@ -33,10 +33,6 @@ import org.oscim.utils.ScanBox;
|
||||
import org.oscim.utils.quadtree.QuadTree;
|
||||
import org.oscim.utils.quadtree.QuadTreeIndex;
|
||||
|
||||
/**
|
||||
* @TODO - prefetching to cache file - this class should probably not be in
|
||||
* 'renderer' -> tilemap? - make it general for reuse in tile-overlays
|
||||
*/
|
||||
public class TileManager {
|
||||
static final String TAG = TileManager.class.getName();
|
||||
|
||||
@ -110,6 +106,7 @@ public class TileManager {
|
||||
};
|
||||
|
||||
private final float[] mMapPlane = new float[8];
|
||||
|
||||
//private final TileLayer<?> mTileLayer;
|
||||
|
||||
public TileManager(Map map, int minZoom, int maxZoom, int cacheLimit) {
|
||||
@ -182,7 +179,7 @@ public class TileManager {
|
||||
/**
|
||||
* 1. Update mCurrentTiles TileSet of currently visible tiles. 2. Add not
|
||||
* yet loaded (or loading) tiles to JobQueue. 3. Manage cache
|
||||
*
|
||||
*
|
||||
* @param pos
|
||||
* current MapPosition
|
||||
*/
|
||||
@ -242,14 +239,10 @@ public class TileManager {
|
||||
if (changed) {
|
||||
synchronized (mTilelock) {
|
||||
// lock new tiles
|
||||
for (int i = 0; i < newCnt; i++)
|
||||
newTiles[i].lock();
|
||||
mNewTiles.lockTiles();
|
||||
|
||||
// unlock previous tiles
|
||||
for (int i = 0; i < curCnt; i++) {
|
||||
curTiles[i].unlock();
|
||||
curTiles[i] = null;
|
||||
}
|
||||
mCurrentTiles.releaseTiles();
|
||||
|
||||
// make new tiles current
|
||||
TileSet tmp = mCurrentTiles;
|
||||
@ -258,7 +251,7 @@ public class TileManager {
|
||||
|
||||
mUpdateSerial++;
|
||||
}
|
||||
//Log.d(TAG, newCnt + " << " + Arrays.deepToString(mCurrentTiles.tiles));
|
||||
|
||||
// request rendering as tiles changed
|
||||
mMap.render();
|
||||
}
|
||||
@ -272,9 +265,7 @@ public class TileManager {
|
||||
updateTileDistances(jobs, jobs.length, pos);
|
||||
|
||||
// sets tiles to state == LOADING
|
||||
|
||||
jobQueue.setJobs(jobs);
|
||||
//mTileLayer.notifyLoaders();
|
||||
|
||||
mJobs.clear();
|
||||
|
||||
@ -298,7 +289,7 @@ public class TileManager {
|
||||
* Retrive a TileSet of current tiles. Tiles remain locked in cache until
|
||||
* the set is unlocked by either passing it again to this function or to
|
||||
* releaseTiles. If passed TileSet is null it will be allocated.
|
||||
*
|
||||
*
|
||||
* @param tileSet
|
||||
* to be updated
|
||||
* @return true if TileSet has changed
|
||||
@ -313,44 +304,22 @@ public class TileManager {
|
||||
if (tileSet.serial == mUpdateSerial)
|
||||
return false;
|
||||
|
||||
// dont flip new/currentTiles while copying
|
||||
// dont flip mNew/mCurrentTiles while copying
|
||||
synchronized (mTilelock) {
|
||||
MapTile[] newTiles = mCurrentTiles.tiles;
|
||||
int cnt = mCurrentTiles.cnt;
|
||||
|
||||
// lock tiles (and their proxies) to not be removed from cache
|
||||
for (int i = 0; i < cnt; i++)
|
||||
newTiles[i].lock();
|
||||
|
||||
MapTile[] nextTiles;
|
||||
nextTiles = tileSet.tiles;
|
||||
|
||||
// unlock previously active tiles
|
||||
for (int i = 0, n = tileSet.cnt; i < n; i++)
|
||||
nextTiles[i].unlock();
|
||||
|
||||
if (nextTiles.length != mCurrentTiles.tiles.length) {
|
||||
tileSet.tiles = nextTiles = new MapTile[mCurrentTiles.tiles.length];
|
||||
}
|
||||
|
||||
// copy newTiles to nextTiles
|
||||
System.arraycopy(newTiles, 0, nextTiles, 0, cnt);
|
||||
|
||||
tileSet.setTiles(mCurrentTiles);
|
||||
tileSet.serial = mUpdateSerial;
|
||||
tileSet.cnt = cnt;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tiles ...
|
||||
* Unlock tiles and clear all item references.
|
||||
*
|
||||
* @param tiles
|
||||
*/
|
||||
public void releaseTiles(TileSet tileSet) {
|
||||
// unlock previously active tiles
|
||||
for (int i = 0, n = tileSet.cnt; i < n; i++)
|
||||
tileSet.tiles[i].unlock();
|
||||
tileSet.cnt = 0;
|
||||
tileSet.releaseTiles();
|
||||
}
|
||||
|
||||
/* package */MapTile addTile(int x, int y, int zoomLevel) {
|
||||
@ -385,22 +354,6 @@ public class TileManager {
|
||||
p.state = STATE_LOADING;
|
||||
mJobs.add(p);
|
||||
}
|
||||
|
||||
// if (zoomLevel > 3) {
|
||||
// // prefetch grand parent
|
||||
// p = tile.rel.parent.parent.item;
|
||||
// add = false;
|
||||
// if (p == null) {
|
||||
// p = mIndex.create(x >> 2, y >> 2, zoomLevel - 2);
|
||||
// addToCache(p);
|
||||
// add = true;
|
||||
// }
|
||||
//
|
||||
// if (add || !p.isActive()) {
|
||||
// p.state = STATE_LOADING;
|
||||
// mJobs.add(p);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return tile;
|
||||
@ -570,7 +523,7 @@ public class TileManager {
|
||||
|
||||
/**
|
||||
* called from MapWorker Thread when tile is loaded by MapTileLoader
|
||||
*
|
||||
*
|
||||
* @param tile
|
||||
* Tile ready for upload in TileRenderLayer
|
||||
* @return caller does not care
|
||||
|
||||
@ -221,10 +221,6 @@ public class TileRenderer extends LayerRenderer {
|
||||
return false;
|
||||
}
|
||||
|
||||
// same tiles as before
|
||||
// if (tileSet.serial == mDrawTiles.serial)
|
||||
// return false;
|
||||
|
||||
int prevSerial = tileSet.serial;
|
||||
|
||||
// ensure tiles keep visible state
|
||||
@ -234,9 +230,8 @@ public class TileRenderer extends LayerRenderer {
|
||||
int cnt = mDrawTiles.cnt;
|
||||
|
||||
// unlock previous tiles
|
||||
for (int i = 0; i < tileSet.cnt; i++)
|
||||
tileSet.tiles[i].unlock();
|
||||
|
||||
tileSet.releaseTiles();
|
||||
|
||||
// ensure same size
|
||||
if (tileSet.tiles.length != mDrawTiles.tiles.length) {
|
||||
tileSet.tiles = new MapTile[mDrawTiles.tiles.length];
|
||||
@ -251,18 +246,15 @@ public class TileRenderer extends LayerRenderer {
|
||||
tileSet.tiles[tileSet.cnt++] = t;
|
||||
}
|
||||
}
|
||||
|
||||
tileSet.serial = mUploadSerial;
|
||||
}
|
||||
|
||||
return prevSerial != tileSet.serial;
|
||||
}
|
||||
|
||||
public void releaseTiles(TileSet td) {
|
||||
for (int i = 0; i < td.cnt; i++) {
|
||||
td.tiles[i].unlock();
|
||||
td.tiles[i] = null;
|
||||
}
|
||||
td.cnt = 0;
|
||||
public void releaseTiles(TileSet tileSet) {
|
||||
tileSet.releaseTiles();
|
||||
}
|
||||
|
||||
// Add additional tiles that serve as placeholer when flipping
|
||||
|
||||
@ -18,20 +18,17 @@ import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* use with TileManager.getActiveTiles(TileSet) to get the current tiles. tiles
|
||||
* are locked to not be modifed until getActiveTiles passes them back on a
|
||||
* second invocation or TODO: implement TileManager.releaseTiles(TileSet).
|
||||
* TileSet for use with TileManager.getActiveTiles(TileSet) to get the current
|
||||
* tiles. Tiles will locked and not be modifed until getActiveTiles passes them
|
||||
* back to TileManager on a second invocation or TileManager.releaseTiles().
|
||||
*/
|
||||
public final class TileSet {
|
||||
public int cnt = 0;
|
||||
public MapTile[] tiles;
|
||||
|
||||
/** update counter will be set by getActiveTiles when TileSet has changed */
|
||||
int serial;
|
||||
|
||||
public int getSerial() {
|
||||
return serial;
|
||||
}
|
||||
|
||||
public TileSet() {
|
||||
tiles = new MapTile[1];
|
||||
}
|
||||
@ -48,11 +45,46 @@ public final class TileSet {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
/**
|
||||
* Locked tiles to ensure that they are not released from cache.
|
||||
* Call releaseTiles() when tiles are not needed any longer.
|
||||
*/
|
||||
public void lockTiles() {
|
||||
for (int i = 0; i < cnt; i++)
|
||||
tiles[i].lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Release locked tiles.
|
||||
*/
|
||||
public void releaseTiles() {
|
||||
for (int i = 0; i < cnt; i++)
|
||||
tiles[i].unlock();
|
||||
|
||||
Arrays.fill(tiles, null);
|
||||
cnt = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone TileSet from source. Release previous tiles and lock
|
||||
* new tiles.
|
||||
*/
|
||||
public void setTiles(TileSet source) {
|
||||
//lock tiles (and their proxies) to not be removed from cache
|
||||
source.lockTiles();
|
||||
|
||||
// unlock previous tiles
|
||||
releaseTiles();
|
||||
|
||||
if (source.tiles.length != tiles.length) {
|
||||
tiles = new MapTile[source.tiles.length];
|
||||
}
|
||||
|
||||
System.arraycopy(source.tiles, 0, tiles, 0, source.cnt);
|
||||
|
||||
cnt = source.cnt;
|
||||
}
|
||||
|
||||
public static Comparator<MapTile> coordComparator = new CoordComparator();
|
||||
|
||||
public static class CoordComparator implements Comparator<MapTile> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user