Skip to content

Commit

Permalink
Merge branch 'FCL-Team:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjing-GitHub-Code committed Mar 14, 2023
2 parents 7902bfd + 8e7a26f commit 386ba8d
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 38 deletions.
Binary file modified FCL/src/main/assets/app_runtime/lwjgl2/lwjgl.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion FCL/src/main/assets/app_runtime/lwjgl2/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1678097863965
1678768784860
51 changes: 50 additions & 1 deletion FCL/src/main/java/com/tungsten/fcl/FCLApplication.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package com.tungsten.fcl;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.os.StrictMode;

public class FCLApplication extends Application {
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.lang.ref.WeakReference;

public class FCLApplication extends Application implements Application.ActivityLifecycleCallbacks {
private static WeakReference<Activity> currentActivity;

@Override
public void onCreate() {
// enabledStrictMode();
super.onCreate();
this.registerActivityLifecycleCallbacks(this);
}

public static Activity getCurrentActivity(){
return currentActivity.get();
}

private void enabledStrictMode() {
Expand All @@ -28,4 +41,40 @@ private void enabledStrictMode() {
.build());
}

@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {

}

@Override
public void onActivityStarted(@NonNull Activity activity) {
currentActivity = new WeakReference<>(activity);
}

@Override
public void onActivityResumed(@NonNull Activity activity) {

}

@Override
public void onActivityPaused(@NonNull Activity activity) {

}

@Override
public void onActivityStopped(@NonNull Activity activity) {

}

@Override
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {

}

@Override
public void onActivityDestroyed(@NonNull Activity activity) {
if (currentActivity.get() == activity){
currentActivity = null;
}
}
}
1 change: 1 addition & 0 deletions FCL/src/main/java/com/tungsten/fcl/control/GameMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ public void onCursorModeChange(int mode) {
this.cursorMode = mode;
activity.runOnUiThread(() -> {
if (mode == FCLBridge.CursorEnabled) {
getInput().setPointer(getCursorX(),getCursorY());
getCursor().setVisibility(View.VISIBLE);
gameItemBar.setVisibility(View.GONE);
} else {
Expand Down
35 changes: 18 additions & 17 deletions FCL/src/main/java/com/tungsten/fcl/control/view/MenuView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import com.tungsten.fcl.FCLApplication;
import com.tungsten.fcl.R;
import com.tungsten.fcl.control.GameMenu;
import com.tungsten.fcl.util.AndroidUtils;
Expand All @@ -25,27 +26,27 @@ public class MenuView extends View {
private final int screenWidth;
private final int screenHeight;

private final int DEFAULT_WIDTH = ConvertUtils.dip2px(getContext(), 40);
private final int DEFAULT_HEIGHT = ConvertUtils.dip2px(getContext(), 40);
private final int DEFAULT_WIDTH = ConvertUtils.dip2px(FCLApplication.getCurrentActivity(), 40);
private final int DEFAULT_HEIGHT = ConvertUtils.dip2px(FCLApplication.getCurrentActivity(), 40);

private GameMenu gameMenu;

public MenuView(Context context) {
super(context);
this.screenWidth = AndroidUtils.getScreenWidth(getContext());
this.screenHeight = AndroidUtils.getScreenHeight(getContext());
this.screenWidth = AndroidUtils.getScreenWidth(FCLApplication.getCurrentActivity());
this.screenHeight = AndroidUtils.getScreenHeight(FCLApplication.getCurrentActivity());
}

public MenuView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.screenWidth = AndroidUtils.getScreenWidth(getContext());
this.screenHeight = AndroidUtils.getScreenHeight(getContext());
this.screenWidth = AndroidUtils.getScreenWidth(FCLApplication.getCurrentActivity());
this.screenHeight = AndroidUtils.getScreenHeight(FCLApplication.getCurrentActivity());
}

public MenuView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.screenWidth = AndroidUtils.getScreenWidth(getContext());
this.screenHeight = AndroidUtils.getScreenHeight(getContext());
this.screenWidth = AndroidUtils.getScreenWidth(FCLApplication.getCurrentActivity());
this.screenHeight = AndroidUtils.getScreenHeight(FCLApplication.getCurrentActivity());
}

public void setup(GameMenu gameMenu) {
Expand All @@ -55,21 +56,21 @@ public void setup(GameMenu gameMenu) {
strokePaint.setAntiAlias(true);
strokePaint.setColor(Color.DKGRAY);
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setStrokeWidth(ConvertUtils.dip2px(getContext(), 2));
strokePaint.setStrokeWidth(ConvertUtils.dip2px(FCLApplication.getCurrentActivity(), 2));

areaPaint = new Paint();
areaPaint.setAntiAlias(true);

iconPaint = new Paint();
iconPaint.setAntiAlias(true);

icon = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.img_app);
icon = BitmapFactory.decodeResource(FCLApplication.getCurrentActivity().getResources(), R.drawable.img_app);

srcRect = new Rect(0, 0, icon.getWidth(), icon.getHeight());
destRect = new Rect(ConvertUtils.dip2px(getContext(), 6),
ConvertUtils.dip2px(getContext(), 6),
ConvertUtils.dip2px(getContext(), 34),
ConvertUtils.dip2px(getContext(), 34));
destRect = new Rect(ConvertUtils.dip2px(FCLApplication.getCurrentActivity(), 6),
ConvertUtils.dip2px(FCLApplication.getCurrentActivity(), 6),
ConvertUtils.dip2px(FCLApplication.getCurrentActivity(), 34),
ConvertUtils.dip2px(FCLApplication.getCurrentActivity(), 34));
}

@Override
Expand All @@ -93,12 +94,12 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (pressed) {
areaPaint.setColor(getContext().getColor(R.color.ui_bg_color));
areaPaint.setColor(FCLApplication.getCurrentActivity().getColor(R.color.ui_bg_color));
} else {
areaPaint.setColor(Color.TRANSPARENT);
}
canvas.drawCircle(getMeasuredWidth() >> 1, getMeasuredHeight() >> 1, (getMeasuredWidth() >> 1) - ConvertUtils.dip2px(getContext(), 1), strokePaint);
canvas.drawCircle(getMeasuredWidth() >> 1, getMeasuredHeight() >> 1, (getMeasuredWidth() >> 1) - ConvertUtils.dip2px(getContext(), 2), areaPaint);
canvas.drawCircle(getMeasuredWidth() >> 1, getMeasuredHeight() >> 1, (getMeasuredWidth() >> 1) - ConvertUtils.dip2px(FCLApplication.getCurrentActivity(), 1), strokePaint);
canvas.drawCircle(getMeasuredWidth() >> 1, getMeasuredHeight() >> 1, (getMeasuredWidth() >> 1) - ConvertUtils.dip2px(FCLApplication.getCurrentActivity(), 2), areaPaint);
canvas.drawBitmap(icon, srcRect, destRect, iconPaint);
}

Expand Down
13 changes: 7 additions & 6 deletions FCL/src/main/java/com/tungsten/fcl/control/view/TouchPad.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.MotionEvent;
import android.view.View;

import com.tungsten.fcl.FCLApplication;
import com.tungsten.fcl.control.FCLInput;
import com.tungsten.fcl.control.GameMenu;
import com.tungsten.fcl.control.GestureMode;
Expand All @@ -26,20 +27,20 @@ public void init(GameMenu gameMenu) {

public TouchPad(Context context) {
super(context);
this.screenWidth = AndroidUtils.getScreenWidth(getContext());
this.screenHeight = AndroidUtils.getScreenHeight(getContext());
this.screenWidth = AndroidUtils.getScreenWidth(FCLApplication.getCurrentActivity());
this.screenHeight = AndroidUtils.getScreenHeight(FCLApplication.getCurrentActivity());
}

public TouchPad(Context context, AttributeSet attrs) {
super(context, attrs);
this.screenWidth = AndroidUtils.getScreenWidth(getContext());
this.screenHeight = AndroidUtils.getScreenHeight(getContext());
this.screenWidth = AndroidUtils.getScreenWidth(FCLApplication.getCurrentActivity());
this.screenHeight = AndroidUtils.getScreenHeight(FCLApplication.getCurrentActivity());
}

public TouchPad(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.screenWidth = AndroidUtils.getScreenWidth(getContext());
this.screenHeight = AndroidUtils.getScreenHeight(getContext());
this.screenWidth = AndroidUtils.getScreenWidth(FCLApplication.getCurrentActivity());
this.screenHeight = AndroidUtils.getScreenHeight(FCLApplication.getCurrentActivity());
}

private int downX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.tungsten.fcl.FCLApplication;
import com.tungsten.fcl.R;
import com.tungsten.fcl.setting.Profile;
import com.tungsten.fcl.setting.VersionSetting;
Expand Down Expand Up @@ -331,8 +332,8 @@ public LaunchOptions getLaunchOptions(String version, JavaVersion javaVersion, F
) / 1024 / 1024))
.setMinMemory(vs.getMinMemory())
.setMetaspace(Lang.toIntOrNull(vs.getPermSize()))
.setWidth((int) (AndroidUtils.getScreenWidth(FCLPath.CONTEXT) * vs.getScaleFactor()))
.setHeight((int) (AndroidUtils.getScreenHeight(FCLPath.CONTEXT) * vs.getScaleFactor()))
.setWidth((int) (AndroidUtils.getScreenWidth(FCLApplication.getCurrentActivity()) * vs.getScaleFactor()))
.setHeight((int) (AndroidUtils.getScreenHeight(FCLApplication.getCurrentActivity()) * vs.getScaleFactor()))
.setServerIp(vs.getServerIp())
.setProcessPriority(vs.getProcessPriority())
.setJavaAgents(javaAgents)
Expand Down
17 changes: 12 additions & 5 deletions FCL/src/main/java/com/tungsten/fcl/game/TexturesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ public static LoadedTexture loadTexture(Texture texture) throws IOException {
}
}
}

