"Localize" renderer selection mechanism to several other classes
Add renderer changer to Per-Version Config
Move Per-Version Config to a separate class
This commit is contained in:
artdeell 2021-07-22 16:20:15 +03:00
parent ea6bd5f5a3
commit 67fac9a610
8 changed files with 182 additions and 94 deletions

View File

@ -103,7 +103,7 @@ public class BaseMainActivity extends LoggableActivity {
private File logFile;
private PrintStream logStream;
private PerVersionConfig.VersionConfig config;
/*
private LinearLayout contentCanvas;
private AWTSurfaceView contentCanvasView;
@ -140,14 +140,17 @@ public class BaseMainActivity extends LoggableActivity {
setTitle("Minecraft " + mProfile.selectedVersion);
PerVersionConfig.update();
PerVersionConfig.VersionConfig cfg = PerVersionConfig.configMap.get(mProfile.selectedVersion);
config = PerVersionConfig.configMap.get(mProfile.selectedVersion);
String runtime = LauncherPreferences.PREF_DEFAULT_RUNTIME;
if(cfg != null) {
if(cfg.selectedRuntime != null) {
if(MultiRTUtils.forceReread(cfg.selectedRuntime).versionString != null) {
runtime = cfg.selectedRuntime;
if(config != null) {
if(config.selectedRuntime != null) {
if(MultiRTUtils.forceReread(config.selectedRuntime).versionString != null) {
runtime = config.selectedRuntime;
}
}
if(config.renderer != null) {
Tools.LOCAL_RENDERER = config.renderer;
}
}
MultiRTUtils.setRuntimeNamed(this,runtime);
// Minecraft 1.13+
@ -904,10 +907,12 @@ public class BaseMainActivity extends LoggableActivity {
mLogObserver.startWatching();
}
*/
if(Tools.LOCAL_RENDERER == null) {
Tools.LOCAL_RENDERER = LauncherPreferences.PREF_RENDERER;
}
appendlnToLog("--------- beggining with launcher debug");
appendlnToLog("Info: Launcher version: " + BuildConfig.VERSION_NAME);
if (LauncherPreferences.PREF_RENDERER.equals("vulkan_zink")) {
if (Tools.LOCAL_RENDERER.equals("vulkan_zink")) {
checkVulkanZinkIsSupported();
}
checkLWJGL3Installed();

View File

@ -45,6 +45,7 @@ public final class Tools
public static String DIR_DATA = "/data/data/" + BuildConfig.APPLICATION_ID;
public static String MULTIRT_HOME = DIR_DATA+"/runtimes";
public static String LOCAL_RENDERER = null;
public static String CURRENT_ARCHITECTURE;
// New since 3.3.1
@ -79,7 +80,8 @@ public final class Tools
ctx.runOnUiThread(() -> {
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, (dialogInterface, i) -> {synchronized(memoryErrorLock){memoryErrorLock.notifyAll();}});
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {synchronized(memoryErrorLock){memoryErrorLock.notifyAll();}})
.setOnCancelListener((i) -> {synchronized(memoryErrorLock){memoryErrorLock.notifyAll();}});
b.show();
});
synchronized (memoryErrorLock) {
@ -155,7 +157,7 @@ public final class Tools
javaArgList.add(cacioClasspath.toString());
}
public static void getJavaArgs(Context ctx, List<String> javaArgList) {
public static void getJavaArgs(Context ctx, List<String> javaArgList, String renderLib) {
List<String> overrideableArgList = new ArrayList<String>();
overrideableArgList.add("-Djava.home=" + Tools.DIR_HOME_JRE);
@ -173,7 +175,7 @@ public final class Tools
// javaArgList.add("-Dorg.lwjgl.libname=liblwjgl3.so");
// javaArgList.add("-Dorg.lwjgl.system.jemalloc.libname=libjemalloc.so");
overrideableArgList.add("-Dorg.lwjgl.opengl.libname=" + LauncherPreferences.PREF_CUSTOM_OPENGL_LIBNAME);
overrideableArgList.add("-Dorg.lwjgl.opengl.libname=" + renderLib);
// overrideableArgList.add("-Dorg.lwjgl.opengl.libname=libgl4es_115.so");
// javaArgList.add("-Dorg.lwjgl.opengl.libname=libRegal.so");

View File

@ -86,22 +86,6 @@ public class LauncherPreferences
if (PREF_RENDERER.equals("2") || PREF_RENDERER.equals("3")) {
PREF_RENDERER = "opengles" + PREF_RENDERER;
}
switch (PREF_RENDERER) {
case "opengles2":
PREF_CUSTOM_OPENGL_LIBNAME = "libgl4es_114.so";
break;
case "opengles2_5":
case "opengles3":
PREF_CUSTOM_OPENGL_LIBNAME = "libgl4es_115.so";
break;
case "vulkan_zink":
PREF_CUSTOM_OPENGL_LIBNAME = "libOSMesa_8.so";
break;
default:
throw new RuntimeException("Undefined renderer: " + PREF_RENDERER);
}
String argLwjglLibname = "-Dorg.lwjgl.opengl.libname=";
for (String arg : PREF_CUSTOM_JAVA_ARGS.split(" ")) {
if (arg.startsWith(argLwjglLibname)) {

View File

@ -0,0 +1,120 @@
package net.kdt.pojavlaunch.prefs;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import androidx.appcompat.app.AlertDialog;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
import net.kdt.pojavlaunch.multirt.RTSpinnerAdapter;
import net.kdt.pojavlaunch.tasks.RefreshVersionListTask;
import net.kdt.pojavlaunch.value.PerVersionConfig;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class PerVersionConfigDialog{
final Context ctx;
final AlertDialog dialog;
final View v;
List<MultiRTUtils.Runtime> runtimes;
final Spinner javaVMSpinner;
final Spinner rendererSpinner;
final EditText customDirText;
final EditText jvmArgsEditText;
final List<String> renderNames;
String selectedGameVersion = null;
public PerVersionConfigDialog(Context _ctx) {
ctx = _ctx;
v = LayoutInflater.from(ctx).inflate(R.layout.pvc_popup,null);
javaVMSpinner = v.findViewById(R.id.pvc_javaVm);
rendererSpinner = v.findViewById(R.id.pvc_renderer);
{
List<String> renderList = new ArrayList<>();
Collections.addAll(renderList, ctx.getResources().getStringArray(R.array.renderer));
renderList.add("Default");
renderNames = Arrays.asList(ctx.getResources().getStringArray(R.array.renderer_values));
rendererSpinner.setAdapter(new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_dropdown_item,renderList));
}
customDirText = v.findViewById(R.id.pvc_customDir);
jvmArgsEditText = v.findViewById(R.id.pvc_jvmArgs);
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setView(v);
builder.setTitle("Per-version settings");
builder.setNegativeButton(android.R.string.cancel,(dialogInterface,i)->dialogInterface.dismiss());
builder.setPositiveButton(android.R.string.ok,this::save);
dialog = builder.create();
}
public void refreshRuntimes() {
if(runtimes!=null)runtimes.clear();
runtimes = MultiRTUtils.getRuntimes();
//runtimes.add(new MultiRTUtils.Runtime("<Default>"));
}
private void save(DialogInterface i, int which) {
if(selectedGameVersion == null) {
i.dismiss();
return;
}
PerVersionConfig.VersionConfig conf1 = PerVersionConfig.configMap.get(selectedGameVersion);
if(conf1==null){
conf1=new PerVersionConfig.VersionConfig();
}
conf1.jvmArgs=jvmArgsEditText.getText().toString();
conf1.gamePath=customDirText.getText().toString();
if(rendererSpinner.getSelectedItemPosition() == renderNames.size()) conf1.renderer = null;
else conf1.renderer = renderNames.get(rendererSpinner.getSelectedItemPosition());
String runtime=((MultiRTUtils.Runtime)javaVMSpinner.getSelectedItem()).name;;
if(!runtime.equals("<Default>"))conf1.selectedRuntime=runtime;
else conf1.selectedRuntime=null;
PerVersionConfig.configMap.put(selectedGameVersion,conf1);
try{
PerVersionConfig.update();
}catch(IOException e){
e.printStackTrace();
}
}
public boolean openConfig(String selectedVersion) {
selectedGameVersion = selectedVersion;
try{
PerVersionConfig.update();
}catch(IOException e){
e.printStackTrace();
}
PerVersionConfig.VersionConfig conf=PerVersionConfig.configMap.get(selectedGameVersion);
refreshRuntimes();
javaVMSpinner.setAdapter(new RTSpinnerAdapter(ctx,runtimes));
{
int jvm_index = runtimes.indexOf(new MultiRTUtils.Runtime("<Default>"));
int rnd_index = rendererSpinner.getAdapter().getCount()-1;
if (conf != null) {
customDirText.setText(conf.gamePath);
jvmArgsEditText.setText(conf.jvmArgs);
if (conf.selectedRuntime != null) {
int nindex = runtimes.indexOf(new MultiRTUtils.Runtime(conf.selectedRuntime));
if (nindex != -1) jvm_index = nindex;
}
if(conf.renderer != null) {
int nindex = renderNames.indexOf(conf.renderer);
if (nindex != -1) rnd_index = nindex;
}
}
javaVMSpinner.setSelection(jvm_index);
rendererSpinner.setSelection(rnd_index);
}
dialog.show();
return true;
}
}

View File

@ -71,60 +71,9 @@ public class RefreshVersionListTask extends AsyncTask<Void, Void, ArrayList<Stri
} else {
mActivity.mVersionSelector.setSelection(selectAt(mActivity.mAvailableVersions, mActivity.mProfile.selectedVersion));
}
View.OnLongClickListener listener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
final View v = LayoutInflater.from(view.getContext()).inflate(R.layout.pvc_popup,null);
final List<MultiRTUtils.Runtime> runtimes = MultiRTUtils.getRuntimes();
final Spinner javaVMSpinner = ((Spinner)v.findViewById(R.id.pvc_javaVm));
final EditText customDirText = ((EditText)v.findViewById(R.id.pvc_customDir));
final EditText jvmArgsEditText = ((EditText)v.findViewById(R.id.pvc_jvmArgs));
javaVMSpinner.setAdapter(new RTSpinnerAdapter(RefreshVersionListTask.this.mActivity,runtimes));
try {
PerVersionConfig.update();
}catch (IOException e) {
e.printStackTrace();
}
PerVersionConfig.VersionConfig conf = PerVersionConfig.configMap.get(mActivity.mProfile.selectedVersion);
int index = runtimes.indexOf(new MultiRTUtils.Runtime("<Default>"));
if(conf != null) {
customDirText.setText(conf.gamePath);
jvmArgsEditText.setText(conf.jvmArgs);
if(conf.selectedRuntime != null) {
int nindex = runtimes.indexOf(new MultiRTUtils.Runtime(conf.selectedRuntime));
if(nindex != -1) index = nindex;
}
}
javaVMSpinner.setSelection(index);
builder.setView(v);
builder.setTitle("Per-version settings");
builder.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> dialogInterface.dismiss());
builder.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
PerVersionConfig.VersionConfig conf1 = PerVersionConfig.configMap.get(mActivity.mProfile.selectedVersion);
if(conf1 == null) {
conf1 = new PerVersionConfig.VersionConfig();
}
conf1.jvmArgs = jvmArgsEditText.getText().toString();
conf1.gamePath = customDirText.getText().toString();
String runtime = ((MultiRTUtils.Runtime)javaVMSpinner.getSelectedItem()).name;;
if(!runtime.equals("<Default>")) conf1.selectedRuntime = runtime;
else conf1.selectedRuntime = null;
PerVersionConfig.configMap.put(mActivity.mProfile.selectedVersion, conf1);
try {
PerVersionConfig.update();
}catch (IOException e) {
e.printStackTrace();
}
});
builder.show();
return true;
}
};
mActivity.mVersionSelector.setOnLongClickListener(listener);
PerVersionConfigDialog dialog = new PerVersionConfigDialog(this.mActivity);
mActivity.mVersionSelector.setOnLongClickListener((v)->dialog.openConfig(mActivity.mProfile.selectedVersion));
mActivity.mVersionSelector.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> p1, View p2, int p3, long p4)
{

View File

@ -87,15 +87,6 @@ public class JREUtils
}
dlopen(nativeLibDir + "/libopenal.so");
// may not necessary
if (LauncherPreferences.PREF_CUSTOM_OPENGL_LIBNAME.equals("libgl4es_114.so")) {
LauncherPreferences.PREF_CUSTOM_OPENGL_LIBNAME = nativeLibDir + "/libgl4es_114.so";
}
if (!dlopen(LauncherPreferences.PREF_CUSTOM_OPENGL_LIBNAME) && !dlopen(findInLdLibPath(LauncherPreferences.PREF_CUSTOM_OPENGL_LIBNAME))) {
System.err.println("Failed to load custom OpenGL library " + LauncherPreferences.PREF_CUSTOM_OPENGL_LIBNAME + ". Fallbacking to GL4ES.");
dlopen(nativeLibDir + "/libgl4es_114.so");
}
}
public static Map<String, String> readJREReleaseProperties() throws IOException {
@ -225,7 +216,7 @@ public class JREUtils
envMap.put("REGAL_GL_RENDERER", "Regal");
envMap.put("REGAL_GL_VERSION", "4.5");
envMap.put("POJAV_RENDERER", LauncherPreferences.PREF_RENDERER);
envMap.put("POJAV_RENDERER", Tools.LOCAL_RENDERER);
envMap.put("AWTSTUB_WIDTH", Integer.toString(CallbackBridge.windowWidth > 0 ? CallbackBridge.windowWidth : CallbackBridge.physicalWidth));
envMap.put("AWTSTUB_HEIGHT", Integer.toString(CallbackBridge.windowHeight > 0 ? CallbackBridge.windowHeight : CallbackBridge.physicalHeight));
@ -248,8 +239,8 @@ public class JREUtils
if (glesMajor < 3) {
//fallback to 2 since it's the minimum for the entire app
envMap.put("LIBGL_ES","2");
} else if (LauncherPreferences.PREF_RENDERER.startsWith("opengles")) {
envMap.put("LIBGL_ES", LauncherPreferences.PREF_RENDERER.replace("opengles", "").replace("_5", ""));
} else if (Tools.LOCAL_RENDERER.startsWith("opengles")) {
envMap.put("LIBGL_ES", Tools.LOCAL_RENDERER.replace("opengles", "").replace("_5", ""));
} else {
// TODO if can: other backends such as Vulkan.
// Sure, they should provide GLES 3 support.
@ -273,10 +264,34 @@ public class JREUtils
public static int launchJavaVM(final LoggableActivity ctx, final List<String> args) throws Throwable {
JREUtils.relocateLibPath(ctx);
// ctx.appendlnToLog("LD_LIBRARY_PATH = " + JREUtils.LD_LIBRARY_PATH);
final String graphicsLib;
if(Tools.LOCAL_RENDERER != null){
switch (Tools.LOCAL_RENDERER) {
case "opengles2":
graphicsLib = "libgl4es_114.so";
break;
case "opengles2_5":
case "opengles3":
graphicsLib = "libgl4es_115.so";
break;
case "vulkan_zink":
graphicsLib = "libOSMesa_8.so";
break;
default:
throw new RuntimeException("Undefined renderer: " + Tools.LOCAL_RENDERER);
}
if (!dlopen(graphicsLib) && !dlopen(findInLdLibPath(graphicsLib))) {
System.err.println("Failed to load renderer " + graphicsLib + ". Falling back to GL4ES 1.1.4");
Tools.LOCAL_RENDERER = "opengles2";
dlopen(nativeLibDir + "/libgl4es_114.so");
}
}else{
graphicsLib = null;
}
List<String> javaArgList = new ArrayList<String>();
javaArgList.add(Tools.DIR_HOME_JRE + "/bin/java");
Tools.getJavaArgs(ctx, javaArgList);
Tools.getJavaArgs(ctx, javaArgList,graphicsLib);
purgeArg(javaArgList,"-Xms");
purgeArg(javaArgList,"-Xmx");
/*if(Tools.CURRENT_ARCHITECTURE.contains("32") && ((mi.availMem / 1048576L)-50) > 300) {
@ -421,6 +436,7 @@ public class JREUtils
static {
System.loadLibrary("pojavexec");
System.loadLibrary("pojavexec_awt");
dlopen("libxhook.so");
System.loadLibrary("istdio");
}
}

View File

@ -28,5 +28,6 @@ public class PerVersionConfig {
public String jvmArgs;
public String gamePath;
public String selectedRuntime;
public String renderer;
}
}

View File

@ -44,4 +44,15 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pvc_customDir" />
<Spinner
android:id="@+id/pvc_renderer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pvc_javaVm" />
</androidx.constraintlayout.widget.ConstraintLayout>