From ac790b1ece28c696a333ad9b0828a218f9e2701c Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 11 Jul 2021 16:09:24 -0400 Subject: [PATCH] v0.9.4: game now periodically clears texture cache when changing scenes --- .../scenes/AlchemyScene.java | 4 +++ .../scenes/AmuletScene.java | 4 +++ .../scenes/GameScene.java | 4 +++ .../scenes/InterlevelScene.java | 26 ++++++++++++++----- .../scenes/IntroScene.java | 4 +++ .../scenes/PixelScene.java | 22 +++++++++------- 6 files changed, 49 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java index 34aff6d12..8272aca68 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java @@ -80,6 +80,10 @@ public class AlchemyScene extends PixelScene { private RedButton btnCombine; private static final int BTN_SIZE = 28; + + { + inGameScene = true; + } @Override public void create() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AmuletScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AmuletScene.java index a62cda40c..23d919bc0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AmuletScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AmuletScene.java @@ -45,6 +45,10 @@ public class AmuletScene extends PixelScene { public static boolean noText = false; private Image amulet; + + { + inGameScene = true; + } @Override public void create() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 7a0d11e1a..b0f7efd1f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -171,6 +171,10 @@ public class GameScene extends PixelScene { private LootIndicator loot; private ActionIndicator action; private ResumeIndicator resume; + + { + inGameScene = true; + } @Override public void create() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java index 74cf029cc..59a1467d1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java @@ -89,6 +89,12 @@ public class InterlevelScene extends PixelScene { private static Thread thread; private static Exception error = null; private float waitingTime; + + public static int lastRegion = -1; + + { + inGameScene = true; + } @Override public void create() { @@ -136,12 +142,20 @@ public class InterlevelScene extends PixelScene { scrollSpeed = returnDepth > Dungeon.depth ? 15 : -15; break; } - if (loadingDepth <= 5) loadingAsset = Assets.Interfaces.LOADING_SEWERS; - else if (loadingDepth <= 10) loadingAsset = Assets.Interfaces.LOADING_PRISON; - else if (loadingDepth <= 15) loadingAsset = Assets.Interfaces.LOADING_CAVES; - else if (loadingDepth <= 20) loadingAsset = Assets.Interfaces.LOADING_CITY; - else if (loadingDepth <= 25) loadingAsset = Assets.Interfaces.LOADING_HALLS; - else loadingAsset = Assets.Interfaces.SHADOW; + + //flush the texture cache whenever moving between regions, helps reduce memory load + int region = (int)Math.ceil(loadingDepth / 5f); + if (region != lastRegion){ + TextureCache.clear(); + lastRegion = region; + } + + if (lastRegion == 1) loadingAsset = Assets.Interfaces.LOADING_SEWERS; + else if (lastRegion == 2) loadingAsset = Assets.Interfaces.LOADING_PRISON; + else if (lastRegion == 3) loadingAsset = Assets.Interfaces.LOADING_CAVES; + else if (lastRegion == 4) loadingAsset = Assets.Interfaces.LOADING_CITY; + else if (lastRegion == 5) loadingAsset = Assets.Interfaces.LOADING_HALLS; + else loadingAsset = Assets.Interfaces.SHADOW; //slow down transition when displaying an install prompt if (Updates.isInstallable()){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/IntroScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/IntroScene.java index f3c6ebbbe..6d350892e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/IntroScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/IntroScene.java @@ -26,6 +26,10 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory; import com.watabou.noosa.Game; public class IntroScene extends PixelScene { + + { + inGameScene = true; + } @Override public void create() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java index e1724d579..97eaa85b9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java @@ -67,6 +67,8 @@ public class PixelScene extends Scene { //stylized 3x5 bitmapped pixel font. Only latin characters supported. public static BitmapText.Font pixelFont; + protected boolean inGameScene = false; + @Override public void create() { @@ -74,6 +76,12 @@ public class PixelScene extends Scene { GameScene.scene = null; + //flush the texture cache whenever moving from ingame to menu, helps reduce memory load + if (!inGameScene && InterlevelScene.lastRegion != -1){ + InterlevelScene.lastRegion = -1; + TextureCache.clear(); + } + float minWidth, minHeight; if (landscape()) { minWidth = MIN_WIDTH_L; @@ -100,15 +108,11 @@ public class PixelScene extends Scene { uiCamera = Camera.createFullscreen( uiZoom ); Camera.add( uiCamera ); - if (pixelFont == null) { - - // 3x5 (6) - pixelFont = Font.colorMarked( - TextureCache.get( Assets.Fonts.PIXELFONT), 0x00000000, BitmapText.Font.LATIN_FULL ); - pixelFont.baseLine = 6; - pixelFont.tracking = -1; - - } + // 3x5 (6) + pixelFont = Font.colorMarked( + TextureCache.get( Assets.Fonts.PIXELFONT), 0x00000000, BitmapText.Font.LATIN_FULL ); + pixelFont.baseLine = 6; + pixelFont.tracking = -1; //set up the texture size which rendered text will use for any new glyphs. int renderedTextPageSize;