Bitmap img = BitmapFactory.decodeStream(Files.newInputStream(file));
if (img == null)
Bitmap img;
try(InputStream in = Files.newInputStream(file)){
img = BitmapFactory.decodeStream(in);
}
if (img == null) {
throw new IOException("Texture is malformed");
}

Map<String, String> metadata = texture.getMetadata();
if (metadata == null) {
Expand Down Expand Up @@ -144,9 +147,13 @@ private static Bitmap loadCape(Texture texture) throws IOException {
}
}

Bitmap img = BitmapFactory.decodeStream(Files.newInputStream(file));
if (img == null)
Bitmap img;
try(InputStream in = Files.newInputStream(file)){
img = BitmapFactory.decodeStream(in);
}
if (img == null) {
throw new IOException("Texture is malformed");
}

return img;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private void create() {
rendererDataList.add(FCLConfig.Renderer.RENDERER_GL4ES);
rendererDataList.add(FCLConfig.Renderer.RENDERER_ZINK);
rendererDataList.add(FCLConfig.Renderer.RENDERER_ANGLE);
rendererDataList.add(FCLConfig.Renderer.RENDERER_VGPU);
rendererSpinner.setDataList(rendererDataList);

// add spinner text
Expand All @@ -175,6 +176,7 @@ private void create() {
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_gl4es));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_virgl));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_angle));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_vgpu));
ArrayAdapter<String> rendererAdapter = new ArrayAdapter<>(getContext(), R.layout.item_spinner, rendererList);
rendererAdapter.setDropDownViewResource(R.layout.item_spinner_dropdown);
rendererSpinner.setAdapter(rendererAdapter);
Expand Down
28 changes: 26 additions & 2 deletions FCL/src/main/java/com/tungsten/fcl/util/AndroidUtils.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.tungsten.fcl.util;

