Make CallbackBridge static again for more performance

This commit is contained in:
artdeell
2022-05-10 21:10:32 +03:00
parent dd63c7e242
commit 52243eff92
5 changed files with 19 additions and 30 deletions

View File

@@ -1 +1 @@
1652124351110
1652206097040

View File

@@ -41,7 +41,6 @@ static float grabCursorX, grabCursorY, lastCursorX, lastCursorY;
jclass inputBridgeClass_ANDROID, inputBridgeClass_JRE;
jmethodID inputBridgeMethod_ANDROID, inputBridgeMethod_JRE;
jobject inputBridgeObject_ANDROID;
jclass bridgeClazz;
jboolean isGrabbing;
@@ -123,10 +122,10 @@ void sendData(int type, int i1, int i2, int i3, int i4) {
LOGE("BUG: Input is ready but thread is not attached yet.");
return;
}
if(inputBridgeObject_ANDROID == NULL) return;
(*runtimeJNIEnvPtr_ANDROID)->CallVoidMethod(
if(inputBridgeClass_ANDROID == NULL) return;
(*runtimeJNIEnvPtr_ANDROID)->CallStaticVoidMethod(
runtimeJNIEnvPtr_ANDROID,
inputBridgeObject_ANDROID,
inputBridgeClass_ANDROID,
inputBridgeMethod_ANDROID,
type,
i1, i2, i3, i4
@@ -382,9 +381,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetWindowAttrib(
}
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);
Java_org_lwjgl_glfw_CallbackBridge_setClass(JNIEnv *env, jclass clazz) {
// TODO: implement setClass()
inputBridgeMethod_ANDROID = (*env)->GetStaticMethodID(env, clazz, "receiveCallback", "(IIIII)V");
inputBridgeClass_ANDROID = (*env)->NewGlobalRef(env, clazz);
}

View File

@@ -18,9 +18,8 @@ public class CallbackBridge {
public static final int ANDROID_TYPE_GRAB_STATE = 0;
// Should pending events be limited?
volatile public List<Integer[]> pendingEventList = new ArrayList<>();
volatile public boolean pendingEventReady = false;
private static CallbackBridge thisBridge = null;
volatile public static List<Integer[]> PENDING_EVENT_LIST = new ArrayList<>();
volatile public static boolean PENDING_EVENT_READY = false;
public static final boolean INPUT_DEBUG_ENABLED;
@@ -49,27 +48,20 @@ public class CallbackBridge {
GLFW.mGLFWIsGrabbing = grab;
nativeSetGrabbing(grab, xset, yset);
}
public static CallbackBridge getSingleton() {
if(thisBridge == null) {
thisBridge = new CallbackBridge();
initBridge(thisBridge);
}
return thisBridge;
}
// Called from Android side
public void receiveCallback(int type, int i1, int i2, int i3, int i4) {
public static void receiveCallback(int type, int i1, int i2, int i3, int i4) {
/*
if (INPUT_DEBUG_ENABLED) {
System.out.println("LWJGL GLFW Callback received type=" + Integer.toString(type) + ", data=" + i1 + ", " + i2 + ", " + i3 + ", " + i4);
}
*/
if (pendingEventReady) {
if (PENDING_EVENT_READY) {
if (type == EVENT_TYPE_CURSOR_POS) {
GLFW.mGLFWCursorX = (double) i1;
GLFW.mGLFWCursorY = (double) i2;
} else {
pendingEventList.add(new Integer[]{type, (int) i1, (int)i2, i3, i4});
PENDING_EVENT_LIST.add(new Integer[]{type, (int) i1, (int)i2, i3, i4});
}
} // else System.out.println("Event input is not ready yet!");
}
@@ -82,6 +74,6 @@ public class CallbackBridge {
public static native String nativeClipboard(int action, String copy);
public static native void nativeAttachThreadToOther(boolean isAndroid, boolean isUseStackQueueBool);
private static native void nativeSetGrabbing(boolean grab, int xset, int yset);
private static native void initBridge(CallbackBridge bridge);
public static native void setClass();
}

View File

@@ -523,7 +523,7 @@ public class GLFW
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
}
CallbackBridge.setClass();
mGLFWErrorCallback = GLFWErrorCallback.createPrint();
mGLFWKeyCodes = new ArrayMap<>();
@@ -1066,14 +1066,13 @@ public class GLFW
mGLFWIsInputReady = true;
mGLFWIsUseStackQueue = CallbackBridge.nativeSetInputReady(true);
}
CallbackBridge singleton = CallbackBridge.getSingleton();
if(!singleton.pendingEventReady) {
singleton.pendingEventReady = true;
if(!CallbackBridge.PENDING_EVENT_READY) {
CallbackBridge.PENDING_EVENT_READY = true;
}
// Indirect event
while (singleton.pendingEventList.size() > 0) {
Integer[] dataArr = singleton.pendingEventList.remove(0);
while (CallbackBridge.PENDING_EVENT_LIST.size() > 0) {
Integer[] dataArr = CallbackBridge.PENDING_EVENT_LIST.remove(0);
for (Long ptr : mGLFWWindowMap.keySet()) {
try {
switch (dataArr[0]) {