mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 07:39:00 -04:00
Make CallbackBridge indirect input pipe non-static
It made the input work!!!
This commit is contained in:
parent
ab0ff09950
commit
d9c4d91d14
Binary file not shown.
@ -1 +1 @@
|
|||||||
1652110329813
|
1652124351110
|
@ -41,6 +41,7 @@ static float grabCursorX, grabCursorY, lastCursorX, lastCursorY;
|
|||||||
|
|
||||||
jclass inputBridgeClass_ANDROID, inputBridgeClass_JRE;
|
jclass inputBridgeClass_ANDROID, inputBridgeClass_JRE;
|
||||||
jmethodID inputBridgeMethod_ANDROID, inputBridgeMethod_JRE;
|
jmethodID inputBridgeMethod_ANDROID, inputBridgeMethod_JRE;
|
||||||
|
jobject inputBridgeObject_ANDROID;
|
||||||
jclass bridgeClazz;
|
jclass bridgeClazz;
|
||||||
jboolean isGrabbing;
|
jboolean isGrabbing;
|
||||||
|
|
||||||
@ -114,18 +115,6 @@ jboolean attachThread(bool isAndroid, JNIEnv** secondJNIEnvPtr) {
|
|||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getJavaInputBridge(jclass* clazz, jmethodID* method) {
|
|
||||||
#ifdef DEBUG
|
|
||||||
LOGD("Debug: Initializing input bridge, method.isNull=%d, jnienv.isNull=%d\n", *method == NULL, runtimeJNIEnvPtr_ANDROID == NULL);
|
|
||||||
#endif
|
|
||||||
if (*method == NULL && runtimeJNIEnvPtr_ANDROID != NULL) {
|
|
||||||
*clazz = (*runtimeJNIEnvPtr_ANDROID)->FindClass(runtimeJNIEnvPtr_ANDROID, "org/lwjgl/glfw/CallbackBridge");
|
|
||||||
assert(*clazz != NULL);
|
|
||||||
*method = (*runtimeJNIEnvPtr_ANDROID)->GetStaticMethodID(runtimeJNIEnvPtr_ANDROID, *clazz, "receiveCallback", "(IIIII)V");
|
|
||||||
assert(*method != NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendData(int type, int i1, int i2, int i3, int i4) {
|
void sendData(int type, int i1, int i2, int i3, int i4) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
LOGD("Debug: Send data, jnienv.isNull=%d\n", runtimeJNIEnvPtr_ANDROID == NULL);
|
LOGD("Debug: Send data, jnienv.isNull=%d\n", runtimeJNIEnvPtr_ANDROID == NULL);
|
||||||
@ -134,9 +123,10 @@ void sendData(int type, int i1, int i2, int i3, int i4) {
|
|||||||
LOGE("BUG: Input is ready but thread is not attached yet.");
|
LOGE("BUG: Input is ready but thread is not attached yet.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(*runtimeJNIEnvPtr_ANDROID)->CallStaticVoidMethod(
|
if(inputBridgeObject_ANDROID == NULL) return;
|
||||||
|
(*runtimeJNIEnvPtr_ANDROID)->CallVoidMethod(
|
||||||
runtimeJNIEnvPtr_ANDROID,
|
runtimeJNIEnvPtr_ANDROID,
|
||||||
inputBridgeClass_ANDROID,
|
inputBridgeObject_ANDROID,
|
||||||
inputBridgeMethod_ANDROID,
|
inputBridgeMethod_ANDROID,
|
||||||
type,
|
type,
|
||||||
i1, i2, i3, i4
|
i1, i2, i3, i4
|
||||||
@ -183,8 +173,6 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThread
|
|||||||
if (isUseStackQueueCall && isAndroid && result) {
|
if (isUseStackQueueCall && isAndroid && result) {
|
||||||
isPrepareGrabPos = true;
|
isPrepareGrabPos = true;
|
||||||
}
|
}
|
||||||
getJavaInputBridge(&inputBridgeClass_ANDROID, &inputBridgeMethod_ANDROID);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,3 +380,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetWindowAttrib(
|
|||||||
(jlong) showingWindow, attrib, value
|
(jlong) showingWindow, attrib, value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_lwjgl_glfw_CallbackBridge_initBridge(JNIEnv *env, jclass clazz, jobject bridge) {
|
||||||
|
// Due to Forge's ability to create TWO static classes, we are doing this.
|
||||||
|
printf("%p\n",bridge);
|
||||||
|
inputBridgeMethod_ANDROID = (*env)->GetMethodID(env, clazz, "receiveCallback", "(IIIII)V");
|
||||||
|
inputBridgeObject_ANDROID = (*env)->NewGlobalRef(env, bridge);
|
||||||
|
}
|
@ -1,7 +1,5 @@
|
|||||||
package org.lwjgl.glfw;
|
package org.lwjgl.glfw;
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import android.util.*;
|
|
||||||
|
|
||||||
public class CallbackBridge {
|
public class CallbackBridge {
|
||||||
public static final int CLIPBOARD_COPY = 2000;
|
public static final int CLIPBOARD_COPY = 2000;
|
||||||
@ -20,8 +18,9 @@ public class CallbackBridge {
|
|||||||
public static final int ANDROID_TYPE_GRAB_STATE = 0;
|
public static final int ANDROID_TYPE_GRAB_STATE = 0;
|
||||||
|
|
||||||
// Should pending events be limited?
|
// Should pending events be limited?
|
||||||
volatile public static List<Integer[]> PENDING_EVENT_LIST = new ArrayList<>();
|
volatile public List<Integer[]> pendingEventList = new ArrayList<>();
|
||||||
volatile public static boolean PENDING_EVENT_READY = false;
|
volatile public boolean pendingEventReady = false;
|
||||||
|
private static CallbackBridge thisBridge = null;
|
||||||
|
|
||||||
public static final boolean INPUT_DEBUG_ENABLED;
|
public static final boolean INPUT_DEBUG_ENABLED;
|
||||||
|
|
||||||
@ -51,33 +50,38 @@ public class CallbackBridge {
|
|||||||
GLFW.mGLFWIsGrabbing = grab;
|
GLFW.mGLFWIsGrabbing = grab;
|
||||||
nativeSetGrabbing(grab, xset, yset);
|
nativeSetGrabbing(grab, xset, yset);
|
||||||
}
|
}
|
||||||
|
public static CallbackBridge getSingleton() {
|
||||||
|
if(thisBridge == null) {
|
||||||
|
thisBridge = new CallbackBridge();
|
||||||
|
initBridge(thisBridge);
|
||||||
|
}
|
||||||
|
return thisBridge;
|
||||||
|
}
|
||||||
// Called from Android side
|
// Called from Android side
|
||||||
public static void receiveCallback(int type, int i1, int i2, int i3, int i4) {
|
public void receiveCallback(int type, int i1, int i2, int i3, int i4) {
|
||||||
/*
|
/*
|
||||||
if (INPUT_DEBUG_ENABLED) {
|
if (INPUT_DEBUG_ENABLED) {
|
||||||
System.out.println("LWJGL GLFW Callback received type=" + Integer.toString(type) + ", data=" + i1 + ", " + i2 + ", " + i3 + ", " + i4);
|
System.out.println("LWJGL GLFW Callback received type=" + Integer.toString(type) + ", data=" + i1 + ", " + i2 + ", " + i3 + ", " + i4);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (PENDING_EVENT_READY) {
|
if (pendingEventReady) {
|
||||||
if (type == EVENT_TYPE_CURSOR_POS) {
|
if (type == EVENT_TYPE_CURSOR_POS) {
|
||||||
GLFW.mGLFWCursorX = (double) i1;
|
GLFW.mGLFWCursorX = (double) i1;
|
||||||
GLFW.mGLFWCursorY = (double) i2;
|
GLFW.mGLFWCursorY = (double) i2;
|
||||||
} else {
|
} else {
|
||||||
PENDING_EVENT_LIST.add(new Integer[]{type, (int) i1, (int)i2, i3, i4});
|
pendingEventList.add(new Integer[]{type, (int) i1, (int)i2, i3, i4});
|
||||||
}
|
}
|
||||||
} // else System.out.println("Event input is not ready yet!");
|
} // else System.out.println("Event input is not ready yet!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendData(int type, String data) {
|
public static void sendData(int type, String data) {
|
||||||
nativeSendData(false, type, data);
|
nativeSendData(false, type, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static native void nativeSendData(boolean isAndroid, int type, String data);
|
public static native void nativeSendData(boolean isAndroid, int type, String data);
|
||||||
public static native boolean nativeSetInputReady(boolean ready);
|
public static native boolean nativeSetInputReady(boolean ready);
|
||||||
public static native String nativeClipboard(int action, String copy);
|
public static native String nativeClipboard(int action, String copy);
|
||||||
public static native void nativeAttachThreadToOther(boolean isAndroid, boolean isUseStackQueueBool);
|
public static native void nativeAttachThreadToOther(boolean isAndroid, boolean isUseStackQueueBool);
|
||||||
|
|
||||||
private static native void nativeSetGrabbing(boolean grab, int xset, int yset);
|
private static native void nativeSetGrabbing(boolean grab, int xset, int yset);
|
||||||
|
private static native void initBridge(CallbackBridge bridge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import java.nio.*;
|
|||||||
import javax.annotation.*;
|
import javax.annotation.*;
|
||||||
|
|
||||||
import org.lwjgl.*;
|
import org.lwjgl.*;
|
||||||
import org.lwjgl.opengl.GL;
|
|
||||||
import org.lwjgl.system.*;
|
import org.lwjgl.system.*;
|
||||||
|
|
||||||
import static org.lwjgl.system.APIUtil.*;
|
import static org.lwjgl.system.APIUtil.*;
|
||||||
@ -1067,21 +1066,14 @@ public class GLFW
|
|||||||
mGLFWIsInputReady = true;
|
mGLFWIsInputReady = true;
|
||||||
mGLFWIsUseStackQueue = CallbackBridge.nativeSetInputReady(true);
|
mGLFWIsUseStackQueue = CallbackBridge.nativeSetInputReady(true);
|
||||||
}
|
}
|
||||||
|
CallbackBridge singleton = CallbackBridge.getSingleton();
|
||||||
if (!CallbackBridge.PENDING_EVENT_READY) {
|
if(!singleton.pendingEventReady) {
|
||||||
CallbackBridge.PENDING_EVENT_READY = true;
|
singleton.pendingEventReady = true;
|
||||||
// nglfwSetInputReady();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indirect event
|
// Indirect event
|
||||||
while (CallbackBridge.PENDING_EVENT_LIST.size() > 0) {
|
while (singleton.pendingEventList.size() > 0) {
|
||||||
Integer[] dataArr = CallbackBridge.PENDING_EVENT_LIST.remove(0);
|
Integer[] dataArr = CallbackBridge.getSingleton().pendingEventList.remove(0);
|
||||||
|
|
||||||
if (dataArr == null) { // It should not be null, but still should be catched
|
|
||||||
// System.out.println("GLFW: popped callback is null, skipping");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Long ptr : mGLFWWindowMap.keySet()) {
|
for (Long ptr : mGLFWWindowMap.keySet()) {
|
||||||
try {
|
try {
|
||||||
switch (dataArr[0]) {
|
switch (dataArr[0]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user