make TileManager.jobQueue private

- use hasTileJobs(), getTileJob(), jobCompleted() instead
This commit is contained in:
Hannes Janetzek 2013-10-06 20:39:43 +02:00
parent e35f39c9f4
commit 18d0bfc3c5
3 changed files with 24 additions and 17 deletions

View File

@ -57,7 +57,7 @@ public abstract class TileLoader {
mPausing = false; mPausing = false;
// FIXME // FIXME
mWorking = false; mWorking = false;
if (!mTileManager.jobQueue.isEmpty()) if (mTileManager.hasTileJobs())
go(); go();
} }
@ -76,7 +76,7 @@ public abstract class TileLoader {
return; return;
} }
MapTile tile = mTileManager.jobQueue.poll(); MapTile tile = mTileManager.getTileJob();
if (tile == null) if (tile == null)
return; return;
@ -96,16 +96,14 @@ public abstract class TileLoader {
} }
public void jobCompleted(MapTile tile, boolean success) { public void jobCompleted(MapTile tile, boolean success) {
//if (success) { if (isInterrupted)
if (!isInterrupted) { success = false;
// pass tile to main thread
mTileManager.passTile(tile, success); mTileManager.jobCompleted(tile, success);
}
//}
mWorking = false; mWorking = false;
if (!mPausing && !mTileManager.jobQueue.isEmpty()) { if (!mPausing && mTileManager.hasTileJobs()) {
Gdx.app.postRunnable(new Runnable() { Gdx.app.postRunnable(new Runnable() {

View File

@ -40,7 +40,7 @@ public abstract class TileLoader extends PausableThread {
@Override @Override
protected void doWork() { protected void doWork() {
MapTile tile = mTileManager.jobQueue.poll(); MapTile tile = mTileManager.getTileJob();
if (tile == null) if (tile == null)
return; return;
@ -54,9 +54,10 @@ public abstract class TileLoader extends PausableThread {
return; return;
} }
if (!isInterrupted()) { if (isInterrupted())
mTileManager.passTile(tile, success); success = false;
}
mTileManager.jobCompleted(tile, success);
} }
public void jobCompleted(MapTile tile, boolean success) { public void jobCompleted(MapTile tile, boolean success) {
@ -75,6 +76,6 @@ public abstract class TileLoader extends PausableThread {
@Override @Override
protected boolean hasWork() { protected boolean hasWork() {
return !mTileManager.jobQueue.isEmpty(); return mTileManager.hasTileJobs();
} }
} }

View File

@ -81,7 +81,7 @@ public class TileManager {
/* package */TileSet mNewTiles; /* package */TileSet mNewTiles;
// job queue filled in TileManager and polled by TileLoaders // job queue filled in TileManager and polled by TileLoaders
final JobQueue jobQueue; private final JobQueue jobQueue;
private final QuadTreeIndex<MapTile> mIndex = new QuadTreeIndex<MapTile>() { private final QuadTreeIndex<MapTile> mIndex = new QuadTreeIndex<MapTile>() {
@ -294,6 +294,14 @@ public class TileManager {
jobQueue.clear(); jobQueue.clear();
} }
public boolean hasTileJobs() {
return !jobQueue.isEmpty();
}
public MapTile getTileJob() {
return jobQueue.poll();
}
/** /**
* Retrive a TileSet of current tiles. Tiles remain locked in cache until * 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 * the set is unlocked by either passing it again to this function or to
@ -537,7 +545,7 @@ public class TileManager {
* Tile ready for upload in TileRenderLayer * Tile ready for upload in TileRenderLayer
* @return caller does not care * @return caller does not care
*/ */
public void passTile(MapTile tile, boolean success) { public void jobCompleted(MapTile tile, boolean success) {
if (!success) { if (!success) {
tile.clear(); tile.clear();
@ -547,7 +555,7 @@ public class TileManager {
tile.state = STATE_NEW_DATA; tile.state = STATE_NEW_DATA;
// is volatile // is volatile
mTilesForUpload++; mTilesForUpload += 1;
// locked means the tile is visible or referenced by // locked means the tile is visible or referenced by
// a tile that might be visible. // a tile that might be visible.