mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-07-30 10:16:51 -04:00
rework: move utilities to utils.c
This commit is contained in:
@@ -32,14 +32,7 @@
|
||||
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
||||
#define EVENT_TYPE_SCROLL 1007
|
||||
|
||||
#define TRY_ATTACH_ENV(env_name, vm, error_message, then) JNIEnv* env_name;\
|
||||
do { \
|
||||
env_name = get_attached_env(vm); \
|
||||
if(env_name == NULL) { \
|
||||
printf(error_message); \
|
||||
then \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
static void registerFunctions(JNIEnv *env);
|
||||
|
||||
|
||||
@@ -10,41 +10,10 @@
|
||||
#include <jni.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SET_DLSYM_PTR(fn) \
|
||||
fn##_t fn##_p; \
|
||||
do { \
|
||||
dlerror(); \
|
||||
void *_p = dlsym(RTLD_NEXT, #fn); \
|
||||
const char *_e = dlerror(); \
|
||||
if (_e || !_p) { \
|
||||
LOGE("dlsym(%s) failed: %s\n", #fn, _e ? _e : "unknown error"); \
|
||||
} \
|
||||
fn##_p = (typeof(fn##_t))_p; \
|
||||
} while (0)
|
||||
|
||||
#define DECL_DLSYM(fn) typedef typeof(&fn) fn##_t;
|
||||
|
||||
#define TRY_ATTACH_ENV(fn) \
|
||||
JNIEnv *dvm_env; \
|
||||
dvm_env = get_attached_env(pojav_environ->dalvikJavaVMPtr); \
|
||||
if (dvm_env == ((void *) 0)) {printf("%s notify to launcher-side integration failed!\n", #fn);}
|
||||
|
||||
|
||||
DECL_DLSYM(SDL_InitSubSystem)
|
||||
DECL_DLSYM(SDL_SetHint);
|
||||
DECL_DLSYM(SDL_SetTextInputArea);
|
||||
|
||||
static bool notifyLauncher(JNIEnv *dvm_env, int type, int actions[], int len){
|
||||
jintArray actionArray = (*dvm_env)->NewIntArray(dvm_env, len);
|
||||
(*dvm_env)->SetIntArrayRegion(dvm_env, actionArray, 0, len, actions);
|
||||
return (*dvm_env)->CallStaticBooleanMethod(dvm_env, pojav_environ->bridgeClazz,
|
||||
pojav_environ->method_notifyLauncher, type, actionArray);
|
||||
}
|
||||
|
||||
#define NOTIF_TYPE_SDL 0
|
||||
#define ACTION_INIT_LAUNCHER_INTEGRATION 0
|
||||
#define ACTION_SEND_TEXTBOX_RECT 1
|
||||
|
||||
DECL_DLSYM(SDL_SetError);
|
||||
|
||||
|
||||
static bool custom_SDL_InitSubSystem_Func(SDL_InitFlags flags) {
|
||||
|
||||
@@ -1,11 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "environ/environ.h"
|
||||
|
||||
#define CLIPBOARD_COPY 2000
|
||||
#define CLIPBOARD_PASTE 2001
|
||||
#define CLIPBOARD_OPEN 2002
|
||||
|
||||
#define NOTIF_TYPE_SDL 0
|
||||
#define ACTION_INIT_LAUNCHER_INTEGRATION 0
|
||||
#define ACTION_SEND_TEXTBOX_RECT 1
|
||||
|
||||
#define DECL_DLSYM(fn) typedef typeof(&fn) fn##_t;
|
||||
|
||||
#define SET_DLSYM_PTR(fn) \
|
||||
fn##_t fn##_p; \
|
||||
do { \
|
||||
dlerror(); \
|
||||
void *_p = dlsym(RTLD_NEXT, #fn); \
|
||||
const char *_e = dlerror(); \
|
||||
if (_e || !_p) { \
|
||||
LOGE("dlsym(%s) failed: %s\n", #fn, _e ? _e : "unknown error"); \
|
||||
} \
|
||||
fn##_p = (typeof(fn##_t))_p; \
|
||||
} while (0)
|
||||
|
||||
#define TRY_ATTACH_ENV(env_name, vm, error_message, then) JNIEnv* env_name;\
|
||||
do { \
|
||||
env_name = get_attached_env(vm); \
|
||||
if(env_name == NULL) { \
|
||||
printf(error_message); \
|
||||
then \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
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);
|
||||
@@ -15,3 +43,9 @@ jintArray convertIntArrayJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jintArray srcIntArr
|
||||
JNIEnv* get_attached_env(JavaVM* jvm);
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, jclass clazz, jint action, jbyteArray copySrc);
|
||||
|
||||
static bool notifyLauncher(JNIEnv *dvm_env, int type, int actions[], int len){
|
||||
jintArray actionArray = (*dvm_env)->NewIntArray(dvm_env, len);
|
||||
(*dvm_env)->SetIntArrayRegion(dvm_env, actionArray, 0, len, actions);
|
||||
return (*dvm_env)->CallStaticBooleanMethod(dvm_env, pojav_environ->bridgeClazz,
|
||||
pojav_environ->method_notifyLauncher, type, actionArray);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user