Compare commits

..
5 changed files with 63 additions and 19 deletions

No files matched your search

@@ -21,7 +21,14 @@ public class ModpackInstaller {
public static ModLoader installModpack(ModDetail modDetail, int selectedVersion, InstallFunction installFunction) throws IOException {
String versionUrl = modDetail.versionUrls[selectedVersion];
String versionHash = modDetail.versionHashes[selectedVersion];
String modpackName = modDetail.title.toLowerCase(Locale.ROOT).trim().replace(" ", "_" );
String modpackName = (modDetail.title.toLowerCase(Locale.ROOT) + " " + modDetail.versionNames[selectedVersion])
.trim().replaceAll("[\\\\/:*?\"<>| \\t\\n]", "_" );
if (versionHash != null) {
modpackName += "_" + versionHash;
}
if (modpackName.length() > 255){
modpackName = modpackName.substring(0,255);
}
// Build a new minecraft instance, folder first
@@ -23,6 +23,8 @@ public class CustomSeekBarPreference extends SeekBarPreference {
private int mMin;
/** The textview associated by default to the preference */
private TextView mTextView;
/** Seekbar increment in case the max gets set */
private final int mIncrement;
@SuppressLint("PrivateResource")
@@ -31,6 +33,7 @@ public class CustomSeekBarPreference extends SeekBarPreference {
try (TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.SeekBarPreference, defStyleAttr, defStyleRes)) {
mMin = a.getInt(R.styleable.SeekBarPreference_min, 0);
mIncrement = a.getInt(R.styleable.SeekBarPreference_seekBarIncrement, 0);
}
}
@@ -111,7 +114,12 @@ public class CustomSeekBarPreference extends SeekBarPreference {
*/
public void setRange(int min, int max){
setMin(min);
setMax(max);
setMaxKeepIncrement(max);
}
public void setMaxKeepIncrement(int max) {
super.setMax(max);
setSeekBarIncrement(mIncrement);
}
@@ -141,14 +141,14 @@ public class LauncherPreferences {
*/
private static int findBestRAMAllocation(Context ctx){
int deviceRam = Tools.getTotalDeviceMemory(ctx);
if (deviceRam < 1024) return 300;
if (deviceRam < 1536) return 450;
if (deviceRam < 2048) return 600;
if (deviceRam < 1024) return 296;
if (deviceRam < 1536) return 448;
if (deviceRam < 2048) return 656;
// Limit the max for 32 bits devices more harshly
if (is32BitsDevice()) return 700;
if (is32BitsDevice()) return 696;
if (deviceRam < 3064) return 936;
if (deviceRam < 4096) return 1148;
if (deviceRam < 4096) return 1144;
if (deviceRam < 6144) return 1536;
return 2048; //Default RAM allocation for 64 bits
}
@@ -38,7 +38,7 @@ public class LauncherPreferenceJavaFragment extends LauncherPreferenceFragment {
if(is32BitsDevice() || deviceRam < 2048) maxRAM = Math.min(1024, deviceRam);
else maxRAM = deviceRam - (deviceRam < 3064 ? 800 : 1024); //To have a minimum for the device to breathe
memorySeekbar.setMax(maxRAM);
memorySeekbar.setMaxKeepIncrement(maxRAM);
memorySeekbar.setValue(ramAllocation);
memorySeekbar.setSuffix(" MB");
@@ -4,6 +4,7 @@ import android.opengl.EGL14;
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLSurface;
import android.opengl.GLES20;
import android.opengl.GLES30;
import android.util.Log;
@@ -46,13 +47,27 @@ public class GLInfoUtils {
private static EGLContext tryCreateContext(EGLDisplay eglDisplay, EGLConfig config, int majorVersion) {
int[] egl_context_attributes = new int[] { EGL14.EGL_CONTEXT_CLIENT_VERSION, majorVersion, EGL14.EGL_NONE };
EGLContext context = EGL14.eglCreateContext(eglDisplay, config, EGL14.EGL_NO_CONTEXT, egl_context_attributes, 0);
if(context == EGL14.EGL_NO_CONTEXT) {
if(context == EGL14.EGL_NO_CONTEXT || context == null) {
Log.e("GLInfoUtils", "Failed to create a context with major version "+majorVersion);
return null;
}
return context;
}
private static EGLContext tryMakeCurrent(EGLDisplay eglDisplay, EGLConfig config, EGLSurface surface, int majorVersion) {
EGLContext context = tryCreateContext(eglDisplay, config, majorVersion);
if(context == null) return null;
// Old Mali drivers are broken, and will actually let us create a context with GLES 3
// But won't let us make it current, which will break the check anyway...
boolean makeCurrentResult = EGL14.eglMakeCurrent(eglDisplay, surface, surface, context);
if(!makeCurrentResult) {
Log.i("GLInfoUtils", "Failed to make context GL version "+majorVersion +" current");
EGL14.eglDestroyContext(eglDisplay, context);
return null;
}
return context;
}
private static boolean initAndQueryInfo() {
// This is here just to satisfy Android M which incorrectly null-checks it
int[] egl_version = new int[2];
@@ -64,7 +79,7 @@ public class GLInfoUtils {
EGL14.EGL_RED_SIZE, 8,
EGL14.EGL_ALPHA_SIZE, 8,
EGL14.EGL_DEPTH_SIZE, 24,
EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT|EGL14.EGL_WINDOW_BIT,
EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT,
EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
EGL14.EGL_NONE
};
@@ -76,19 +91,33 @@ public class GLInfoUtils {
return false;
}
int contextGLVersion = 3;
// Create PBuffer surface as some devices might actually not support surfaceless.
int[] pbuffer_attributes = new int[] {
EGL14.EGL_WIDTH, 16,
EGL14.EGL_HEIGHT, 16,
EGL14.EGL_NONE
};
EGLContext context;
context = tryCreateContext(eglDisplay, config[0], 3);
if(context == null) {
contextGLVersion = 2;
context = tryCreateContext(eglDisplay, config[0], 2);
EGLSurface surface = EGL14.eglCreatePbufferSurface(eglDisplay, config[0], pbuffer_attributes, 0);
if(surface == null || surface == EGL14.EGL_NO_SURFACE) {
Log.e("GLInfoUtils", "Failed to create pbuffer surface");
EGL14.eglTerminate(eglDisplay);
return false;
}
if(!EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, context)) {
Log.e("GLInfoUtils", "Failed to make context current");
EGL14.eglDestroyContext(eglDisplay, context);
int contextGLVersion = 3;
EGLContext context = tryMakeCurrent(eglDisplay, config[0], surface, contextGLVersion);
if(context == null) {
contextGLVersion = 2;
context = tryMakeCurrent(eglDisplay, config[0], surface, contextGLVersion);
}
// Creation/currenting failed in both cases
if(context == null) {
Log.e("GLInfoUtils", "Failed to create and make context current");
EGL14.eglDestroySurface(eglDisplay, surface);
EGL14.eglTerminate(eglDisplay);
return false;
}
info = queryInfo(contextGLVersion);