diff options
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/android_input_handler.cpp | 5 | ||||
-rw-r--r-- | platform/android/api/jni_singleton.h | 22 | ||||
-rw-r--r-- | platform/android/audio_driver_opensl.cpp | 9 | ||||
-rw-r--r-- | platform/android/dir_access_jandroid.cpp | 50 | ||||
-rw-r--r-- | platform/android/file_access_android.cpp | 25 | ||||
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java | 5 | ||||
-rw-r--r-- | platform/android/java_class_wrapper.cpp | 90 | ||||
-rw-r--r-- | platform/android/java_godot_io_wrapper.cpp | 1 | ||||
-rw-r--r-- | platform/android/java_godot_lib_jni.cpp | 46 | ||||
-rw-r--r-- | platform/android/java_godot_wrapper.cpp | 12 | ||||
-rw-r--r-- | platform/android/jni_utils.cpp | 44 | ||||
-rw-r--r-- | platform/android/net_socket_android.cpp | 21 | ||||
-rw-r--r-- | platform/android/os_android.cpp | 30 |
13 files changed, 210 insertions, 150 deletions
diff --git a/platform/android/android_input_handler.cpp b/platform/android/android_input_handler.cpp index 246ec6b198..10f23b320b 100644 --- a/platform/android/android_input_handler.cpp +++ b/platform/android/android_input_handler.cpp @@ -165,8 +165,9 @@ void AndroidInputHandler::process_touch(int p_event, int p_pointer, const Vector ERR_CONTINUE(idx == -1); - if (touch[i].pos == p_points[idx].pos) - continue; //no move unncesearily + if (touch[i].pos == p_points[idx].pos) { + continue; // Don't move unnecessarily. + } Ref<InputEventScreenDrag> ev; ev.instantiate(); diff --git a/platform/android/api/jni_singleton.h b/platform/android/api/jni_singleton.h index d8503b6caf..57d08ac83e 100644 --- a/platform/android/api/jni_singleton.h +++ b/platform/android/api/jni_singleton.h @@ -31,10 +31,10 @@ #ifndef JNI_SINGLETON_H #define JNI_SINGLETON_H -#include <core/config/engine.h> -#include <core/variant/variant.h> +#include "core/config/engine.h" +#include "core/variant/variant.h" #ifdef ANDROID_ENABLED -#include <platform/android/jni_utils.h> +#include "platform/android/jni_utils.h" #endif class JNISingleton : public Object { @@ -93,8 +93,9 @@ public: for (int i = 0; i < p_argcount; i++) { jvalret vr = _variant_to_jvalue(env, E->get().argtypes[i], p_args[i]); v[i] = vr.val; - if (vr.obj) + if (vr.obj) { to_erase.push_back(vr.obj); + } } Variant ret; @@ -197,18 +198,19 @@ public: } void add_signal(const StringName &p_name, const Vector<Variant::Type> &p_args) { - if (p_args.size() == 0) + if (p_args.size() == 0) { ADD_SIGNAL(MethodInfo(p_name)); - else if (p_args.size() == 1) + } else if (p_args.size() == 1) { ADD_SIGNAL(MethodInfo(p_name, PropertyInfo(p_args[0], "arg1"))); - else if (p_args.size() == 2) + } else if (p_args.size() == 2) { ADD_SIGNAL(MethodInfo(p_name, PropertyInfo(p_args[0], "arg1"), PropertyInfo(p_args[1], "arg2"))); - else if (p_args.size() == 3) + } else if (p_args.size() == 3) { ADD_SIGNAL(MethodInfo(p_name, PropertyInfo(p_args[0], "arg1"), PropertyInfo(p_args[1], "arg2"), PropertyInfo(p_args[2], "arg3"))); - else if (p_args.size() == 4) + } else if (p_args.size() == 4) { ADD_SIGNAL(MethodInfo(p_name, PropertyInfo(p_args[0], "arg1"), PropertyInfo(p_args[1], "arg2"), PropertyInfo(p_args[2], "arg3"), PropertyInfo(p_args[3], "arg4"))); - else if (p_args.size() == 5) + } else if (p_args.size() == 5) { ADD_SIGNAL(MethodInfo(p_name, PropertyInfo(p_args[0], "arg1"), PropertyInfo(p_args[1], "arg2"), PropertyInfo(p_args[2], "arg3"), PropertyInfo(p_args[3], "arg4"), PropertyInfo(p_args[4], "arg5"))); + } } #endif diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index cd478bb90f..8495d2cc18 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -56,8 +56,9 @@ void AudioDriverOpenSL::_buffer_callback( } } - if (mix) + if (mix) { mutex.unlock(); + } const int32_t *src_buff = mixdown_buffer; @@ -312,13 +313,15 @@ AudioDriver::SpeakerMode AudioDriverOpenSL::get_speaker_mode() const { } void AudioDriverOpenSL::lock() { - if (active) + if (active) { mutex.lock(); + } } void AudioDriverOpenSL::unlock() { - if (active) + if (active) { mutex.unlock(); + } } void AudioDriverOpenSL::finish() { diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index 5461a3aefa..7fb4f54fca 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "dir_access_jandroid.h" + #include "core/string/print_string.h" #include "file_access_android.h" #include "string_android.h" @@ -51,8 +52,9 @@ Error DirAccessJAndroid::list_dir_begin() { jstring js = env->NewStringUTF(current_dir.utf8().get_data()); int res = env->CallIntMethod(io, _dir_open, js); - if (res <= 0) + if (res <= 0) { return ERR_CANT_OPEN; + } id = res; @@ -64,8 +66,9 @@ String DirAccessJAndroid::get_next() { JNIEnv *env = get_jni_env(); jstring str = (jstring)env->CallObjectMethod(io, _dir_next, id); - if (!str) + if (!str) { return ""; + } String ret = jstring_to_string((jstring)str, env); env->DeleteLocalRef((jobject)str); @@ -83,8 +86,9 @@ bool DirAccessJAndroid::current_is_hidden() const { } void DirAccessJAndroid::list_dir_end() { - if (id == 0) + if (id == 0) { return; + } JNIEnv *env = get_jni_env(); env->CallVoidMethod(io, _dir_close, id); @@ -102,22 +106,25 @@ String DirAccessJAndroid::get_drive(int p_drive) { Error DirAccessJAndroid::change_dir(String p_dir) { JNIEnv *env = get_jni_env(); - if (p_dir.is_empty() || p_dir == "." || (p_dir == ".." && current_dir.is_empty())) + if (p_dir.is_empty() || p_dir == "." || (p_dir == ".." && current_dir.is_empty())) { return OK; + } String new_dir; - if (p_dir != "res://" && p_dir.length() > 1 && p_dir.ends_with("/")) + if (p_dir != "res://" && p_dir.length() > 1 && p_dir.ends_with("/")) { p_dir = p_dir.substr(0, p_dir.length() - 1); + } - if (p_dir.begins_with("/")) + if (p_dir.begins_with("/")) { new_dir = p_dir.substr(1, p_dir.length()); - else if (p_dir.begins_with("res://")) + } else if (p_dir.begins_with("res://")) { new_dir = p_dir.substr(6, p_dir.length()); - else if (current_dir.is_empty()) + } else if (current_dir.is_empty()) { new_dir = p_dir; - else + } else { new_dir = current_dir.plus_file(p_dir); + } //test if newdir exists new_dir = new_dir.simplify_path(); @@ -125,8 +132,9 @@ Error DirAccessJAndroid::change_dir(String p_dir) { jstring js = env->NewStringUTF(new_dir.utf8().get_data()); int res = env->CallIntMethod(io, _dir_open, js); env->DeleteLocalRef(js); - if (res <= 0) + if (res <= 0) { return ERR_INVALID_PARAMETER; + } env->CallVoidMethod(io, _dir_close, res); @@ -141,10 +149,11 @@ String DirAccessJAndroid::get_current_dir(bool p_include_drive) { bool DirAccessJAndroid::file_exists(String p_file) { String sd; - if (current_dir.is_empty()) + if (current_dir.is_empty()) { sd = p_file; - else + } else { sd = current_dir.plus_file(p_file); + } FileAccessAndroid *f = memnew(FileAccessAndroid); bool exists = f->file_exists(sd); @@ -158,27 +167,30 @@ bool DirAccessJAndroid::dir_exists(String p_dir) { String sd; - if (current_dir.is_empty()) + if (current_dir.is_empty()) { sd = p_dir; - else { - if (p_dir.is_relative_path()) + } else { + if (p_dir.is_relative_path()) { sd = current_dir.plus_file(p_dir); - else + } else { sd = fix_path(p_dir); + } } String path = sd.simplify_path(); - if (path.begins_with("/")) + if (path.begins_with("/")) { path = path.substr(1, path.length()); - else if (path.begins_with("res://")) + } else if (path.begins_with("res://")) { path = path.substr(6, path.length()); + } jstring js = env->NewStringUTF(path.utf8().get_data()); int res = env->CallIntMethod(io, _dir_open, js); env->DeleteLocalRef(js); - if (res <= 0) + if (res <= 0) { return false; + } env->CallVoidMethod(io, _dir_close, res); diff --git a/platform/android/file_access_android.cpp b/platform/android/file_access_android.cpp index 26bdcb9520..c84a919b6b 100644 --- a/platform/android/file_access_android.cpp +++ b/platform/android/file_access_android.cpp @@ -29,30 +29,28 @@ /*************************************************************************/ #include "file_access_android.h" + #include "core/string/print_string.h" AAssetManager *FileAccessAndroid::asset_manager = nullptr; -/*void FileAccessAndroid::make_default() { - create_func=create_android; -}*/ - FileAccess *FileAccessAndroid::create_android() { return memnew(FileAccessAndroid); } Error FileAccessAndroid::_open(const String &p_path, int p_mode_flags) { String path = fix_path(p_path).simplify_path(); - if (path.begins_with("/")) + if (path.begins_with("/")) { path = path.substr(1, path.length()); - else if (path.begins_with("res://")) + } else if (path.begins_with("res://")) { path = path.substr(6, path.length()); + } ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, ERR_UNAVAILABLE); //can't write on android.. a = AAssetManager_open(asset_manager, path.utf8().get_data(), AASSET_MODE_STREAMING); - if (!a) + if (!a) { return ERR_CANT_OPEN; - //ERR_FAIL_COND_V(!a,ERR_FILE_NOT_FOUND); + } len = AAsset_getLength(a); pos = 0; eof = false; @@ -61,8 +59,9 @@ Error FileAccessAndroid::_open(const String &p_path, int p_mode_flags) { } void FileAccessAndroid::close() { - if (!a) + if (!a) { return; + } AAsset_close(a); a = nullptr; } @@ -146,15 +145,17 @@ void FileAccessAndroid::store_8(uint8_t p_dest) { bool FileAccessAndroid::file_exists(const String &p_path) { String path = fix_path(p_path).simplify_path(); - if (path.begins_with("/")) + if (path.begins_with("/")) { path = path.substr(1, path.length()); - else if (path.begins_with("res://")) + } else if (path.begins_with("res://")) { path = path.substr(6, path.length()); + } AAsset *at = AAssetManager_open(asset_manager, path.utf8().get_data(), AASSET_MODE_STREAMING); - if (!at) + if (!at) { return false; + } AAsset_close(at); return true; diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java b/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java index 8fc16ab7ba..4525c5c212 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java +++ b/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java @@ -147,8 +147,9 @@ public class GLUtils { Log.i(TAG, String.format(" %s: %d\n", name, value[0])); } else { // Log.w(TAG, String.format(" %s: failed\n", name)); - while (egl.eglGetError() != EGL10.EGL_SUCCESS) - ; + while (egl.eglGetError() != EGL10.EGL_SUCCESS) { + // Continue. + } } } } diff --git a/platform/android/java_class_wrapper.cpp b/platform/android/java_class_wrapper.cpp index f823e2c27f..7c788b4dc4 100644 --- a/platform/android/java_class_wrapper.cpp +++ b/platform/android/java_class_wrapper.cpp @@ -29,13 +29,15 @@ /*************************************************************************/ #include "api/java_class_wrapper.h" + #include "string_android.h" #include "thread_jandroid.h" bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error, Variant &ret) { Map<StringName, List<MethodInfo>>::Element *M = methods.find(p_method); - if (!M) + if (!M) { return false; + } JNIEnv *env = get_jni_env(); ERR_FAIL_COND_V(env == nullptr, false); @@ -68,8 +70,9 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, //bug? } break; case ARG_TYPE_BOOLEAN: { - if (p_args[i]->get_type() != Variant::BOOL) + if (p_args[i]->get_type() != Variant::BOOL) { arg_expected = Variant::BOOL; + } } break; case ARG_NUMBER_CLASS_BIT | ARG_TYPE_BYTE: case ARG_NUMBER_CLASS_BIT | ARG_TYPE_CHAR: @@ -81,27 +84,27 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, case ARG_TYPE_SHORT: case ARG_TYPE_INT: case ARG_TYPE_LONG: { - if (!p_args[i]->is_num()) + if (!p_args[i]->is_num()) { arg_expected = Variant::INT; - + } } break; case ARG_NUMBER_CLASS_BIT | ARG_TYPE_FLOAT: case ARG_NUMBER_CLASS_BIT | ARG_TYPE_DOUBLE: case ARG_TYPE_FLOAT: case ARG_TYPE_DOUBLE: { - if (!p_args[i]->is_num()) + if (!p_args[i]->is_num()) { arg_expected = Variant::FLOAT; - + } } break; case ARG_TYPE_STRING: { - if (p_args[i]->get_type() != Variant::STRING) + if (p_args[i]->get_type() != Variant::STRING) { arg_expected = Variant::STRING; - + } } break; case ARG_TYPE_CLASS: { - if (p_args[i]->get_type() != Variant::OBJECT) + if (p_args[i]->get_type() != Variant::OBJECT) { arg_expected = Variant::OBJECT; - else { + } else { Ref<RefCounted> ref = *p_args[i]; if (!ref.is_null()) { if (Object::cast_to<JavaObject>(ref.ptr())) { @@ -118,12 +121,11 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, } } } - } break; default: { - if (p_args[i]->get_type() != Variant::ARRAY) + if (p_args[i]->get_type() != Variant::ARRAY) { arg_expected = Variant::ARRAY; - + } } break; } @@ -135,15 +137,17 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, break; } } - if (!valid) + if (!valid) { continue; + } method = &E; break; } - if (!method) + if (!method) { return true; //no version convinces + } r_error.error = Callable::CallError::CALL_OK; @@ -780,9 +784,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va for (int i = 0; i < count; i++) { jobject o = env->GetObjectArrayElement(arr, i); - if (!o) + if (!o) { ret.push_back(Variant()); - else { + } else { bool val = env->CallBooleanMethod(o, JavaClassWrapper::singleton->Boolean_booleanValue); ret.push_back(val); } @@ -801,9 +805,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va for (int i = 0; i < count; i++) { jobject o = env->GetObjectArrayElement(arr, i); - if (!o) + if (!o) { ret.push_back(Variant()); - else { + } else { int val = env->CallByteMethod(o, JavaClassWrapper::singleton->Byte_byteValue); ret.push_back(val); } @@ -821,9 +825,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va for (int i = 0; i < count; i++) { jobject o = env->GetObjectArrayElement(arr, i); - if (!o) + if (!o) { ret.push_back(Variant()); - else { + } else { int val = env->CallCharMethod(o, JavaClassWrapper::singleton->Character_characterValue); ret.push_back(val); } @@ -841,9 +845,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va for (int i = 0; i < count; i++) { jobject o = env->GetObjectArrayElement(arr, i); - if (!o) + if (!o) { ret.push_back(Variant()); - else { + } else { int val = env->CallShortMethod(o, JavaClassWrapper::singleton->Short_shortValue); ret.push_back(val); } @@ -861,9 +865,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va for (int i = 0; i < count; i++) { jobject o = env->GetObjectArrayElement(arr, i); - if (!o) + if (!o) { ret.push_back(Variant()); - else { + } else { int val = env->CallIntMethod(o, JavaClassWrapper::singleton->Integer_integerValue); ret.push_back(val); } @@ -881,9 +885,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va for (int i = 0; i < count; i++) { jobject o = env->GetObjectArrayElement(arr, i); - if (!o) + if (!o) { ret.push_back(Variant()); - else { + } else { int64_t val = env->CallLongMethod(o, JavaClassWrapper::singleton->Long_longValue); ret.push_back(val); } @@ -901,9 +905,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va for (int i = 0; i < count; i++) { jobject o = env->GetObjectArrayElement(arr, i); - if (!o) + if (!o) { ret.push_back(Variant()); - else { + } else { float val = env->CallFloatMethod(o, JavaClassWrapper::singleton->Float_floatValue); ret.push_back(val); } @@ -921,9 +925,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va for (int i = 0; i < count; i++) { jobject o = env->GetObjectArrayElement(arr, i); - if (!o) + if (!o) { ret.push_back(Variant()); - else { + } else { double val = env->CallDoubleMethod(o, JavaClassWrapper::singleton->Double_doubleValue); ret.push_back(val); } @@ -942,9 +946,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va for (int i = 0; i < count; i++) { jobject o = env->GetObjectArrayElement(arr, i); - if (!o) + if (!o) { ret.push_back(Variant()); - else { + } else { String val = jstring_to_string((jstring)o, env); ret.push_back(val); } @@ -962,8 +966,9 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va } Ref<JavaClass> JavaClassWrapper::wrap(const String &p_class) { - if (class_cache.has(p_class)) + if (class_cache.has(p_class)) { return class_cache[p_class]; + } JNIEnv *env = get_jni_env(); ERR_FAIL_COND_V(env == nullptr, Ref<JavaClass>()); @@ -971,10 +976,6 @@ Ref<JavaClass> JavaClassWrapper::wrap(const String &p_class) { jclass bclass = env->FindClass(p_class.utf8().get_data()); ERR_FAIL_COND_V(!bclass, Ref<JavaClass>()); - //jmethodID getDeclaredMethods = env->GetMethodID(bclass,"getDeclaredMethods", "()[Ljava/lang/reflect/Method;"); - - //ERR_FAIL_COND_V(!getDeclaredMethods,Ref<JavaClass>()); - jobjectArray methods = (jobjectArray)env->CallObjectMethod(bclass, getDeclaredMethods); ERR_FAIL_COND_V(!methods, Ref<JavaClass>()); @@ -1057,8 +1058,9 @@ Ref<JavaClass> JavaClassWrapper::wrap(const String &p_class) { float new_likeliness = 0; float existing_likeliness = 0; - if (E->get().param_types.size() != mi.param_types.size()) + if (E->get().param_types.size() != mi.param_types.size()) { continue; + } bool valid = true; for (int j = 0; j < E->get().param_types.size(); j++) { Variant::Type _new; @@ -1075,8 +1077,9 @@ Ref<JavaClass> JavaClassWrapper::wrap(const String &p_class) { existing_likeliness = existing_l; } - if (!valid) + if (!valid) { continue; + } if (new_likeliness > existing_likeliness) { java_class->methods[str_method].erase(E); @@ -1087,10 +1090,11 @@ Ref<JavaClass> JavaClassWrapper::wrap(const String &p_class) { } if (!discard) { - if (mi._static) + if (mi._static) { mi.method = env->GetStaticMethodID(bclass, str_method.utf8().get_data(), signature.utf8().get_data()); - else + } else { mi.method = env->GetMethodID(bclass, str_method.utf8().get_data(), signature.utf8().get_data()); + } ERR_CONTINUE(!mi.method); @@ -1100,7 +1104,7 @@ Ref<JavaClass> JavaClassWrapper::wrap(const String &p_class) { env->DeleteLocalRef(obj); env->DeleteLocalRef(param_types); env->DeleteLocalRef(return_type); - }; + } env->DeleteLocalRef(methods); diff --git a/platform/android/java_godot_io_wrapper.cpp b/platform/android/java_godot_io_wrapper.cpp index ff0bcf0716..d6e3ad90b1 100644 --- a/platform/android/java_godot_io_wrapper.cpp +++ b/platform/android/java_godot_io_wrapper.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "java_godot_io_wrapper.h" + #include "core/error/error_list.h" // JNIEnv is only valid within the thread it belongs to, in a multi threading environment diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index e7ab0ef7ed..dd4fa9de7b 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -200,8 +200,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *en } JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jclass clazz) { - if (step.get() == 0) + if (step.get() == 0) { return; + } if (DisplayServerAndroid *dsa = Object::cast_to<DisplayServerAndroid>(DisplayServer::get_singleton())) { dsa->send_window_event(DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST); @@ -209,8 +210,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jcl } JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jclass clazz) { - if (step.get() == -1) + if (step.get() == -1) { return; + } if (step.get() == 0) { // Since Godot is initialized on the UI thread, main_thread_id was set to that thread's id, @@ -243,8 +245,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jcl } void touch_preprocessing(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jint buttons_mask, jfloat vertical_factor, jfloat horizontal_factor) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } Vector<AndroidInputHandler::TouchPos> points; for (int i = 0; i < pointer_count; i++) { @@ -279,32 +282,36 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FIFF(JNI // Called on the UI thread JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jfloat p_x, jfloat p_y) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } input_handler->process_hover(p_type, Point2(p_x, p_y)); } // Called on the UI thread JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubleTap(JNIEnv *env, jclass clazz, jint p_button_mask, jint p_x, jint p_y) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } input_handler->process_double_tap(p_button_mask, Point2(p_x, p_y)); } // Called on the UI thread JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_scroll(JNIEnv *env, jclass clazz, jint p_x, jint p_y) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } input_handler->process_scroll(Point2(p_x, p_y)); } // Called on the UI thread JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } AndroidInputHandler::JoypadEvent jevent; jevent.device = p_device; @@ -369,8 +376,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged( // Called on the UI thread JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_keycode, jint p_scancode, jint p_unicode_char, jboolean p_pressed) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } input_handler->process_key_event(p_keycode, p_scancode, p_unicode_char, p_pressed); } @@ -392,15 +400,17 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env } JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } os_android->main_loop_focusin(); } JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } os_android->main_loop_focusout(); } @@ -426,13 +436,14 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *en for (int i = 0; i < count; i++) { jobject obj = env->GetObjectArrayElement(params, i); Variant v; - if (obj) + if (obj) { v = _jobject_to_variant(env, obj); + } memnew_placement(&vlist[i], Variant); vlist[i] = v; vptr[i] = &vlist[i]; env->DeleteLocalRef(obj); - }; + } Callable::CallError err; obj->call(str_method, (const Variant **)vptr, count, err); @@ -455,10 +466,11 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv * for (int i = 0; i < MIN(count, VARIANT_ARG_MAX); i++) { jobject obj = env->GetObjectArrayElement(params, i); - if (obj) + if (obj) { args[i] = _jobject_to_variant(env, obj); + } env->DeleteLocalRef(obj); - }; + } static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); obj->call_deferred(str_method, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); @@ -478,8 +490,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResu } JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNIEnv *env, jclass clazz) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } if (os_android->get_main_loop()) { os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_RESUMED); @@ -487,8 +500,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNI } JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIEnv *env, jclass clazz) { - if (step.get() <= 0) + if (step.get() <= 0) { return; + } if (os_android->get_main_loop()) { os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_PAUSED); diff --git a/platform/android/java_godot_wrapper.cpp b/platform/android/java_godot_wrapper.cpp index 5beec6b611..754267c834 100644 --- a/platform/android/java_godot_wrapper.cpp +++ b/platform/android/java_godot_wrapper.cpp @@ -92,8 +92,9 @@ 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 == nullptr) + if (p_env == nullptr) { p_env = get_jni_env(); + } ERR_FAIL_COND_V(p_env == nullptr, nullptr); @@ -129,8 +130,9 @@ GodotJavaViewWrapper *GodotJavaWrapper::get_godot_view() { void GodotJavaWrapper::on_video_init(JNIEnv *p_env) { if (_on_video_init) { - if (p_env == nullptr) + if (p_env == nullptr) { p_env = get_jni_env(); + } ERR_FAIL_COND(p_env == nullptr); p_env->CallVoidMethod(godot_instance, _on_video_init); @@ -158,8 +160,9 @@ void GodotJavaWrapper::on_godot_main_loop_started(JNIEnv *p_env) { void GodotJavaWrapper::restart(JNIEnv *p_env) { if (_restart) { - if (p_env == nullptr) + if (p_env == nullptr) { p_env = get_jni_env(); + } ERR_FAIL_COND(p_env == nullptr); p_env->CallVoidMethod(godot_instance, _restart); @@ -168,8 +171,9 @@ void GodotJavaWrapper::restart(JNIEnv *p_env) { void GodotJavaWrapper::force_quit(JNIEnv *p_env) { if (_finish) { - if (p_env == nullptr) + if (p_env == nullptr) { p_env = get_jni_env(); + } ERR_FAIL_COND(p_env == nullptr); p_env->CallVoidMethod(godot_instance, _finish); diff --git a/platform/android/jni_utils.cpp b/platform/android/jni_utils.cpp index 7e81565d9d..e2573d10f8 100644 --- a/platform/android/jni_utils.cpp +++ b/platform/android/jni_utils.cpp @@ -46,7 +46,7 @@ jvalret _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant *p_a env->DeleteLocalRef(bclass); } else { v.val.z = *p_arg; - }; + } } break; case Variant::INT: { if (force_jobject) { @@ -61,7 +61,7 @@ jvalret _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant *p_a } else { v.val.i = *p_arg; - }; + } } break; case Variant::FLOAT: { if (force_jobject) { @@ -76,7 +76,7 @@ jvalret _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant *p_a } else { v.val.f = *p_arg; - }; + } } break; case Variant::STRING: { String s = *p_arg; @@ -111,7 +111,7 @@ jvalret _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant *p_a jstring str = env->NewStringUTF(String(keys[j]).utf8().get_data()); env->SetObjectArrayElement(jkeys, j, str); env->DeleteLocalRef(str); - }; + } jmethodID set_keys = env->GetMethodID(dclass, "set_keys", "([Ljava/lang/String;)V"); jvalue val; @@ -128,7 +128,7 @@ jvalret _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant *p_a if (v.obj) { env->DeleteLocalRef(v.obj); } - }; + } jmethodID set_values = env->GetMethodID(dclass, "set_values", "([Ljava/lang/Object;)V"); val.l = jvalues; @@ -205,7 +205,7 @@ Variant _jobject_to_variant(JNIEnv *env, jobject obj) { if (name == "java.lang.String") { return jstring_to_string((jstring)obj, env); - }; + } if (name == "[Ljava.lang.String;") { jobjectArray arr = (jobjectArray)obj; @@ -219,20 +219,20 @@ Variant _jobject_to_variant(JNIEnv *env, jobject obj) { } return sarr; - }; + } if (name == "java.lang.Boolean") { jmethodID boolValue = env->GetMethodID(c, "booleanValue", "()Z"); bool ret = env->CallBooleanMethod(obj, boolValue); return ret; - }; + } if (name == "java.lang.Integer" || name == "java.lang.Long") { jclass nclass = env->FindClass("java/lang/Number"); jmethodID longValue = env->GetMethodID(nclass, "longValue", "()J"); jlong ret = env->CallLongMethod(obj, longValue); return ret; - }; + } if (name == "[I") { jintArray arr = (jintArray)obj; @@ -243,7 +243,7 @@ Variant _jobject_to_variant(JNIEnv *env, jobject obj) { int *w = sarr.ptrw(); env->GetIntArrayRegion(arr, 0, fCount, w); return sarr; - }; + } if (name == "[B") { jbyteArray arr = (jbyteArray)obj; @@ -254,14 +254,14 @@ Variant _jobject_to_variant(JNIEnv *env, jobject obj) { uint8_t *w = sarr.ptrw(); env->GetByteArrayRegion(arr, 0, fCount, reinterpret_cast<signed char *>(w)); return sarr; - }; + } if (name == "java.lang.Float" || name == "java.lang.Double") { jclass nclass = env->FindClass("java/lang/Number"); jmethodID doubleValue = env->GetMethodID(nclass, "doubleValue", "()D"); double ret = env->CallDoubleMethod(obj, doubleValue); return ret; - }; + } if (name == "[D") { jdoubleArray arr = (jdoubleArray)obj; @@ -275,9 +275,9 @@ Variant _jobject_to_variant(JNIEnv *env, jobject obj) { double n; env->GetDoubleArrayRegion(arr, i, 1, &n); w[i] = n; - }; + } return sarr; - }; + } if (name == "[F") { jfloatArray arr = (jfloatArray)obj; @@ -291,9 +291,9 @@ Variant _jobject_to_variant(JNIEnv *env, jobject obj) { float n; env->GetFloatArrayRegion(arr, i, 1, &n); w[i] = n; - }; + } return sarr; - }; + } if (name == "[Ljava.lang.Object;") { jobjectArray arr = (jobjectArray)obj; @@ -308,7 +308,7 @@ Variant _jobject_to_variant(JNIEnv *env, jobject obj) { } return varr; - }; + } if (name == "java.util.HashMap" || name == "org.godotengine.godot.Dictionary") { Dictionary ret; @@ -327,10 +327,10 @@ Variant _jobject_to_variant(JNIEnv *env, jobject obj) { for (int i = 0; i < keys.size(); i++) { ret[keys[i]] = vals[i]; - }; + } return ret; - }; + } env->DeleteLocalRef(c); @@ -359,8 +359,9 @@ Variant::Type get_jni_type(const String &p_type) { int idx = 0; while (_type_to_vtype[idx].name) { - if (p_type == _type_to_vtype[idx].name) + if (p_type == _type_to_vtype[idx].name) { return _type_to_vtype[idx].type; + } idx++; } @@ -390,8 +391,9 @@ const char *get_jni_sig(const String &p_type) { int idx = 0; while (_type_to_vtype[idx].name) { - if (p_type == _type_to_vtype[idx].name) + if (p_type == _type_to_vtype[idx].name) { return _type_to_vtype[idx].sig; + } idx++; } diff --git a/platform/android/net_socket_android.cpp b/platform/android/net_socket_android.cpp index 620df539e4..a65e7c6724 100644 --- a/platform/android/net_socket_android.cpp +++ b/platform/android/net_socket_android.cpp @@ -77,18 +77,21 @@ NetSocketAndroid::~NetSocketAndroid() { void NetSocketAndroid::close() { NetSocketPosix::close(); - if (wants_broadcast) + if (wants_broadcast) { multicast_lock_release(); - if (multicast_groups) + } + if (multicast_groups) { multicast_lock_release(); + } wants_broadcast = false; multicast_groups = 0; } Error NetSocketAndroid::set_broadcasting_enabled(bool p_enabled) { Error err = NetSocketPosix::set_broadcasting_enabled(p_enabled); - if (err != OK) + if (err != OK) { return err; + } if (p_enabled != wants_broadcast) { if (p_enabled) { @@ -105,11 +108,13 @@ Error NetSocketAndroid::set_broadcasting_enabled(bool p_enabled) { Error NetSocketAndroid::join_multicast_group(const IPAddress &p_multi_address, String p_if_name) { Error err = NetSocketPosix::join_multicast_group(p_multi_address, p_if_name); - if (err != OK) + if (err != OK) { return err; + } - if (!multicast_groups) + if (!multicast_groups) { multicast_lock_acquire(); + } multicast_groups++; return OK; @@ -117,14 +122,16 @@ Error NetSocketAndroid::join_multicast_group(const IPAddress &p_multi_address, S Error NetSocketAndroid::leave_multicast_group(const IPAddress &p_multi_address, String p_if_name) { Error err = NetSocketPosix::leave_multicast_group(p_multi_address, p_if_name); - if (err != OK) + if (err != OK) { return err; + } ERR_FAIL_COND_V(multicast_groups == 0, ERR_BUG); multicast_groups--; - if (!multicast_groups) + if (!multicast_groups) { multicast_lock_release(); + } return OK; } diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index d1672d6ea3..b17b0f3139 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -81,17 +81,18 @@ void OS_Android::alert(const String &p_alert, const String &p_title) { void OS_Android::initialize_core() { OS_Unix::initialize_core(); - if (use_apk_expansion) + if (use_apk_expansion) { FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES); - else { + } else { FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES); } FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA); FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM); - if (use_apk_expansion) + if (use_apk_expansion) { DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_RESOURCES); - else + } else { DirAccess::make_default<DirAccessJAndroid>(DirAccess::ACCESS_RESOURCES); + } DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA); DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM); @@ -162,20 +163,23 @@ MainLoop *OS_Android::get_main_loop() const { } void OS_Android::main_loop_begin() { - if (main_loop) + if (main_loop) { main_loop->initialize(); + } } bool OS_Android::main_loop_iterate() { - if (!main_loop) + if (!main_loop) { return false; + } DisplayServerAndroid::get_singleton()->process_events(); return Main::iteration(); } void OS_Android::main_loop_end() { - if (main_loop) + if (main_loop) { main_loop->finalize(); + } } void OS_Android::main_loop_focusout() { @@ -207,8 +211,9 @@ String OS_Android::get_locale() const { String OS_Android::get_model_name() const { String model = godot_io_java->get_model(); - if (!model.is_empty()) + if (!model.is_empty()) { return model; + } return OS_Unix::get_model_name(); } @@ -218,8 +223,9 @@ String OS_Android::get_data_path() const { } String OS_Android::get_user_data_dir() const { - if (!data_dir_cache.is_empty()) + if (!data_dir_cache.is_empty()) { return data_dir_cache; + } String data_dir = godot_io_java->get_user_data_dir(); if (!data_dir.is_empty()) { @@ -230,8 +236,9 @@ String OS_Android::get_user_data_dir() const { } String OS_Android::get_cache_path() const { - if (!cache_dir_cache.is_empty()) + if (!cache_dir_cache.is_empty()) { return cache_dir_cache; + } String cache_dir = godot_io_java->get_cache_dir(); if (!cache_dir.is_empty()) { @@ -243,8 +250,9 @@ String OS_Android::get_cache_path() const { String OS_Android::get_unique_id() const { String unique_id = godot_io_java->get_unique_id(); - if (!unique_id.is_empty()) + if (!unique_id.is_empty()) { return unique_id; + } return OS::get_unique_id(); } |