Only fire cursor pos callback if detect move

This commit is contained in:
khanhduytran0 2020-10-17 13:36:03 +07:00
parent 69f4e4841b
commit fe82d4418c

View File

@ -121,8 +121,9 @@ void invokeCursorPos(int x, int y) {
return; return;
} }
} }
if (!isUseStackQueueCall) if (!isUseStackQueueCall) {
GLFW_invoke_CursorPos(showingWindow, (double) (isGrabbing ? grabCursorX : x), (double) (isGrabbing ? grabCursorY : y)); GLFW_invoke_CursorPos(showingWindow, (double) (isGrabbing ? grabCursorX : x), (double) (isGrabbing ? grabCursorY : y));
}
lastCursorX = x; lastCursorX = x;
lastCursorY = y; lastCursorY = y;
} }
@ -159,26 +160,26 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeIsGrabbing(J
return isGrabbing; return isGrabbing;
} }
int diffX, diffY, logTimes; int diffX, diffY, diffGrabX, diffGrabY;
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwPollEvents(JNIEnv* env, jclass clazz) { JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwPollEvents(JNIEnv* env, jclass clazz) {
if (!isInputReady) isInputReady = true; if (!isInputReady) isInputReady = true;
if (isUseStackQueueCall) { if (isUseStackQueueCall) {
/* if (!isGrabbing && (diffX != lastCursorX || diffY != lastCursorY)) {
LOGI("Mouse pos curr! x=%d, y=%d; Input length=%d", lastCursorX, lastCursorY, glfwInputEventIndex);
if (diffX != lastCursorX || diffY != lastCursorY) {
if (logTimes < 1000) {
logTimes++;
LOGI("Mouse pos diff! x=%d, y=%d", lastCursorX, lastCursorY);
}
diffX = lastCursorX; diffX = lastCursorX;
diffY = lastCursorY; diffY = lastCursorY;
if (GLFW_invoke_CursorPos) {
GLFW_invoke_CursorPos(showingWindow, (double) lastCursorX), (double) lastCursorY));
}
} else if (isGrabbing && (diffGrabX != grabCursorX || diffGrabY != grabCursorY)) {
diffGrabX = grabCursorX;
diffGrabY = grabCursorY;
if (GLFW_invoke_CursorPos) {
GLFW_invoke_CursorPos(showingWindow, (double) grabCursorX, (double) grabCursorY);
}
} }
*/
if (GLFW_invoke_CursorPos) {
GLFW_invoke_CursorPos(showingWindow, (double) (isGrabbing ? grabCursorX : lastCursorX), (double) (isGrabbing ? grabCursorY : lastCursorY));
}
for (int i = 0; i < glfwInputEventIndex; i++) { for (int i = 0; i < glfwInputEventIndex; i++) {
struct GLFWInputEvent curr = glfwInputEventArr[i]; struct GLFWInputEvent curr = glfwInputEventArr[i];
switch (curr.type) { switch (curr.type) {