mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Support delay loading images
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user