Move android platform code into Platform_Android.c

This commit is contained in:
UnknownShadow200 2021-09-26 17:07:03 +10:00
parent f10596a5cd
commit d1f9797412
7 changed files with 254 additions and 212 deletions

View file

@ -533,12 +533,7 @@ void Game_TakeScreenshot(void) {
Chat_Add1("&eTaken screenshot as: %s", &filename);
#ifdef CC_BUILD_ANDROID
path.length = 0;
JavaCall_String_String("shareScreenshot", &filename, &path);
if (!path.length) return;
Chat_AddRaw("&cError sharing screenshot");
Chat_Add1(" &c%s", &path);
Platform_ShareScreenshot(&filename);
#endif
#endif
}

View file

@ -494,7 +494,7 @@ static void RS_CreateRasterState(void) {
desc.CullMode = D3D11_CULL_NONE;
desc.FillMode = D3D11_FILL_SOLID;
desc.FrontCounterClockwise = true;
desc.DepthClipEnable = true; // otherwise vertices beyond far plane are still wrongly rendered
desc.DepthClipEnable = true; // otherwise vertices/pixels beyond far plane are still wrongly rendered
ID3D11Device_CreateRasterizerState(device, &desc, &rs_state);
}

View file

@ -643,7 +643,7 @@ cc_bool Http_DescribeError(cc_result res, cc_string* dst) {
JavaGetCurrentEnv(env);
args[0].i = res;
obj = JavaInstanceCall_Obj(env, JAVA_httpDescribeError, args);
obj = JavaICall_Obj(env, JAVA_httpDescribeError, args);
if (!obj) return false;
err = JavaGetString(env, obj, buffer);
@ -660,7 +660,7 @@ static void Http_AddHeader(struct HttpRequest* req, const char* key, const cc_st
args[0].l = JavaMakeConst(env, key);
args[1].l = JavaMakeString(env, value);
JavaInstanceCall_Void(env, JAVA_httpSetHeader, args);
JavaICall_Void(env, JAVA_httpSetHeader, args);
(*env)->DeleteLocalRef(env, args[0].l);
(*env)->DeleteLocalRef(env, args[1].l);
}
@ -687,12 +687,12 @@ static const JNINativeMethod methods[] = {
{ "httpAppendData", "([BI)V", java_HttpAppendData }
};
static void CacheMethodRefs(JNIEnv* env) {
JAVA_httpInit = JavaGetMethod(env, "httpInit", "(Ljava/lang/String;Ljava/lang/String;)I");
JAVA_httpSetHeader = JavaGetMethod(env, "httpSetHeader", "(Ljava/lang/String;Ljava/lang/String;)V");
JAVA_httpPerform = JavaGetMethod(env, "httpPerform", "()I");
JAVA_httpSetData = JavaGetMethod(env, "httpSetData", "([B)I");
JAVA_httpInit = JavaGetIMethod(env, "httpInit", "(Ljava/lang/String;Ljava/lang/String;)I");
JAVA_httpSetHeader = JavaGetIMethod(env, "httpSetHeader", "(Ljava/lang/String;Ljava/lang/String;)V");
JAVA_httpPerform = JavaGetIMethod(env, "httpPerform", "()I");
JAVA_httpSetData = JavaGetIMethod(env, "httpSetData", "([B)I");
JAVA_httpDescribeError = JavaGetMethod(env, "httpDescribeError", "(I)Ljava/lang/String;");
JAVA_httpDescribeError = JavaGetIMethod(env, "httpDescribeError", "(I)Ljava/lang/String;");
}
static void HttpBackend_Init(void) {
@ -710,7 +710,7 @@ static cc_result Http_InitReq(JNIEnv* env, struct HttpRequest* req, cc_string* u
args[0].l = JavaMakeString(env, url);
args[1].l = JavaMakeConst(env, verbs[req->requestType]);
res = JavaInstanceCall_Int(env, JAVA_httpInit, args);
res = JavaICall_Int(env, JAVA_httpInit, args);
(*env)->DeleteLocalRef(env, args[0].l);
(*env)->DeleteLocalRef(env, args[1].l);
return res;
@ -721,7 +721,7 @@ static cc_result Http_SetData(JNIEnv* env, struct HttpRequest* req) {
jint res;
args[0].l = JavaMakeBytes(env, req->data, req->size);
res = JavaInstanceCall_Int(env, JAVA_httpSetData, args);
res = JavaICall_Int(env, JAVA_httpSetData, args);
(*env)->DeleteLocalRef(env, args[0].l);
return res;
}
@ -741,7 +741,7 @@ static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* url) {
req->_capacity = 0;
http_curProgress = HTTP_PROGRESS_FETCHING_DATA;
res = JavaInstanceCall_Int(env, JAVA_httpPerform, NULL);
res = JavaICall_Int(env, JAVA_httpPerform, NULL);
http_curProgress = 100;
return res;
}

View file

@ -243,12 +243,13 @@ CC_API cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success);
extern jclass App_Class;
extern jobject App_Instance;
extern JavaVM* VM_Ptr;
void Platform_ShareScreenshot(const cc_string* filename);
#define JavaGetCurrentEnv(env) (*VM_Ptr)->AttachCurrentThread(VM_Ptr, &env, NULL)
#define JavaMakeConst(env, str) (*env)->NewStringUTF(env, str)
#define JavaRegisterNatives(env, methods) (*env)->RegisterNatives(env, App_Class, methods, Array_Elems(methods));
#define JavaGetMethod(env, name, sig) (*env)->GetMethodID(env, App_Class, name, sig)
#define JavaGetIMethod(env, name, sig) (*env)->GetMethodID(env, App_Class, name, sig)
/* Creates a string from the given java string. buffer must be at least NATIVE_STR_LEN long. */
/* NOTE: Don't forget to call env->ReleaseStringUTFChars. Only works with ASCII strings. */
@ -261,8 +262,6 @@ jbyteArray JavaMakeBytes(JNIEnv* env, const void* src, cc_uint32 len);
void JavaCallVoid(JNIEnv* env, const char* name, const char* sig, jvalue* args);
/* Calls a method in the activity class that returns a jint. */
jlong JavaCallLong(JNIEnv* env, const char* name, const char* sig, jvalue* args);
/* Calls a method in the activity class that returns a jint. */
jfloat JavaCallFloat(JNIEnv* env, const char* name, const char* sig, jvalue* args);
/* Calls a method in the activity class that returns a jobject. */
jobject JavaCallObject(JNIEnv* env, const char* name, const char* sig, jvalue* args);
/* Calls a method in the activity class that takes a string and returns nothing. */
@ -272,12 +271,12 @@ void JavaCall_Void_String(const char* name, cc_string* dst);
/* Calls a method in the activity class that takes a string and returns a string. */
void JavaCall_String_String(const char* name, const cc_string* arg, cc_string* dst);
#define JavaInstanceCall_Void(env, method, args) (*env)->CallVoidMethodA(env, App_Instance, method, args)
#define JavaICall_Void(env, method, args) (*env)->CallVoidMethodA(env, App_Instance, method, args)
/* Calls an instance method in the activity class that returns a jint */
#define JavaInstanceCall_Int(env, method, args) (*env)->CallIntMethodA(env, App_Instance, method, args)
#define JavaInstanceCall_Long(env, method, args) (*env)->CallLongMethodA(env, App_Instance, method, args)
#define JavaICall_Int(env, method, args) (*env)->CallIntMethodA(env, App_Instance, method, args)
#define JavaICall_Long(env, method, args) (*env)->CallLongMethodA(env, App_Instance, method, args)
/* Calls an instance method in the activity class that returns a jfloat */
#define JavaInstanceCall_Float(env,method, args) (*env)->CallFloatMethodA(env, App_Instance, method, args)
#define JavaInstanceCall_Obj(env, method, args) (*env)->CallObjectMethodA(env,App_Instance, method, args)
#define JavaICall_Float(env,method, args) (*env)->CallFloatMethodA(env, App_Instance, method, args)
#define JavaICall_Obj(env, method, args) (*env)->CallObjectMethodA(env,App_Instance, method, args)
#endif
#endif

201
src/Platform_Android.c Normal file
View file

@ -0,0 +1,201 @@
#include "Core.h"
#if defined CC_BUILD_ANDROID
#include "Chat.h"
#include "Constants.h"
#include "Errors.h"
#include "Funcs.h"
#include "String.h"
#include "Platform.h"
#include <unistd.h>
#include <android/log.h>
/*########################################################################################################################*
*------------------------------------------------------Logging/Time-------------------------------------------------------*
*#########################################################################################################################*/
void Platform_Log(const char* msg, int len) {
char tmp[2048 + 1];
len = min(len, 2048);
Mem_Copy(tmp, msg, len); tmp[len] = '\0';
/* log using logchat */
__android_log_write(ANDROID_LOG_DEBUG, "ClassiCube", tmp);
}
/*########################################################################################################################*
*-----------------------------------------------------Process/Module------------------------------------------------------*
*#########################################################################################################################*/
static char gameArgsBuffer[512];
static cc_string gameArgs = String_FromArray(gameArgsBuffer);
cc_result Process_StartGame(const cc_string* args) {
String_Copy(&gameArgs, args);
return 0;
}
cc_result Process_StartOpen(const cc_string* args) {
JavaCall_String_Void("startOpen", args);
return 0;
}
/*########################################################################################################################*
*--------------------------------------------------------Updater----------------------------------------------------------*
*#########################################################################################################################*/
const char* const Updater_OGL = NULL;
const char* const Updater_D3D9 = NULL;
cc_bool Updater_Clean(void) { return true; }
cc_result Updater_GetBuildTime(cc_uint64* t) {
JNIEnv* env;
JavaGetCurrentEnv(env);
*t = JavaCallLong(env, "getApkUpdateTime", "()J", NULL);
return 0;
}
cc_result Updater_Start(const char** action) { *action = "Updating game"; return ERR_NOT_SUPPORTED; }
cc_result Updater_MarkExecutable(void) { return 0; }
cc_result Updater_SetNewBuildTime(cc_uint64 t) { return ERR_NOT_SUPPORTED; }
/*########################################################################################################################*
*--------------------------------------------------------Platform---------------------------------------------------------*
*#########################################################################################################################*/
void Platform_ShareScreenshot(const cc_string* filename) {
cc_string path; char pathBuffer[FILENAME_SIZE];
String_InitArray(path, pathBuffer);
JavaCall_String_String("shareScreenshot", filename, &path);
if (!path.length) return;
Chat_AddRaw("&cError sharing screenshot");
Chat_Add1(" &c%s", &path);
}
/*########################################################################################################################*
*-----------------------------------------------------Configuration-------------------------------------------------------*
*#########################################################################################################################*/
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
int count = 0;
if (gameArgs.length) {
count = String_UNSAFE_Split(&gameArgs, ' ', args, GAME_MAX_CMDARGS);
/* clear arguments so after game is closed, launcher is started */
gameArgs.length = 0;
}
return count;
}
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
cc_string dir; char dirBuffer[FILENAME_SIZE + 1];
String_InitArray_NT(dir, dirBuffer);
JavaCall_Void_String("getExternalAppDir", &dir);
dir.buffer[dir.length] = '\0';
Platform_Log1("EXTERNAL DIR: %s|", &dir);
return chdir(dir.buffer) == -1 ? errno : 0;
}
/*########################################################################################################################*
*-----------------------------------------------------Java Interop--------------------------------------------------------*
*#########################################################################################################################*/
jclass App_Class;
jobject App_Instance;
JavaVM* VM_Ptr;
/* JNI helpers */
cc_string JavaGetString(JNIEnv* env, jstring str, char* buffer) {
const char* src; int len;
cc_string dst;
src = (*env)->GetStringUTFChars(env, str, NULL);
len = (*env)->GetStringUTFLength(env, str);
dst.buffer = buffer;
dst.length = 0;
dst.capacity = NATIVE_STR_LEN;
String_AppendUtf8(&dst, src, len);
(*env)->ReleaseStringUTFChars(env, str, src);
return dst;
}
jobject JavaMakeString(JNIEnv* env, const cc_string* str) {
cc_uint8 tmp[2048 + 4];
cc_uint8* cur;
int i, len = 0;
for (i = 0; i < str->length && len < 2048; i++) {
cur = tmp + len;
len += Convert_CP437ToUtf8(str->buffer[i], cur);
}
tmp[len] = '\0';
return (*env)->NewStringUTF(env, (const char*)tmp);
}
jbyteArray JavaMakeBytes(JNIEnv* env, const void* src, cc_uint32 len) {
if (!len) return NULL;
jbyteArray arr = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, arr, 0, len, src);
return arr;
}
void JavaCallVoid(JNIEnv* env, const char* name, const char* sig, jvalue* args) {
jmethodID method = (*env)->GetMethodID(env, App_Class, name, sig);
(*env)->CallVoidMethodA(env, App_Instance, method, args);
}
jlong JavaCallLong(JNIEnv* env, const char* name, const char* sig, jvalue* args) {
jmethodID method = (*env)->GetMethodID(env, App_Class, name, sig);
return (*env)->CallLongMethodA(env, App_Instance, method, args);
}
jobject JavaCallObject(JNIEnv* env, const char* name, const char* sig, jvalue* args) {
jmethodID method = (*env)->GetMethodID(env, App_Class, name, sig);
return (*env)->CallObjectMethodA(env, App_Instance, method, args);
}
void JavaCall_String_Void(const char* name, const cc_string* value) {
JNIEnv* env;
jvalue args[1];
JavaGetCurrentEnv(env);
args[0].l = JavaMakeString(env, value);
JavaCallVoid(env, name, "(Ljava/lang/String;)V", args);
(*env)->DeleteLocalRef(env, args[0].l);
}
static void ReturnString(JNIEnv* env, jobject obj, cc_string* dst) {
const jchar* src;
jsize len;
if (!obj) return;
src = (*env)->GetStringChars(env, obj, NULL);
len = (*env)->GetStringLength(env, obj);
String_AppendUtf16(dst, src, len * 2);
(*env)->ReleaseStringChars(env, obj, src);
(*env)->DeleteLocalRef(env, obj);
}
void JavaCall_Void_String(const char* name, cc_string* dst) {
JNIEnv* env;
jobject obj;
JavaGetCurrentEnv(env);
obj = JavaCallObject(env, name, "()Ljava/lang/String;", NULL);
ReturnString(env, obj, dst);
}
void JavaCall_String_String(const char* name, const cc_string* arg, cc_string* dst) {
JNIEnv* env;
jobject obj;
jvalue args[1];
JavaGetCurrentEnv(env);
args[0].l = JavaMakeString(env, arg);
obj = JavaCallObject(env, name, "(Ljava/lang/String;)Ljava/lang/String;", args);
ReturnString(env, obj, dst);
(*env)->DeleteLocalRef(env, args[0].l);
}
#endif

