Manual RAM allocator

This commit is contained in:
artdeell 2021-03-20 16:27:01 +03:00
parent 665de1767d
commit b7220184ab
7 changed files with 46 additions and 16 deletions

View file

@ -70,6 +70,22 @@ public final class Tools
public static final String LIBNAME_OPTIFINE = "optifine:OptiFine";
public static void launchMinecraft(final LoggableActivity ctx, MinecraftAccount profile, String versionName) throws Throwable {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
((ActivityManager)ctx.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mi);
if(LauncherPreferences.PREF_RAM_ALLOCATION > (mi.availMem/1048576L)) {
ctx.runOnUiThread(new Runnable() {
@Override
public void run() {
androidx.appcompat.app.AlertDialog.Builder b = new androidx.appcompat.app.AlertDialog.Builder(ctx)
.setMessage(ctx.getString(R.string.memory_warning_msg,(mi.availMem/1048576L),LauncherPreferences.PREF_RAM_ALLOCATION))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {}
});
b.show();
}
});
}
JMinecraftVersionList.Version versionInfo = Tools.getVersionInfo(null,versionName);
PerVersionConfig.update();
PerVersionConfig.VersionConfig pvcConfig = PerVersionConfig.configMap.get(versionName);

View file

@ -5,6 +5,8 @@ import android.os.*;
import androidx.preference.*;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import android.content.*;
public class LauncherPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener
@ -45,6 +47,14 @@ public class LauncherPreferenceFragment extends PreferenceFragmentCompat impleme
seek6.setValue((int)(LauncherPreferences.PREF_MOUSESPEED*100f));
seek6.setMax(300);
seek6.setSuffix(" %");
CustomSeekBarPreference seek7 = (CustomSeekBarPreference) findPreference("allocation");
seek7.setMin(256);
if(Tools.CURRENT_ARCHITECTURE.contains("32")) seek7.setMax(800);
else seek7.setMax(4096);
seek7.setValue(LauncherPreferences.PREF_RAM_ALLOCATION);
seek7.setSuffix(" MB");
// #724 bug fix
if (seek5.getValue() < 25) {
seek5.setValue(100);

View file

@ -28,6 +28,7 @@ public class LauncherPreferences
public static boolean PREF_CHECK_LIBRARY_SHA = true;
public static boolean PREF_DISABLE_GESTURES = false;
public static float PREF_MOUSESPEED = 1f;
public static int PREF_RAM_ALLOCATION=300;
public static void loadPreferences() {
PREF_RENDERER = DEFAULT_PREF.getString("renderer", "opengles2");
PREF_BUTTONSIZE = DEFAULT_PREF.getInt("buttonscale", 100);
@ -47,6 +48,7 @@ public class LauncherPreferences
PREF_LANGUAGE = DEFAULT_PREF.getString("language", "default");
PREF_CHECK_LIBRARY_SHA = DEFAULT_PREF.getBoolean("checkLibraries",true);
PREF_DISABLE_GESTURES = DEFAULT_PREF.getBoolean("disableGestures",false);
PREF_RAM_ALLOCATION = DEFAULT_PREF.getInt("allocation",300);
// Get double of max Android heap to set default heap size
int androidHeap = (int) (Runtime.getRuntime().maxMemory() / 1024l / 512l);
int doubleAndroidHeap = androidHeap * 2;

View file

@ -286,25 +286,21 @@ public class JREUtils
List<String> javaArgList = new ArrayList<String>();
javaArgList.add(Tools.DIR_HOME_JRE + "/bin/java");
Tools.getJavaArgs(ctx, javaArgList);
if(LauncherPreferences.DEFAULT_PREF.getBoolean("autoRam",true)) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
((ActivityManager)ctx.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mi);
purgeArg(javaArgList,"-Xms");
purgeArg(javaArgList,"-Xmx");
if(Tools.CURRENT_ARCHITECTURE.contains("32") && ((mi.availMem / 1048576L)-50) > 300) {
/*if(Tools.CURRENT_ARCHITECTURE.contains("32") && ((mi.availMem / 1048576L)-50) > 300) {
javaArgList.add("-Xms300M");
javaArgList.add("-Xmx300M");
}else {
javaArgList.add("-Xms" + ((mi.availMem / 1048576L) - 50) + "M");
javaArgList.add("-Xmx" + ((mi.availMem / 1048576L) - 50) + "M");
}
}else {*/
javaArgList.add("-Xms" + LauncherPreferences.PREF_RAM_ALLOCATION + "M");
javaArgList.add("-Xmx" + LauncherPreferences.PREF_RAM_ALLOCATION + "M");
//}
ctx.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(ctx, ctx.getString(R.string.autoram_info_msg,((mi.availMem / 1048576L)-50)), Toast.LENGTH_SHORT).show();
Toast.makeText(ctx, ctx.getString(R.string.autoram_info_msg,LauncherPreferences.PREF_RAM_ALLOCATION), Toast.LENGTH_SHORT).show();
}
});
System.out.println(javaArgList);
}
javaArgList.addAll(args);
// For debugging only!

View file

@ -184,4 +184,6 @@
<string name="dl_library_sha_pass">Библиотека %s преверена и может быть использована</string>
<string name="mcl_disable_gestures">Отключение жестов</string>
<string name="mcl_disable_gestures_subtitle">Отключает жесты, такие как удержание, чтобы сломать блок, и нажатие, чтобы разместить блок.</string>
<string name="mcl_memory_allocation">Выделение памяти</string>
<string name="mcl_memory_allocation_subtitle">Управляет количеством выделенной игре памяти</string>
</resources>

View file

@ -220,4 +220,7 @@
<string name="mcl_setting_subtitle_mousespeed">Changes the speed of the software mouse</string>
<string name="customctrl_passthru">Mouse pass-thru</string>
<string name="customctrl_rounded">Rounded</string>
<string name="memory_warning_msg">The current amount of free RAM (%d) is lower than allocated RAM (%d), which may lead to crashes. Change the allocation if the game crashes.</string>
<string name="mcl_memory_allocation">Memory allocation</string>
<string name="mcl_memory_allocation_subtitle">Controls how much memory is given to Minecraft</string>
</resources>

View file

@ -53,18 +53,19 @@
android:summary="@string/mcl_setting_subtitle_hide_sidebar"
android:title="@string/mcl_setting_title_hide_sidebar"
app2:icon="@drawable/hide_sidebar" />
<net.kdt.pojavlaunch.prefs.CustomSeekBarPreference
android:key="allocation"
android:icon="@drawable/ic_auto_ram"
android:summary="@string/mcl_memory_allocation_subtitle"
android:title="@string/mcl_memory_allocation"
app2:showSeekBarValue="true"
app2:selectable="false"/>
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="ignoreNotch"
android:summary="@string/mcl_setting_subtitle_ignore_notch"
android:title="@string/mcl_setting_title_ignore_notch"
app2:icon="@drawable/ignore_notch" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:icon="@drawable/ic_auto_ram"
android:key="autoRam"
android:summary="@string/auto_ram_subtitle"
android:title="@string/auto_ram_title" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_map_rmb"