mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 08:05:34 -04:00
Not to use switch case on input queue
This commit is contained in:
parent
fc3a11219b
commit
279bc726fc
@ -5,17 +5,18 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
struct GLFWInputEvent {
|
struct GLFWInputEvent {
|
||||||
int type;
|
void* trigger;
|
||||||
|
// int type;
|
||||||
unsigned int ui1;
|
unsigned int ui1;
|
||||||
int i1, i2, i3, i4;
|
int i1, i2, i3, i4;
|
||||||
double d1, d2;
|
double d1, d2;
|
||||||
};
|
};
|
||||||
// struct char* glfwInputEventArr[100];
|
struct char* glfwInputEventArr[100];
|
||||||
struct GLFWInputEvent glfwInputEventArr[100];
|
// struct GLFWInputEvent glfwInputEventArr[100];
|
||||||
int glfwInputEventIndex;
|
int glfwInputEventIndex;
|
||||||
|
|
||||||
int grabCursorX, grabCursorY, lastCursorX, lastCursorY;
|
int grabCursorX, grabCursorY, lastCursorX, lastCursorY;
|
||||||
|
/*
|
||||||
#define EVENT_TYPE_CHAR 1000
|
#define EVENT_TYPE_CHAR 1000
|
||||||
#define EVENT_TYPE_CHAR_MODS 1001
|
#define EVENT_TYPE_CHAR_MODS 1001
|
||||||
#define EVENT_TYPE_CURSOR_ENTER 1002
|
#define EVENT_TYPE_CURSOR_ENTER 1002
|
||||||
@ -25,7 +26,7 @@ int grabCursorX, grabCursorY, lastCursorX, lastCursorY;
|
|||||||
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
||||||
#define EVENT_TYPE_SCROLL 1007
|
#define EVENT_TYPE_SCROLL 1007
|
||||||
#define EVENT_TYPE_WINDOW_SIZE 1008
|
#define EVENT_TYPE_WINDOW_SIZE 1008
|
||||||
|
*/
|
||||||
typedef void GLFW_invoke_Char_func(void* window, unsigned int codepoint);
|
typedef void GLFW_invoke_Char_func(void* window, unsigned int codepoint);
|
||||||
typedef void GLFW_invoke_CharMods_func(void* window, unsigned int codepoint, int mods);
|
typedef void GLFW_invoke_CharMods_func(void* window, unsigned int codepoint, int mods);
|
||||||
typedef void GLFW_invoke_CursorEnter_func(void* window, int entered);
|
typedef void GLFW_invoke_CursorEnter_func(void* window, int entered);
|
||||||
@ -36,6 +37,8 @@ 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_Scroll_func(void* window, double xoffset, double yoffset);
|
||||||
typedef void GLFW_invoke_WindowSize_func(void* window, int width, int height);
|
typedef void GLFW_invoke_WindowSize_func(void* window, int width, int height);
|
||||||
|
|
||||||
|
typedef void GLFW_invoke_callback(struct GLFWInputEvent event);
|
||||||
|
|
||||||
JavaVM* firstJavaVM;
|
JavaVM* firstJavaVM;
|
||||||
JavaVM* secondJavaVM;
|
JavaVM* secondJavaVM;
|
||||||
|
|
||||||
@ -130,15 +133,61 @@ void invokeCursorPos(int x, int y) {
|
|||||||
lastCursorX = x;
|
lastCursorX = x;
|
||||||
lastCursorY = y;
|
lastCursorY = y;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
void addInputToQueue(GLFWInputEvent event) {
|
void addInputToQueue(struct GLFWInputEvent event) {
|
||||||
if (glfwInputEventIndex++ >= 100) {
|
if (glfwInputEventIndex++ >= 100) {
|
||||||
// player type too fast? or fps lower than player tps?
|
// player type too fast? or fps lower than player tps?
|
||||||
glfwInputEventIndex = 0;
|
glfwInputEventIndex = 0;
|
||||||
}
|
}
|
||||||
glfwInputEventArr[glfwInputEventIndex] = (char*) event;
|
glfwInputEventArr[glfwInputEventIndex] = (char*) event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO merge other defines to
|
||||||
|
#define ADD_TRIGGER_WWIN(NAME, VALUE) \
|
||||||
|
void trigger##NAME##(struct GLFWInputEvent event) { \
|
||||||
|
if (GLFW_invoke_##NAME##) { \
|
||||||
|
GLFW_invoke_##NAME##(##VALUES##); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
ADD_TRIGGER_WWIN(Char, (event.ui1));
|
||||||
|
ADD_TRIGGER_WWIN(CharMods, (event.ui1, event.i2));
|
||||||
|
ADD_TRIGGER_WWIN(CursorEnter, (event.i1));
|
||||||
|
ADD_TRIGGER_WWIN(CursorPos, ((double) event.i1, (double) event.i2));
|
||||||
|
ADD_TRIGGER_WWIN(FramebufferSize, (event.i1, event.i2));
|
||||||
|
ADD_TRIGGER_WWIN(Key, (event.i1, event.i2, event.i3, event.i4));
|
||||||
|
ADD_TRIGGER_WWIN(MouseButton, (event.i1, event.i2, event.i3));
|
||||||
|
ADD_TRIGGER_WWIN(Scroll, ((double) event.i1, (double) event.i2));
|
||||||
|
ADD_TRIGGER_WWIN(WindowSize, (event.i1, event.i2));
|
||||||
|
|
||||||
|
#undef ADD_TRIGGER_WWIN
|
||||||
|
|
||||||
|
/*
|
||||||
|
void triggerChar(struct GLFWInputEvent event) {
|
||||||
|
if (GLFW_invoke_Char) {
|
||||||
|
GLFW_invoke_Char(showingWindow, event.ui1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void triggerCharMods(struct GLFWInputEvent event) {
|
||||||
|
if (GLFW_invoke_CharMods) {
|
||||||
|
GLFW_invoke_CharMods(showingWindow, event.ui1, event.i2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void triggerCursorEnter(struct GLFWInputEvent event) {
|
||||||
|
if (GLFW_invoke_CursorEnter) {
|
||||||
|
GLFW_invoke_CursorEnter(showingWindow, event.ui1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void triggerChar(struct GLFWInputEvent event) {
|
||||||
|
if (GLFW_invoke_Char) {
|
||||||
|
GLFW_invoke_Char(showingWindow, event.ui1);
|
||||||
|
}
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThreadToOther(JNIEnv* env, jclass clazz, jboolean isAndroid, jboolean isUseStackQueue) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThreadToOther(JNIEnv* env, jclass clazz, jboolean isAndroid, jboolean isUseStackQueue) {
|
||||||
glfwInputEventIndex = -1;
|
glfwInputEventIndex = -1;
|
||||||
// isUseStackQueueCall = 1;
|
// isUseStackQueueCall = 1;
|
||||||
@ -187,17 +236,20 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwPollEvents(JNIEnv* env, jcl
|
|||||||
diffY = lastCursorY;
|
diffY = lastCursorY;
|
||||||
|
|
||||||
if (GLFW_invoke_CursorPos) {
|
if (GLFW_invoke_CursorPos) {
|
||||||
GLFW_invoke_CursorPos(showingWindow, (double) (isGrabbing ? grabCursorX : lastCursorX), (double) (isGrabbing ? grabCursorY : lastCursorY));
|
GLFW_invoke_CursorPos(showingWindow,
|
||||||
|
isGrabbing ? grabCursorX : lastCursorX,
|
||||||
|
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 = (GLFWInputEvent) glfwInputEventArr[i];
|
||||||
|
((GLFW_invoke_callback) curr.trigger)(curr);
|
||||||
|
|
||||||
|
// if (debugTimes < 1000) {
|
||||||
|
// LOGI("INPUT: Got input event %d", curr.type);
|
||||||
|
// }
|
||||||
/*
|
/*
|
||||||
if (debugTimes < 1000) {
|
|
||||||
LOGI("INPUT: Got input event %d", curr.type);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
switch (curr.type) {
|
switch (curr.type) {
|
||||||
case EVENT_TYPE_CHAR:
|
case EVENT_TYPE_CHAR:
|
||||||
if (GLFW_invoke_Char) {
|
if (GLFW_invoke_Char) {
|
||||||
@ -243,6 +295,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwPollEvents(JNIEnv* env, jcl
|
|||||||
LOGW("Unknown GLFW input event: %d", curr.type);
|
LOGW("Unknown GLFW input event: %d", curr.type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
glfwInputEventIndex = -1;
|
glfwInputEventIndex = -1;
|
||||||
}
|
}
|
||||||
@ -251,9 +304,10 @@ 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) {
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendChar(JNIEnv* env, jclass clazz, jint codepoint) {
|
||||||
if (GLFW_invoke_Char && isInputReady) {
|
if (GLFW_invoke_Char && isInputReady) {
|
||||||
if (isUseStackQueueCall) {
|
if (isUseStackQueueCall) {
|
||||||
struct GLFWInputEvent curr = glfwInputEventArr[glfwInputEventIndex++];
|
struct GLFWInputEvent curr;
|
||||||
curr.type = EVENT_TYPE_CHAR;
|
curr.trigger = triggerChar;
|
||||||
curr.ui1 = (unsigned int) codepoint;
|
curr.ui1 = (unsigned int) codepoint;
|
||||||
|
addInputToQueue(curr);
|
||||||
} else
|
} else
|
||||||
GLFW_invoke_Char(showingWindow, codepoint);
|
GLFW_invoke_Char(showingWindow, codepoint);
|
||||||
return JNI_TRUE;
|
return JNI_TRUE;
|
||||||
@ -264,10 +318,11 @@ 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) {
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods(JNIEnv* env, jclass clazz, jint codepoint, jint mods) {
|
||||||
if (GLFW_invoke_CharMods && isInputReady) {
|
if (GLFW_invoke_CharMods && isInputReady) {
|
||||||
if (isUseStackQueueCall) {
|
if (isUseStackQueueCall) {
|
||||||
struct GLFWInputEvent curr = glfwInputEventArr[glfwInputEventIndex++];
|
struct GLFWInputEvent curr;
|
||||||
curr.type = EVENT_TYPE_CHAR_MODS;
|
curr.trigger = triggerCharMods;
|
||||||
curr.ui1 = (unsigned int) codepoint;
|
curr.ui1 = (unsigned int) codepoint;
|
||||||
curr.i2 = mods;
|
curr.i2 = mods;
|
||||||
|
addInputToQueue(curr);
|
||||||
} else
|
} else
|
||||||
GLFW_invoke_CharMods(showingWindow, codepoint, mods);
|
GLFW_invoke_CharMods(showingWindow, codepoint, mods);
|
||||||
return JNI_TRUE;
|
return JNI_TRUE;
|
||||||
@ -287,9 +342,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JN
|
|||||||
if (GLFW_invoke_CursorEnter) {
|
if (GLFW_invoke_CursorEnter) {
|
||||||
isCursorEntered = true;
|
isCursorEntered = true;
|
||||||
if (isUseStackQueueCall) {
|
if (isUseStackQueueCall) {
|
||||||
struct GLFWInputEvent curr = glfwInputEventArr[glfwInputEventIndex++];
|
struct GLFWInputEvent curr;
|
||||||
curr.type = EVENT_TYPE_CURSOR_ENTER;
|
curr.trigger = triggerCursorEnter;
|
||||||
curr.i1 = 1;
|
curr.i1 = 1;
|
||||||
|
addInputToQueue(curr);
|
||||||
} else
|
} else
|
||||||
GLFW_invoke_CursorEnter(showingWindow, 1);
|
GLFW_invoke_CursorEnter(showingWindow, 1);
|
||||||
} else if (isGrabbing) {
|
} else if (isGrabbing) {
|
||||||
@ -306,10 +362,11 @@ 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) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendFramebufferSize(JNIEnv* env, jclass clazz, jint width, jint height) {
|
||||||
if (GLFW_invoke_FramebufferSize && isInputReady) {
|
if (GLFW_invoke_FramebufferSize && isInputReady) {
|
||||||
if (isUseStackQueueCall) {
|
if (isUseStackQueueCall) {
|
||||||
struct GLFWInputEvent curr = glfwInputEventArr[glfwInputEventIndex++];
|
struct GLFWInputEvent curr;
|
||||||
curr.type = EVENT_TYPE_FRAMEBUFFER_SIZE;
|
curr.trigger = triggerFramebufferSize;
|
||||||
curr.i1 = width;
|
curr.i1 = width;
|
||||||
curr.i2 = height;
|
curr.i2 = height;
|
||||||
|
addInputToQueue(curr);
|
||||||
} else
|
} else
|
||||||
GLFW_invoke_FramebufferSize(showingWindow, width, height);
|
GLFW_invoke_FramebufferSize(showingWindow, width, height);
|
||||||
}
|
}
|
||||||
@ -318,13 +375,13 @@ 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) {
|
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 (GLFW_invoke_Key && isInputReady) {
|
||||||
if (isUseStackQueueCall) {
|
if (isUseStackQueueCall) {
|
||||||
struct GLFWInputEvent curr = glfwInputEventArr[glfwInputEventIndex++];
|
struct GLFWInputEvent curr;
|
||||||
curr.type = EVENT_TYPE_KEY;
|
curr.trigger = triggerKey;
|
||||||
curr.i1 = key;
|
curr.i1 = key;
|
||||||
curr.i2 = scancode;
|
curr.i2 = scancode;
|
||||||
curr.i3 = action;
|
curr.i3 = action;
|
||||||
curr.i4 = mods;
|
curr.i4 = mods;
|
||||||
// addInputToQueue(curr);
|
addInputToQueue(curr);
|
||||||
} else
|
} else
|
||||||
GLFW_invoke_Key(showingWindow, key, scancode, action, mods);
|
GLFW_invoke_Key(showingWindow, key, scancode, action, mods);
|
||||||
}
|
}
|
||||||
@ -337,11 +394,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(
|
|||||||
isPrepareGrabPos = true;
|
isPrepareGrabPos = true;
|
||||||
} else if (GLFW_invoke_MouseButton) {
|
} else if (GLFW_invoke_MouseButton) {
|
||||||
if (isUseStackQueueCall) {
|
if (isUseStackQueueCall) {
|
||||||
struct GLFWInputEvent curr = glfwInputEventArr[glfwInputEventIndex++];
|
struct GLFWInputEvent curr;
|
||||||
curr.type = EVENT_TYPE_MOUSE_BUTTON;
|
curr.trigger = triggerMouseButton;
|
||||||
curr.i1 = button;
|
curr.i1 = button;
|
||||||
curr.i2 = action;
|
curr.i2 = action;
|
||||||
curr.i3 = mods;
|
curr.i3 = mods;
|
||||||
|
addInputToQueue(curr);
|
||||||
} else
|
} else
|
||||||
GLFW_invoke_MouseButton(showingWindow, button, action, mods);
|
GLFW_invoke_MouseButton(showingWindow, button, action, mods);
|
||||||
}
|
}
|
||||||
@ -351,10 +409,11 @@ 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) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScroll(JNIEnv* env, jclass clazz, jdouble xoffset, jdouble yoffset) {
|
||||||
if (GLFW_invoke_Scroll && isInputReady) {
|
if (GLFW_invoke_Scroll && isInputReady) {
|
||||||
if (isUseStackQueueCall) {
|
if (isUseStackQueueCall) {
|
||||||
struct GLFWInputEvent curr = glfwInputEventArr[glfwInputEventIndex++];
|
struct GLFWInputEvent curr;
|
||||||
curr.type = EVENT_TYPE_SCROLL;
|
curr.trigger = triggerScroll;
|
||||||
curr.d1 = (double) xoffset;
|
curr.d1 = (double) xoffset;
|
||||||
curr.d2 = (double) yoffset;
|
curr.d2 = (double) yoffset;
|
||||||
|
addInputToQueue(curr);
|
||||||
} else
|
} else
|
||||||
GLFW_invoke_Scroll(showingWindow, (double) xoffset, (double) yoffset);
|
GLFW_invoke_Scroll(showingWindow, (double) xoffset, (double) yoffset);
|
||||||
}
|
}
|
||||||
@ -363,10 +422,11 @@ 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) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendWindowSize(JNIEnv* env, jclass clazz, jint width, jint height) {
|
||||||
if (GLFW_invoke_WindowSize && isInputReady) {
|
if (GLFW_invoke_WindowSize && isInputReady) {
|
||||||
if (isUseStackQueueCall) {
|
if (isUseStackQueueCall) {
|
||||||
struct GLFWInputEvent curr = glfwInputEventArr[glfwInputEventIndex++];
|
struct GLFWInputEvent curr;
|
||||||
curr.type = EVENT_TYPE_WINDOW_SIZE;
|
curr.trigger = triggerWindowSize;
|
||||||
curr.i1 = width;
|
curr.i1 = width;
|
||||||
curr.i2 = height;
|
curr.i2 = height;
|
||||||
|
addInputToQueue(curr);
|
||||||
} else
|
} else
|
||||||
GLFW_invoke_WindowSize(showingWindow, width, height);
|
GLFW_invoke_WindowSize(showingWindow, width, height);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user