[1.13+ input] Try use pointer

This commit is contained in:
khanhduytran0 2020-10-28 15:14:32 +07:00
parent 6c4114a0e8
commit 2c00580903

View File

@ -4,14 +4,14 @@
#include "log.h" #include "log.h"
#include "utils.h" #include "utils.h"
struct GLFWInputEvent { typedef struct {
void* trigger; void* trigger;
// int type; // int type;
unsigned int ui1; unsigned int ui1;
int i1, i2, i3, i4; int i1, i2, i3, i4;
double d1, d2; double d1, d2;
} GLFWInputEvent_t; } GLFWInputEvent;
void* glfwInputEventArr[100]; GLFWInputEvent* glfwInputEventArr[100];
// struct GLFWInputEvent glfwInputEventArr[100]; // struct GLFWInputEvent glfwInputEventArr[100];
int glfwInputEventIndex; 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_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(GLFWInputEvent_t event); typedef void GLFW_invoke_callback(GLFWInputEvent event);
JavaVM* firstJavaVM; JavaVM* firstJavaVM;
JavaVM* secondJavaVM; JavaVM* secondJavaVM;
@ -134,17 +134,17 @@ void invokeCursorPos(int x, int y) {
lastCursorY = y; lastCursorY = y;
} }
void addInputToQueue(GLFWInputEvent_t event) { void addInputToQueue(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] = (void*) &event; glfwInputEventArr[glfwInputEventIndex] = &event;
} }
// TODO merge other defines to // TODO merge other defines to
#define ADD_TRIGGER(NAME, VALUES) \ #define ADD_TRIGGER(NAME, VALUES) \
void trigger##NAME(GLFWInputEvent_t event) { \ void trigger##NAME(GLFWInputEvent event) { \
if (GLFW_invoke_##NAME) { \ if (GLFW_invoke_##NAME) { \
GLFW_invoke_##NAME VALUES; \ GLFW_invoke_##NAME VALUES; \
} \ } \
@ -163,25 +163,25 @@ ADD_TRIGGER(WindowSize, (showingWindow, event.i1, event.i2));
#undef ADD_TRIGGER #undef ADD_TRIGGER
/* /*
void triggerChar(GLFWInputEvent_t event) { void triggerChar(GLFWInputEvent event) {
if (GLFW_invoke_Char) { if (GLFW_invoke_Char) {
GLFW_invoke_Char(showingWindow, event.ui1); GLFW_invoke_Char(showingWindow, event.ui1);
} }
} }
void triggerCharMods(GLFWInputEvent_t event) { void triggerCharMods(GLFWInputEvent event) {
if (GLFW_invoke_CharMods) { if (GLFW_invoke_CharMods) {
GLFW_invoke_CharMods(showingWindow, event.ui1, event.i2); GLFW_invoke_CharMods(showingWindow, event.ui1, event.i2);
} }
} }
void triggerCursorEnter(GLFWInputEvent_t event) { void triggerCursorEnter(GLFWInputEvent event) {
if (GLFW_invoke_CursorEnter) { if (GLFW_invoke_CursorEnter) {
GLFW_invoke_CursorEnter(showingWindow, event.ui1); GLFW_invoke_CursorEnter(showingWindow, event.ui1);
} }
} }
void triggerChar(GLFWInputEvent_t event) { void triggerChar(GLFWInputEvent event) {
if (GLFW_invoke_Char) { if (GLFW_invoke_Char) {
GLFW_invoke_Char(showingWindow, event.ui1); 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++) { for (int i = 0; i <= glfwInputEventIndex; i++) {
GLFWInputEvent_t curr = *(GLFWInputEvent_t*) glfwInputEventArr[i]; GLFWInputEvent curr = *glfwInputEventArr[i];
((GLFW_invoke_callback*) curr.trigger)(curr); ((GLFW_invoke_callback*) curr.trigger)(curr);
// if (debugTimes < 1000) { // 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) { 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) {
GLFWInputEvent_t curr; GLFWInputEvent curr;
curr.trigger = triggerChar; curr.trigger = triggerChar;
curr.ui1 = (unsigned int) codepoint; curr.ui1 = (unsigned int) codepoint;
addInputToQueue(curr); 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) { 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) {
GLFWInputEvent_t curr; GLFWInputEvent curr;
curr.trigger = triggerCharMods; curr.trigger = triggerCharMods;
curr.ui1 = (unsigned int) codepoint; curr.ui1 = (unsigned int) codepoint;
curr.i2 = mods; curr.i2 = mods;
@ -342,7 +342,7 @@ 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) {
GLFWInputEvent_t curr; GLFWInputEvent curr;
curr.trigger = triggerCursorEnter; curr.trigger = triggerCursorEnter;
curr.i1 = 1; curr.i1 = 1;
addInputToQueue(curr); 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) { 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) {
GLFWInputEvent_t curr; GLFWInputEvent curr;
curr.trigger = triggerFramebufferSize; curr.trigger = triggerFramebufferSize;
curr.i1 = width; curr.i1 = width;
curr.i2 = height; 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) { 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) {
GLFWInputEvent_t curr; GLFWInputEvent curr;
curr.trigger = triggerKey; curr.trigger = triggerKey;
curr.i1 = key; curr.i1 = key;
curr.i2 = scancode; curr.i2 = scancode;
@ -394,7 +394,7 @@ 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) {
GLFWInputEvent_t curr; GLFWInputEvent curr;
curr.trigger = triggerMouseButton; curr.trigger = triggerMouseButton;
curr.i1 = button; curr.i1 = button;
curr.i2 = action; 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) { 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) {
GLFWInputEvent_t curr; GLFWInputEvent curr;
curr.trigger = triggerScroll; curr.trigger = triggerScroll;
curr.d1 = (double) xoffset; curr.d1 = (double) xoffset;
curr.d2 = (double) yoffset; 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) { 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) {
GLFWInputEvent_t curr; GLFWInputEvent curr;
curr.trigger = triggerWindowSize; curr.trigger = triggerWindowSize;
curr.i1 = width; curr.i1 = width;
curr.i2 = height; curr.i2 = height;