async loading
This commit is contained in:
parent
407e7126d6
commit
7381c9b298
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.layers.tile;
|
package org.oscim.layers.tile;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.utils.Timer;
|
import com.badlogic.gdx.utils.Timer;
|
||||||
|
|
||||||
public abstract class TileLoader {
|
public abstract class TileLoader {
|
||||||
@ -52,7 +53,7 @@ public abstract class TileLoader {
|
|||||||
public void proceed() {
|
public void proceed() {
|
||||||
mPausing = false;
|
mPausing = false;
|
||||||
// FIXME
|
// FIXME
|
||||||
hasWork = false;
|
mWorking = false;
|
||||||
if (!mTileManager.jobQueue.isEmpty())
|
if (!mTileManager.jobQueue.isEmpty())
|
||||||
go();
|
go();
|
||||||
}
|
}
|
||||||
@ -64,33 +65,31 @@ public abstract class TileLoader {
|
|||||||
public void start() {
|
public void start() {
|
||||||
mPausing = false;
|
mPausing = false;
|
||||||
}
|
}
|
||||||
boolean hasWork;
|
|
||||||
|
boolean mWorking;
|
||||||
|
|
||||||
public void go() {
|
public void go() {
|
||||||
if (hasWork)
|
if (mWorking) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapTile tile = mTileManager.jobQueue.poll();
|
||||||
|
|
||||||
|
if (tile == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final TileLoader loader = this;
|
try {
|
||||||
mTimer.scheduleTask(new Timer.Task() {
|
tile.loader = this;
|
||||||
|
executeJob(tile);
|
||||||
|
|
||||||
@Override
|
mWorking = true;
|
||||||
public void run() {
|
|
||||||
|
|
||||||
MapTile tile = mTileManager.jobQueue.poll();
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
if (tile == null)
|
tile.clear();
|
||||||
return;
|
jobCompleted(tile, false);
|
||||||
|
}
|
||||||
try {
|
|
||||||
tile.loader = loader;
|
|
||||||
executeJob(tile);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0.01f);
|
|
||||||
hasWork = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void jobCompleted(MapTile tile, boolean success) {
|
public void jobCompleted(MapTile tile, boolean success) {
|
||||||
@ -100,8 +99,18 @@ public abstract class TileLoader {
|
|||||||
mTileManager.passTile(tile);
|
mTileManager.passTile(tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasWork = false;
|
mWorking = false;
|
||||||
if (!mPausing && !mTileManager.jobQueue.isEmpty())
|
|
||||||
go();
|
if (!mPausing && !mTileManager.jobQueue.isEmpty()){
|
||||||
|
|
||||||
|
Gdx.app.postRunnable(new Runnable(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
go();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,7 +76,6 @@ public class BitmapTileLayer extends TileLayer<TileLoader> {
|
|||||||
tile.loader.jobCompleted(tile, false);
|
tile.loader.jobCompleted(tile, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,6 +87,7 @@ public class BitmapTileLayer extends TileLayer<TileLoader> {
|
|||||||
loadImage(tile, url.toString());
|
loadImage(tile, url.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
tile.loader.jobCompleted(tile, false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user