gwt: use LoadDelayTask to only load max one tile per frame
This commit is contained in:
parent
a46940a6b1
commit
818ea0b0c7
@ -0,0 +1,19 @@
|
||||
package org.oscim.layers.tile;
|
||||
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
public abstract class LoadDelayTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (MapRenderer.frametime == TileLoader.lastLoadTime) {
|
||||
Gdx.app.postRunnable(this);
|
||||
return;
|
||||
}
|
||||
continueLoading();
|
||||
}
|
||||
|
||||
public abstract void continueLoading();
|
||||
}
|
@ -19,12 +19,16 @@ import static org.oscim.tiling.ITileDataSink.QueryResult.SUCCESS;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.Timer;
|
||||
|
||||
public abstract class TileLoader implements ITileDataSink {
|
||||
final static Logger log = LoggerFactory.getLogger(TileLoader.class);
|
||||
|
||||
private final TileManager mTileManager;
|
||||
private Timer mTimer;
|
||||
@ -98,6 +102,8 @@ public abstract class TileLoader implements ITileDataSink {
|
||||
}
|
||||
}
|
||||
|
||||
public static long lastLoadTime;
|
||||
|
||||
/**
|
||||
* Callback to be called by TileDataSource when finished
|
||||
* loading or on failure. MUST BE CALLED IN ANY CASE!
|
||||
@ -105,6 +111,10 @@ public abstract class TileLoader implements ITileDataSink {
|
||||
@Override
|
||||
public void completed(QueryResult result) {
|
||||
boolean success = (result == SUCCESS) && !isInterrupted;
|
||||
long now = MapRenderer.frametime;
|
||||
|
||||
log.debug("completed {} diff time:{}", mTile, (now - lastLoadTime));
|
||||
lastLoadTime = now;
|
||||
|
||||
mTileManager.jobCompleted(mTile, success);
|
||||
mTile = null;
|
||||
@ -138,4 +148,8 @@ public abstract class TileLoader implements ITileDataSink {
|
||||
|
||||
}
|
||||
|
||||
public static void postLoadDelay(LoadDelayTask task) {
|
||||
Gdx.app.postRunnable(task);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
import org.oscim.layers.tile.TileLoader;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.slf4j.Logger;
|
||||
@ -58,25 +59,31 @@ public class UrlTileDataSource implements ITileDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
public void process(InputStream is) {
|
||||
public void process(final InputStream is) {
|
||||
TileLoader.postLoadDelay(new org.oscim.layers.tile.LoadDelayTask() {
|
||||
|
||||
boolean win = false;
|
||||
if (is != null) {
|
||||
try {
|
||||
win = mTileDecoder.decode(mTile, mSink, is);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@Override
|
||||
public void continueLoading() {
|
||||
boolean win = false;
|
||||
if (is != null) {
|
||||
try {
|
||||
win = mTileDecoder.decode(mTile, mSink, is);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!win)
|
||||
log.debug("{} failed", mTile);
|
||||
|
||||
mConn.requestCompleted();
|
||||
|
||||
mSink.completed(win ? SUCCESS : FAILED);
|
||||
|
||||
mTile = null;
|
||||
mSink = null;
|
||||
}
|
||||
}
|
||||
if (!win)
|
||||
log.debug("{} failed", mTile);
|
||||
});
|
||||
|
||||
mConn.requestCompleted();
|
||||
|
||||
mSink.completed(win ? SUCCESS : FAILED);
|
||||
|
||||
mTile = null;
|
||||
mSink = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@ import static org.oscim.tiling.ITileDataSink.QueryResult.SUCCESS;
|
||||
|
||||
import org.oscim.gdx.client.GwtBitmap;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
import org.oscim.layers.tile.TileLoader;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.source.LwHttp;
|
||||
@ -75,8 +76,14 @@ public abstract class BitmapTileSource extends UrlTileSource {
|
||||
|
||||
img.addLoadHandler(new LoadHandler() {
|
||||
public void onLoad(LoadEvent event) {
|
||||
sink.setTileImage(new GwtBitmap(img));
|
||||
sink.completed(SUCCESS);
|
||||
TileLoader.postLoadDelay(new org.oscim.layers.tile.LoadDelayTask() {
|
||||
|
||||
@Override
|
||||
public void continueLoading() {
|
||||
sink.setTileImage(new GwtBitmap(img));
|
||||
sink.completed(SUCCESS);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user