diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/api/api.cpp | 56 | ||||
-rw-r--r-- | platform/android/api/api.h | 32 | ||||
-rw-r--r-- | platform/android/api/java_class_wrapper.h (renamed from platform/android/java_class_wrapper.h) | 19 | ||||
-rw-r--r-- | platform/android/java_class_wrapper.cpp | 7 | ||||
-rw-r--r-- | platform/android/java_godot_lib_jni.cpp | 3 |
5 files changed, 108 insertions, 9 deletions
diff --git a/platform/android/api/api.cpp b/platform/android/api/api.cpp new file mode 100644 index 0000000000..7a8ff93414 --- /dev/null +++ b/platform/android/api/api.cpp @@ -0,0 +1,56 @@ +#include "api.h" + +#include "core/engine.h" +#include "java_class_wrapper.h" + +#if !defined(ANDROID_ENABLED) +static JavaClassWrapper *java_class_wrapper = NULL; +#endif + +void register_android_api() { + +#if !defined(ANDROID_ENABLED) + java_class_wrapper = memnew(JavaClassWrapper); // Dummy +#endif + + ClassDB::register_class<JavaClass>(); + ClassDB::register_class<JavaClassWrapper>(); + Engine::get_singleton()->add_singleton(Engine::Singleton("JavaClassWrapper", JavaClassWrapper::get_singleton())); +} + +void unregister_android_api() { + +#if !defined(ANDROID_ENABLED) + memdelete(java_class_wrapper); +#endif +} + +void JavaClassWrapper::_bind_methods() { + + ClassDB::bind_method(D_METHOD("wrap", "name"), &JavaClassWrapper::wrap); +} + +#if !defined(ANDROID_ENABLED) + +Variant JavaClass::call(const StringName &, const Variant **, int, Variant::CallError &) { + return Variant(); +} + +JavaClass::JavaClass() { +} + +Variant JavaObject::call(const StringName &, const Variant **, int, Variant::CallError &) { + return Variant(); +} + +JavaClassWrapper *JavaClassWrapper::singleton = NULL; + +Ref<JavaClass> JavaClassWrapper::wrap(const String &) { + return Ref<JavaClass>(); +} + +JavaClassWrapper::JavaClassWrapper() { + singleton = this; +} + +#endif diff --git a/platform/android/api/api.h b/platform/android/api/api.h new file mode 100644 index 0000000000..c7296d92a7 --- /dev/null +++ b/platform/android/api/api.h @@ -0,0 +1,32 @@ +/*************************************************************************/ +/* api.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +void register_android_api(); +void unregister_android_api(); diff --git a/platform/android/java_class_wrapper.h b/platform/android/api/java_class_wrapper.h index 8075b297b0..6c06d57ac1 100644 --- a/platform/android/java_class_wrapper.h +++ b/platform/android/api/java_class_wrapper.h @@ -32,16 +32,22 @@ #define JAVA_CLASS_WRAPPER_H #include "core/reference.h" + +#ifdef ANDROID_ENABLED #include <android/log.h> #include <jni.h> +#endif +#ifdef ANDROID_ENABLED class JavaObject; +#endif class JavaClass : public Reference { GDCLASS(JavaClass, Reference); - enum ArgumentType { +#ifdef ANDROID_ENABLED + enum ArgumentType{ ARG_TYPE_VOID, ARG_TYPE_BOOLEAN, @@ -159,6 +165,7 @@ class JavaClass : public Reference { friend class JavaClassWrapper; Map<StringName, List<MethodInfo> > methods; jclass _class; +#endif public: virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error); @@ -170,22 +177,27 @@ class JavaObject : public Reference { GDCLASS(JavaObject, Reference); +#ifdef ANDROID_ENABLED Ref<JavaClass> base_class; friend class JavaClass; jobject instance; +#endif public: virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error); +#ifdef ANDROID_ENABLED JavaObject(const Ref<JavaClass> &p_base, jobject *p_instance); ~JavaObject(); +#endif }; class JavaClassWrapper : public Object { GDCLASS(JavaClassWrapper, Object); +#ifdef ANDROID_ENABLED Map<String, Ref<JavaClass> > class_cache; friend class JavaClass; jclass activityClass; @@ -211,6 +223,7 @@ class JavaClassWrapper : public Object { jobject classLoader; bool _get_type_sig(JNIEnv *env, jobject obj, uint32_t &sig, String &strsig); +#endif static JavaClassWrapper *singleton; @@ -222,7 +235,11 @@ public: Ref<JavaClass> wrap(const String &p_class); +#ifdef ANDROID_ENABLED JavaClassWrapper(jobject p_activity = NULL); +#else + JavaClassWrapper(); +#endif }; #endif // JAVA_CLASS_WRAPPER_H diff --git a/platform/android/java_class_wrapper.cpp b/platform/android/java_class_wrapper.cpp index feebea2738..fe2fd89710 100644 --- a/platform/android/java_class_wrapper.cpp +++ b/platform/android/java_class_wrapper.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "java_class_wrapper.h" +#include "api/java_class_wrapper.h" #include "string_android.h" #include "thread_jandroid.h" @@ -546,11 +546,6 @@ JavaObject::~JavaObject() { //////////////////// -void JavaClassWrapper::_bind_methods() { - - ClassDB::bind_method(D_METHOD("wrap", "name"), &JavaClassWrapper::wrap); -} - bool JavaClassWrapper::_get_type_sig(JNIEnv *env, jobject obj, uint32_t &sig, String &strsig) { jstring name2 = (jstring)env->CallObjectMethod(obj, Class_getName); diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index 858ff89cbc..dedb2ee114 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -33,6 +33,7 @@ #include "java_godot_wrapper.h" #include "android/asset_manager_jni.h" +#include "api/java_class_wrapper.h" #include "audio_driver_jandroid.h" #include "core/engine.h" #include "core/os/keyboard.h" @@ -40,7 +41,6 @@ #include "dir_access_jandroid.h" #include "file_access_android.h" #include "file_access_jandroid.h" -#include "java_class_wrapper.h" #include "main/input_default.h" #include "main/main.h" #include "net_socket_android.h" @@ -739,7 +739,6 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jo } java_class_wrapper = memnew(JavaClassWrapper(godot_java->get_activity())); - Engine::get_singleton()->add_singleton(Engine::Singleton("JavaClassWrapper", java_class_wrapper)); _initialize_java_modules(); } |