mirror of
https://github.com/godotengine/godot.git
synced 2025-10-26 11:14:17 +00:00
Cleanup Android C++ code
This commit is contained in:
parent
340283f5be
commit
7a782edeaa
29 changed files with 405 additions and 459 deletions
|
|
@ -96,42 +96,33 @@ jobject GodotJavaWrapper::get_activity() {
|
|||
|
||||
jobject GodotJavaWrapper::get_member_object(const char *p_name, const char *p_class, JNIEnv *p_env) {
|
||||
if (godot_class) {
|
||||
if (p_env == NULL)
|
||||
if (p_env == nullptr) {
|
||||
p_env = get_jni_env();
|
||||
|
||||
ERR_FAIL_COND_V(p_env == nullptr, nullptr);
|
||||
|
||||
}
|
||||
ERR_FAIL_NULL_V(p_env, nullptr);
|
||||
jfieldID fid = p_env->GetStaticFieldID(godot_class, p_name, p_class);
|
||||
return p_env->GetStaticObjectField(godot_class, fid);
|
||||
} else {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
jobject GodotJavaWrapper::get_class_loader() {
|
||||
if (_get_class_loader) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, nullptr);
|
||||
|
||||
ERR_FAIL_NULL_V(env, nullptr);
|
||||
return env->CallObjectMethod(activity, _get_class_loader);
|
||||
} else {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void GodotJavaWrapper::gfx_init(bool gl2) {
|
||||
// beats me what this once did, there was no code,
|
||||
// but we're getting false if our GLES3 driver is initialised
|
||||
// and true for our GLES2 driver
|
||||
// Maybe we're supposed to communicate this back or store it?
|
||||
}
|
||||
|
||||
void GodotJavaWrapper::on_video_init(JNIEnv *p_env) {
|
||||
if (_on_video_init) {
|
||||
if (p_env == NULL)
|
||||
if (p_env == nullptr) {
|
||||
p_env = get_jni_env();
|
||||
ERR_FAIL_COND(p_env == nullptr);
|
||||
|
||||
}
|
||||
ERR_FAIL_NULL(p_env);
|
||||
p_env->CallVoidMethod(godot_instance, _on_video_init);
|
||||
}
|
||||
}
|
||||
|
|
@ -152,49 +143,50 @@ void GodotJavaWrapper::destroy_offscreen_gl(JNIEnv *p_env) {
|
|||
|
||||
void GodotJavaWrapper::set_offscreen_gl_current(JNIEnv *p_env, bool p_current) {
|
||||
if (_set_offscreen_gl_current) {
|
||||
if (p_env == NULL)
|
||||
if (p_env == nullptr) {
|
||||
p_env = get_jni_env();
|
||||
ERR_FAIL_COND(p_env == nullptr);
|
||||
}
|
||||
ERR_FAIL_NULL(p_env);
|
||||
p_env->CallVoidMethod(godot_instance, _set_offscreen_gl_current, p_current);
|
||||
}
|
||||
}
|
||||
|
||||
void GodotJavaWrapper::on_godot_setup_completed(JNIEnv *p_env) {
|
||||
if (_on_godot_setup_completed) {
|
||||
if (p_env == NULL) {
|
||||
if (p_env == nullptr) {
|
||||
p_env = get_jni_env();
|
||||
}
|
||||
ERR_FAIL_COND(p_env == nullptr);
|
||||
ERR_FAIL_NULL(p_env);
|
||||
p_env->CallVoidMethod(godot_instance, _on_godot_setup_completed);
|
||||
}
|
||||
}
|
||||
|
||||
void GodotJavaWrapper::on_godot_main_loop_started(JNIEnv *p_env) {
|
||||
if (_on_godot_main_loop_started) {
|
||||
if (p_env == NULL) {
|
||||
if (p_env == nullptr) {
|
||||
p_env = get_jni_env();
|
||||
}
|
||||
ERR_FAIL_COND(p_env == nullptr);
|
||||
ERR_FAIL_NULL(p_env);
|
||||
p_env->CallVoidMethod(godot_instance, _on_godot_main_loop_started);
|
||||
}
|
||||
}
|
||||
|
||||
void GodotJavaWrapper::restart(JNIEnv *p_env) {
|
||||
if (_restart) {
|
||||
if (p_env == NULL)
|
||||
if (p_env == nullptr) {
|
||||
p_env = get_jni_env();
|
||||
ERR_FAIL_COND(p_env == nullptr);
|
||||
|
||||
}
|
||||
ERR_FAIL_NULL(p_env);
|
||||
p_env->CallVoidMethod(godot_instance, _restart);
|
||||
}
|
||||
}
|
||||
|
||||
void GodotJavaWrapper::force_quit(JNIEnv *p_env) {
|
||||
if (_finish) {
|
||||
if (p_env == NULL)
|
||||
if (p_env == nullptr) {
|
||||
p_env = get_jni_env();
|
||||
ERR_FAIL_COND(p_env == nullptr);
|
||||
|
||||
}
|
||||
ERR_FAIL_NULL(p_env);
|
||||
p_env->CallVoidMethod(godot_instance, _finish);
|
||||
}
|
||||
}
|
||||
|
|
@ -202,8 +194,7 @@ void GodotJavaWrapper::force_quit(JNIEnv *p_env) {
|
|||
void GodotJavaWrapper::set_keep_screen_on(bool p_enabled) {
|
||||
if (_set_keep_screen_on) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
|
||||
ERR_FAIL_NULL(env);
|
||||
env->CallVoidMethod(godot_instance, _set_keep_screen_on, p_enabled);
|
||||
}
|
||||
}
|
||||
|
|
@ -211,8 +202,7 @@ void GodotJavaWrapper::set_keep_screen_on(bool p_enabled) {
|
|||
void GodotJavaWrapper::alert(const String &p_message, const String &p_title) {
|
||||
if (_alert) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
|
||||
ERR_FAIL_NULL(env);
|
||||
jstring jStrMessage = env->NewStringUTF(p_message.utf8().get_data());
|
||||
jstring jStrTitle = env->NewStringUTF(p_title.utf8().get_data());
|
||||
env->CallVoidMethod(godot_instance, _alert, jStrMessage, jStrTitle);
|
||||
|
|
@ -221,24 +211,21 @@ void GodotJavaWrapper::alert(const String &p_message, const String &p_title) {
|
|||
|
||||
int GodotJavaWrapper::get_gles_version_code() {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, 0);
|
||||
|
||||
ERR_FAIL_NULL_V(env, 0);
|
||||
if (_get_GLES_version_code) {
|
||||
return env->CallIntMethod(godot_instance, _get_GLES_version_code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GodotJavaWrapper::has_get_clipboard() {
|
||||
return _get_clipboard != 0;
|
||||
return _get_clipboard != nullptr;
|
||||
}
|
||||
|
||||
String GodotJavaWrapper::get_clipboard() {
|
||||
if (_get_clipboard) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, String());
|
||||
|
||||
ERR_FAIL_NULL_V(env, String());
|
||||
jstring s = (jstring)env->CallObjectMethod(godot_instance, _get_clipboard);
|
||||
return jstring_to_string(s, env);
|
||||
} else {
|
||||
|
|
@ -249,8 +236,7 @@ String GodotJavaWrapper::get_clipboard() {
|
|||
String GodotJavaWrapper::get_input_fallback_mapping() {
|
||||
if (_get_input_fallback_mapping) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, String());
|
||||
|
||||
ERR_FAIL_NULL_V(env, String());
|
||||
jstring fallback_mapping = (jstring)env->CallObjectMethod(godot_instance, _get_input_fallback_mapping);
|
||||
return jstring_to_string(fallback_mapping, env);
|
||||
} else {
|
||||
|
|
@ -259,28 +245,26 @@ String GodotJavaWrapper::get_input_fallback_mapping() {
|
|||
}
|
||||
|
||||
bool GodotJavaWrapper::has_set_clipboard() {
|
||||
return _set_clipboard != 0;
|
||||
return _set_clipboard != nullptr;
|
||||
}
|
||||
|
||||
void GodotJavaWrapper::set_clipboard(const String &p_text) {
|
||||
if (_set_clipboard) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
|
||||
ERR_FAIL_NULL(env);
|
||||
jstring jStr = env->NewStringUTF(p_text.utf8().get_data());
|
||||
env->CallVoidMethod(godot_instance, _set_clipboard, jStr);
|
||||
}
|
||||
}
|
||||
|
||||
bool GodotJavaWrapper::has_has_clipboard() {
|
||||
return _has_clipboard != 0;
|
||||
return _has_clipboard != nullptr;
|
||||
}
|
||||
|
||||
bool GodotJavaWrapper::has_clipboard() {
|
||||
if (_has_clipboard) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, false);
|
||||
|
||||
ERR_FAIL_NULL_V(env, false);
|
||||
return env->CallBooleanMethod(godot_instance, _has_clipboard);
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -290,8 +274,7 @@ bool GodotJavaWrapper::has_clipboard() {
|
|||
bool GodotJavaWrapper::request_permission(const String &p_name) {
|
||||
if (_request_permission) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, false);
|
||||
|
||||
ERR_FAIL_NULL_V(env, false);
|
||||
jstring jStrName = env->NewStringUTF(p_name.utf8().get_data());
|
||||
return env->CallBooleanMethod(godot_instance, _request_permission, jStrName);
|
||||
} else {
|
||||
|
|
@ -302,8 +285,7 @@ bool GodotJavaWrapper::request_permission(const String &p_name) {
|
|||
bool GodotJavaWrapper::request_permissions() {
|
||||
if (_request_permissions) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, false);
|
||||
|
||||
ERR_FAIL_NULL_V(env, false);
|
||||
return env->CallBooleanMethod(godot_instance, _request_permissions);
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -314,14 +296,12 @@ Vector<String> GodotJavaWrapper::get_granted_permissions() const {
|
|||
Vector<String> permissions_list;
|
||||
if (_get_granted_permissions) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, permissions_list);
|
||||
|
||||
ERR_FAIL_NULL_V(env, permissions_list);
|
||||
jobject permissions_object = env->CallObjectMethod(godot_instance, _get_granted_permissions);
|
||||
jobjectArray *arr = reinterpret_cast<jobjectArray *>(&permissions_object);
|
||||
|
||||
int i = 0;
|
||||
jsize len = env->GetArrayLength(*arr);
|
||||
for (i = 0; i < len; i++) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
jstring jstr = (jstring)env->GetObjectArrayElement(*arr, i);
|
||||
String str = jstring_to_string(jstr, env);
|
||||
permissions_list.push_back(str);
|
||||
|
|
@ -334,8 +314,7 @@ Vector<String> GodotJavaWrapper::get_granted_permissions() const {
|
|||
void GodotJavaWrapper::init_input_devices() {
|
||||
if (_init_input_devices) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
|
||||
ERR_FAIL_NULL(env);
|
||||
env->CallVoidMethod(godot_instance, _init_input_devices);
|
||||
}
|
||||
}
|
||||
|
|
@ -343,19 +322,17 @@ void GodotJavaWrapper::init_input_devices() {
|
|||
jobject GodotJavaWrapper::get_surface() {
|
||||
if (_get_surface) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, nullptr);
|
||||
|
||||
ERR_FAIL_NULL_V(env, nullptr);
|
||||
return env->CallObjectMethod(godot_instance, _get_surface);
|
||||
} else {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool GodotJavaWrapper::is_activity_resumed() {
|
||||
if (_is_activity_resumed) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND_V(env == nullptr, false);
|
||||
|
||||
ERR_FAIL_NULL_V(env, false);
|
||||
return env->CallBooleanMethod(godot_instance, _is_activity_resumed);
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -365,8 +342,7 @@ bool GodotJavaWrapper::is_activity_resumed() {
|
|||
void GodotJavaWrapper::vibrate(int p_duration_ms) {
|
||||
if (_vibrate) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
|
||||
ERR_FAIL_NULL(env);
|
||||
env->CallVoidMethod(godot_instance, _vibrate, p_duration_ms);
|
||||
}
|
||||
}
|
||||
|
|
@ -374,8 +350,7 @@ void GodotJavaWrapper::vibrate(int p_duration_ms) {
|
|||
void GodotJavaWrapper::create_new_godot_instance(List<String> args) {
|
||||
if (_create_new_godot_instance) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_COND(env == nullptr);
|
||||
|
||||
ERR_FAIL_NULL(env);
|
||||
jobjectArray jargs = env->NewObjectArray(args.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
|
||||
for (int i = 0; i < args.size(); i++) {
|
||||
env->SetObjectArrayElement(jargs, i, env->NewStringUTF(args[i].utf8().get_data()));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue