make TileManager non static
This commit is contained in:
parent
45122270b1
commit
db93fbe4f6
@ -46,43 +46,39 @@ public class TileManager {
|
|||||||
private static final int MAX_TILES_IN_QUEUE = 40;
|
private static final int MAX_TILES_IN_QUEUE = 40;
|
||||||
private static final int CACHE_THRESHOLD = 30;
|
private static final int CACHE_THRESHOLD = 30;
|
||||||
|
|
||||||
private static MapView mMapView;
|
private final MapView mMapView;
|
||||||
|
|
||||||
private static final MapPosition mMapPosition = new MapPosition();
|
private final MapPosition mMapPosition = new MapPosition();
|
||||||
private final MapViewPosition mMapViewPosition;
|
private final MapViewPosition mMapViewPosition;
|
||||||
|
|
||||||
// all tiles
|
// all tiles
|
||||||
private static MapTile[] mTiles;
|
private MapTile[] mTiles;
|
||||||
// actual number of tiles in mTiles
|
// actual number of tiles in mTiles
|
||||||
private static int mTilesCount;
|
private int mTilesCount;
|
||||||
// current end position in mTiles
|
// current end position in mTiles
|
||||||
private static int mTilesSize;
|
private int mTilesSize;
|
||||||
// first free slot in mTiles
|
// first free slot in mTiles
|
||||||
//private static int mTilesFirst;
|
//private static int mTilesFirst;
|
||||||
|
|
||||||
// new jobs for MapWorkers
|
// new jobs for MapWorkers
|
||||||
private static ArrayList<JobTile> mJobs;
|
private ArrayList<JobTile> mJobs;
|
||||||
|
|
||||||
// tiles that have new data to upload, see passTile()
|
// tiles that have new data to upload, see passTile()
|
||||||
private static ArrayList<MapTile> mTilesLoaded;
|
private ArrayList<MapTile> mTilesLoaded;
|
||||||
|
|
||||||
private static boolean mInitialized;
|
private boolean mInitialized;
|
||||||
|
|
||||||
// private static MapPosition mCurPosition, mDrawPosition;
|
// private static MapPosition mCurPosition, mDrawPosition;
|
||||||
private static int mWidth = 0, mHeight = 0;
|
private int mWidth = 0, mHeight = 0;
|
||||||
|
|
||||||
// maps zoom-level to available zoom-levels in MapDatabase
|
private float[] mTileCoords = new float[8];
|
||||||
// e.g. 16->16, 15->16, 14->13, 13->13, 12->13,....
|
|
||||||
// private static int[] mZoomLevels;
|
|
||||||
|
|
||||||
private static float[] mTileCoords = new float[8];
|
private static int mUpdateCnt;
|
||||||
|
private static Object tilelock = new Object();
|
||||||
static int mUpdateCnt;
|
private static TileSet mCurrentTiles;
|
||||||
static Object tilelock = new Object();
|
|
||||||
static TileSet mCurrentTiles;
|
|
||||||
/* package */static TileSet mNewTiles;
|
/* package */static TileSet mNewTiles;
|
||||||
|
|
||||||
private static ScanBox mScanBox = new ScanBox() {
|
private final ScanBox mScanBox = new ScanBox() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void setVisible(int y, int x1, int x2) {
|
void setVisible(int y, int x1, int x2) {
|
||||||
@ -129,27 +125,13 @@ public class TileManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static volatile TileManager SINGLETON;
|
|
||||||
|
|
||||||
public static TileManager create(MapView mapView) {
|
|
||||||
if (SINGLETON != null)
|
|
||||||
throw new IllegalStateException();
|
|
||||||
|
|
||||||
return SINGLETON = new TileManager(mapView);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
SINGLETON = null;
|
|
||||||
// there might be some leaks in here
|
// there might be some leaks in here
|
||||||
// mRenderer = null;
|
// mRenderer = null;
|
||||||
// mTiles = null;
|
|
||||||
// mTilesLoaded = null;
|
|
||||||
// mJobs = null;
|
|
||||||
// mOverlays = null;
|
|
||||||
// ... free pools
|
// ... free pools
|
||||||
}
|
}
|
||||||
|
|
||||||
private TileManager(MapView mapView) {
|
public TileManager(MapView mapView) {
|
||||||
Log.d(TAG, "init TileManager");
|
Log.d(TAG, "init TileManager");
|
||||||
mMapView = mapView;
|
mMapView = mapView;
|
||||||
mMapViewPosition = mapView.getMapViewPosition();
|
mMapViewPosition = mapView.getMapViewPosition();
|
||||||
@ -269,7 +251,7 @@ public class TileManager {
|
|||||||
return td;
|
return td;
|
||||||
|
|
||||||
// dont flip new/currentTiles while copying
|
// dont flip new/currentTiles while copying
|
||||||
synchronized (TileManager.tilelock) {
|
synchronized (tilelock) {
|
||||||
MapTile[] newTiles = mCurrentTiles.tiles;
|
MapTile[] newTiles = mCurrentTiles.tiles;
|
||||||
int cnt = mCurrentTiles.cnt;
|
int cnt = mCurrentTiles.cnt;
|
||||||
|
|
||||||
@ -313,7 +295,7 @@ public class TileManager {
|
|||||||
* zoom direction
|
* zoom direction
|
||||||
* @return true if new tiles were loaded
|
* @return true if new tiles were loaded
|
||||||
*/
|
*/
|
||||||
private static boolean updateVisibleList(MapPosition mapPosition, int zdir) {
|
private boolean updateVisibleList(MapPosition mapPosition, int zdir) {
|
||||||
// clear JobQueue and set tiles to state == NONE.
|
// clear JobQueue and set tiles to state == NONE.
|
||||||
// one could also append new tiles and sort in JobQueue
|
// one could also append new tiles and sort in JobQueue
|
||||||
// but this has the nice side-effect that MapWorkers dont
|
// but this has the nice side-effect that MapWorkers dont
|
||||||
@ -342,7 +324,7 @@ public class TileManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
synchronized (TileManager.tilelock) {
|
synchronized (tilelock) {
|
||||||
for (int i = 0, n = mNewTiles.cnt; i < n; i++)
|
for (int i = 0, n = mNewTiles.cnt; i < n; i++)
|
||||||
newTiles[i].lock();
|
newTiles[i].lock();
|
||||||
|
|
||||||
@ -386,7 +368,7 @@ public class TileManager {
|
|||||||
* @return ...
|
* @return ...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* package */static MapTile addTile(int x, int y, byte zoomLevel, int zdir) {
|
/* package */MapTile addTile(int x, int y, byte zoomLevel, int zdir) {
|
||||||
MapTile tile;
|
MapTile tile;
|
||||||
|
|
||||||
tile = QuadTree.getTile(x, y, zoomLevel);
|
tile = QuadTree.getTile(x, y, zoomLevel);
|
||||||
@ -431,7 +413,7 @@ public class TileManager {
|
|||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void clearTile(MapTile t) {
|
private void clearTile(MapTile t) {
|
||||||
if (t == null)
|
if (t == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -462,9 +444,6 @@ public class TileManager {
|
|||||||
int diff;
|
int diff;
|
||||||
long dx, dy;
|
long dx, dy;
|
||||||
|
|
||||||
// TODO this could need some fixing, and optimization
|
|
||||||
// to consider move/zoom direction
|
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
JobTile t = (JobTile) tiles[i];
|
JobTile t = (JobTile) tiles[i];
|
||||||
if (t == null)
|
if (t == null)
|
||||||
@ -478,11 +457,8 @@ public class TileManager {
|
|||||||
dx %= center;
|
dx %= center;
|
||||||
dy %= center;
|
dy %= center;
|
||||||
t.distance = (dx * dx + dy * dy) * 0.5f;
|
t.distance = (dx * dx + dy * dy) * 0.5f;
|
||||||
//t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)) * 0.25f;
|
|
||||||
//t.distance = (float) Math.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
|
||||||
|
|
||||||
if (diff < 3) {
|
if (diff < 3) {
|
||||||
dx = ((t.pixelX + h) >> diff) - x;
|
dx = ((t.pixelX + h) >> diff) - x;
|
||||||
dy = ((t.pixelY + h) >> diff) - y;
|
dy = ((t.pixelY + h) >> diff) - y;
|
||||||
@ -494,8 +470,6 @@ public class TileManager {
|
|||||||
dx %= center;
|
dx %= center;
|
||||||
dy %= center;
|
dy %= center;
|
||||||
t.distance = (dx * dx + dy * dy);
|
t.distance = (dx * dx + dy * dy);
|
||||||
//t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy));
|
|
||||||
//t.distance = (float) Math.sqrt((dx * dx + dy * dy));
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// tile zoom level is parent of current
|
// tile zoom level is parent of current
|
||||||
@ -504,13 +478,11 @@ public class TileManager {
|
|||||||
dx %= center;
|
dx %= center;
|
||||||
dy %= center;
|
dy %= center;
|
||||||
t.distance = (dx * dx + dy * dy) * (-diff * 0.7f);
|
t.distance = (dx * dx + dy * dy) * (-diff * 0.7f);
|
||||||
//t.distance = ((dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy)) * (-diff * 0.5f);
|
|
||||||
//t.distance = (float) Math.sqrt((dx * dx + dy * dy)) * (-diff * 0.5f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void limitCache(MapPosition mapPosition, int remove) {
|
private void limitCache(MapPosition mapPosition, int remove) {
|
||||||
MapTile[] tiles = mTiles;
|
MapTile[] tiles = mTiles;
|
||||||
int size = mTilesSize;
|
int size = mTilesSize;
|
||||||
|
|
||||||
@ -570,7 +542,7 @@ public class TileManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void limitLoadQueue() {
|
private void limitLoadQueue() {
|
||||||
int size = mTilesLoaded.size();
|
int size = mTilesLoaded.size();
|
||||||
|
|
||||||
if (size < MAX_TILES_IN_QUEUE)
|
if (size < MAX_TILES_IN_QUEUE)
|
||||||
@ -651,7 +623,7 @@ public class TileManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onSizeChanged(int w, int h) {
|
public void onSizeChanged(int w, int h) {
|
||||||
Log.d(TAG, "onSizeChanged" + w + " " + h);
|
Log.d(TAG, "onSizeChanged" + w + " " + h);
|
||||||
|
|
||||||
mWidth = w;
|
mWidth = w;
|
||||||
|
@ -154,7 +154,7 @@ public class MapView extends RelativeLayout {
|
|||||||
|
|
||||||
mJobQueue = new JobQueue();
|
mJobQueue = new JobQueue();
|
||||||
|
|
||||||
mTileManager = TileManager.create(this);
|
mTileManager = new TileManager(this);
|
||||||
|
|
||||||
mGLView = new GLView(context, this);
|
mGLView = new GLView(context, this);
|
||||||
|
|
||||||
@ -479,7 +479,7 @@ public class MapView extends RelativeLayout {
|
|||||||
if (width != 0 && height != 0)
|
if (width != 0 && height != 0)
|
||||||
mMapViewPosition.setViewport(width, height);
|
mMapViewPosition.setViewport(width, height);
|
||||||
|
|
||||||
TileManager.onSizeChanged(width, height);
|
mTileManager.onSizeChanged(width, height);
|
||||||
|
|
||||||
mapWorkersProceed();
|
mapWorkersProceed();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user