import static android.content.Context.CLIPBOARD_SERVICE;
import static android.content.Context.MODE_PRIVATE;
import static android.os.Build.VERSION.SDK_INT;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.WindowManager;
import android.webkit.CookieManager;
Expand Down Expand Up @@ -74,11 +81,28 @@ public static int getScreenHeight(Context context) {
return point.y;
}

public static int getScreenWidth(Context context) {
public static int getScreenWidth(Activity context) {
SharedPreferences sharedPreferences;
sharedPreferences = context.getSharedPreferences("theme", MODE_PRIVATE);
boolean fullscreen = sharedPreferences.getBoolean("fullscreen", false);
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Point point = new Point();
wm.getDefaultDisplay().getRealSize(point);
return point.x;
if (fullscreen || SDK_INT < Build.VERSION_CODES.P){
return point.x;
} else {
try {
Rect notchRect;
if(SDK_INT >= Build.VERSION_CODES.S){
notchRect = wm.getCurrentWindowMetrics().getWindowInsets().getDisplayCutout().getBoundingRects().get(0);
} else {
notchRect = context.getWindow().getDecorView().getRootWindowInsets().getDisplayCutout().getBoundingRects().get(0);
}
return point.x-Math.min(notchRect.width(), notchRect.height());
} catch (Exception e){
return point.x;
}
}
}

}
1 change: 1 addition & 0 deletions FCL/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
<string name="settings_fcl_renderer_gl4es" translatable="false">Holy GL4ES (OpenGL 2.1)</string>
<string name="settings_fcl_renderer_virgl" translatable="false">VirGLRenderer (OpenGL 4.3)</string>
<string name="settings_fcl_renderer_angle">ANGLE (OpenGL 4.6, only support 1.17+)</string>
<string name="settings_fcl_renderer_vgpu" translatable="false">Vgpu (OpenGL 2.1+)</string>

