Support delay loading images

This commit is contained in:
drdev
2014-08-02 15:18:25 +00:00
parent 146a73185d
commit 0b414a22c9
2 changed files with 22 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ import com.badlogic.gdx.utils.Clipboard;
import forge.assets.AssetsDownloader;
import forge.assets.FSkin;
import forge.assets.FSkinFont;
import forge.assets.ImageCache;
import forge.error.BugReporter;
import forge.error.ExceptionHandler;
import forge.model.FModel;
@@ -205,6 +206,7 @@ public class Forge implements ApplicationListener {
@Override
public void render() {
try {
ImageCache.allowSingleLoad();
Animation.advanceAll();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Clear the screen.

View File

@@ -58,6 +58,12 @@ public class ImageCache {
private static final LoadingCache<String, Texture> cache = CacheBuilder.newBuilder().softValues().build(new ImageLoader());
public static final Texture defaultImage;
private static boolean imageLoaded, delayLoadRequested;
public static void allowSingleLoad() {
imageLoaded = false; //reset at the beginning of each render
delayLoadRequested = false;
}
static {
Texture defImage = null;
try {
@@ -132,9 +138,21 @@ public class ImageCache {
}
// Load from file and add to cache if not found in cache initially.
Texture image;
Texture image = cache.getIfPresent(imageKey);
if (image != null) { return image; }
if (imageLoaded) { //prevent loading more than one image each render for performance
if (!delayLoadRequested) {
//ensure images continue to load even if no input is being received
delayLoadRequested = true;
Gdx.graphics.requestRendering();
}
return null;
}
imageLoaded = true;
try {
image = ImageCache.cache.get(imageKey);
image = cache.get(imageKey);
}
catch (final ExecutionException ex) {
if (!(ex.getCause() instanceof NullPointerException)) {