From 2c0058090303d04c4d53e590ec17e93b08ce1397 Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Wed, 28 Oct 2020 15:14:32 +0700 Subject: [PATCH] [1.13+ input] Try use pointer --- app/src/main/jni/input_bridge.c | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/app/src/main/jni/input_bridge.c b/app/src/main/jni/input_bridge.c index 4af85be98..0e859c48e 100644 --- a/app/src/main/jni/input_bridge.c +++ b/app/src/main/jni/input_bridge.c @@ -4,14 +4,14 @@ #include "log.h" #include "utils.h" -struct GLFWInputEvent { +typedef struct { void* trigger; // int type; unsigned int ui1; int i1, i2, i3, i4; double d1, d2; -} GLFWInputEvent_t; -void* glfwInputEventArr[100]; +} GLFWInputEvent; +GLFWInputEvent* glfwInputEventArr[100]; // struct GLFWInputEvent glfwInputEventArr[100]; int glfwInputEventIndex; @@ -37,7 +37,7 @@ typedef void GLFW_invoke_MouseButton_func(void* window, int button, int action, typedef void GLFW_invoke_Scroll_func(void* window, double xoffset, double yoffset); typedef void GLFW_invoke_WindowSize_func(void* window, int width, int height); -typedef void GLFW_invoke_callback(GLFWInputEvent_t event); +typedef void GLFW_invoke_callback(GLFWInputEvent event); JavaVM* firstJavaVM; JavaVM* secondJavaVM; @@ -134,17 +134,17 @@ void invokeCursorPos(int x, int y) { lastCursorY = y; } -void addInputToQueue(GLFWInputEvent_t event) { +void addInputToQueue(GLFWInputEvent event) { if (glfwInputEventIndex++ >= 100) { // player type too fast? or fps lower than player tps? glfwInputEventIndex = 0; } - glfwInputEventArr[glfwInputEventIndex] = (void*) &event; + glfwInputEventArr[glfwInputEventIndex] = &event; } // TODO merge other defines to #define ADD_TRIGGER(NAME, VALUES) \ -void trigger##NAME(GLFWInputEvent_t event) { \ +void trigger##NAME(GLFWInputEvent event) { \ if (GLFW_invoke_##NAME) { \ GLFW_invoke_##NAME VALUES; \ } \ @@ -163,25 +163,25 @@ ADD_TRIGGER(WindowSize, (showingWindow, event.i1, event.i2)); #undef ADD_TRIGGER /* -void triggerChar(GLFWInputEvent_t event) { +void triggerChar(GLFWInputEvent event) { if (GLFW_invoke_Char) { GLFW_invoke_Char(showingWindow, event.ui1); } } -void triggerCharMods(GLFWInputEvent_t event) { +void triggerCharMods(GLFWInputEvent event) { if (GLFW_invoke_CharMods) { GLFW_invoke_CharMods(showingWindow, event.ui1, event.i2); } } -void triggerCursorEnter(GLFWInputEvent_t event) { +void triggerCursorEnter(GLFWInputEvent event) { if (GLFW_invoke_CursorEnter) { GLFW_invoke_CursorEnter(showingWindow, event.ui1); } } -void triggerChar(GLFWInputEvent_t event) { +void triggerChar(GLFWInputEvent event) { if (GLFW_invoke_Char) { GLFW_invoke_Char(showingWindow, event.ui1); } @@ -243,7 +243,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwPollEvents(JNIEnv* env, jcl } for (int i = 0; i <= glfwInputEventIndex; i++) { - GLFWInputEvent_t curr = *(GLFWInputEvent_t*) glfwInputEventArr[i]; + GLFWInputEvent curr = *glfwInputEventArr[i]; ((GLFW_invoke_callback*) curr.trigger)(curr); // if (debugTimes < 1000) { @@ -304,7 +304,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwPollEvents(JNIEnv* env, jcl JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendChar(JNIEnv* env, jclass clazz, jint codepoint) { if (GLFW_invoke_Char && isInputReady) { if (isUseStackQueueCall) { - GLFWInputEvent_t curr; + GLFWInputEvent curr; curr.trigger = triggerChar; curr.ui1 = (unsigned int) codepoint; addInputToQueue(curr); @@ -318,7 +318,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendChar(JNI JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods(JNIEnv* env, jclass clazz, jint codepoint, jint mods) { if (GLFW_invoke_CharMods && isInputReady) { if (isUseStackQueueCall) { - GLFWInputEvent_t curr; + GLFWInputEvent curr; curr.trigger = triggerCharMods; curr.ui1 = (unsigned int) codepoint; curr.i2 = mods; @@ -342,7 +342,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JN if (GLFW_invoke_CursorEnter) { isCursorEntered = true; if (isUseStackQueueCall) { - GLFWInputEvent_t curr; + GLFWInputEvent curr; curr.trigger = triggerCursorEnter; curr.i1 = 1; addInputToQueue(curr); @@ -362,7 +362,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JN JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendFramebufferSize(JNIEnv* env, jclass clazz, jint width, jint height) { if (GLFW_invoke_FramebufferSize && isInputReady) { if (isUseStackQueueCall) { - GLFWInputEvent_t curr; + GLFWInputEvent curr; curr.trigger = triggerFramebufferSize; curr.i1 = width; curr.i2 = height; @@ -375,7 +375,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendFramebufferS JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(JNIEnv* env, jclass clazz, jint key, jint scancode, jint action, jint mods) { if (GLFW_invoke_Key && isInputReady) { if (isUseStackQueueCall) { - GLFWInputEvent_t curr; + GLFWInputEvent curr; curr.trigger = triggerKey; curr.i1 = key; curr.i2 = scancode; @@ -394,7 +394,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton( isPrepareGrabPos = true; } else if (GLFW_invoke_MouseButton) { if (isUseStackQueueCall) { - GLFWInputEvent_t curr; + GLFWInputEvent curr; curr.trigger = triggerMouseButton; curr.i1 = button; curr.i2 = action; @@ -409,7 +409,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton( JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScroll(JNIEnv* env, jclass clazz, jdouble xoffset, jdouble yoffset) { if (GLFW_invoke_Scroll && isInputReady) { if (isUseStackQueueCall) { - GLFWInputEvent_t curr; + GLFWInputEvent curr; curr.trigger = triggerScroll; curr.d1 = (double) xoffset; curr.d2 = (double) yoffset; @@ -422,7 +422,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScroll(JNIEn JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendWindowSize(JNIEnv* env, jclass clazz, jint width, jint height) { if (GLFW_invoke_WindowSize && isInputReady) { if (isUseStackQueueCall) { - GLFWInputEvent_t curr; + GLFWInputEvent curr; curr.trigger = triggerWindowSize; curr.i1 = width; curr.i2 = height;