Skip to content

Commit

Permalink
A bunch of fixes and removal of stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Novampr committed Jun 25, 2024
1 parent ebfe0a7 commit 443435d
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 161 deletions.
17 changes: 8 additions & 9 deletions src/main/java/org/lwjgl/glfw/CallbackBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

public class CallbackBridge {
public static final int ANDROID_TYPE_GRAB_STATE = 0;

public static final int CLIPBOARD_COPY = 2000;
public static final int CLIPBOARD_PASTE = 2001;

public static volatile int physicalWidth, physicalHeight;
public static float mouseX, mouseY;
public static StringBuilder DEBUG_STRING = new StringBuilder();
Expand All @@ -23,7 +23,7 @@ public static void putMouseEventWithCoords(int button, float x, float y) {
handler.postDelayed(() -> putMouseEventWithCoords(button, false, x, y), 22);

}

public static void putMouseEventWithCoords(int button, boolean isDown, float x, float y /* , int dz, long nanos */) {
sendCursorPos(x, y);
sendMouseKeycode(button, CallbackBridge.getCurrentMods(), isDown);
Expand All @@ -34,13 +34,13 @@ public static void sendCursorPos(float x, float y) {
if (!threadAttached) {
threadAttached = CallbackBridge.nativeAttachThreadToOther(true, true);
}

DEBUG_STRING.append("CursorPos=").append(x).append(", ").append(y).append("\n");
mouseX = x;
mouseY = y;
nativeSendCursorPos(mouseX, mouseY);
}

public static void sendPrepareGrabInitialPos() {
DEBUG_STRING.append("Prepare set grab initial posititon: ignored");
}
Expand Down Expand Up @@ -88,9 +88,8 @@ public static void sendMouseKeycode(int button, int modifiers, boolean isDown) {

public static void sendMouseKeycode(int keycode) {
sendMouseKeycode(keycode, CallbackBridge.getCurrentMods(), true);
sendMouseKeycode(keycode, CallbackBridge.getCurrentMods(), false);
}

sendMouseKeycode(keycode, CallbackBridge.getCurrentMods(), false);}

public static void sendScroll(double xoffset, double yoffset) {
DEBUG_STRING.append("ScrollX=").append(xoffset).append(",ScrollY=").append(yoffset);
nativeSendScroll(xoffset, yoffset);
Expand Down Expand Up @@ -124,7 +123,7 @@ public static int getCurrentMods() {
// GLFW: GLFWCharModsCallback deprecated, but is Minecraft still use?
private static native boolean nativeSendCharMods(char codepoint, int mods);
private static native void nativeSendKey(int key, int scancode, int action, int mods);
// private static native void nativeSendCursorEnter(int entered);
private static native void nativeSendCursorEnter(int entered);
private static native void nativeSendCursorPos(float x, float y);
private static native void nativeSendMouseButton(int button, int action, int mods);
private static native void nativeSendScroll(double xoffset, double yoffset);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/pojlib/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ public static void startGame(
"--assetsDir", assetsDir, "--assetIndex", assetIndex, "--uuid", formattedUuid,
"--accessToken", accessToken, "--userType", userType, "--versionType", "release"};

List<String> allArgs = new ArrayList<>(Arrays.asList(mcArgs));
allArgs.addAll(Arrays.asList(additionalArgs));
JREUtils.redirectAndPrintJRELog();
List<String> allArgs = new ArrayList<>(Arrays.asList(additionalArgs));
JREUtils.redirectAndPrintJRELog(activity);
VLoader.setAndroidInitInfo(activity);
try {
JREUtils.launchJavaVM(activity, allArgs, versionName, gameDir, memoryValue, questModel, mainClass);
JREUtils.launchJavaVM(activity, allArgs, mcArgs, gameDir, memoryValue, questModel, mainClass);
} catch (Throwable t) {
throw new RuntimeException("JVM has stopped.", t);
}
Expand Down
85 changes: 44 additions & 41 deletions src/main/java/pojlib/UnityPlayerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
import com.unity3d.player.IUnityPlayerLifecycleEvents;
import com.unity3d.player.UnityPlayer;

import java.io.File;

import pojlib.util.FileUtil;

public class UnityPlayerActivity extends ActivityGroup implements IUnityPlayerLifecycleEvents
{
public class UnityPlayerActivity extends ActivityGroup implements IUnityPlayerLifecycleEvents {
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code

// Override this in your custom UnityPlayerActivity to tweak the command line arguments passed to the Unity Android Player
Expand All @@ -32,7 +27,8 @@ protected String updateUnityCommandLineArguments(String cmdLine)
}

// Setup activity layout
@Override protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);

Expand All @@ -44,22 +40,18 @@ protected String updateUnityCommandLineArguments(String cmdLine)
mUnityPlayer.requestFocus();
}

@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
return super.onKeyMultiple(keyCode, repeatCount, event);
}

// When Unity player unloaded move task to background
@Override public void onUnityPlayerUnloaded() {
@Override
public void onUnityPlayerUnloaded() {
moveTaskToBack(true);
}

// Callback before Unity player process is killed
@Override public void onUnityPlayerQuitted() {
}
@Override
public void onUnityPlayerQuitted() {}

@Override protected void onNewIntent(Intent intent)
{
@Override
protected void onNewIntent(Intent intent) {
// To support deep linking, we need to make sure that the client can get access to
// the last sent intent. The clients access this through a JNI api that allows them
// to get the intent set on launch. To update that after launch we have to manually
Expand All @@ -69,8 +61,8 @@ public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
}

// Quit Unity
@Override protected void onDestroy ()
{
@Override
protected void onDestroy () {
mUnityPlayer.destroy();
super.onDestroy();
}
Expand All @@ -79,46 +71,46 @@ public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
// onStart/onStop (the visibility callbacks) to determine when to pause/resume.
// Otherwise it will be done in onPause/onResume as Unity has done historically to preserve
// existing behavior.
@Override protected void onStop()
{
@Override
protected void onStop() {
super.onStop();

mUnityPlayer.pause();
}

@Override protected void onStart()
{
@Override
protected void onStart() {
super.onStart();

mUnityPlayer.resume();
}

// Pause Unity
@Override protected void onPause()
{
@Override
protected void onPause() {
super.onPause();

mUnityPlayer.pause();
}

// Resume Unity
@Override protected void onResume()
{
@Override
protected void onResume() {
super.onResume();

mUnityPlayer.resume();
}

// Low Memory Unity
@Override public void onLowMemory()
{
@Override
public void onLowMemory() {
super.onLowMemory();
mUnityPlayer.lowMemory();
}

// Trim Memory Unity
@Override public void onTrimMemory(int level)
{
@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
if (level == TRIM_MEMORY_RUNNING_CRITICAL)
{
Expand All @@ -127,35 +119,46 @@ public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
}

// This ensures the layout will be correct.
@Override public void onConfigurationChanged(Configuration newConfig)
{
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}

// Notify Unity of the focus change.
@Override public void onWindowFocusChanged(boolean hasFocus)
{
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}

// For some reason the multiple keyevent type is not supported by the ndk.
// Force event injection by overriding dispatchKeyEvent().
@Override public boolean dispatchKeyEvent(KeyEvent event)
{
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
return mUnityPlayer.injectEvent(event);
return super.dispatchKeyEvent(event);
}

// Pass any events not handled by (unfocused) views straight to UnityPlayer
@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return mUnityPlayer.injectEvent(event);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return mUnityPlayer.injectEvent(event);
}
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {

@Override
public boolean onTouchEvent(MotionEvent event) {
return mUnityPlayer.injectEvent(event);
}
// API12
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
return mUnityPlayer.injectEvent(event);
}
@Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
/*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
}
79 changes: 0 additions & 79 deletions src/main/java/pojlib/util/FileUtil.java

This file was deleted.

Loading

0 comments on commit 443435d

Please sign in to comment.