mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-14 17:58:01 +00:00
[Android] Increase default cache size
-Increase the default cache size depending on the device detected RAM (higher end tablets and phones will have greater benefit for having large RAM).
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package forge.app;
|
package forge.app;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@@ -56,9 +57,15 @@ public class Main extends AndroidApplication {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
//get total device RAM in mb
|
||||||
|
ActivityManager actManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
||||||
|
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
|
||||||
|
actManager.getMemoryInfo(memInfo);
|
||||||
|
int totalMemory = Math.round(memInfo.totalMem / 1024f / 1024f);
|
||||||
|
|
||||||
boolean permissiongranted = checkPermission();
|
boolean permissiongranted = checkPermission();
|
||||||
Gadapter = new AndroidAdapter(this.getContext());
|
Gadapter = new AndroidAdapter(this.getContext());
|
||||||
initForge(Gadapter, permissiongranted);
|
initForge(Gadapter, permissiongranted, totalMemory);
|
||||||
|
|
||||||
//permission
|
//permission
|
||||||
if(!permissiongranted){
|
if(!permissiongranted){
|
||||||
@@ -185,7 +192,7 @@ public class Main extends AndroidApplication {
|
|||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initForge(AndroidAdapter adapter, boolean permissiongranted){
|
private void initForge(AndroidAdapter adapter, boolean permissiongranted, int totalRAM){
|
||||||
boolean isPortrait;
|
boolean isPortrait;
|
||||||
if (permissiongranted){
|
if (permissiongranted){
|
||||||
//establish assets directory
|
//establish assets directory
|
||||||
@@ -225,12 +232,12 @@ public class Main extends AndroidApplication {
|
|||||||
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(Forge.getApp(new AndroidClipboard(), adapter, assetsDir, propertyConfig, isPortrait));
|
initialize(Forge.getApp(new AndroidClipboard(), adapter, assetsDir, propertyConfig, isPortrait, totalRAM));
|
||||||
} else {
|
} else {
|
||||||
isPortrait = true;
|
isPortrait = true;
|
||||||
//set current orientation
|
//set current orientation
|
||||||
Main.this.setRequestedOrientation(Main.this.getResources().getConfiguration().orientation);
|
Main.this.setRequestedOrientation(Main.this.getResources().getConfiguration().orientation);
|
||||||
initialize(Forge.getApp(new AndroidClipboard(), adapter, "", false, isPortrait));
|
initialize(Forge.getApp(new AndroidClipboard(), adapter, "", false, isPortrait, totalRAM));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ public class Main extends IOSApplication.Delegate {
|
|||||||
config.useAccelerometer = false;
|
config.useAccelerometer = false;
|
||||||
config.useCompass = false;
|
config.useCompass = false;
|
||||||
ForgePreferences prefs = FModel.getPreferences();
|
ForgePreferences prefs = FModel.getPreferences();
|
||||||
boolean propertyConfig = prefs != null && prefs.getPrefBoolean(ForgePreferences.FPref.UI_NETPLAY_COMPAT);
|
boolean propertyConfig = prefs != null && prefs.getPrefBoolean(ForgePreferences.FPref.UI_NETPLAY_COMPAT);//todo get totalRAM
|
||||||
final ApplicationListener app = Forge.getApp(new IOSClipboard(), new IOSAdapter(), assetsDir, propertyConfig, false);
|
final ApplicationListener app = Forge.getApp(new IOSClipboard(), new IOSAdapter(), assetsDir, propertyConfig, false, 0);
|
||||||
final IOSApplication iosApp = new IOSApplication(app, config);
|
final IOSApplication iosApp = new IOSApplication(app, config);
|
||||||
return iosApp;
|
return iosApp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ public class Main {
|
|||||||
|
|
||||||
ForgePreferences prefs = FModel.getPreferences();
|
ForgePreferences prefs = FModel.getPreferences();
|
||||||
boolean propertyConfig = prefs != null && prefs.getPrefBoolean(ForgePreferences.FPref.UI_NETPLAY_COMPAT);
|
boolean propertyConfig = prefs != null && prefs.getPrefBoolean(ForgePreferences.FPref.UI_NETPLAY_COMPAT);
|
||||||
new LwjglApplication(Forge.getApp(new LwjglClipboard(), new DesktopAdapter(switchOrientationFile),
|
new LwjglApplication(Forge.getApp(new LwjglClipboard(), new DesktopAdapter(switchOrientationFile),//todo get totalRAM
|
||||||
desktopMode ? desktopModeAssetsDir : assetsDir, propertyConfig, false), config);
|
desktopMode ? desktopModeAssetsDir : assetsDir, propertyConfig, false, 0), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DesktopAdapter implements IDeviceAdapter {
|
private static class DesktopAdapter implements IDeviceAdapter {
|
||||||
|
|||||||
@@ -71,14 +71,20 @@ public class Forge implements ApplicationListener {
|
|||||||
public static boolean hdstart = false;
|
public static boolean hdstart = false;
|
||||||
public static boolean isPortraitMode = false;
|
public static boolean isPortraitMode = false;
|
||||||
public static boolean gameInProgress = false;
|
public static boolean gameInProgress = false;
|
||||||
|
public static int cacheSize = 400;
|
||||||
|
public static int totalDeviceRAM = 0;
|
||||||
|
|
||||||
public static ApplicationListener getApp(Clipboard clipboard0, IDeviceAdapter deviceAdapter0, String assetDir0, boolean value, boolean androidOrientation) {
|
public static ApplicationListener getApp(Clipboard clipboard0, IDeviceAdapter deviceAdapter0, String assetDir0, boolean value, boolean androidOrientation, int totalRAM) {
|
||||||
if (GuiBase.getInterface() == null) {
|
if (GuiBase.getInterface() == null) {
|
||||||
clipboard = clipboard0;
|
clipboard = clipboard0;
|
||||||
deviceAdapter = deviceAdapter0;
|
deviceAdapter = deviceAdapter0;
|
||||||
GuiBase.setInterface(new GuiMobile(assetDir0));
|
GuiBase.setInterface(new GuiMobile(assetDir0));
|
||||||
GuiBase.enablePropertyConfig(value);
|
GuiBase.enablePropertyConfig(value);
|
||||||
isPortraitMode = androidOrientation;
|
isPortraitMode = androidOrientation;
|
||||||
|
totalDeviceRAM = totalRAM;
|
||||||
|
//increase cacheSize for devices with RAM more than 5GB, default is 400. Some phones have more than 10GB RAM (Mi 10, OnePlus 8, S20, etc..)
|
||||||
|
if (totalDeviceRAM>5000) //devices with more than 10GB RAM will have 1000 Cache size, 700 Cache size for morethan 5GB RAM
|
||||||
|
cacheSize = totalDeviceRAM>10000 ? 1000: 700;
|
||||||
}
|
}
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
@@ -142,8 +148,12 @@ public class Forge implements ApplicationListener {
|
|||||||
splashScreen.getProgressBar().setDescription(localizer.getMessage("lblFinishingStartup"));
|
splashScreen.getProgressBar().setDescription(localizer.getMessage("lblFinishingStartup"));
|
||||||
|
|
||||||
//add reminder to preload
|
//add reminder to preload
|
||||||
if (enablePreloadExtendedArt)
|
if (enablePreloadExtendedArt) {
|
||||||
splashScreen.getProgressBar().setDescription(localizer.getMessage("lblPreloadExtendedArt"));
|
splashScreen.getProgressBar().setDescription(localizer.getMessage("lblPreloadExtendedArt")+"\nDetected RAM: " +totalDeviceRAM+"MB. Cache size: "+cacheSize);
|
||||||
|
} else {
|
||||||
|
splashScreen.getProgressBar().setDescription(localizer.getMessage("lblFinishingStartup")+"\nDetected RAM: " +totalDeviceRAM+"MB. Cache size: "+cacheSize);
|
||||||
|
}
|
||||||
|
|
||||||
Gdx.app.postRunnable(new Runnable() {
|
Gdx.app.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class ImageCache {
|
|||||||
|
|
||||||
private static final Set<String> missingIconKeys = new HashSet<>();
|
private static final Set<String> missingIconKeys = new HashSet<>();
|
||||||
private static final LoadingCache<String, Texture> cache = CacheBuilder.newBuilder()
|
private static final LoadingCache<String, Texture> cache = CacheBuilder.newBuilder()
|
||||||
.maximumSize(400)
|
.maximumSize(Forge.cacheSize)
|
||||||
.expireAfterAccess(15, TimeUnit.MINUTES)
|
.expireAfterAccess(15, TimeUnit.MINUTES)
|
||||||
.removalListener(new RemovalListener<String, Texture>() {
|
.removalListener(new RemovalListener<String, Texture>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user