mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-14 15:17:02 -04:00
Code cleanup!
This commit is contained in:
parent
944be73f55
commit
f732916f8a
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* V1 input bridge implementation.
|
||||
*
|
||||
* Status:
|
||||
* - Abandoned.
|
||||
* - Works in any versions.
|
||||
* - More lag than v2 and v3
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
jclass inputBridgeClass_ANDROID;
|
||||
jmethodID inputBridgeMethod_ANDROID;
|
||||
|
||||
jclass inputBridgeClass_JRE;
|
||||
jmethodID inputBridgeMethod_JRE;
|
||||
|
||||
jboolean isGrabbing;
|
||||
|
||||
JavaVM* firstJavaVM;
|
||||
JNIEnv* firstJNIEnv;
|
||||
|
||||
JavaVM* secondJavaVM;
|
||||
JNIEnv* secondJNIEnv;
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
if (dalvikJavaVMPtr == NULL) {
|
||||
//Save dalvik global JavaVM pointer
|
||||
dalvikJavaVMPtr = vm;
|
||||
(*vm)->GetEnv(vm, (void**) &dalvikJNIEnvPtr_ANDROID, JNI_VERSION_1_4);
|
||||
} else if (dalvikJavaVMPtr != vm) {
|
||||
runtimeJavaVMPtr = vm;
|
||||
(*vm)->GetEnv(vm, (void**) &runtimeJNIEnvPtr_JRE, JNI_VERSION_1_4);
|
||||
}
|
||||
|
||||
isGrabbing = JNI_FALSE;
|
||||
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
// Should be?
|
||||
/*
|
||||
void JNI_OnUnload(JavaVM* vm, void* reserved) {
|
||||
if (dalvikJavaVMPtr == vm) {
|
||||
} else {
|
||||
}
|
||||
|
||||
DetachCurrentThread(vm);
|
||||
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
*/
|
||||
|
||||
void attachThreadIfNeed(bool* isAttached, JNIEnv** secondJNIEnvPtr) {
|
||||
if (!*isAttached && secondJavaVM) {
|
||||
(*secondJavaVM)->AttachCurrentThread(secondJavaVM, secondJNIEnvPtr, NULL);
|
||||
*isAttached = true;
|
||||
}
|
||||
secondJNIEnv = *secondJNIEnvPtr;
|
||||
}
|
||||
|
||||
void getJavaInputBridge(jclass* clazz, jmethodID* method) {
|
||||
if (*method == NULL && secondJNIEnv != NULL) {
|
||||
*clazz = (*secondJNIEnv)->FindClass(secondJNIEnv, "org/lwjgl/glfw/CallbackBridge");
|
||||
assert(*clazz != NULL);
|
||||
*method = (*secondJNIEnv)->GetStaticMethodID(secondJNIEnv, *clazz, "receiveCallback", "(ILjava/lang/String;)V");
|
||||
assert(*method != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendData(JNIEnv* env, jclass clazz, jboolean isAndroid, jint type, jstring data) {
|
||||
if (isAndroid == JNI_TRUE) {
|
||||
firstJavaVM = dalvikJavaVMPtr;
|
||||
firstJNIEnv = dalvikJNIEnvPtr_ANDROID;
|
||||
secondJavaVM = runtimeJavaVMPtr;
|
||||
|
||||
attachThreadIfNeed(&isAndroidThreadAttached, &runtimeJNIEnvPtr_ANDROID);
|
||||
getJavaInputBridge(&inputBridgeClass_ANDROID, &inputBridgeMethod_ANDROID);
|
||||
} else {
|
||||
firstJavaVM = runtimeJavaVMPtr;
|
||||
firstJNIEnv = runtimeJNIEnvPtr_JRE;
|
||||
secondJavaVM = dalvikJavaVMPtr;
|
||||
|
||||
attachThreadIfNeed(&isRuntimeThreadAttached, &dalvikJNIEnvPtr_JRE);
|
||||
getJavaInputBridge(&inputBridgeClass_JRE, &inputBridgeMethod_JRE);
|
||||
}
|
||||
|
||||
// printf("isAndroid=%p, isSecondJVMNull=%p\n", isAndroid, secondJavaVM == NULL);
|
||||
|
||||
if (secondJavaVM != NULL) {
|
||||
char *data_c = (char*)(*env)->GetStringUTFChars(env, data, 0);
|
||||
// printf("data=%s\n", data_c);
|
||||
jstring data_jre = (*secondJNIEnv)->NewStringUTF(secondJNIEnv, data_c);
|
||||
(*env)->ReleaseStringUTFChars(env, data, data_c);
|
||||
(*secondJNIEnv)->CallStaticVoidMethod(
|
||||
secondJNIEnv,
|
||||
isAndroid == JNI_TRUE ? inputBridgeClass_ANDROID : inputBridgeClass_JRE,
|
||||
isAndroid == JNI_TRUE ? inputBridgeMethod_ANDROID : inputBridgeMethod_JRE,
|
||||
type,
|
||||
data_jre
|
||||
);
|
||||
}
|
||||
// else: too early!
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(JNIEnv* env, jclass clazz, jboolean grabbing) {
|
||||
isGrabbing = grabbing;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeIsGrabbing(JNIEnv* env, jclass clazz) {
|
||||
return isGrabbing;
|
||||
}
|
||||
|
@ -1,446 +0,0 @@
|
||||
/*
|
||||
* V2 input bridge implementation.
|
||||
*
|
||||
* Status:
|
||||
* - Abandoned.
|
||||
* - 1.13+ works, but below them don't.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "utils.h"
|
||||
|
||||
typedef struct {
|
||||
void* trigger;
|
||||
// int type;
|
||||
unsigned int ui1;
|
||||
int i1, i2, i3, i4;
|
||||
double d1, d2;
|
||||
} GLFWInputEvent;
|
||||
GLFWInputEvent* glfwInputEventArr[100];
|
||||
// struct GLFWInputEvent glfwInputEventArr[100];
|
||||
int glfwInputEventIndex;
|
||||
|
||||
int grabCursorX, grabCursorY, lastCursorX, lastCursorY;
|
||||
/*
|
||||
#define EVENT_TYPE_CHAR 1000
|
||||
#define EVENT_TYPE_CHAR_MODS 1001
|
||||
#define EVENT_TYPE_CURSOR_ENTER 1002
|
||||
#define EVENT_TYPE_CURSOR_POS 1003
|
||||
#define EVENT_TYPE_FRAMEBUFFER_SIZE 1004
|
||||
#define EVENT_TYPE_KEY 1005
|
||||
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
||||
#define EVENT_TYPE_SCROLL 1007
|
||||
#define EVENT_TYPE_WINDOW_SIZE 1008
|
||||
*/
|
||||
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_CursorEnter_func(void* window, int entered);
|
||||
typedef void GLFW_invoke_CursorPos_func(void* window, double xpos, double ypos);
|
||||
typedef void GLFW_invoke_FramebufferSize_func(void* window, int width, int height);
|
||||
typedef void GLFW_invoke_Key_func(void* window, int key, int scancode, int action, int mods);
|
||||
typedef void GLFW_invoke_MouseButton_func(void* window, int button, int action, int mods);
|
||||
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 event);
|
||||
|
||||
JavaVM* firstJavaVM;
|
||||
JavaVM* secondJavaVM;
|
||||
|
||||
JNIEnv* firstJNIEnv;
|
||||
JNIEnv* secondJNIEnv;
|
||||
|
||||
jclass inputBridgeClass_ANDROID, inputBridgeClass_JRE;
|
||||
jmethodID inputBridgeMethod_ANDROID, inputBridgeMethod_JRE;
|
||||
|
||||
jboolean isGrabbing, isUseStackQueueCall;
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
if (dalvikJavaVMPtr == NULL) {
|
||||
//Save dalvik global JavaVM pointer
|
||||
dalvikJavaVMPtr = vm;
|
||||
(*vm)->GetEnv(vm, (void**) &dalvikJNIEnvPtr_ANDROID, JNI_VERSION_1_4);
|
||||
} else if (dalvikJavaVMPtr != vm) {
|
||||
runtimeJavaVMPtr = vm;
|
||||
(*vm)->GetEnv(vm, (void**) &runtimeJNIEnvPtr_JRE, JNI_VERSION_1_4);
|
||||
}
|
||||
|
||||
isGrabbing = JNI_FALSE;
|
||||
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
// Should be?
|
||||
void JNI_OnUnload(JavaVM* vm, void* reserved) {
|
||||
/*
|
||||
if (dalvikJavaVMPtr == vm) {
|
||||
} else {
|
||||
}
|
||||
|
||||
DetachCurrentThread(vm);
|
||||
*/
|
||||
|
||||
free(glfwInputEventArr);
|
||||
}
|
||||
|
||||
#define ADD_CALLBACK_WWIN(NAME) \
|
||||
GLFW_invoke_##NAME##_func* GLFW_invoke_##NAME; \
|
||||
JNIEXPORT jlong JNICALL Java_org_lwjgl_glfw_GLFW_nglfwSet##NAME##Callback(JNIEnv * env, jclass cls, jlong window, jlong callbackptr) { \
|
||||
void** oldCallback = &GLFW_invoke_##NAME; \
|
||||
GLFW_invoke_##NAME = (GLFW_invoke_##NAME##_func*) (uintptr_t) callbackptr; \
|
||||
return (jlong) (uintptr_t) *oldCallback; \
|
||||
}
|
||||
|
||||
ADD_CALLBACK_WWIN(Char);
|
||||
ADD_CALLBACK_WWIN(CharMods);
|
||||
ADD_CALLBACK_WWIN(CursorEnter);
|
||||
ADD_CALLBACK_WWIN(CursorPos);
|
||||
ADD_CALLBACK_WWIN(FramebufferSize);
|
||||
ADD_CALLBACK_WWIN(Key);
|
||||
ADD_CALLBACK_WWIN(MouseButton);
|
||||
ADD_CALLBACK_WWIN(Scroll);
|
||||
ADD_CALLBACK_WWIN(WindowSize);
|
||||
|
||||
#undef ADD_CALLBACK_WWIN
|
||||
|
||||
void attachThreadIfNeed(bool* isAttached, JNIEnv** secondJNIEnvPtr) {
|
||||
if (!*isAttached && secondJavaVM) {
|
||||
(*secondJavaVM)->AttachCurrentThread(secondJavaVM, secondJNIEnvPtr, NULL);
|
||||
*isAttached = true;
|
||||
}
|
||||
secondJNIEnv = *secondJNIEnvPtr;
|
||||
}
|
||||
|
||||
void getJavaInputBridge(jclass* clazz, jmethodID* method) {
|
||||
if (*method == NULL && secondJNIEnv != NULL) {
|
||||
*clazz = (*secondJNIEnv)->FindClass(secondJNIEnv, "org/lwjgl/glfw/CallbackBridge");
|
||||
assert(*clazz != NULL);
|
||||
*method = (*secondJNIEnv)->GetStaticMethodID(secondJNIEnv, *clazz, "receiveCallback", "(ILjava/lang/String;)V");
|
||||
assert(*method != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void invokeCursorPos(int x, int y) {
|
||||
if (isGrabbing) {
|
||||
if (!isPrepareGrabPos) {
|
||||
grabCursorX += x - lastCursorX;
|
||||
grabCursorY += y - lastCursorY;
|
||||
} else {
|
||||
isPrepareGrabPos = false;
|
||||
lastCursorX = x;
|
||||
lastCursorY = y;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!isUseStackQueueCall && GLFW_invoke_CursorPos) {
|
||||
GLFW_invoke_CursorPos(showingWindow, (double) (isGrabbing ? grabCursorX : x), (double) (isGrabbing ? grabCursorY : y));
|
||||
}
|
||||
lastCursorX = x;
|
||||
lastCursorY = y;
|
||||
}
|
||||
|
||||
void addInputToQueue(GLFWInputEvent event) {
|
||||
if (glfwInputEventIndex++ >= 100) {
|
||||
// player type too fast? or fps lower than player tps?
|
||||
glfwInputEventIndex = 0;
|
||||
}
|
||||
glfwInputEventArr[glfwInputEventIndex] = &event;
|
||||
}
|
||||
|
||||
// TODO merge other defines to
|
||||
#define ADD_TRIGGER(NAME, VALUES) \
|
||||
void trigger##NAME(GLFWInputEvent event) { \
|
||||
if (GLFW_invoke_##NAME) { \
|
||||
GLFW_invoke_##NAME VALUES; \
|
||||
} \
|
||||
}
|
||||
|
||||
ADD_TRIGGER(Char, (showingWindow, event.ui1));
|
||||
ADD_TRIGGER(CharMods, (showingWindow, event.ui1, event.i2));
|
||||
ADD_TRIGGER(CursorEnter, (showingWindow, event.i1));
|
||||
ADD_TRIGGER(CursorPos, (showingWindow, (double) event.i1, (double) event.i2));
|
||||
ADD_TRIGGER(FramebufferSize, (showingWindow, event.i1, event.i2));
|
||||
ADD_TRIGGER(Key, (showingWindow, event.i1, event.i2, event.i3, event.i4));
|
||||
ADD_TRIGGER(MouseButton, (showingWindow, event.i1, event.i2, event.i3));
|
||||
ADD_TRIGGER(Scroll, (showingWindow, (double) event.i1, (double) event.i2));
|
||||
ADD_TRIGGER(WindowSize, (showingWindow, event.i1, event.i2));
|
||||
|
||||
#undef ADD_TRIGGER
|
||||
|
||||
/*
|
||||
void triggerChar(GLFWInputEvent event) {
|
||||
if (GLFW_invoke_Char) {
|
||||
GLFW_invoke_Char(showingWindow, event.ui1);
|
||||
}
|
||||
}
|
||||
|
||||
void triggerCharMods(GLFWInputEvent event) {
|
||||
if (GLFW_invoke_CharMods) {
|
||||
GLFW_invoke_CharMods(showingWindow, event.ui1, event.i2);
|
||||
}
|
||||
}
|
||||
|
||||
void triggerCursorEnter(GLFWInputEvent event) {
|
||||
if (GLFW_invoke_CursorEnter) {
|
||||
GLFW_invoke_CursorEnter(showingWindow, event.ui1);
|
||||
}
|
||||
}
|
||||
|
||||
void triggerChar(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) {
|
||||
glfwInputEventIndex = -1;
|
||||
// isUseStackQueueCall = 1;
|
||||
isUseStackQueueCall = (int) isUseStackQueue;
|
||||
if (isUseStackQueue) {
|
||||
isPrepareGrabPos = true;
|
||||
} else if (isAndroid) {
|
||||
firstJavaVM = dalvikJavaVMPtr;
|
||||
firstJNIEnv = dalvikJNIEnvPtr_ANDROID;
|
||||
secondJavaVM = runtimeJavaVMPtr;
|
||||
|
||||
attachThreadIfNeed(&isAndroidThreadAttached, &runtimeJNIEnvPtr_ANDROID);
|
||||
getJavaInputBridge(&inputBridgeClass_ANDROID, &inputBridgeMethod_ANDROID);
|
||||
|
||||
isPrepareGrabPos = true;
|
||||
} else {
|
||||
firstJavaVM = runtimeJavaVMPtr;
|
||||
firstJNIEnv = runtimeJNIEnvPtr_JRE;
|
||||
secondJavaVM = dalvikJavaVMPtr;
|
||||
|
||||
attachThreadIfNeed(&isRuntimeThreadAttached, &dalvikJNIEnvPtr_JRE);
|
||||
getJavaInputBridge(&inputBridgeClass_JRE, &inputBridgeMethod_JRE);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(JNIEnv* env, jclass clazz, jboolean grabbing) {
|
||||
isGrabbing = grabbing;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeIsGrabbing(JNIEnv* env, jclass clazz) {
|
||||
return isGrabbing;
|
||||
}
|
||||
|
||||
int diffX, diffY, diffGrabX, diffGrabY, debugTimes;
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwPollEvents(JNIEnv* env, jclass clazz) {
|
||||
if (!isInputReady) isInputReady = true;
|
||||
/*
|
||||
if (debugTimes < 1000) {
|
||||
debugTimes++;
|
||||
LOGI("INPUT: IsUseStackQueue=%d, CurrentInputLength=%d, CursorX=%d, CursorY=%d", isUseStackQueueCall, glfwInputEventIndex, lastCursorX, lastCursorY);
|
||||
}
|
||||
*/
|
||||
if (isUseStackQueueCall) {
|
||||
if (diffX != lastCursorX || diffY != lastCursorY) {
|
||||
diffX = lastCursorX;
|
||||
diffY = lastCursorY;
|
||||
|
||||
if (GLFW_invoke_CursorPos) {
|
||||
GLFW_invoke_CursorPos(showingWindow,
|
||||
isGrabbing ? grabCursorX : lastCursorX,
|
||||
isGrabbing ? grabCursorY : lastCursorY);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i <= glfwInputEventIndex; i++) {
|
||||
GLFWInputEvent curr = *glfwInputEventArr[i];
|
||||
((GLFW_invoke_callback*) curr.trigger)(curr);
|
||||
|
||||
// if (debugTimes < 1000) {
|
||||
// LOGI("INPUT: Got input event %d", curr.type);
|
||||
// }
|
||||
/*
|
||||
switch (curr.type) {
|
||||
case EVENT_TYPE_CHAR:
|
||||
if (GLFW_invoke_Char) {
|
||||
GLFW_invoke_Char(showingWindow, curr.ui1);
|
||||
}
|
||||
break;
|
||||
case EVENT_TYPE_CHAR_MODS:
|
||||
if (GLFW_invoke_CharMods) {
|
||||
GLFW_invoke_CharMods(showingWindow, curr.ui1, curr.i2);
|
||||
}
|
||||
break;
|
||||
case EVENT_TYPE_CURSOR_ENTER:
|
||||
if (GLFW_invoke_CursorEnter) {
|
||||
GLFW_invoke_CursorEnter(showingWindow, curr.i1);
|
||||
}
|
||||
break;
|
||||
case EVENT_TYPE_FRAMEBUFFER_SIZE:
|
||||
if (GLFW_invoke_FramebufferSize) {
|
||||
GLFW_invoke_FramebufferSize(showingWindow, curr.i1, curr.i2);
|
||||
}
|
||||
break;
|
||||
case EVENT_TYPE_KEY:
|
||||
if (GLFW_invoke_Key) {
|
||||
GLFW_invoke_Key(showingWindow, curr.i1, curr.i2, curr.i3, curr.i4);
|
||||
}
|
||||
break;
|
||||
case EVENT_TYPE_MOUSE_BUTTON:
|
||||
if (GLFW_invoke_MouseButton) {
|
||||
GLFW_invoke_MouseButton(showingWindow, curr.i1, curr.i2, curr.i3);
|
||||
}
|
||||
break;
|
||||
case EVENT_TYPE_SCROLL:
|
||||
if (GLFW_invoke_Scroll) {
|
||||
GLFW_invoke_Scroll(showingWindow, curr.d1, curr.d2);
|
||||
}
|
||||
break;
|
||||
case EVENT_TYPE_WINDOW_SIZE:
|
||||
if (GLFW_invoke_WindowSize) {
|
||||
GLFW_invoke_WindowSize(showingWindow, curr.i1, curr.i2);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOGW("Unknown GLFW input event: %d", curr.type);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
glfwInputEventIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendChar(JNIEnv* env, jclass clazz, jint codepoint) {
|
||||
if (GLFW_invoke_Char && isInputReady) {
|
||||
if (isUseStackQueueCall) {
|
||||
GLFWInputEvent curr;
|
||||
curr.trigger = triggerChar;
|
||||
curr.ui1 = (unsigned int) codepoint;
|
||||
addInputToQueue(curr);
|
||||
} else
|
||||
GLFW_invoke_Char(showingWindow, codepoint);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
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 curr;
|
||||
curr.trigger = triggerCharMods;
|
||||
curr.ui1 = (unsigned int) codepoint;
|
||||
curr.i2 = mods;
|
||||
addInputToQueue(curr);
|
||||
} else
|
||||
GLFW_invoke_CharMods(showingWindow, codepoint, mods);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
return JNI_FALSE;
|
||||
}
|
||||
/*
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorEnter(JNIEnv* env, jclass clazz, jint entered) {
|
||||
if (GLFW_invoke_CursorEnter && isInputReady) {
|
||||
GLFW_invoke_CursorEnter(showingWindow, entered);
|
||||
}
|
||||
}
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JNIEnv* env, jclass clazz, jint x, jint y) {
|
||||
if (GLFW_invoke_CursorPos && isInputReady) {
|
||||
if (!isCursorEntered) {
|
||||
if (GLFW_invoke_CursorEnter) {
|
||||
isCursorEntered = true;
|
||||
if (isUseStackQueueCall) {
|
||||
GLFWInputEvent curr;
|
||||
curr.trigger = triggerCursorEnter;
|
||||
curr.i1 = 1;
|
||||
addInputToQueue(curr);
|
||||
} else
|
||||
GLFW_invoke_CursorEnter(showingWindow, 1);
|
||||
} else if (isGrabbing) {
|
||||
// Some Minecraft versions does not use GLFWCursorEnterCallback
|
||||
// This is a smart check, as Minecraft will not in grab mode if already not.
|
||||
isCursorEntered = true;
|
||||
}
|
||||
}
|
||||
|
||||
invokeCursorPos(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
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 curr;
|
||||
curr.trigger = triggerFramebufferSize;
|
||||
curr.i1 = width;
|
||||
curr.i2 = height;
|
||||
addInputToQueue(curr);
|
||||
} else
|
||||
GLFW_invoke_FramebufferSize(showingWindow, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
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 curr;
|
||||
curr.trigger = triggerKey;
|
||||
curr.i1 = key;
|
||||
curr.i2 = scancode;
|
||||
curr.i3 = action;
|
||||
curr.i4 = mods;
|
||||
addInputToQueue(curr);
|
||||
} else
|
||||
GLFW_invoke_Key(showingWindow, key, scancode, action, mods);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(JNIEnv* env, jclass clazz, jint button, jint action, jint mods) {
|
||||
if (isInputReady) {
|
||||
if (button == -1) {
|
||||
// Notify to prepare set new grab pos
|
||||
isPrepareGrabPos = true;
|
||||
} else if (GLFW_invoke_MouseButton) {
|
||||
if (isUseStackQueueCall) {
|
||||
GLFWInputEvent curr;
|
||||
curr.trigger = triggerMouseButton;
|
||||
curr.i1 = button;
|
||||
curr.i2 = action;
|
||||
curr.i3 = mods;
|
||||
addInputToQueue(curr);
|
||||
} else
|
||||
GLFW_invoke_MouseButton(showingWindow, button, action, mods);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 curr;
|
||||
curr.trigger = triggerScroll;
|
||||
curr.d1 = (double) xoffset;
|
||||
curr.d2 = (double) yoffset;
|
||||
addInputToQueue(curr);
|
||||
} else
|
||||
GLFW_invoke_Scroll(showingWindow, (double) xoffset, (double) yoffset);
|
||||
}
|
||||
}
|
||||
|
||||
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 curr;
|
||||
curr.trigger = triggerWindowSize;
|
||||
curr.i1 = width;
|
||||
curr.i2 = height;
|
||||
addInputToQueue(curr);
|
||||
} else
|
||||
GLFW_invoke_WindowSize(showingWindow, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwSetShowingWindow(JNIEnv* env, jclass clazz, jlong window) {
|
||||
showingWindow = (long) window;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
#define EVENT_TYPE_CHAR 1000
|
||||
#define EVENT_TYPE_CHAR_MODS 1001
|
||||
#define EVENT_TYPE_CURSOR_ENTER 1002
|
||||
#define EVENT_TYPE_CURSOR_POS 1003
|
||||
#define EVENT_TYPE_FRAMEBUFFER_SIZE 1004
|
||||
#define EVENT_TYPE_KEY 1005
|
||||
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
||||
@ -35,7 +34,7 @@
|
||||
jint (*orig_ProcessImpl_forkAndExec)(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream);
|
||||
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
||||
if (pojav_environ->dalvikJavaVMPtr == NULL) {
|
||||
__android_log_print(ANDROID_LOG_INFO, "Native", "Saving DVM environ...");
|
||||
//Save dalvik global JavaVM pointer
|
||||
@ -63,66 +62,30 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
// Should be?
|
||||
void JNI_OnUnload(JavaVM* vm, void* reserved) {
|
||||
/*
|
||||
if (pojav_environ->dalvikJavaVMPtr == vm) {
|
||||
} else {
|
||||
}
|
||||
|
||||
DetachCurrentThread(vm);
|
||||
*/
|
||||
|
||||
//dalvikJNIEnvPtr_JRE = NULL;
|
||||
//runtimeJNIEnvPtr_ANDROID = NULL;
|
||||
}
|
||||
|
||||
#define ADD_CALLBACK_WWIN(NAME) \
|
||||
JNIEXPORT jlong JNICALL Java_org_lwjgl_glfw_GLFW_nglfwSet##NAME##Callback(JNIEnv * env, jclass cls, jlong window, jlong callbackptr) { \
|
||||
__android_log_print(ANDROID_LOG_INFO, "NativeInput", "%p Set callback for #NAME to %p", &JNI_OnLoad, callbackptr); \
|
||||
void** oldCallback = (void**) &pojav_environ->GLFW_invoke_##NAME; \
|
||||
pojav_environ->GLFW_invoke_##NAME = (GLFW_invoke_##NAME##_func*) (uintptr_t) callbackptr; \
|
||||
return (jlong) (uintptr_t) *oldCallback; \
|
||||
}
|
||||
|
||||
ADD_CALLBACK_WWIN(Char);
|
||||
ADD_CALLBACK_WWIN(CharMods);
|
||||
ADD_CALLBACK_WWIN(CursorEnter);
|
||||
ADD_CALLBACK_WWIN(CursorPos);
|
||||
ADD_CALLBACK_WWIN(FramebufferSize);
|
||||
ADD_CALLBACK_WWIN(Key);
|
||||
ADD_CALLBACK_WWIN(MouseButton);
|
||||
ADD_CALLBACK_WWIN(Scroll);
|
||||
ADD_CALLBACK_WWIN(WindowSize);
|
||||
ADD_CALLBACK_WWIN(Char)
|
||||
ADD_CALLBACK_WWIN(CharMods)
|
||||
ADD_CALLBACK_WWIN(CursorEnter)
|
||||
ADD_CALLBACK_WWIN(CursorPos)
|
||||
ADD_CALLBACK_WWIN(FramebufferSize)
|
||||
ADD_CALLBACK_WWIN(Key)
|
||||
ADD_CALLBACK_WWIN(MouseButton)
|
||||
ADD_CALLBACK_WWIN(Scroll)
|
||||
ADD_CALLBACK_WWIN(WindowSize)
|
||||
|
||||
#undef ADD_CALLBACK_WWIN
|
||||
|
||||
jboolean attachThread(bool isAndroid, JNIEnv** secondJNIEnvPtr) {
|
||||
#ifdef DEBUG
|
||||
LOGD("Debug: Attaching %s thread to %s, javavm.isNull=%d\n", isAndroid ? "Android" : "JRE", isAndroid ? "JRE" : "Android", (isAndroid ? pojav_environ->runtimeJavaVMPtr : pojav_environ->dalvikJavaVMPtr) == NULL);
|
||||
#endif
|
||||
|
||||
if (*secondJNIEnvPtr != NULL || (!pojav_environ->isUseStackQueueCall)) return JNI_TRUE;
|
||||
|
||||
if (isAndroid && pojav_environ->runtimeJavaVMPtr) {
|
||||
(*pojav_environ->runtimeJavaVMPtr)->AttachCurrentThread(pojav_environ->runtimeJavaVMPtr, secondJNIEnvPtr, NULL);
|
||||
return JNI_TRUE;
|
||||
} else if (!isAndroid && pojav_environ->dalvikJavaVMPtr) {
|
||||
(*pojav_environ->dalvikJavaVMPtr)->AttachCurrentThread(pojav_environ->dalvikJavaVMPtr, secondJNIEnvPtr, NULL);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void handleFramebufferSizeJava(long window, int w, int h) {
|
||||
(*pojav_environ->runtimeJNIEnvPtr_JRE)->CallStaticVoidMethod(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, pojav_environ->method_internalWindowSizeChanged, (long)window, w, h);
|
||||
}
|
||||
|
||||
void pojavPumpEvents(void* window) {
|
||||
//__android_log_print(ANDROID_LOG_INFO, "input_bridge_v3", "pojavPumppojav_environ->events %d", pojav_environ->eventCounter);
|
||||
size_t counter = atomic_load_explicit(&pojav_environ->eventCounter, memory_order_acquire);
|
||||
for(size_t i = 0; i < counter; i++) {
|
||||
GLFWInputEvent event = pojav_environ->events[i];
|
||||
@ -164,63 +127,39 @@ void pojavRewindEvents() {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_lwjgl_glfw_GLFW_nglfwGetCursorPos(JNIEnv *env, jclass clazz, jlong window, jobject xpos,
|
||||
Java_org_lwjgl_glfw_GLFW_nglfwGetCursorPos(JNIEnv *env, __attribute__((unused)) jclass clazz, __attribute__((unused)) jlong window, jobject xpos,
|
||||
jobject ypos) {
|
||||
*(double*)(*env)->GetDirectBufferAddress(env, xpos) = pojav_environ->cursorX;
|
||||
*(double*)(*env)->GetDirectBufferAddress(env, ypos) = pojav_environ->cursorY;
|
||||
// TODO: implement glfwGetCursorPos()
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_lwjgl_glfw_GLFW_nglfwGetCursorPosA(JNIEnv *env, jclass clazz, jlong window,
|
||||
Java_org_lwjgl_glfw_GLFW_nglfwGetCursorPosA(JNIEnv *env, __attribute__((unused)) jclass clazz, __attribute__((unused)) jlong window,
|
||||
jdoubleArray xpos, jdoubleArray ypos) {
|
||||
(*env)->SetDoubleArrayRegion(env, xpos, 0,1, &pojav_environ->cursorX);
|
||||
(*env)->SetDoubleArrayRegion(env, ypos, 0,1, &pojav_environ->cursorY);
|
||||
// TODO: implement nglfwGetCursorPosA()
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_lwjgl_glfw_GLFW_glfwSetCursorPos(JNIEnv *env, jclass clazz, jlong window, jdouble xpos,
|
||||
Java_org_lwjgl_glfw_GLFW_glfwSetCursorPos(__attribute__((unused)) JNIEnv *env, __attribute__((unused)) jclass clazz, __attribute__((unused)) jlong window, jdouble xpos,
|
||||
jdouble ypos) {
|
||||
pojav_environ->cLastX = pojav_environ->cursorX = xpos;
|
||||
pojav_environ->cLastY = pojav_environ->cursorY = ypos;
|
||||
// TODO: implement glfwSetCursorPos()
|
||||
}
|
||||
|
||||
|
||||
|
||||
void sendData(int type, int i1, int i2, int i3, int i4) {
|
||||
if(type == EVENT_TYPE_CURSOR_POS) {
|
||||
pojav_environ->cursorX = i1;
|
||||
pojav_environ->cursorY = i2;
|
||||
}else {
|
||||
size_t counter = atomic_load_explicit(&pojav_environ->eventCounter, memory_order_acquire);
|
||||
if (counter < 7999) {
|
||||
GLFWInputEvent *event = &pojav_environ->events[counter++];
|
||||
event->type = type;
|
||||
event->i1 = i1;
|
||||
event->i2 = i2;
|
||||
event->i3 = i3;
|
||||
event->i4 = i4;
|
||||
}
|
||||
atomic_store_explicit(&pojav_environ->eventCounter, counter, memory_order_release);
|
||||
size_t counter = atomic_load_explicit(&pojav_environ->eventCounter, memory_order_acquire);
|
||||
if (counter < 7999) {
|
||||
GLFWInputEvent *event = &pojav_environ->events[counter++];
|
||||
event->type = type;
|
||||
event->i1 = i1;
|
||||
event->i2 = i2;
|
||||
event->i3 = i3;
|
||||
event->i4 = i4;
|
||||
}
|
||||
}
|
||||
|
||||
void closeGLFWWindow() {
|
||||
/*
|
||||
jclass glfwClazz = (*pojav_environ->runtimeJNIEnvPtr_JRE)->FindClass(pojav_environ->runtimeJNIEnvPtr_JRE, "org/lwjgl/glfw/GLFW");
|
||||
assert(glfwClazz != NULL);
|
||||
jmethodID glfwMethod = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticMethodID(pojav_environ->runtimeJNIEnvPtr_JRE, glfwMethod, "glfwSetWindowShouldClose", "(JZ)V");
|
||||
assert(glfwMethod != NULL);
|
||||
|
||||
(*pojav_environ->runtimeJNIEnvPtr_JRE)->CallStaticVoidMethod(
|
||||
pojav_environ->runtimeJNIEnvPtr_JRE,
|
||||
glfwClazz, glfwMethod,
|
||||
(jlong) pojav_environ->showingWindow, JNI_TRUE
|
||||
);
|
||||
*/
|
||||
exit(-1);
|
||||
atomic_store_explicit(&pojav_environ->eventCounter, counter, memory_order_release);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,7 +171,7 @@ hooked_ProcessImpl_forkAndExec(JNIEnv *env, jobject process, jint mode, jbyteArr
|
||||
char *pProg = (char *)((*env)->GetByteArrayElements(env, prog, NULL));
|
||||
|
||||
// Here we only handle the "xdg-open" command
|
||||
if (strcmp(basename(pProg), "xdg-open")) {
|
||||
if (strcmp(basename(pProg), "xdg-open") != 0) {
|
||||
(*env)->ReleaseByteArrayElements(env, prog, (jbyte *)pProg, 0);
|
||||
return orig_ProcessImpl_forkAndExec(env, process, mode, helperpath, prog, argBlock, argc, envBlock, envc, dir, std_fds, redirectErrorStream);
|
||||
}
|
||||
@ -259,12 +198,12 @@ void hookExec() {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_lwjgl_glfw_CallbackBridge_nativeSetUseInputStackQueue(JNIEnv *env, jclass clazz,
|
||||
Java_org_lwjgl_glfw_CallbackBridge_nativeSetUseInputStackQueue(__attribute__((unused)) JNIEnv *env, __attribute__((unused)) jclass clazz,
|
||||
jboolean use_input_stack_queue) {
|
||||
pojav_environ->isUseStackQueueCall = (int) use_input_stack_queue;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThreadToOther(JNIEnv* env, jclass clazz, jboolean isAndroid, jboolean isUseStackQueueBool) {
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThreadToOther(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jboolean isAndroid, jboolean __attribute__((unused)) isUseStackQueueBool) {
|
||||
#ifdef DEBUG
|
||||
LOGD("Debug: JNI attaching thread, isUseStackQueue=%d\n", isUseStackQueueBool);
|
||||
#endif
|
||||
@ -274,7 +213,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThread
|
||||
return true;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, jclass clazz, jint action, jbyteArray copySrc) {
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, __attribute__((unused)) jclass clazz, jint action, jbyteArray copySrc) {
|
||||
#ifdef DEBUG
|
||||
LOGD("Debug: Clipboard access is going on\n", pojav_environ->isUseStackQueueCall);
|
||||
#endif
|
||||
@ -285,7 +224,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
|
||||
assert(pojav_environ->bridgeClazz != NULL);
|
||||
|
||||
LOGD("Clipboard: Converting string\n");
|
||||
char *copySrcC = NULL;
|
||||
char *copySrcC;
|
||||
jstring copyDst = NULL;
|
||||
if (copySrc) {
|
||||
copySrcC = (char *)((*env)->GetByteArrayElements(env, copySrc, NULL));
|
||||
@ -303,7 +242,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
|
||||
return pasteDst;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputReady(JNIEnv* env, jclass clazz, jboolean inputReady) {
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputReady(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jboolean inputReady) {
|
||||
#ifdef DEBUG
|
||||
LOGD("Debug: Changing input state, isReady=%d, pojav_environ->isUseStackQueueCall=%d\n", inputReady, pojav_environ->isUseStackQueueCall);
|
||||
#endif
|
||||
@ -312,7 +251,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputRead
|
||||
return pojav_environ->isUseStackQueueCall;
|
||||
}
|
||||
|
||||
static void updateGrabCursor(jint xset, jint yset) {
|
||||
static void updateGrabCursor(float xset, float yset) {
|
||||
if (pojav_environ->isGrabbing == JNI_TRUE) {
|
||||
pojav_environ->grabCursorX = xset; // pojav_environ->savedWidth / 2;
|
||||
pojav_environ->grabCursorY = yset; // pojav_environ->savedHeight / 2;
|
||||
@ -320,36 +259,31 @@ static void updateGrabCursor(jint xset, jint yset) {
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(JNIEnv* env, jclass clazz, jboolean grabbing) {
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jboolean grabbing) {
|
||||
JNIEnv *dalvikEnv;
|
||||
(*pojav_environ->dalvikJavaVMPtr)->AttachCurrentThread(pojav_environ->dalvikJavaVMPtr, &dalvikEnv, NULL);
|
||||
(*dalvikEnv)->CallStaticVoidMethod(dalvikEnv, pojav_environ->bridgeClazz, pojav_environ->method_onGrabStateChanged, grabbing);
|
||||
(*pojav_environ->dalvikJavaVMPtr)->DetachCurrentThread(pojav_environ->dalvikJavaVMPtr);
|
||||
pojav_environ->isGrabbing = grabbing;
|
||||
updateGrabCursor((jint)pojav_environ->cursorX, (jint)pojav_environ->cursorY);
|
||||
updateGrabCursor((float)pojav_environ->cursorX, (float)pojav_environ->cursorY);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeisGrabbing(JNIEnv* env, jclass clazz) {
|
||||
return pojav_environ->isGrabbing;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendChar(JNIEnv* env, jclass clazz, jchar codepoint /* jint codepoint */) {
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendChar(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jchar codepoint /* jint codepoint */) {
|
||||
if (pojav_environ->GLFW_invoke_Char && pojav_environ->isInputReady) {
|
||||
if (pojav_environ->isUseStackQueueCall) {
|
||||
sendData(EVENT_TYPE_CHAR, codepoint, 0, 0, 0);
|
||||
} else {
|
||||
pojav_environ->GLFW_invoke_Char((void*) pojav_environ->showingWindow, (unsigned int) codepoint);
|
||||
// return lwjgl2_triggerCharEvent(codepoint);
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods(JNIEnv* env, jclass clazz, jchar codepoint, jint mods) {
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jchar codepoint, jint mods) {
|
||||
if (pojav_environ->GLFW_invoke_CharMods && pojav_environ->isInputReady) {
|
||||
if (pojav_environ->isUseStackQueueCall) {
|
||||
sendData(EVENT_TYPE_CHAR_MODS, (unsigned int) codepoint, mods, 0, 0);
|
||||
sendData(EVENT_TYPE_CHAR_MODS, (int) codepoint, mods, 0, 0);
|
||||
} else {
|
||||
pojav_environ->GLFW_invoke_CharMods((void*) pojav_environ->showingWindow, codepoint, mods);
|
||||
}
|
||||
@ -364,7 +298,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorEnter(
|
||||
}
|
||||
}
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JNIEnv* env, jclass clazz, jfloat x, jfloat y) {
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jfloat x, jfloat y) {
|
||||
#ifdef DEBUG
|
||||
LOGD("Sending cursor position \n");
|
||||
#endif
|
||||
@ -405,7 +339,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JN
|
||||
if (!pojav_environ->isUseStackQueueCall) {
|
||||
pojav_environ->GLFW_invoke_CursorPos((void*) pojav_environ->showingWindow, (double) (x), (double) (y));
|
||||
} else {
|
||||
sendData(EVENT_TYPE_CURSOR_POS, (pojav_environ->isGrabbing ? pojav_environ->grabCursorX : x), (pojav_environ->isGrabbing ? pojav_environ->grabCursorY : y), 0, 0);
|
||||
pojav_environ->cursorX = x;
|
||||
pojav_environ->cursorY = y;
|
||||
}
|
||||
|
||||
pojav_environ->lastCursorX = x;
|
||||
@ -416,7 +351,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JN
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
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(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jint key, jint scancode, jint action, jint mods) {
|
||||
if (pojav_environ->GLFW_invoke_Key && pojav_environ->isInputReady) {
|
||||
pojav_environ->keyDownBuffer[max(0, key-31)]=(jbyte)action;
|
||||
if (pojav_environ->isUseStackQueueCall) {
|
||||
@ -429,7 +364,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(JNIEnv*
|
||||
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(JNIEnv* env, jclass clazz, jint button, jint action, jint mods) {
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jint button, jint action, jint mods) {
|
||||
if (pojav_environ->isInputReady) {
|
||||
if (button == -1) {
|
||||
// Notify to prepare set new grab pos
|
||||
@ -444,7 +379,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(JNIEnv* env, jclass clazz, jint width, jint height) {
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jint width, jint height) {
|
||||
pojav_environ->savedWidth = width;
|
||||
pojav_environ->savedHeight = height;
|
||||
if (pojav_environ->isInputReady) {
|
||||
@ -468,21 +403,21 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(J
|
||||
// return (pojav_environ->isInputReady && (pojav_environ->GLFW_invoke_FramebufferSize || pojav_environ->GLFW_invoke_WindowSize));
|
||||
}
|
||||
|
||||
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(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jdouble xoffset, jdouble yoffset) {
|
||||
if (pojav_environ->GLFW_invoke_Scroll && pojav_environ->isInputReady) {
|
||||
if (pojav_environ->isUseStackQueueCall) {
|
||||
sendData(EVENT_TYPE_SCROLL, xoffset, yoffset, 0, 0);
|
||||
sendData(EVENT_TYPE_SCROLL, (int)xoffset, (int)yoffset, 0, 0);
|
||||
} else {
|
||||
pojav_environ->GLFW_invoke_Scroll((void*) pojav_environ->showingWindow, (double) xoffset, (double) yoffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwSetShowingWindow(JNIEnv* env, jclass clazz, jlong window) {
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_GLFW_nglfwSetShowingWindow(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jlong window) {
|
||||
pojav_environ->showingWindow = (long) window;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetWindowAttrib(JNIEnv* env, jclass clazz, jint attrib, jint value) {
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetWindowAttrib(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jint attrib, jint value) {
|
||||
if (!pojav_environ->showingWindow || !pojav_environ->isUseStackQueueCall) {
|
||||
// If the window is not shown, there is nothing to do yet.
|
||||
// For Minecraft < 1.13, calling to JNI functions here crashes the JVM for some reason, therefore it is skipped for now.
|
||||
|
@ -9,9 +9,9 @@
|
||||
//
|
||||
// Created by maks on 17.02.21.
|
||||
//
|
||||
static JavaVM *_______jvm;
|
||||
static volatile jmethodID _______method;
|
||||
static volatile jobject _______obj;
|
||||
static JavaVM *stdiois_jvm;
|
||||
static volatile jmethodID log_cbMethod;
|
||||
static volatile jobject log_cbObject;
|
||||
static volatile jobject exitTrap_ctx;
|
||||
static volatile jclass exitTrap_exitClass;
|
||||
static volatile jmethodID exitTrap_staticMethod;
|
||||
@ -21,7 +21,7 @@ static pthread_t logger;
|
||||
static void *logger_thread() {
|
||||
JNIEnv *env;
|
||||
jstring str;
|
||||
(*_______jvm)->AttachCurrentThread(_______jvm,&env,NULL);
|
||||
(*stdiois_jvm)->AttachCurrentThread(stdiois_jvm, &env, NULL);
|
||||
ssize_t rsize;
|
||||
char buf[2048];
|
||||
while((rsize = read(pfd[0], buf, sizeof(buf)-1)) > 0) {
|
||||
@ -30,20 +30,21 @@ static void *logger_thread() {
|
||||
}
|
||||
buf[rsize]=0x00;
|
||||
str = (*env)->NewStringUTF(env,buf);
|
||||
(*env)->CallVoidMethod(env,_______obj,_______method,str);
|
||||
(*env)->CallVoidMethod(env, log_cbObject, log_cbMethod, str);
|
||||
(*env)->DeleteLocalRef(env,str);
|
||||
}
|
||||
(*env)->DeleteGlobalRef(env,_______method);
|
||||
(*env)->DeleteGlobalRef(env,_______obj);
|
||||
(*_______jvm)->DetachCurrentThread(_______jvm);
|
||||
(*env)->DeleteGlobalRef(env, log_cbMethod);
|
||||
(*env)->DeleteGlobalRef(env, log_cbObject);
|
||||
(*stdiois_jvm)->DetachCurrentThread(stdiois_jvm);
|
||||
return NULL;
|
||||
}
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_kdt_pojavlaunch_utils_JREUtils_logToLogger(JNIEnv *env, jclass clazz, jobject javaLogger) {
|
||||
Java_net_kdt_pojavlaunch_utils_JREUtils_logToLogger(JNIEnv *env, __attribute((unused)) jclass clazz, jobject javaLogger) {
|
||||
// TODO: implement logToActivity()
|
||||
jclass loggableActivityClass = (*env)->FindClass(env,"net/kdt/pojavlaunch/Logger");
|
||||
_______method = (*env)->GetMethodID(env,loggableActivityClass,"appendToLog", "(Ljava/lang/String;)V");
|
||||
(*env)->GetJavaVM(env,&_______jvm);
|
||||
_______obj = (*env)->NewGlobalRef(env, javaLogger);
|
||||
log_cbMethod = (*env)->GetMethodID(env, loggableActivityClass, "appendToLog", "(Ljava/lang/String;)V");
|
||||
(*env)->GetJavaVM(env,&stdiois_jvm);
|
||||
log_cbObject = (*env)->NewGlobalRef(env, javaLogger);
|
||||
|
||||
setvbuf(stdout, 0, _IOLBF, 0); // make stdout line-buffered
|
||||
setvbuf(stderr, 0, _IONBF, 0); // make stderr unbuffered
|
||||
@ -54,12 +55,12 @@ Java_net_kdt_pojavlaunch_utils_JREUtils_logToLogger(JNIEnv *env, jclass clazz, j
|
||||
dup2(pfd[1], 2);
|
||||
|
||||
/* spawn the logging thread */
|
||||
if(pthread_create(&logger, 0, logger_thread, 0) == -1) {
|
||||
if(pthread_create(&logger, 0, logger_thread, 0) != 0) {
|
||||
jstring str = (*env)->NewStringUTF(env,"Failed to start logging!");
|
||||
(*env)->CallVoidMethod(env,_______obj,_______method,str);
|
||||
(*env)->CallVoidMethod(env, log_cbObject, log_cbMethod, str);
|
||||
(*env)->DeleteLocalRef(env,str);
|
||||
(*env)->DeleteGlobalRef(env,_______method);
|
||||
(*env)->DeleteGlobalRef(env,_______obj);
|
||||
(*env)->DeleteGlobalRef(env, log_cbMethod);
|
||||
(*env)->DeleteGlobalRef(env, log_cbObject);
|
||||
}
|
||||
pthread_detach(logger);
|
||||
|
||||
@ -77,12 +78,12 @@ void custom_exit(int code) {
|
||||
}
|
||||
old_exit(code);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupExitTrap(JNIEnv *env, jclass clazz, jobject context) {
|
||||
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupExitTrap(JNIEnv *env, __attribute((unused)) jclass clazz, jobject context) {
|
||||
exitTrap_ctx = (*env)->NewGlobalRef(env,context);
|
||||
(*env)->GetJavaVM(env,&exitTrap_jvm);
|
||||
exitTrap_exitClass = (*env)->NewGlobalRef(env,(*env)->FindClass(env,"net/kdt/pojavlaunch/ExitActivity"));
|
||||
exitTrap_staticMethod = (*env)->GetStaticMethodID(env,exitTrap_exitClass,"showExitMessage","(Landroid/content/Context;I)V");
|
||||
xhook_enable_debug(1);
|
||||
xhook_register(".*\\.so$","exit",custom_exit,&old_exit);
|
||||
xhook_enable_debug(0);
|
||||
xhook_register(".*\\.so$", "exit", custom_exit, (void **) &old_exit);
|
||||
xhook_refresh(1);
|
||||
}
|
||||
|
@ -4,13 +4,11 @@
|
||||
|
||||
|
||||
|
||||
jboolean attachThread(bool isAndroid, JNIEnv** secondJNIEnvPtr);
|
||||
char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
|
||||
jobjectArray convert_from_char_array(JNIEnv *env, char **charArray, int num_rows);
|
||||
void free_char_array(JNIEnv *env, jobjectArray jstringArray, const char **charArray);
|
||||
jstring convertStringJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jstring srcStr);
|
||||
|
||||
void closeGLFWWindow();
|
||||
void hookExec();
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, jclass clazz, jint action, jbyteArray copySrc);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user