Skip to content

Commit

Permalink
fix everything
Browse files Browse the repository at this point in the history
  • Loading branch information
computer-catt committed Dec 30, 2024
1 parent d128915 commit daa42b3
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 565 deletions.
13 changes: 0 additions & 13 deletions src/main/java/pojlib/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,6 @@ public static void startGame(
}
}

/**
* Should the screen be kept on
* @param activity The Android activity
*/
@SuppressWarnings("unused")
public static void keepScreenOn(Activity activity, boolean doThing) {
if (doThing) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} else {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}

@SuppressWarnings("unused")
public static String getTestString() {
return "Successful load!\n";
Expand Down
7 changes: 4 additions & 3 deletions src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ HERE_PATH := $(LOCAL_PATH)
LOCAL_PATH := $(HERE_PATH)

include $(CLEAR_VARS)
LOCAL_MODULE := mcxr-loader
LOCAL_SRC_FILES := mcxr_loader.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/
LOCAL_LDLIBS := -lGLESv3
LOCAL_MODULE := mcxr_loader
LOCAL_SRC_FILES := \
mcxr_loader.cpp
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
Expand Down
6 changes: 3 additions & 3 deletions src/main/jni/egl_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,17 +739,17 @@ void pojavMakeCurrent(void* window) {
}

JNIEXPORT JNICALL jlong
Java_pojlib_util_JREUtils_getEGLDisplayPtr(JNIEnv *env, jclass clazz) {
Java_pojlib_JREUtils_getEGLDisplayPtr(JNIEnv *env, jclass clazz) {
return (jlong) &xrEglDisplay;
}

JNIEXPORT JNICALL jlong
Java_pojlib_util_JREUtils_getEGLContextPtr(JNIEnv *env, jclass clazz) {
Java_pojlib_JREUtils_getEGLContextPtr(JNIEnv *env, jclass clazz) {
return (jlong) &xrEglContext;
}

JNIEXPORT JNICALL jlong
Java_pojlib_util_JREUtils_getEGLConfigPtr(JNIEnv *env, jclass clazz) {
Java_pojlib_JREUtils_getEGLConfigPtr(JNIEnv *env, jclass clazz) {
return (jlong) &xrConfig;
}

Expand Down
Binary file modified src/main/jni/libopenxr_loader.so
Binary file not shown.
26 changes: 24 additions & 2 deletions src/main/jni/mcxr_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <jni.h>
#include <thread>
#include <GLES3/gl3.h>

//
// Created by Judge on 23rd December 2021
// Modified by Nova on 17th August 2024
// Created by Judge on 12/23/2021.
// Modified by Nova on 8/7/2024
//

static jobject* context;
static jobject* app;
static JavaVM* jvm;

Expand All @@ -22,12 +24,32 @@ Java_net_sorenon_mcxr_play_MCXRNativeLoad_getJVMPtr(JNIEnv *env, jclass clazz) {
return reinterpret_cast<jlong>(&jvm);
}

JNIEXPORT JNICALL
extern "C" void
Java_net_sorenon_mcxr_play_MCXRNativeLoad_renderImage(JNIEnv *env, jclass clazz, jint colorAttachment, jint index) {
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorAttachment, 0, index);
}

JNIEXPORT JNICALL
extern "C" jlong
Java_net_sorenon_mcxr_play_MCXRNativeLoad_getApplicationActivityPtr(JNIEnv *env, jclass clazz) {
return reinterpret_cast<jlong>(&app);
}

extern "C"
JNIEXPORT void JNICALL
Java_net_kdt_pojavlaunch_MCXRLoader_launch(JNIEnv *env, jclass clazz, jobject main) {
main = (*env).NewGlobalRef(main);
jclass clazz1 = (*env).GetObjectClass(main);
jmethodID id = (*env).GetMethodID(clazz1, "runCraft", "()V");
std::thread thread([=]() {
JNIEnv* threadEnv;
jvm->AttachCurrentThread(&threadEnv, nullptr);
threadEnv->CallVoidMethod(main, id);
});
thread.detach();
}

extern "C"
JNIEXPORT void JNICALL
Java_pojlib_VLoader_setActivity(JNIEnv *env, jclass clazz, jobject ctx) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/jni/stdio_is.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void *logger_thread() {
JNIEXPORT void JNICALL
Java_pojlib_JREUtils_logToLogger(JNIEnv *env, jclass clazz, jobject javaLogger) {
// TODO: implement logToActivity()
jclass loggableActivityClass = (*env)->FindClass(env,"pojlib/util/Logger");
jclass loggableActivityClass = (*env)->FindClass(env,"pojlib/Logger");
_______method = (*env)->GetMethodID(env,loggableActivityClass,"appendToLog", "(Ljava/lang/String;)V");
(*env)->GetJavaVM(env,&_______jvm);
_______obj = (*env)->NewGlobalRef(env, javaLogger);
Expand All @@ -59,4 +59,4 @@ Java_pojlib_JREUtils_logToLogger(JNIEnv *env, jclass clazz, jobject javaLogger)
}
pthread_detach(logger);

}
}
8 changes: 4 additions & 4 deletions src/main/jni/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ JNIEXPORT jint JNICALL Java_android_os_OpenJDKNativeRegister_nativeRegisterNativ
return (jint) result;
}

JNIEXPORT void JNICALL Java_pojlib_util_JREUtils_setLdLibraryPath(JNIEnv *env, jclass clazz, jstring ldLibraryPath) {
JNIEXPORT void JNICALL Java_pojlib_JREUtils_setLdLibraryPath(JNIEnv *env, jclass clazz, jstring ldLibraryPath) {
android_update_LD_LIBRARY_PATH_t android_update_LD_LIBRARY_PATH;

void *libdl_handle = dlopen("libdl.so", RTLD_LAZY);
Expand All @@ -79,7 +79,7 @@ JNIEXPORT void JNICALL Java_pojlib_util_JREUtils_setLdLibraryPath(JNIEnv *env, j
(*env)->ReleaseStringUTFChars(env, ldLibraryPath, ldLibPathUtf);
}

JNIEXPORT jboolean JNICALL Java_pojlib_util_JREUtils_dlopen(JNIEnv *env, jclass clazz, jstring name) {
JNIEXPORT jboolean JNICALL Java_pojlib_JREUtils_dlopen(JNIEnv *env, jclass clazz, jstring name) {
const char *nameUtf = (*env)->GetStringUTFChars(env, name, 0);
void* handle = dlopen(nameUtf, RTLD_GLOBAL | RTLD_LAZY);
if (!handle) {
Expand All @@ -91,14 +91,14 @@ JNIEXPORT jboolean JNICALL Java_pojlib_util_JREUtils_dlopen(JNIEnv *env, jclass
return handle != NULL;
}

JNIEXPORT jint JNICALL Java_pojlib_util_JREUtils_chdir(JNIEnv *env, jclass clazz, jstring nameStr) {
JNIEXPORT jint JNICALL Java_pojlib_JREUtils_chdir(JNIEnv *env, jclass clazz, jstring nameStr) {
const char *name = (*env)->GetStringUTFChars(env, nameStr, NULL);
int retval = chdir(name);
(*env)->ReleaseStringUTFChars(env, nameStr, name);
return retval;
}

JNIEXPORT jint JNICALL Java_pojlib_util_JREUtils_executeBinary(JNIEnv *env, jclass clazz, jobjectArray cmdArgs) {
JNIEXPORT jint JNICALL Java_pojlib_JREUtils_executeBinary(JNIEnv *env, jclass clazz, jobjectArray cmdArgs) {
jclass exception_cls = (*env)->FindClass(env, "java/lang/UnsatisfiedLinkError");
jstring execFile = (*env)->GetObjectArrayElement(env, cmdArgs, 0);

Expand Down
4 changes: 2 additions & 2 deletions src/main/jni/vloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static std::string load_file(const char *path) {

extern "C"
JNIEXPORT void JNICALL
Java_pojlib_VLoader_setActivity(JNIEnv *env, jclass clazz, jobject ctx) {
Java_pojlib_VLoader_setAndroidInitInfo(JNIEnv *env, jclass clazz, jobject ctx) {
OpenComposite_Android_Load_Input_File = load_file;

env->GetJavaVM(&jvm);
Expand Down Expand Up @@ -118,4 +118,4 @@ Java_org_vivecraft_util_VLoader_setEGLGlobal(JNIEnv* env, jclass clazz) {
(void*) cfg,
(void*)eglGetCurrentContext()
};
}
}
Loading

0 comments on commit daa42b3

Please sign in to comment.