View file

@ -92,16 +92,8 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
return ((end - beg) * sw_freqMul) / sw_freqDiv;
}
/* log to android logcat */
#ifdef CC_BUILD_ANDROID
#include <android/log.h>
void Platform_Log(const char* msg, int len) {
char tmp[2048 + 1];
len = min(len, 2048);
Mem_Copy(tmp, msg, len); tmp[len] = '\0';
__android_log_write(ANDROID_LOG_DEBUG, "ClassiCube", tmp);
}
/* implemented in Platform_Android.c */
#else
void Platform_Log(const char* msg, int len) {
write(STDOUT_FILENO, msg, len);
@ -609,13 +601,7 @@ cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
*-----------------------------------------------------Process/Module------------------------------------------------------*
*#########################################################################################################################*/
#if defined CC_BUILD_ANDROID
static char gameArgsBuffer[512];
static cc_string gameArgs = String_FromArray(gameArgsBuffer);
cc_result Process_StartGame(const cc_string* args) {
String_Copy(&gameArgs, args);
return 0; /* TODO: Is there a clean way of handling an error */
}
/* implemented in Platform_Android.c */
#elif defined CC_BUILD_IOS
/* implemented in interop_ios.m */
#else
@ -666,10 +652,7 @@ void Process_Exit(cc_result code) { exit(code); }
/* Opening browser/starting shell is not really standardised */
#if defined CC_BUILD_ANDROID
cc_result Process_StartOpen(const cc_string* args) {
JavaCall_String_Void("startOpen", args);
return 0;
}
/* Implemented in Platform_Android.c */
#elif defined CC_BUILD_MACOS
cc_result Process_StartOpen(const cc_string* args) {
UInt8 str[NATIVE_STR_LEN];
@ -790,24 +773,12 @@ static cc_result Process_RawGetExePath(char* path, int* len) {
/*########################################################################################################################*
*--------------------------------------------------------Updater----------------------------------------------------------*
*#########################################################################################################################*/
#if defined CC_BUILD_ANDROID
/* implemented in Platform_Android.c */
#else
const char* const Updater_D3D9 = NULL;
cc_bool Updater_Clean(void) { return true; }
#if defined CC_BUILD_ANDROID
const char* const Updater_OGL = NULL;
cc_result Updater_GetBuildTime(cc_uint64* t) {
JNIEnv* env;
JavaGetCurrentEnv(env);
*t = JavaCallLong(env, "getApkUpdateTime", "()J", NULL);
return 0;
}
cc_result Updater_Start(const char** action) { *action = "Updating game"; return ERR_NOT_SUPPORTED; }
cc_result Updater_MarkExecutable(void) { return 0; }
cc_result Updater_SetNewBuildTime(cc_uint64 t) { return ERR_NOT_SUPPORTED; }
#else
#if defined CC_BUILD_LINUX
#if __x86_64__
const char* const Updater_OGL = "ClassiCube";
@ -1228,25 +1199,7 @@ cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
*-----------------------------------------------------Configuration-------------------------------------------------------*
*#########################################################################################################################*/
#if defined CC_BUILD_ANDROID
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
int count = 0;
if (gameArgs.length) {
count = String_UNSAFE_Split(&gameArgs, ' ', args, GAME_MAX_CMDARGS);
/* clear arguments so after game is closed, launcher is started */
gameArgs.length = 0;
}
return count;
}
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
cc_string dir; char dirBuffer[FILENAME_SIZE + 1];
String_InitArray_NT(dir, dirBuffer);
JavaCall_Void_String("getExternalAppDir", &dir);
dir.buffer[dir.length] = '\0';
Platform_Log1("EXTERNAL DIR: %s|", &dir);
return chdir(dir.buffer) == -1 ? errno : 0;
}
/* implemented in Platform_Android.c */
#elif defined CC_BUILD_IOS
/* implemented in interop_ios.m */
#else
@ -1318,110 +1271,4 @@ cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
return chdir(path) == -1 ? errno : 0;
}
#endif
/* Android java interop stuff */
#if defined CC_BUILD_ANDROID
jclass App_Class;
jobject App_Instance;
JavaVM* VM_Ptr;
/* JNI helpers */
cc_string JavaGetString(JNIEnv* env, jstring str, char* buffer) {
const char* src; int len;
cc_string dst;
src = (*env)->GetStringUTFChars(env, str, NULL);
len = (*env)->GetStringUTFLength(env, str);
dst.buffer = buffer;
dst.length = 0;
dst.capacity = NATIVE_STR_LEN;
String_AppendUtf8(&dst, src, len);
(*env)->ReleaseStringUTFChars(env, str, src);
return dst;
}
jobject JavaMakeString(JNIEnv* env, const cc_string* str) {
cc_uint8 tmp[2048 + 4];
cc_uint8* cur;
int i, len = 0;
for (i = 0; i < str->length && len < 2048; i++) {
cur = tmp + len;
len += Convert_CP437ToUtf8(str->buffer[i], cur);
}
tmp[len] = '\0';
return (*env)->NewStringUTF(env, (const char*)tmp);
}
jbyteArray JavaMakeBytes(JNIEnv* env, const void* src, cc_uint32 len) {
if (!len) return NULL;
jbyteArray arr = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, arr, 0, len, src);
return arr;
}
void JavaCallVoid(JNIEnv* env, const char* name, const char* sig, jvalue* args) {
jmethodID method = (*env)->GetMethodID(env, App_Class, name, sig);
(*env)->CallVoidMethodA(env, App_Instance, method, args);
}
jlong JavaCallLong(JNIEnv* env, const char* name, const char* sig, jvalue* args) {
jmethodID method = (*env)->GetMethodID(env, App_Class, name, sig);
return (*env)->CallLongMethodA(env, App_Instance, method, args);
}
jfloat JavaCallFloat(JNIEnv* env, const char* name, const char* sig, jvalue* args) {
jmethodID method = (*env)->GetMethodID(env, App_Class, name, sig);
return (*env)->CallFloatMethodA(env, App_Instance, method, args);
}
jobject JavaCallObject(JNIEnv* env, const char* name, const char* sig, jvalue* args) {
jmethodID method = (*env)->GetMethodID(env, App_Class, name, sig);
return (*env)->CallObjectMethodA(env, App_Instance, method, args);
}
void JavaCall_String_Void(const char* name, const cc_string* value) {
JNIEnv* env;
jvalue args[1];
JavaGetCurrentEnv(env);
args[0].l = JavaMakeString(env, value);
JavaCallVoid(env, name, "(Ljava/lang/String;)V", args);
(*env)->DeleteLocalRef(env, args[0].l);
}
static void ReturnString(JNIEnv* env, jobject obj, cc_string* dst) {
const jchar* src;
jsize len;
if (!obj) return;
src = (*env)->GetStringChars(env, obj, NULL);
len = (*env)->GetStringLength(env, obj);
String_AppendUtf16(dst, src, len * 2);
(*env)->ReleaseStringChars(env, obj, src);
(*env)->DeleteLocalRef(env, obj);
}
void JavaCall_Void_String(const char* name, cc_string* dst) {
JNIEnv* env;
jobject obj;
JavaGetCurrentEnv(env);
obj = JavaCallObject(env, name, "()Ljava/lang/String;", NULL);
ReturnString(env, obj, dst);
}
void JavaCall_String_String(const char* name, const cc_string* arg, cc_string* dst) {
JNIEnv* env;
jobject obj;
jvalue args[1];
JavaGetCurrentEnv(env);
args[0].l = JavaMakeString(env, arg);
obj = JavaCallObject(env, name, "(Ljava/lang/String;)Ljava/lang/String;", args);
ReturnString(env, obj, dst);
(*env)->DeleteLocalRef(env, args[0].l);
}
#endif
#endif

