refactoring: MapTile -> JobTile, GLMapTile -> MapTile, TreeTile -> QuadTree
This commit is contained in:
parent
d2a2dfb2f2
commit
2d90a4dea4
@ -15,7 +15,7 @@
|
||||
package org.mapsforge.android;
|
||||
|
||||
import org.mapsforge.android.mapgenerator.IMapGenerator;
|
||||
import org.mapsforge.android.mapgenerator.MapTile;
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
import org.mapsforge.android.rendertheme.RenderTheme;
|
||||
|
||||
import android.opengl.GLSurfaceView;
|
||||
@ -30,7 +30,7 @@ public interface IMapRenderer extends GLSurfaceView.Renderer {
|
||||
* the mapGeneratorJob holding Tile data
|
||||
* @return true if the tile was processed
|
||||
*/
|
||||
public boolean passTile(MapTile tile);
|
||||
public boolean passTile(JobTile tile);
|
||||
|
||||
/**
|
||||
* @return true when tile passed to renderer is processed false otherwise. used to lock overwriting resources passed
|
||||
|
||||
@ -28,7 +28,7 @@ import org.mapsforge.android.mapgenerator.MapDatabaseFactory;
|
||||
import org.mapsforge.android.mapgenerator.MapDatabases;
|
||||
import org.mapsforge.android.mapgenerator.MapRendererFactory;
|
||||
import org.mapsforge.android.mapgenerator.MapRenderers;
|
||||
import org.mapsforge.android.mapgenerator.MapTile;
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
import org.mapsforge.android.mapgenerator.MapWorker;
|
||||
import org.mapsforge.android.mapgenerator.Theme;
|
||||
import org.mapsforge.android.rendertheme.ExternalRenderTheme;
|
||||
@ -651,7 +651,7 @@ public class MapView extends GLSurfaceView {
|
||||
* @param jobs
|
||||
* tile jobs
|
||||
*/
|
||||
public void addJobs(ArrayList<MapTile> jobs) {
|
||||
public void addJobs(ArrayList<JobTile> jobs) {
|
||||
if (jobs == null) {
|
||||
mJobQueue.clear();
|
||||
return;
|
||||
|
||||
@ -69,7 +69,7 @@ class LineLayers {
|
||||
|
||||
static final boolean mFast = true;
|
||||
|
||||
static LineLayer drawLines(GLMapTile tile, LineLayer layer, int next, float[] matrix,
|
||||
static LineLayer drawLines(MapTile tile, LineLayer layer, int next, float[] matrix,
|
||||
float div, double zoom, float scale) {
|
||||
|
||||
float z = 1 / div;
|
||||
|
||||
@ -17,7 +17,7 @@ package org.mapsforge.android.glrenderer;
|
||||
import org.mapsforge.android.DebugSettings;
|
||||
import org.mapsforge.android.MapView;
|
||||
import org.mapsforge.android.mapgenerator.IMapGenerator;
|
||||
import org.mapsforge.android.mapgenerator.MapTile;
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
import org.mapsforge.android.rendertheme.IRenderCallback;
|
||||
import org.mapsforge.android.rendertheme.RenderTheme;
|
||||
import org.mapsforge.android.rendertheme.renderinstruction.Area;
|
||||
@ -57,7 +57,7 @@ public class MapGenerator implements IMapGenerator, IRenderCallback, IMapDatabas
|
||||
|
||||
private IMapDatabase mMapDatabase;
|
||||
|
||||
private GLMapTile mCurrentTile;
|
||||
private MapTile mCurrentTile;
|
||||
|
||||
private float[] mWayNodes;
|
||||
private short[] mWays;
|
||||
@ -415,13 +415,13 @@ public class MapGenerator implements IMapGenerator, IRenderCallback, IMapDatabas
|
||||
boolean mDebugDrawUnmatched;
|
||||
|
||||
@Override
|
||||
public boolean executeJob(MapTile mapTile) {
|
||||
GLMapTile tile;
|
||||
public boolean executeJob(JobTile jobTile) {
|
||||
MapTile tile;
|
||||
|
||||
if (mMapDatabase == null)
|
||||
return false;
|
||||
|
||||
tile = mCurrentTile = (GLMapTile) mapTile;
|
||||
tile = mCurrentTile = (MapTile) jobTile;
|
||||
DebugSettings debugSettings = mMapView.getDebugSettings();
|
||||
|
||||
mDebugDrawPolygons = !debugSettings.mDisablePolygons;
|
||||
|
||||
@ -43,7 +43,7 @@ import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import org.mapsforge.android.MapView;
|
||||
import org.mapsforge.android.mapgenerator.IMapGenerator;
|
||||
import org.mapsforge.android.mapgenerator.MapTile;
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
import org.mapsforge.android.rendertheme.RenderTheme;
|
||||
import org.mapsforge.android.utils.GlUtils;
|
||||
import org.mapsforge.core.MapPosition;
|
||||
@ -70,14 +70,14 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
private static int CACHE_TILES = CACHE_TILES_MAX;
|
||||
|
||||
private final MapView mMapView;
|
||||
private static ArrayList<MapTile> mJobList;
|
||||
private static ArrayList<JobTile> mJobList;
|
||||
private static ArrayList<VertexBufferObject> mVBOs;
|
||||
|
||||
// all tiles currently referenced
|
||||
private static ArrayList<GLMapTile> mTiles;
|
||||
private static ArrayList<MapTile> mTiles;
|
||||
|
||||
// tiles that have new data to upload, see passTile()
|
||||
private static ArrayList<GLMapTile> mTilesLoaded;
|
||||
private static ArrayList<MapTile> mTilesLoaded;
|
||||
|
||||
private static int mWidth, mHeight;
|
||||
private static float mAspect;
|
||||
@ -97,10 +97,10 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
class TilesData {
|
||||
int cnt = 0;
|
||||
final GLMapTile[] tiles;
|
||||
final MapTile[] tiles;
|
||||
|
||||
TilesData(int numTiles) {
|
||||
tiles = new GLMapTile[numTiles];
|
||||
tiles = new MapTile[numTiles];
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,16 +142,16 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
if (mInitial)
|
||||
return;
|
||||
|
||||
mJobList = new ArrayList<MapTile>();
|
||||
mTiles = new ArrayList<GLMapTile>();
|
||||
mTilesLoaded = new ArrayList<GLMapTile>(30);
|
||||
mJobList = new ArrayList<JobTile>();
|
||||
mTiles = new ArrayList<MapTile>();
|
||||
mTilesLoaded = new ArrayList<MapTile>(30);
|
||||
|
||||
Matrix.setIdentityM(mMVPMatrix, 0);
|
||||
|
||||
mInitial = true;
|
||||
mUpdateTiles = false;
|
||||
|
||||
TreeTile.init();
|
||||
QuadTree.init();
|
||||
}
|
||||
|
||||
private static int updateTileDistances(ArrayList<?> tiles,
|
||||
@ -169,7 +169,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
// to consider move/zoom direction
|
||||
|
||||
for (int i = 0, n = tiles.size(); i < n; i++) {
|
||||
MapTile t = (MapTile) tiles.get(i);
|
||||
JobTile t = (JobTile) tiles.get(i);
|
||||
diff = (t.zoomLevel - zoom);
|
||||
if (t.isActive)
|
||||
cnt++;
|
||||
@ -205,8 +205,8 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
private static boolean childIsActive(GLMapTile t) {
|
||||
GLMapTile c = null;
|
||||
private static boolean childIsActive(MapTile t) {
|
||||
MapTile c = null;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (t.rel.child[i] == null)
|
||||
@ -222,20 +222,20 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
// FIXME still the chance that one jumped two zoomlevels between
|
||||
// cur and draw. should use reference counter instead
|
||||
private static boolean tileInUse(GLMapTile t) {
|
||||
private static boolean tileInUse(MapTile t) {
|
||||
byte z = mPrevZoom;
|
||||
|
||||
if (t.isActive) {
|
||||
return true;
|
||||
|
||||
} else if (t.zoomLevel == z + 1) {
|
||||
GLMapTile p = t.rel.parent.tile;
|
||||
MapTile p = t.rel.parent.tile;
|
||||
|
||||
if (p != null && p.isActive && !(p.isReady || p.newData))
|
||||
return true;
|
||||
|
||||
} else if (t.zoomLevel == z + 2) {
|
||||
GLMapTile p = t.rel.parent.parent.tile;
|
||||
MapTile p = t.rel.parent.parent.tile;
|
||||
|
||||
if (p != null && p.isActive && !(p.isReady || p.newData))
|
||||
return true;
|
||||
@ -245,7 +245,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
return true;
|
||||
|
||||
} else if (t.zoomLevel == z - 2) {
|
||||
for (TreeTile c : t.rel.child) {
|
||||
for (QuadTree c : t.rel.child) {
|
||||
if (c == null)
|
||||
continue;
|
||||
|
||||
@ -253,11 +253,11 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
return true;
|
||||
}
|
||||
} else if (t.zoomLevel == z - 3) {
|
||||
for (TreeTile c : t.rel.child) {
|
||||
for (QuadTree c : t.rel.child) {
|
||||
if (c == null)
|
||||
continue;
|
||||
|
||||
for (TreeTile c2 : c.child) {
|
||||
for (QuadTree c2 : c.child) {
|
||||
if (c2 == null)
|
||||
continue;
|
||||
|
||||
@ -276,7 +276,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
// remove orphaned tiles
|
||||
for (int i = 0; i < size;) {
|
||||
GLMapTile cur = mTiles.get(i);
|
||||
MapTile cur = mTiles.get(i);
|
||||
// make sure tile cannot be used by GL or MapWorker Thread
|
||||
if ((!cur.isActive) && (!cur.isLoading) && (!cur.newData)
|
||||
&& (!cur.isReady) && (!tileInUse(cur))) {
|
||||
@ -302,11 +302,11 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
for (int i = 1; i <= removes; i++) {
|
||||
|
||||
GLMapTile t = mTiles.get(0);
|
||||
MapTile t = mTiles.get(0);
|
||||
int pos = 0;
|
||||
|
||||
for (int j = 1; j < size; j++) {
|
||||
GLMapTile t2 = mTiles.get(j);
|
||||
MapTile t2 = mTiles.get(j);
|
||||
if (t2.distance > t.distance) {
|
||||
t = t2;
|
||||
pos = j;
|
||||
@ -347,7 +347,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
// remove uploaded tiles
|
||||
for (int i = 0; i < size;) {
|
||||
GLMapTile t = mTilesLoaded.get(i);
|
||||
MapTile t = mTilesLoaded.get(i);
|
||||
// rel == null means tile is already removed by limitCache
|
||||
if (!t.newData || t.rel == null) {
|
||||
mTilesLoaded.remove(i);
|
||||
@ -362,7 +362,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
return;
|
||||
|
||||
while (size-- > MAX_TILES_IN_QUEUE - 20) {
|
||||
GLMapTile t = mTilesLoaded.get(size);
|
||||
MapTile t = mTilesLoaded.get(size);
|
||||
|
||||
synchronized (t) {
|
||||
if (t.rel == null) {
|
||||
@ -419,12 +419,12 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
if (tiles == max)
|
||||
break;
|
||||
|
||||
GLMapTile tile = TreeTile.getTile(xx, yy, zoomLevel);
|
||||
MapTile tile = QuadTree.getTile(xx, yy, zoomLevel);
|
||||
|
||||
if (tile == null) {
|
||||
tile = new GLMapTile(xx, yy, zoomLevel);
|
||||
tile = new MapTile(xx, yy, zoomLevel);
|
||||
|
||||
TreeTile.add(tile);
|
||||
QuadTree.add(tile);
|
||||
mTiles.add(tile);
|
||||
}
|
||||
|
||||
@ -436,12 +436,12 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
if (zdir > 0 && zoomLevel > 0) {
|
||||
// prefetch parent
|
||||
GLMapTile parent = tile.rel.parent.tile;
|
||||
MapTile parent = tile.rel.parent.tile;
|
||||
|
||||
if (parent == null) {
|
||||
parent = new GLMapTile(xx >> 1, yy >> 1, (byte) (zoomLevel - 1));
|
||||
parent = new MapTile(xx >> 1, yy >> 1, (byte) (zoomLevel - 1));
|
||||
|
||||
TreeTile.add(parent);
|
||||
QuadTree.add(parent);
|
||||
mTiles.add(parent);
|
||||
}
|
||||
|
||||
@ -494,7 +494,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void clearTile(GLMapTile t) {
|
||||
private static void clearTile(MapTile t) {
|
||||
t.newData = false;
|
||||
t.isLoading = false;
|
||||
t.isReady = false;
|
||||
@ -513,7 +513,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
t.vbo = null;
|
||||
}
|
||||
|
||||
TreeTile.remove(t);
|
||||
QuadTree.remove(t);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -534,12 +534,12 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
mInitial = true;
|
||||
synchronized (this) {
|
||||
|
||||
for (GLMapTile t : mTiles)
|
||||
for (MapTile t : mTiles)
|
||||
clearTile(t);
|
||||
|
||||
mTiles.clear();
|
||||
mTilesLoaded.clear();
|
||||
TreeTile.init();
|
||||
QuadTree.init();
|
||||
curTiles.cnt = 0;
|
||||
mBufferMemoryUsage = 0;
|
||||
}
|
||||
@ -613,8 +613,8 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
* called by MapWorkers when tile is loaded
|
||||
*/
|
||||
@Override
|
||||
public synchronized boolean passTile(MapTile mapTile) {
|
||||
GLMapTile tile = (GLMapTile) mapTile;
|
||||
public synchronized boolean passTile(JobTile jobTile) {
|
||||
MapTile tile = (MapTile) jobTile;
|
||||
|
||||
if (tile.isCanceled) {
|
||||
// no one should be able to use this tile now, mapgenerator passed it,
|
||||
@ -655,7 +655,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
// ... asus has just 16 bit?!
|
||||
// private static final float depthStep = 0.00000011920928955078125f;
|
||||
|
||||
private static void setMatrix(GLMapTile tile, float div, int offset) {
|
||||
private static void setMatrix(MapTile tile, float div, int offset) {
|
||||
float x, y, scale;
|
||||
|
||||
scale = (float) (2.0 * mDrawPosition.scale / (mHeight * div));
|
||||
@ -685,7 +685,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
}
|
||||
|
||||
private static boolean setTileScissor(GLMapTile tile, float div) {
|
||||
private static boolean setTileScissor(MapTile tile, float div) {
|
||||
double dx, dy, scale;
|
||||
|
||||
if (div == 0) {
|
||||
@ -715,7 +715,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
private int uploadCnt = 0;
|
||||
|
||||
private boolean uploadTileData(GLMapTile tile) {
|
||||
private boolean uploadTileData(MapTile tile) {
|
||||
ShortBuffer sbuf = null;
|
||||
|
||||
// use multiple buffers to avoid overwriting buffer while current
|
||||
@ -895,14 +895,14 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
}
|
||||
|
||||
int tileCnt = drawTiles.cnt;
|
||||
GLMapTile[] tiles = drawTiles.tiles;
|
||||
MapTile[] tiles = drawTiles.tiles;
|
||||
|
||||
uploadCnt = 0;
|
||||
int updateTextures = 0;
|
||||
|
||||
// check visible tiles, upload new vertex data
|
||||
for (int i = 0; i < tileCnt; i++) {
|
||||
GLMapTile tile = tiles[i];
|
||||
MapTile tile = tiles[i];
|
||||
|
||||
if (!setTileScissor(tile, 1))
|
||||
continue;
|
||||
@ -917,7 +917,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
if (!tile.isReady) {
|
||||
// check near relatives if they can serve as proxy
|
||||
GLMapTile rel = tile.rel.parent.tile;
|
||||
MapTile rel = tile.rel.parent.tile;
|
||||
if (rel != null && rel.newData) {
|
||||
uploadTileData(rel);
|
||||
} else {
|
||||
@ -993,7 +993,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
// used to not draw a tile twice per frame...
|
||||
private static byte mDrawSerial = 0;
|
||||
|
||||
private static void drawTile(GLMapTile tile, float div) {
|
||||
private static void drawTile(MapTile tile, float div) {
|
||||
// draw parents only once
|
||||
if (tile.lastDraw == mDrawSerial)
|
||||
return;
|
||||
@ -1045,13 +1045,13 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean drawProxyChild(GLMapTile tile) {
|
||||
private static boolean drawProxyChild(MapTile tile) {
|
||||
int drawn = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (tile.rel.child[i] == null)
|
||||
continue;
|
||||
|
||||
GLMapTile c = tile.rel.child[i].tile;
|
||||
MapTile c = tile.rel.child[i].tile;
|
||||
if (c == null)
|
||||
continue;
|
||||
|
||||
@ -1068,17 +1068,17 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
return drawn == 4;
|
||||
}
|
||||
|
||||
private static void drawProxyTile(GLMapTile tile) {
|
||||
private static void drawProxyTile(MapTile tile) {
|
||||
|
||||
if (mDrawPosition.scale > 1.5f) {
|
||||
// prefer drawing children
|
||||
if (!drawProxyChild(tile)) {
|
||||
GLMapTile t = tile.rel.parent.tile;
|
||||
MapTile t = tile.rel.parent.tile;
|
||||
if (t != null) {
|
||||
if (t.isReady) {
|
||||
drawTile(t, 0.5f);
|
||||
} else {
|
||||
GLMapTile p = t.rel.parent.tile;
|
||||
MapTile p = t.rel.parent.tile;
|
||||
if (p != null && p.isReady)
|
||||
drawTile(p, 0.25f);
|
||||
}
|
||||
@ -1086,7 +1086,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
}
|
||||
} else {
|
||||
// prefer drawing parent
|
||||
GLMapTile t = tile.rel.parent.tile;
|
||||
MapTile t = tile.rel.parent.tile;
|
||||
|
||||
if (t != null && t.isReady) {
|
||||
drawTile(t, 0.5f);
|
||||
@ -1111,7 +1111,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
mTiles.clear();
|
||||
|
||||
ShortPool.init();
|
||||
TreeTile.init();
|
||||
QuadTree.init();
|
||||
// LineLayers.finish();
|
||||
|
||||
drawTiles = newTiles = curTiles = null;
|
||||
|
||||
@ -14,9 +14,9 @@
|
||||
*/
|
||||
package org.mapsforge.android.glrenderer;
|
||||
|
||||
import org.mapsforge.android.mapgenerator.MapTile;
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
|
||||
class GLMapTile extends MapTile {
|
||||
class MapTile extends JobTile {
|
||||
byte lastDraw = 0;
|
||||
|
||||
// VBO layout:
|
||||
@ -38,9 +38,9 @@ class GLMapTile extends MapTile {
|
||||
boolean newData;
|
||||
|
||||
// pointer to access relatives in TileTree
|
||||
TreeTile rel;
|
||||
QuadTree rel;
|
||||
|
||||
GLMapTile(int tileX, int tileY, byte zoomLevel) {
|
||||
MapTile(int tileX, int tileY, byte zoomLevel) {
|
||||
super(tileX, tileY, zoomLevel);
|
||||
}
|
||||
|
||||
@ -16,43 +16,43 @@ package org.mapsforge.android.glrenderer;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
class TreeTile {
|
||||
private static String TAG = "TreeTile";
|
||||
class QuadTree {
|
||||
private static String TAG = "QuadTree";
|
||||
|
||||
private static TreeTile root;
|
||||
private static QuadTree root;
|
||||
|
||||
// parent pointer is used to link pool items
|
||||
private static TreeTile pool;
|
||||
private static QuadTree pool;
|
||||
|
||||
// TreeTile members
|
||||
TreeTile parent;
|
||||
final TreeTile[] child = new TreeTile[4];
|
||||
QuadTree parent;
|
||||
final QuadTree[] child = new QuadTree[4];
|
||||
int refs = 0;
|
||||
byte id;
|
||||
GLMapTile tile;
|
||||
MapTile tile;
|
||||
|
||||
static void init() {
|
||||
|
||||
pool = null;
|
||||
root = new TreeTile();
|
||||
root = new QuadTree();
|
||||
root.parent = root;
|
||||
|
||||
TreeTile t;
|
||||
QuadTree t;
|
||||
for (int i = 0; i < 200; i++) {
|
||||
t = new TreeTile();
|
||||
t = new QuadTree();
|
||||
t.parent = pool;
|
||||
pool = t;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean remove(GLMapTile t) {
|
||||
static boolean remove(MapTile t) {
|
||||
if (t.rel == null) {
|
||||
Log.d(TAG, "already removed " + t);
|
||||
return true;
|
||||
}
|
||||
|
||||
TreeTile cur = t.rel;
|
||||
TreeTile next;
|
||||
QuadTree cur = t.rel;
|
||||
QuadTree next;
|
||||
|
||||
for (; cur != root;) {
|
||||
// keep pointer to parent
|
||||
@ -79,13 +79,13 @@ class TreeTile {
|
||||
return true;
|
||||
}
|
||||
|
||||
static TreeTile add(GLMapTile tile) {
|
||||
static QuadTree add(MapTile tile) {
|
||||
|
||||
int x = tile.tileX;
|
||||
int y = tile.tileY;
|
||||
int z = tile.zoomLevel;
|
||||
|
||||
TreeTile cur;
|
||||
QuadTree cur;
|
||||
|
||||
// if (x < 0 || x >= 1 << z) {
|
||||
// Log.d(TAG, "invalid position");
|
||||
@ -96,7 +96,7 @@ class TreeTile {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
TreeTile leaf = root;
|
||||
QuadTree leaf = root;
|
||||
|
||||
for (int level = z - 1; level >= 0; level--) {
|
||||
|
||||
@ -115,7 +115,7 @@ class TreeTile {
|
||||
cur = pool;
|
||||
pool = pool.parent;
|
||||
} else {
|
||||
cur = new TreeTile();
|
||||
cur = new QuadTree();
|
||||
}
|
||||
|
||||
cur.refs = 0;
|
||||
@ -133,8 +133,8 @@ class TreeTile {
|
||||
return leaf;
|
||||
}
|
||||
|
||||
static GLMapTile getTile(int x, int y, int z) {
|
||||
TreeTile leaf = root;
|
||||
static MapTile getTile(int x, int y, int z) {
|
||||
QuadTree leaf = root;
|
||||
|
||||
for (int level = z - 1; level >= 0; level--) {
|
||||
|
||||
@ -173,7 +173,7 @@ public class TextRenderer {
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean drawToTexture(GLMapTile tile) {
|
||||
static boolean drawToTexture(MapTile tile) {
|
||||
TextTexture tex = null;
|
||||
|
||||
if (tile.labels == null)
|
||||
@ -427,7 +427,7 @@ public class TextRenderer {
|
||||
GLES20.glDisableVertexAttribArray(hTextVertex);
|
||||
}
|
||||
|
||||
static void drawTile(GLMapTile tile, float[] matrix) {
|
||||
static void drawTile(MapTile tile, float[] matrix) {
|
||||
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tile.texture.id);
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ public class TextTexture {
|
||||
final int id;
|
||||
int length;
|
||||
int offset;
|
||||
GLMapTile tile;
|
||||
MapTile tile;
|
||||
|
||||
String[] text;
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ public interface IMapGenerator {
|
||||
* the job that should be executed.
|
||||
* @return true if the job was executed successfully, false otherwise.
|
||||
*/
|
||||
boolean executeJob(MapTile tile);
|
||||
boolean executeJob(JobTile tile);
|
||||
|
||||
/**
|
||||
* @param mapDatabase
|
||||
|
||||
@ -23,29 +23,36 @@ import java.util.PriorityQueue;
|
||||
public class JobQueue {
|
||||
private static final int INITIAL_CAPACITY = 64;
|
||||
|
||||
private PriorityQueue<MapTile> mPriorityQueue;
|
||||
private PriorityQueue<JobTile> mPriorityQueue;
|
||||
|
||||
/**
|
||||
*/
|
||||
public JobQueue() {
|
||||
mPriorityQueue = new PriorityQueue<MapTile>(INITIAL_CAPACITY);
|
||||
mPriorityQueue = new PriorityQueue<JobTile>(INITIAL_CAPACITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tiles
|
||||
* the job to be added to this queue.
|
||||
*/
|
||||
public synchronized void setJobs(ArrayList<MapTile> tiles) {
|
||||
public synchronized void setJobs(ArrayList<JobTile> tiles) {
|
||||
mPriorityQueue.clear();
|
||||
mPriorityQueue.addAll(tiles);
|
||||
// for (int i = 0, n = tiles.size(); i < n; i++)
|
||||
// mPriorityQueue.offer(tiles.get(i));
|
||||
// mPriorityQueue.addAll(tiles);
|
||||
for (int i = 0, n = tiles.size(); i < n; i++) {
|
||||
JobTile tile = tiles.get(i);
|
||||
tile.isLoading = true;
|
||||
mPriorityQueue.offer(tile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all jobs from this queue.
|
||||
*/
|
||||
public synchronized void clear() {
|
||||
for (int i = 0, n = mPriorityQueue.size(); i < n; i++) {
|
||||
JobTile tile = mPriorityQueue.poll();
|
||||
tile.isLoading = false;
|
||||
}
|
||||
mPriorityQueue.clear();
|
||||
}
|
||||
|
||||
@ -59,10 +66,8 @@ public class JobQueue {
|
||||
/**
|
||||
* @return the most important job from this queue or null, if empty.
|
||||
*/
|
||||
public synchronized MapTile poll() {
|
||||
MapTile tile = mPriorityQueue.poll();
|
||||
if (tile != null)
|
||||
tile.isLoading = true;
|
||||
public synchronized JobTile poll() {
|
||||
JobTile tile = mPriorityQueue.poll();
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ import org.mapsforge.core.Tile;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class MapTile extends Tile implements Comparable<MapTile> {
|
||||
public class JobTile extends Tile implements Comparable<JobTile> {
|
||||
/**
|
||||
* tile is loaded and ready for drawing. (set and used by render thread after uploading data to gl).
|
||||
*/
|
||||
@ -53,12 +53,12 @@ public class MapTile extends Tile implements Comparable<MapTile> {
|
||||
* @param zoomLevel
|
||||
* ..
|
||||
*/
|
||||
public MapTile(int tileX, int tileY, byte zoomLevel) {
|
||||
public JobTile(int tileX, int tileY, byte zoomLevel) {
|
||||
super(tileX, tileY, zoomLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MapTile o) {
|
||||
public int compareTo(JobTile o) {
|
||||
if (this.distance < o.distance) {
|
||||
return -1;
|
||||
} else if (this.distance > o.distance) {
|
||||
@ -62,7 +62,7 @@ public class MapWorker extends PausableThread {
|
||||
|
||||
@Override
|
||||
protected void doWork() {
|
||||
MapTile tile = mJobQueue.poll();
|
||||
JobTile tile = mJobQueue.poll();
|
||||
|
||||
if (mMapGenerator == null || tile == null)
|
||||
return;
|
||||
|
||||
@ -20,10 +20,10 @@ import java.util.Comparator;
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TileDistanceSort implements Comparator<MapTile> {
|
||||
public class TileDistanceSort implements Comparator<JobTile> {
|
||||
|
||||
@Override
|
||||
public int compare(MapTile tile1, MapTile tile2) {
|
||||
public int compare(JobTile tile1, JobTile tile2) {
|
||||
if (tile1.distance == tile2.distance)
|
||||
return 0;
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ import java.util.List;
|
||||
import org.mapsforge.android.DebugSettings;
|
||||
import org.mapsforge.android.MapView;
|
||||
import org.mapsforge.android.mapgenerator.IMapGenerator;
|
||||
import org.mapsforge.android.mapgenerator.MapTile;
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
import org.mapsforge.android.rendertheme.IRenderCallback;
|
||||
import org.mapsforge.android.rendertheme.RenderTheme;
|
||||
import org.mapsforge.android.rendertheme.renderinstruction.Area;
|
||||
@ -138,13 +138,13 @@ public class MapGenerator implements IMapGenerator, IRenderCallback,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeJob(MapTile mapTile) {
|
||||
public boolean executeJob(JobTile jobTile) {
|
||||
long time_load = System.currentTimeMillis();
|
||||
_nodes = 0;
|
||||
_nodesDropped = 0;
|
||||
// _renderTime = 0;
|
||||
|
||||
mCurrentTile = mapTile;
|
||||
mCurrentTile = jobTile;
|
||||
mCurrentTileZoom = ((long) Tile.TILE_SIZE << mCurrentTile.zoomLevel);
|
||||
mCurrentTileX = mCurrentTile.pixelX;
|
||||
mCurrentTileY = mCurrentTile.pixelY;
|
||||
|
||||
@ -27,7 +27,7 @@ import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import org.mapsforge.android.MapView;
|
||||
import org.mapsforge.android.mapgenerator.IMapGenerator;
|
||||
import org.mapsforge.android.mapgenerator.MapTile;
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
import org.mapsforge.android.mapgenerator.TileDistanceSort;
|
||||
import org.mapsforge.android.rendertheme.RenderTheme;
|
||||
import org.mapsforge.android.utils.GlUtils;
|
||||
@ -64,18 +64,18 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
// private JobParameters mJobParameter;
|
||||
private MapPosition mMapPosition, mPrevMapPosition;
|
||||
|
||||
private ArrayList<MapTile> mJobList;
|
||||
private ArrayList<JobTile> mJobList;
|
||||
|
||||
ArrayList<Integer> mTextures;
|
||||
MapView mMapView;
|
||||
|
||||
GLMapTile[] currentTiles;
|
||||
GLMapTile[] newTiles;
|
||||
MapTile[] currentTiles;
|
||||
MapTile[] newTiles;
|
||||
int currentTileCnt = 0;
|
||||
|
||||
// private TileCacheKey mTileCacheKey;
|
||||
// private LinkedHashMap<TileCacheKey, GLMapTile> mTiles;
|
||||
private ArrayList<GLMapTile> mTileList;
|
||||
private ArrayList<MapTile> mTileList;
|
||||
|
||||
private boolean processedTile = true;
|
||||
|
||||
@ -105,10 +105,10 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
mVertices.put(vertices);
|
||||
|
||||
mTextures = new ArrayList<Integer>();
|
||||
mJobList = new ArrayList<MapTile>();
|
||||
mJobList = new ArrayList<JobTile>();
|
||||
|
||||
// mTiles = new LinkedHashMap<TileCacheKey, GLMapTile>(100);
|
||||
mTileList = new ArrayList<GLMapTile>();
|
||||
mTileList = new ArrayList<MapTile>();
|
||||
|
||||
// mTileCacheKey = new TileCacheKey();
|
||||
mInitial = true;
|
||||
@ -119,7 +119,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
long y = mTileY;
|
||||
int diff;
|
||||
|
||||
for (GLMapTile t : mTileList) {
|
||||
for (MapTile t : mTileList) {
|
||||
|
||||
diff = (t.zoomLevel - zoom);
|
||||
|
||||
@ -137,7 +137,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
Collections.sort(mTileList, tileDistanceSort);
|
||||
|
||||
for (int j = mTileList.size() - 1, cnt = 0; cnt < remove; j--, cnt++) {
|
||||
GLMapTile t = mTileList.remove(j);
|
||||
MapTile t = mTileList.remove(j);
|
||||
|
||||
// mTileCacheKey.set(t.tileX, t.tileY, t.zoomLevel);
|
||||
// mTiles.remove(mTileCacheKey);
|
||||
@ -298,7 +298,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
// private MapGeneratorJob mMapGeneratorJob = null;
|
||||
|
||||
@Override
|
||||
public boolean passTile(MapTile mapTile) {
|
||||
public boolean passTile(JobTile jobTile) {
|
||||
|
||||
// mMapGeneratorJob = mapGeneratorJob;
|
||||
processedTile = false;
|
||||
@ -307,7 +307,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean drawTile(GLMapTile tile, int level, float height) {
|
||||
private boolean drawTile(MapTile tile, int level, float height) {
|
||||
|
||||
// do not recurse more than two parents
|
||||
if (level > 2)
|
||||
@ -416,7 +416,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
|
||||
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
|
||||
|
||||
GLMapTile tile, child, child2;
|
||||
MapTile tile, child, child2;
|
||||
|
||||
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
|
||||
|
||||
@ -494,8 +494,8 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
|
||||
mHeight = height;
|
||||
|
||||
int tiles = (mWidth / Tile.TILE_SIZE + 4) * (mHeight / Tile.TILE_SIZE + 4);
|
||||
currentTiles = new GLMapTile[tiles];
|
||||
newTiles = new GLMapTile[tiles];
|
||||
currentTiles = new MapTile[tiles];
|
||||
newTiles = new MapTile[tiles];
|
||||
|
||||
GLES20.glViewport(0, 0, width, height);
|
||||
|
||||
|
||||
@ -14,16 +14,16 @@
|
||||
*/
|
||||
package org.mapsforge.android.swrenderer;
|
||||
|
||||
import org.mapsforge.android.mapgenerator.MapTile;
|
||||
import org.mapsforge.android.mapgenerator.JobTile;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class GLMapTile extends MapTile {
|
||||
public class MapTile extends JobTile {
|
||||
private float mScale;
|
||||
|
||||
final GLMapTile[] child = { null, null, null, null };
|
||||
GLMapTile parent;
|
||||
final MapTile[] child = { null, null, null, null };
|
||||
MapTile parent;
|
||||
|
||||
// private long mLoadTime;
|
||||
private int mTextureID;
|
||||
@ -36,7 +36,7 @@ public class GLMapTile extends MapTile {
|
||||
* @param zoomLevel
|
||||
* ..
|
||||
*/
|
||||
public GLMapTile(int tileX, int tileY, byte zoomLevel) {
|
||||
public MapTile(int tileX, int tileY, byte zoomLevel) {
|
||||
super(tileX, tileY, zoomLevel);
|
||||
mScale = 1;
|
||||
mTextureID = -1;
|
||||
Loading…
x
Reference in New Issue
Block a user