<string name="settings_game">Game Settings</string>
<string name="settings_game_dimension">Resolution</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ private CommandBuilder generateCommandLine() throws IOException {
res.addDefault("-Dlwjgl.platform=", "FCL");
res.addDefault("-Dorg.lwjgl.opengl.libname=", "${gl_lib_name}");
res.addDefault("-Dfml.earlyprogresswindow=", "false");
//TODO:Use right window size
res.addDefault("-Dwindow.width=", options.getWidth() + "");
res.addDefault("-Dwindow.height=", options.getHeight() + "");
res.addDefault("-Duser.home=", options.getGameDir().getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class FCLConfig implements Serializable {
public enum Renderer implements Serializable {
RENDERER_GL4ES("libgl4es.so:libEGL.so"),
RENDERER_ZINK("libGL.so:libEGL.so"),
RENDERER_ANGLE("libtinywrapper.so:libEGL_angle.so");
RENDERER_ANGLE("libtinywrapper.so:libEGL_angle.so"),
RENDERER_VGPU("libvgpu.so:libEGL.so");

private final String glInfo;
private String glVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static void addRendererEnv(FCLConfig config, HashMap<String, String> env
String nativeDir = config.getContext().getApplicationInfo().nativeLibraryDir;
envMap.put("LIBGL_NAME", renderer.getGlLibName());
envMap.put("LIBEGL_NAME", renderer.getEglLibName());
if (renderer == FCLConfig.Renderer.RENDERER_GL4ES) {
if (renderer == FCLConfig.Renderer.RENDERER_GL4ES || renderer == FCLConfig.Renderer.RENDERER_VGPU) {
envMap.put("LIBGL_ES", "2");
envMap.put("LIBGL_MIPMAP", "3");
envMap.put("LIBGL_NORMALIZE", "1");
Expand Down Expand Up @@ -244,7 +244,7 @@ public static FCLBridge launchMinecraft(FCLConfig config) {

// patch linker if using 64 bit device
if (Architecture.is64BitsDevice()) {
bridge.patchLinker();
// bridge.patchLinker();
}

// env
Expand Down
Binary file added FCLauncher/src/main/jniLibs/arm64-v8a/libvgpu.so
Binary file not shown.
Binary file not shown.
Binary file added FCLauncher/src/main/jniLibs/x86/libvgpu.so
Binary file not shown.
Binary file added FCLauncher/src/main/jniLibs/x86_64/libvgpu.so
Binary file not shown.

0 comments on commit 386ba8d

Please sign in to comment.