View file

@ -144,7 +144,7 @@ static void JNICALL java_processSurfaceDestroyed(JNIEnv* env, jobject o) {
/* eglSwapBuffers might return EGL_BAD_SURFACE, EGL_BAD_ALLOC, or some other error */
/* Instead the context is lost here in a consistent manner */
if (Gfx.Created) Gfx_LoseContext("surface lost");
JavaInstanceCall_Void(env, JAVA_processedSurfaceDestroyed, NULL);
JavaICall_Void(env, JAVA_processedSurfaceDestroyed, NULL);
}
static void JNICALL java_processSurfaceResized(JNIEnv* env, jobject o, jobject surface) {
@ -180,7 +180,7 @@ static void JNICALL java_onDestroy(JNIEnv* env, jobject o) {
if (WindowInfo.Exists) Window_Close();
/* TODO: signal to java code we're done */
/* JavaInstanceCall_Void(env, JAVA_processedDestroyed", NULL); */
/* JavaICall_Void(env, JAVA_processedDestroyed", NULL); */
}
static void JNICALL java_onGotFocus(JNIEnv* env, jobject o) {
@ -227,23 +227,23 @@ static const JNINativeMethod methods[] = {
{ "processOnLowMemory", "()V", java_onLowMemory }
};
static void CacheMethodRefs(JNIEnv* env) {
JAVA_openKeyboard = JavaGetMethod(env, "openKeyboard", "(Ljava/lang/String;I)V");
JAVA_setKeyboardText = JavaGetMethod(env, "setKeyboardText", "(Ljava/lang/String;)V");
JAVA_closeKeyboard = JavaGetMethod(env, "closeKeyboard", "()V");
JAVA_openKeyboard = JavaGetIMethod(env, "openKeyboard", "(Ljava/lang/String;I)V");
JAVA_setKeyboardText = JavaGetIMethod(env, "setKeyboardText", "(Ljava/lang/String;)V");
JAVA_closeKeyboard = JavaGetIMethod(env, "closeKeyboard", "()V");
JAVA_getWindowState = JavaGetMethod(env, "getWindowState", "()I");
JAVA_enterFullscreen = JavaGetMethod(env, "enterFullscreen", "()V");
JAVA_exitFullscreen = JavaGetMethod(env, "exitFullscreen", "()V");
JAVA_getWindowState = JavaGetIMethod(env, "getWindowState", "()I");
JAVA_enterFullscreen = JavaGetIMethod(env, "enterFullscreen", "()V");
JAVA_exitFullscreen = JavaGetIMethod(env, "exitFullscreen", "()V");
JAVA_getDpiX = JavaGetMethod(env, "getDpiX", "()F");
JAVA_getDpiY = JavaGetMethod(env, "getDpiY", "()F");
JAVA_setupForGame = JavaGetMethod(env, "setupForGame", "()V");
JAVA_getDpiX = JavaGetIMethod(env, "getDpiX", "()F");
JAVA_getDpiY = JavaGetIMethod(env, "getDpiY", "()F");
JAVA_setupForGame = JavaGetIMethod(env, "setupForGame", "()V");
JAVA_processedSurfaceDestroyed = JavaGetMethod(env, "processedSurfaceDestroyed", "()V");
JAVA_processEvents = JavaGetMethod(env, "processEvents", "()V");
JAVA_processedSurfaceDestroyed = JavaGetIMethod(env, "processedSurfaceDestroyed", "()V");
JAVA_processEvents = JavaGetIMethod(env, "processEvents", "()V");
JAVA_showAlert = JavaGetMethod(env, "showAlert", "(Ljava/lang/String;Ljava/lang/String;)V");
JAVA_setRequestedOrientation = JavaGetMethod(env, "setRequestedOrientation", "(I)V");
JAVA_showAlert = JavaGetIMethod(env, "showAlert", "(Ljava/lang/String;Ljava/lang/String;)V");
JAVA_setRequestedOrientation = JavaGetIMethod(env, "setRequestedOrientation", "(I)V");
}
void Window_Init(void) {
@ -257,8 +257,8 @@ void Window_Init(void) {
Input_SetTouchMode(true);
DisplayInfo.Depth = 32;
DisplayInfo.ScaleX = JavaInstanceCall_Float(env, JAVA_getDpiX, NULL);
DisplayInfo.ScaleY = JavaInstanceCall_Float(env, JAVA_getDpiY, NULL);
DisplayInfo.ScaleX = JavaICall_Float(env, JAVA_getDpiX, NULL);
DisplayInfo.ScaleY = JavaICall_Float(env, JAVA_getDpiY, NULL);
}
static void Window_RemakeSurface(void) {
@ -268,7 +268,7 @@ static void Window_RemakeSurface(void) {
/* Force window to be destroyed and re-created */
/* (see comments in setupForGame for why this has to be done) */
JavaInstanceCall_Void(env, JAVA_setupForGame, NULL);
JavaICall_Void(env, JAVA_setupForGame, NULL);
Platform_LogConst("Entering wait for window exist loop..");
/* Loop until window gets created by main UI thread */
@ -306,20 +306,20 @@ void Window_Show(void) { } /* Window already visible */
int Window_GetWindowState(void) {
JNIEnv* env;
JavaGetCurrentEnv(env);
return JavaInstanceCall_Int(env, JAVA_getWindowState, NULL);
return JavaICall_Int(env, JAVA_getWindowState, NULL);
}
cc_result Window_EnterFullscreen(void) {
JNIEnv* env;
JavaGetCurrentEnv(env);
JavaInstanceCall_Void(env, JAVA_enterFullscreen, NULL);
JavaICall_Void(env, JAVA_enterFullscreen, NULL);
return 0;
}
cc_result Window_ExitFullscreen(void) {
JNIEnv* env;
JavaGetCurrentEnv(env);
JavaInstanceCall_Void(env, JAVA_exitFullscreen, NULL);
JavaICall_Void(env, JAVA_exitFullscreen, NULL);
return 0;
}
@ -336,7 +336,7 @@ void Window_ProcessEvents(void) {
JNIEnv* env;
JavaGetCurrentEnv(env);
/* TODO: Cache the java env */
JavaInstanceCall_Void(env, JAVA_processEvents, NULL);
JavaICall_Void(env, JAVA_processEvents, NULL);
}
/* No actual mouse cursor */
@ -356,7 +356,7 @@ static void ShowDialogCore(const char* title, const char* msg) {
args[0].l = JavaMakeConst(env, title);
args[1].l = JavaMakeConst(env, msg);
JavaInstanceCall_Void(env, JAVA_showAlert, args);
JavaICall_Void(env, JAVA_showAlert, args);
(*env)->DeleteLocalRef(env, args[0].l);
(*env)->DeleteLocalRef(env, args[1].l);
}
@ -412,7 +412,7 @@ void Window_OpenKeyboard(const struct OpenKeyboardArgs* kArgs) {
args[0].l = JavaMakeString(env, kArgs->text);
args[1].i = kArgs->type;
JavaInstanceCall_Void(env, JAVA_openKeyboard, args);
JavaICall_Void(env, JAVA_openKeyboard, args);
(*env)->DeleteLocalRef(env, args[0].l);
}
@ -422,14 +422,14 @@ void Window_SetKeyboardText(const cc_string* text) {
JavaGetCurrentEnv(env);
args[0].l = JavaMakeString(env, text);
JavaInstanceCall_Void(env, JAVA_setKeyboardText, args);
JavaICall_Void(env, JAVA_setKeyboardText, args);
(*env)->DeleteLocalRef(env, args[0].l);
}
void Window_CloseKeyboard(void) {
JNIEnv* env;
JavaGetCurrentEnv(env);
JavaInstanceCall_Void(env, JAVA_closeKeyboard, NULL);
JavaICall_Void(env, JAVA_closeKeyboard, NULL);
}
void Window_LockLandscapeOrientation(cc_bool lock) {
@ -440,7 +440,7 @@ void Window_LockLandscapeOrientation(cc_bool lock) {
/* SCREEN_ORIENTATION_SENSOR_LANDSCAPE = 0x00000006 */
/* SCREEN_ORIENTATION_UNSPECIFIED = 0xffffffff */
args[0].i = lock ? 0x00000006 : 0xffffffff;
JavaInstanceCall_Void(env, JAVA_setRequestedOrientation, args);
JavaICall_Void(env, JAVA_setRequestedOrientation, args);
}
void Window_EnableRawMouse(void) { DefaultEnableRawMouse(); }