mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Merge branch 'newBranch' into 'master'
Fix CardArtCache,LoadingCache Dispose Textures See merge request core-developers/forge!2805
This commit is contained in:
@@ -405,6 +405,7 @@ public class Forge implements ApplicationListener {
|
|||||||
try {
|
try {
|
||||||
endKeyInput(); //end key input before switching screens
|
endKeyInput(); //end key input before switching screens
|
||||||
ForgeAnimation.endAll(); //end all active animations before switching screens
|
ForgeAnimation.endAll(); //end all active animations before switching screens
|
||||||
|
ImageCache.disposeTexture();
|
||||||
|
|
||||||
currentScreen = screen0;
|
currentScreen = screen0;
|
||||||
currentScreen.setSize(screenWidth, screenHeight);
|
currentScreen.setSize(screenWidth, screenHeight);
|
||||||
|
|||||||
@@ -24,8 +24,12 @@ import com.badlogic.gdx.graphics.Texture;
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.cache.RemovalCause;
|
||||||
|
import com.google.common.cache.RemovalListener;
|
||||||
|
import com.google.common.cache.RemovalNotification;
|
||||||
import forge.ImageKeys;
|
import forge.ImageKeys;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
|
import forge.card.CardRenderer;
|
||||||
import forge.game.card.CardView;
|
import forge.game.card.CardView;
|
||||||
import forge.game.player.IHasIcon;
|
import forge.game.player.IHasIcon;
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
@@ -61,6 +65,14 @@ public class ImageCache {
|
|||||||
private static final LoadingCache<String, Texture> cache = CacheBuilder.newBuilder()
|
private static final LoadingCache<String, Texture> cache = CacheBuilder.newBuilder()
|
||||||
.maximumSize(400)
|
.maximumSize(400)
|
||||||
.expireAfterAccess(15, TimeUnit.MINUTES)
|
.expireAfterAccess(15, TimeUnit.MINUTES)
|
||||||
|
.removalListener(new RemovalListener<String, Texture>() {
|
||||||
|
@Override
|
||||||
|
public void onRemoval(RemovalNotification<String, Texture> removalNotification) {
|
||||||
|
if(removalNotification.wasEvicted()||removalNotification.getCause() == RemovalCause.EXPIRED) {
|
||||||
|
removalNotification.getValue().dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
.build(new ImageLoader());
|
.build(new ImageLoader());
|
||||||
public static final Texture defaultImage;
|
public static final Texture defaultImage;
|
||||||
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
||||||
@@ -85,9 +97,18 @@ public class ImageCache {
|
|||||||
|
|
||||||
public static void clear() {
|
public static void clear() {
|
||||||
cache.invalidateAll();
|
cache.invalidateAll();
|
||||||
|
cache.cleanUp();
|
||||||
missingIconKeys.clear();
|
missingIconKeys.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void disposeTexture(){
|
||||||
|
for (Texture t: cache.asMap().values()) {
|
||||||
|
t.dispose();
|
||||||
|
}
|
||||||
|
CardRenderer.clearcardArtCache();
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
public static Texture getImage(InventoryItem ii) {
|
public static Texture getImage(InventoryItem ii) {
|
||||||
return getImage(ii.getImageKey(false), true);
|
return getImage(ii.getImageKey(false), true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,10 @@ public class CardAvatarImage implements FImage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics g, float x, float y, float w, float h) {
|
public void draw(Graphics g, float x, float y, float w, float h) {
|
||||||
if (image == null) { //attempt to retrieve card art if needed
|
//force to get the avatar since the the cardartcache & loadingcache is always cleared on screen change or the battle bar will display black
|
||||||
image = CardRenderer.getCardArt(imageKey, false, false, false);
|
image = CardRenderer.getCardArt(imageKey, false, false, false);
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
return; //can't draw anything if can't be loaded yet
|
return; //can't draw anything if can't be loaded yet
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw scaled image into clipped region so it fills box while maintain aspect ratio
|
//draw scaled image into clipped region so it fills box while maintain aspect ratio
|
||||||
|
|||||||
@@ -196,6 +196,10 @@ public class CardRenderer {
|
|||||||
public static final float CARD_ART_RATIO = 1.302f;
|
public static final float CARD_ART_RATIO = 1.302f;
|
||||||
public static final float CARD_ART_HEIGHT_PERCENTAGE = 0.43f;
|
public static final float CARD_ART_HEIGHT_PERCENTAGE = 0.43f;
|
||||||
|
|
||||||
|
public static void clearcardArtCache(){
|
||||||
|
cardArtCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
//extract card art from the given card
|
//extract card art from the given card
|
||||||
public static FImageComplex getCardArt(IPaperCard pc) {
|
public static FImageComplex getCardArt(IPaperCard pc) {
|
||||||
return getCardArt(pc, false);
|
return getCardArt(pc, false);
|
||||||
|
|||||||
@@ -445,6 +445,7 @@ public class MatchController extends AbstractGuiGame {
|
|||||||
@Override
|
@Override
|
||||||
public void afterGameEnd() {
|
public void afterGameEnd() {
|
||||||
Forge.back();
|
Forge.back();
|
||||||
|
ImageCache.disposeTexture();
|
||||||
//view = null;
|
//view = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package forge.screens.match.winlose;
|
package forge.screens.match.winlose;
|
||||||
|
|
||||||
import forge.Forge;
|
import forge.Forge;
|
||||||
|
import forge.assets.ImageCache;
|
||||||
import forge.game.GameView;
|
import forge.game.GameView;
|
||||||
import forge.game.player.PlayerView;
|
import forge.game.player.PlayerView;
|
||||||
import forge.screens.match.MatchController;
|
import forge.screens.match.MatchController;
|
||||||
@@ -82,8 +83,10 @@ public class ControlWinLose {
|
|||||||
try { MatchController.getHostedMatch().endCurrentGame();
|
try { MatchController.getHostedMatch().endCurrentGame();
|
||||||
} catch (NullPointerException e) {}
|
} catch (NullPointerException e) {}
|
||||||
view.hide();
|
view.hide();
|
||||||
if(humancount == 0)
|
if(humancount == 0) {
|
||||||
Forge.back();
|
Forge.back();
|
||||||
|
ImageCache.disposeTexture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -45,7 +45,12 @@ public class ConquestRegion {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearArt() {
|
||||||
|
art = null;
|
||||||
|
}
|
||||||
|
|
||||||
public ISkinImage getArt() {
|
public ISkinImage getArt() {
|
||||||
|
clearArt(); //force clear this so it will be redrawn since loadingcache invalidates the cache every screen change
|
||||||
if (art == null) {
|
if (art == null) {
|
||||||
PaperCard pc = cardPool.getCard(artCardName);
|
PaperCard pc = cardPool.getCard(artCardName);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user