Fixes and enhancements from my MCPE repository. (https://github.com/mschiller890/mcpe64)

This commit is contained in:
Michal Schiller
2026-03-10 19:31:40 +01:00
parent 0c97ceb340
commit 2fc323639a
69 changed files with 2509 additions and 639 deletions

View File

@@ -3,6 +3,9 @@
//#include "main_android_java.h"
#include "platform/input/Multitouch.h"
#include <unistd.h>
#include <sys/syscall.h>
#define gettid() ((int)syscall(SYS_gettid))
// Horrible, I know. / A
#ifndef MAIN_CLASS
@@ -39,7 +42,12 @@ static void setupExternalPath(JNIEnv* env, MAIN_CLASS* app)
const char* str = env->GetStringUTFChars((jstring) pathString, NULL);
app->externalStoragePath = str;
app->externalCacheStoragePath = str;
LOGI(str);
LOGI("%s", str);
// same fix as the native entry point: make sure cwd is writable
if (chdir(str) != 0) {
LOGI("chdir to %s failed: %s", str, strerror(errno));
}
env->ReleaseStringUTFChars((jstring)pathString, str);
}
@@ -57,6 +65,7 @@ static void pointerMove(int pointerId, int x, int y) {
static App* gApp = 0;
static AppContext gContext;
static bool g_inNativeOnCreate = false;
extern "C" {
JNIEXPORT jint JNICALL
@@ -81,34 +90,53 @@ Java_com_mojang_minecraftpe_MainActivity_nativeUnregisterThis(JNIEnv* env, jobje
}
JNIEXPORT void JNICALL
Java_com_mojang_minecraftpe_MainActivity_nativeOnCreate(JNIEnv* env) {
LOGI("@nativeOnCreate\n");
Java_com_mojang_minecraftpe_MainActivity_nativeOnCreate(JNIEnv* env, jobject thiz, jint screenWidth, jint screenHeight) {
LOGI("@nativeOnCreate w=%d h=%d\n", (int)screenWidth, (int)screenHeight);
g_inNativeOnCreate = true;
appPlatform.instance = g_pActivity;
appPlatform.initConsts();
appPlatform.setScreenDimensions((int)screenWidth, (int)screenHeight);
LOGI("nativeOnCreate: screen set, no initConsts needed\n");
gContext.doRender = false;
gContext.platform = &appPlatform;
LOGI("nativeOnCreate: creating gApp\n");
gApp = new MAIN_CLASS();
LOGI("nativeOnCreate: gApp=%p\n", gApp);
setupExternalPath(env, (MAIN_CLASS*)gApp);
if (env->ExceptionOccurred()) {
LOGI("nativeOnCreate: exception after setupExternalPath!\n");
env->ExceptionDescribe();
env->ExceptionClear();
}
LOGI("nativeOnCreate: done\n");
g_inNativeOnCreate = false;
//gApp->init(gContext);
}
static int s_surfaceCreatedCount = 0;
JNIEXPORT void JNICALL
Java_com_mojang_minecraftpe_GLRenderer_nativeOnSurfaceCreated(JNIEnv* env) {
LOGI("@nativeOnSurfaceCreated\n");
s_surfaceCreatedCount++;
if (g_inNativeOnCreate) {
// Skip re-entrant surface callbacks that fire during nativeOnCreate
return;
}
LOGI("@nativeOnSurfaceCreated #%d tid=%d\n", s_surfaceCreatedCount, (int)gettid());
if (gApp) {
// gApp->setSize( gContext.platform->getScreenWidth(),
// gContext.platform->getScreenHeight(),
// gContext.platform->isTouchscreen());
// Don't call onGraphicsReset the first time
if (gApp->isInited())
if (gApp->isInited()) {
LOGI("nativeOnSurfaceCreated: calling onGraphicsReset\n");
gApp->onGraphicsReset(gContext);
}
if (!gApp->isInited())
if (!gApp->isInited()) {
LOGI("nativeOnSurfaceCreated: calling init\n");
gApp->init(gContext);
LOGI("nativeOnSurfaceCreated: init done, isInited=%d\n", (int)gApp->isInited());
}
}
}
@@ -159,6 +187,11 @@ Java_com_mojang_minecraftpe_MainActivity_nativeOnKeyDown(JNIEnv* env, jclass cls
Keyboard::feed(keyCode, true);
}
JNIEXPORT void JNICALL
Java_com_mojang_minecraftpe_MainActivity_nativeTextChar(JNIEnv* env, jclass cls, jint unicodeChar) {
if (unicodeChar > 0 && unicodeChar < 128)
Keyboard::feedText((char)unicodeChar);
}
JNIEXPORT void JNICALL
Java_com_mojang_minecraftpe_MainActivity_nativeOnKeyUp(JNIEnv* env, jclass cls, jint keyCode) {
LOGI("@nativeOnKeyUp: %d\n", (int)keyCode);
Keyboard::feed(keyCode, false);