summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-09-02 23:13:40 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-09-02 23:13:40 -0300
commit1a2cb755e2d8b9d59178f36702f6dff7235b9088 (patch)
tree4a88f47c8b984522e36ac973accb34bdcb00363b /platform
parent89fa70706f9166765c3ac3f799225a467800f065 (diff)
3D Physics and Other Stuff
-=-=-=-=-=-=-=-=-=-=-=-=-= -New Vehicle (Based on Bullet's RaycastVehicle) - Vehiclebody/VehicleWheel. Demo will come soon, old vehicle (CarBody) will go away soon too. -A lot of fixes to the 3D physics engine -Added KinematicBody with demo -Fixed the space query API for 2D (demo will come soon). 3D is WIP. -Fixed long-standing bug with body_enter/body_exit for Area and Area2D -Performance variables now includes physics (active bodies, collision pairs and islands) -Ability to see what's inside of instanced scenes! -Fixed Blend Shapes (no bs+skeleton yet) -Added an Android JavaClassWrapper singleton for using Android native classes directly from GDScript. This is very Alpha!
Diffstat (limited to 'platform')
-rw-r--r--platform/android/SCsub4
-rw-r--r--platform/android/java/src/com/android/godot/GodotPaymentV3.java8
-rw-r--r--platform/android/java_class_wrapper.cpp1332
-rw-r--r--platform/android/java_class_wrapper.h168
-rw-r--r--platform/android/java_glue.cpp5
-rw-r--r--platform/iphone/app_delegate.mm4
-rw-r--r--platform/iphone/in_app_store.h2
-rw-r--r--platform/iphone/in_app_store.mm31
-rw-r--r--platform/windows/detect.py3
-rw-r--r--platform/windows/os_windows.cpp102
-rw-r--r--platform/windows/os_windows.h4
11 files changed, 1641 insertions, 22 deletions
diff --git a/platform/android/SCsub b/platform/android/SCsub
index 8e61b7d8e0..4d6f14dbde 100644
--- a/platform/android/SCsub
+++ b/platform/android/SCsub
@@ -15,7 +15,9 @@ android_files = [
'audio_driver_jandroid.cpp',
'ifaddrs_android.cpp',
'android_native_app_glue.c',
- 'java_glue.cpp'
+ 'java_glue.cpp',
+ 'java_class_wrapper.cpp'
+
]
#env.Depends('#core/math/vector3.h', 'vector3_psp.h')
diff --git a/platform/android/java/src/com/android/godot/GodotPaymentV3.java b/platform/android/java/src/com/android/godot/GodotPaymentV3.java
index a459f8e15c..0fd102ac55 100644
--- a/platform/android/java/src/com/android/godot/GodotPaymentV3.java
+++ b/platform/android/java/src/com/android/godot/GodotPaymentV3.java
@@ -64,15 +64,15 @@ public class GodotPaymentV3 extends Godot.SingletonBase {
public void callbackSuccess(String ticket, String signature){
- Log.d(this.getClass().getName(), "PRE-Send callback to purchase success");
+// Log.d(this.getClass().getName(), "PRE-Send callback to purchase success");
GodotLib.callobject(purchaseCallbackId, "purchase_success", new Object[]{ticket, signature});
- Log.d(this.getClass().getName(), "POST-Send callback to purchase success");
+// Log.d(this.getClass().getName(), "POST-Send callback to purchase success");
}
public void callbackSuccessProductMassConsumed(String ticket, String signature, String sku){
- Log.d(this.getClass().getName(), "PRE-Send callback to consume success");
+// Log.d(this.getClass().getName(), "PRE-Send callback to consume success");
GodotLib.calldeferred(purchaseCallbackId, "consume_success", new Object[]{ticket, signature, sku});
- Log.d(this.getClass().getName(), "POST-Send callback to consume success");
+// Log.d(this.getClass().getName(), "POST-Send callback to consume success");
}
public void callbackSuccessNoUnconsumedPurchases(){
diff --git a/platform/android/java_class_wrapper.cpp b/platform/android/java_class_wrapper.cpp
new file mode 100644
index 0000000000..d4cf848484
--- /dev/null
+++ b/platform/android/java_class_wrapper.cpp
@@ -0,0 +1,1332 @@
+#include "java_class_wrapper.h"
+#include "thread_jandroid.h"
+
+
+bool JavaClass::_call_method(JavaObject* p_instance,const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error,Variant& ret) {
+
+ Map<StringName,List<MethodInfo> >::Element *M=methods.find(p_method);
+ if (!M)
+ return false;
+
+ JNIEnv *env = ThreadAndroid::get_env();
+
+ MethodInfo *method=NULL;
+ for (List<MethodInfo>::Element *E=M->get().front();E;E=E->next()) {
+
+ if (!p_instance && !E->get()._static) {
+ r_error.error=Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
+ continue;
+ }
+
+ int pc = E->get().param_types.size();
+ if (pc>p_argcount) {
+
+ r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument=pc;
+ continue;
+ }
+ if (pc<p_argcount) {
+
+ r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument=pc;
+ continue;
+ }
+ uint32_t *ptypes=E->get().param_types.ptr();
+ bool valid=true;
+
+ for(int i=0;i<pc;i++) {
+
+ Variant::Type arg_expected=Variant::NIL;
+ switch(ptypes[i]) {
+
+ case ARG_TYPE_VOID: {
+ //bug?
+ } break;
+ case ARG_TYPE_BOOLEAN: {
+ 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:
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_SHORT:
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_INT:
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_LONG:
+ case ARG_TYPE_BYTE:
+ case ARG_TYPE_CHAR:
+ case ARG_TYPE_SHORT:
+ case ARG_TYPE_INT:
+ case ARG_TYPE_LONG: {
+
+ 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())
+ arg_expected=Variant::REAL;
+
+ } break;
+ case ARG_TYPE_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)
+ arg_expected=Variant::OBJECT;
+ else {
+
+ Ref<Reference> ref = *p_args[i];
+ if (!ref.is_null()) {
+ if (ref->cast_to<JavaObject>() ) {
+
+ Ref<JavaObject> jo=ref;
+ //could be faster
+ jclass c = env->FindClass(E->get().param_sigs[i].operator String().utf8().get_data());
+ if (!c || !env->IsInstanceOf(jo->instance,c)) {
+
+ arg_expected=Variant::OBJECT;
+ } else {
+ //ok
+ }
+ } else {
+ arg_expected=Variant::OBJECT;
+ }
+
+ }
+ }
+
+ } break;
+ default: {
+
+ if (p_args[i]->get_type()!=Variant::ARRAY)
+ arg_expected=Variant::ARRAY;
+
+ } break;
+
+ }
+
+ if (arg_expected!=Variant::NIL) {
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument=i;
+ r_error.expected=arg_expected;
+ valid=false;
+ break;
+
+ }
+
+ }
+ if (!valid)
+ continue;
+
+
+ method=&E->get();
+ break;
+
+ }
+
+ if (!method)
+ return true; //no version convinces
+
+
+
+ r_error.error=Variant::CallError::CALL_OK;
+
+ jvalue *argv=NULL;
+
+ if (method->param_types.size()) {
+
+ argv=(jvalue*)alloca( sizeof(jvalue)*method->param_types.size() );
+ }
+
+ List<jobject> to_free;
+ for(int i=0;i<method->param_types.size();i++) {
+
+ switch(method->param_types[i]) {
+ case ARG_TYPE_VOID: {
+ //can't happen
+ argv[i].l=NULL; //I hope this works
+ } break;
+
+ case ARG_TYPE_BOOLEAN: {
+ argv[i].z=*p_args[i];
+ } break;
+ case ARG_TYPE_BYTE: {
+ argv[i].b=*p_args[i];
+ } break;
+ case ARG_TYPE_CHAR: {
+ argv[i].c=*p_args[i];
+ } break;
+ case ARG_TYPE_SHORT: {
+ argv[i].s=*p_args[i];
+ } break;
+ case ARG_TYPE_INT: {
+ argv[i].i=*p_args[i];
+ } break;
+ case ARG_TYPE_LONG: {
+ argv[i].j=*p_args[i];
+ } break;
+ case ARG_TYPE_FLOAT: {
+ argv[i].f=*p_args[i];
+ } break;
+ case ARG_TYPE_DOUBLE: {
+ argv[i].d=*p_args[i];
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_BOOLEAN: {
+ jclass bclass = env->FindClass("java/lang/Boolean");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(Z)V");
+ jvalue val;
+ val.z = (bool)(*p_args[i]);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ argv[i].l = obj;
+ to_free.push_back(obj);
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_BYTE: {
+ jclass bclass = env->FindClass("java/lang/Byte");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(B)V");
+ jvalue val;
+ val.b = (int)(*p_args[i]);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ argv[i].l = obj;
+ to_free.push_back(obj);
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_CHAR: {
+ jclass bclass = env->FindClass("java/lang/Character");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(C)V");
+ jvalue val;
+ val.c = (int)(*p_args[i]);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ argv[i].l = obj;
+ to_free.push_back(obj);
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_SHORT: {
+ jclass bclass = env->FindClass("java/lang/Short");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(S)V");
+ jvalue val;
+ val.s = (int)(*p_args[i]);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ argv[i].l = obj;
+ to_free.push_back(obj);
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_INT: {
+ jclass bclass = env->FindClass("java/lang/Integer");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(I)V");
+ jvalue val;
+ val.i = (int)(*p_args[i]);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ argv[i].l = obj;
+ to_free.push_back(obj);
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_LONG: {
+ jclass bclass = env->FindClass("java/lang/Long");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(J)V");
+ jvalue val;
+ val.j = (int64_t)(*p_args[i]);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ argv[i].l = obj;
+ to_free.push_back(obj);
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_FLOAT: {
+ jclass bclass = env->FindClass("java/lang/Float");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(F)V");
+ jvalue val;
+ val.f = (float)(*p_args[i]);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ argv[i].l = obj;
+ to_free.push_back(obj);
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_TYPE_DOUBLE: {
+ jclass bclass = env->FindClass("java/lang/Double");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(D)V");
+ jvalue val;
+ val.d = (double)(*p_args[i]);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ argv[i].l = obj;
+ to_free.push_back(obj);
+ } break;
+ case ARG_TYPE_STRING: {
+ String s = *p_args[i];
+ jstring jStr = env->NewStringUTF(s.utf8().get_data());
+ argv[i].l=jStr;
+ to_free.push_back(jStr);
+ } break;
+ case ARG_TYPE_CLASS: {
+
+ Ref<JavaObject> jo=*p_args[i];
+ if (jo.is_valid()) {
+
+ argv[i].l=jo->instance;
+ } else {
+ argv[i].l=NULL; //I hope this works
+ }
+
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_BOOLEAN: {
+
+ Array arr = *p_args[i];
+ jbooleanArray a = env->NewBooleanArray(arr.size());
+ for(int j=0;j<arr.size();j++) {
+ jboolean val = arr[j];
+ env->SetBooleanArrayRegion(a,j,1,&val);
+ }
+ argv[i].l=a;
+ to_free.push_back(a);
+
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_BYTE: {
+
+ Array arr = *p_args[i];
+ jbyteArray a = env->NewByteArray(arr.size());
+ for(int j=0;j<arr.size();j++) {
+ jbyte val = arr[j];
+ env->SetByteArrayRegion(a,j,1,&val);
+ }
+ argv[i].l=a;
+ to_free.push_back(a);
+
+
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_CHAR: {
+
+ Array arr = *p_args[i];
+ jcharArray a = env->NewCharArray(arr.size());
+ for(int j=0;j<arr.size();j++) {
+ jchar val = arr[j];
+ env->SetCharArrayRegion(a,j,1,&val);
+ }
+ argv[i].l=a;
+ to_free.push_back(a);
+
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_SHORT: {
+
+ Array arr = *p_args[i];
+ jshortArray a = env->NewShortArray(arr.size());
+ for(int j=0;j<arr.size();j++) {
+ jshort val = arr[j];
+ env->SetShortArrayRegion(a,j,1,&val);
+ }
+ argv[i].l=a;
+ to_free.push_back(a);
+
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_INT: {
+
+ Array arr = *p_args[i];
+ jintArray a = env->NewIntArray(arr.size());
+ for(int j=0;j<arr.size();j++) {
+ jint val = arr[j];
+ env->SetIntArrayRegion(a,j,1,&val);
+ }
+ argv[i].l=a;
+ to_free.push_back(a);
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_LONG: {
+ Array arr = *p_args[i];
+ jlongArray a = env->NewLongArray(arr.size());
+ for(int j=0;j<arr.size();j++) {
+ jlong val = arr[j];
+ env->SetLongArrayRegion(a,j,1,&val);
+ }
+ argv[i].l=a;
+ to_free.push_back(a);
+
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_FLOAT: {
+
+ Array arr = *p_args[i];
+ jfloatArray a = env->NewFloatArray(arr.size());
+ for(int j=0;j<arr.size();j++) {
+ jfloat val = arr[j];
+ env->SetFloatArrayRegion(a,j,1,&val);
+ }
+ argv[i].l=a;
+ to_free.push_back(a);
+
+
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_DOUBLE: {
+
+ Array arr = *p_args[i];
+ jdoubleArray a = env->NewDoubleArray(arr.size());
+ for(int j=0;j<arr.size();j++) {
+ jdouble val = arr[j];
+ env->SetDoubleArrayRegion(a,j,1,&val);
+ }
+ argv[i].l=a;
+ to_free.push_back(a);
+
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_STRING: {
+
+ Array arr = *p_args[i];
+ jobjectArray a = env->NewObjectArray(arr.size(),env->FindClass("java/lang/String"),NULL);
+ for(int j=0;j<arr.size();j++) {
+
+ String s = arr[j];
+ jstring jStr = env->NewStringUTF(s.utf8().get_data());
+ env->SetObjectArrayElement(a,j,jStr);
+ to_free.push_back(jStr);
+ }
+
+ argv[i].l=a;
+ to_free.push_back(a);
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_CLASS: {
+
+ argv[i].l=NULL;
+ } break;
+ }
+ }
+
+ r_error.error=Variant::CallError::CALL_OK;
+ bool success=true;
+
+ switch(method->return_type) {
+
+
+ case ARG_TYPE_VOID: {
+ if (method->_static) {
+ env->CallStaticVoidMethodA(_class,method->method,argv);
+ } else {
+ env->CallVoidMethodA(p_instance->instance,method->method,argv);
+ }
+ ret=Variant();
+
+ } break;
+ case ARG_TYPE_BOOLEAN: {
+ if (method->_static) {
+ ret=env->CallStaticBooleanMethodA(_class,method->method,argv);
+ } else {
+ ret=env->CallBooleanMethodA(p_instance->instance,method->method,argv);
+ }
+ } break;
+ case ARG_TYPE_BYTE: {
+ if (method->_static) {
+ ret=env->CallStaticByteMethodA(_class,method->method,argv);
+ } else {
+ ret=env->CallByteMethodA(p_instance->instance,method->method,argv);
+ }
+ } break;
+ case ARG_TYPE_CHAR: {
+
+ if (method->_static) {
+ ret=env->CallStaticCharMethodA(_class,method->method,argv);
+ } else {
+ ret=env->CallCharMethodA(p_instance->instance,method->method,argv);
+ }
+ } break;
+ case ARG_TYPE_SHORT: {
+
+ if (method->_static) {
+ ret=env->CallStaticShortMethodA(_class,method->method,argv);
+ } else {
+ ret=env->CallShortMethodA(p_instance->instance,method->method,argv);
+ }
+
+ } break;
+ case ARG_TYPE_INT: {
+
+ if (method->_static) {
+ ret=env->CallStaticIntMethodA(_class,method->method,argv);
+ } else {
+ ret=env->CallIntMethodA(p_instance->instance,method->method,argv);
+ }
+
+ } break;
+ case ARG_TYPE_LONG: {
+
+ if (method->_static) {
+ ret=env->CallStaticLongMethodA(_class,method->method,argv);
+ } else {
+ ret=env->CallLongMethodA(p_instance->instance,method->method,argv);
+ }
+
+ } break;
+ case ARG_TYPE_FLOAT: {
+
+ if (method->_static) {
+ ret=env->CallStaticFloatMethodA(_class,method->method,argv);
+ } else {
+ ret=env->CallFloatMethodA(p_instance->instance,method->method,argv);
+ }
+
+ } break;
+ case ARG_TYPE_DOUBLE: {
+
+ if (method->_static) {
+ ret=env->CallStaticDoubleMethodA(_class,method->method,argv);
+ } else {
+ ret=env->CallDoubleMethodA(p_instance->instance,method->method,argv);
+ }
+
+ } break;
+ default: {
+
+ jobject obj;
+ if (method->_static) {
+ obj=env->CallStaticObjectMethodA(_class,method->method,argv);
+ } else {
+ obj=env->CallObjectMethodA(p_instance->instance,method->method,argv);
+ }
+
+ if (!obj) {
+ ret=Variant();
+ } else {
+
+ if (!_convert_object_to_variant(env, obj, ret,method->return_type)) {
+ ret=Variant();
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ success=false;
+ }
+ env->DeleteLocalRef(obj);
+ }
+
+ } break;
+
+ }
+
+ for(List<jobject>::Element *E=to_free.front();E;E=E->next()) {
+ env->DeleteLocalRef(E->get());
+ }
+
+ return success;
+}
+
+Variant JavaClass::call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) {
+
+ Variant ret;
+ bool found = _call_method(NULL,p_method,p_args,p_argcount,r_error,ret);
+ if (found) {
+ return ret;
+ }
+
+ return Reference::call(p_method,p_args,p_argcount,r_error);
+}
+
+JavaClass::JavaClass() {
+
+
+}
+
+/////////////////////
+
+Variant JavaObject::call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error){
+
+
+ return Variant();
+}
+
+JavaObject::JavaObject(const Ref<JavaClass>& p_base,jobject *p_instance) {
+
+
+}
+
+JavaObject::~JavaObject(){
+
+
+}
+
+
+////////////////////
+
+void JavaClassWrapper::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("wrap:JavaClass","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);
+ String str_type = env->GetStringUTFChars( name2, NULL );
+ print_line("name: "+str_type);
+ env->DeleteLocalRef(name2);
+ uint32_t t=0;
+
+ if (str_type.begins_with("[")) {
+
+ t=JavaClass::ARG_ARRAY_BIT;
+ strsig="[";
+ str_type=str_type.substr(1,str_type.length()-1);
+ if (str_type.begins_with("[")) {
+ print_line("Nested arrays not supported for type: "+str_type);
+ return false;
+ }
+ if (str_type.begins_with("L")) {
+ str_type=str_type.substr(1,str_type.length()-2); //ok it's a class
+ }
+ }
+
+ if (str_type=="void" || str_type=="V") {
+ t|=JavaClass::ARG_TYPE_VOID;
+ strsig+="V";
+ } else if (str_type=="boolean" || str_type=="Z") {
+ t|=JavaClass::ARG_TYPE_BOOLEAN;
+ strsig+="Z";
+ } else if (str_type=="byte" || str_type=="B") {
+ t|=JavaClass::ARG_TYPE_BYTE;
+ strsig+="B";
+ } else if (str_type=="char" || str_type=="C") {
+ t|=JavaClass::ARG_TYPE_CHAR;
+ strsig+="C";
+ } else if (str_type=="short" || str_type=="S") {
+ t|=JavaClass::ARG_TYPE_SHORT;
+ strsig+="S";
+ } else if (str_type=="int" || str_type=="I") {
+ t|=JavaClass::ARG_TYPE_INT;
+ strsig+="I";
+ } else if (str_type=="long" || str_type=="J") {
+ t|=JavaClass::ARG_TYPE_LONG;
+ strsig+="J";
+ } else if (str_type=="float" || str_type=="F") {
+ t|=JavaClass::ARG_TYPE_FLOAT;
+ strsig+="F";
+ } else if (str_type=="double" || str_type=="D") {
+ t|=JavaClass::ARG_TYPE_DOUBLE;
+ strsig+="D";
+ } else if (str_type=="java.lang.String") {
+ t|=JavaClass::ARG_TYPE_STRING;
+ strsig+="Ljava/lang/String;";
+ } else if (str_type=="java.lang.Boolean") {
+ t|=JavaClass::ARG_TYPE_BOOLEAN|JavaClass::ARG_NUMBER_CLASS_BIT;
+ strsig+="Ljava/lang/Boolean;";
+ } else if (str_type=="java.lang.Byte") {
+ t|=JavaClass::ARG_TYPE_BYTE|JavaClass::ARG_NUMBER_CLASS_BIT;
+ strsig+="Ljava/lang/Byte;";
+ } else if (str_type=="java.lang.Character") {
+ t|=JavaClass::ARG_TYPE_CHAR|JavaClass::ARG_NUMBER_CLASS_BIT;
+ strsig+="Ljava/lang/Character;";
+ } else if (str_type=="java.lang.Short") {
+ t|=JavaClass::ARG_TYPE_SHORT|JavaClass::ARG_NUMBER_CLASS_BIT;
+ strsig+="Ljava/lang/Short;";
+ } else if (str_type=="java.lang.Integer") {
+ t|=JavaClass::ARG_TYPE_INT|JavaClass::ARG_NUMBER_CLASS_BIT;
+ strsig+="Ljava/lang/Integer;";
+ } else if (str_type=="java.lang.Long") {
+ t|=JavaClass::ARG_TYPE_LONG|JavaClass::ARG_NUMBER_CLASS_BIT;
+ strsig+="Ljava/lang/Long;";
+ } else if (str_type=="java.lang.Float") {
+ t|=JavaClass::ARG_TYPE_FLOAT|JavaClass::ARG_NUMBER_CLASS_BIT;
+ strsig+="Ljava/lang/Float;";
+ } else if (str_type=="java.lang.Double") {
+ t|=JavaClass::ARG_TYPE_DOUBLE|JavaClass::ARG_NUMBER_CLASS_BIT;
+ strsig+="Ljava/lang/Double;";
+ } else {
+ //a class likely
+ strsig+="L"+str_type.replace(".","/")+";";
+ t|=JavaClass::ARG_TYPE_CLASS;
+ }
+
+ sig=t;
+
+
+ return true;
+
+}
+
+bool JavaClass::_convert_object_to_variant(JNIEnv * env, jobject obj, Variant& var,uint32_t p_sig) {
+
+ if (!obj) {
+ var=Variant(); //seems null is just null...
+ return true;
+ }
+
+
+ switch(p_sig) {
+
+ case ARG_TYPE_VOID: {
+
+ return Variant();
+ } break;
+ case ARG_TYPE_BOOLEAN|ARG_NUMBER_CLASS_BIT: {
+
+ var = env->CallBooleanMethod(obj, JavaClassWrapper::singleton->Boolean_booleanValue);
+ return true;
+ } break;
+ case ARG_TYPE_BYTE|ARG_NUMBER_CLASS_BIT: {
+
+ var = env->CallByteMethod(obj, JavaClassWrapper::singleton->Byte_byteValue);
+ return true;
+
+ } break;
+ case ARG_TYPE_CHAR|ARG_NUMBER_CLASS_BIT: {
+
+ var = env->CallCharMethod(obj, JavaClassWrapper::singleton->Character_characterValue);
+ return true;
+
+ } break;
+ case ARG_TYPE_SHORT|ARG_NUMBER_CLASS_BIT: {
+
+ var = env->CallShortMethod(obj, JavaClassWrapper::singleton->Short_shortValue);
+ return true;
+
+ } break;
+ case ARG_TYPE_INT|ARG_NUMBER_CLASS_BIT: {
+
+ var = env->CallIntMethod(obj, JavaClassWrapper::singleton->Integer_integerValue);
+ return true;
+
+ } break;
+ case ARG_TYPE_LONG|ARG_NUMBER_CLASS_BIT: {
+
+ var = env->CallLongMethod(obj, JavaClassWrapper::singleton->Long_longValue);
+ return true;
+
+ } break;
+ case ARG_TYPE_FLOAT|ARG_NUMBER_CLASS_BIT: {
+
+ var = env->CallFloatMethod(obj, JavaClassWrapper::singleton->Float_floatValue);
+ return true;
+
+ } break;
+ case ARG_TYPE_DOUBLE|ARG_NUMBER_CLASS_BIT: {
+
+ var = env->CallDoubleMethod(obj, JavaClassWrapper::singleton->Double_doubleValue);
+ return true;
+ } break;
+ case ARG_TYPE_STRING: {
+
+ var = String::utf8(env->GetStringUTFChars( (jstring)obj, NULL ));
+ return true;
+ } break;
+ case ARG_TYPE_CLASS: {
+
+ return false;
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_VOID: {
+
+ var = Array(); // ?
+ return true;
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_BOOLEAN: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jboolean val;
+ env->GetBooleanArrayRegion((jbooleanArray)arr,0,1,&val);
+ ret.push_back(val);
+ }
+
+ var=ret;
+ return true;
+
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_BYTE: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jbyte val;
+ env->GetByteArrayRegion((jbyteArray)arr,0,1,&val);
+ ret.push_back(val);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_CHAR: {
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jchar val;
+ env->GetCharArrayRegion((jcharArray)arr,0,1,&val);
+ ret.push_back(val);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_SHORT: {
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jshort val;
+ env->GetShortArrayRegion((jshortArray)arr,0,1,&val);
+ ret.push_back(val);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_INT: {
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jint val;
+ env->GetIntArrayRegion((jintArray)arr,0,1,&val);
+ ret.push_back(val);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_LONG: {
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jlong val;
+ env->GetLongArrayRegion((jlongArray)arr,0,1,&val);
+ ret.push_back(val);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_FLOAT: {
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jfloat val;
+ env->GetFloatArrayRegion((jfloatArray)arr,0,1,&val);
+ ret.push_back(val);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_DOUBLE: {
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jdouble val;
+ env->GetDoubleArrayRegion((jdoubleArray)arr,0,1,&val);
+ ret.push_back(val);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_ARRAY_BIT|ARG_TYPE_BOOLEAN: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jobject o = env->GetObjectArrayElement(arr, i);
+ if (!o)
+ ret.push_back(Variant());
+ else {
+ bool val = env->CallBooleanMethod(o, JavaClassWrapper::singleton->Boolean_booleanValue);
+ ret.push_back(val);
+
+ }
+ env->DeleteLocalRef(o);
+ }
+
+ var=ret;
+ return true;
+
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_ARRAY_BIT|ARG_TYPE_BYTE: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jobject o = env->GetObjectArrayElement(arr, i);
+ if (!o)
+ ret.push_back(Variant());
+ else {
+ int val = env->CallByteMethod(o, JavaClassWrapper::singleton->Byte_byteValue);
+ ret.push_back(val);
+
+ }
+ env->DeleteLocalRef(o);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_ARRAY_BIT|ARG_TYPE_CHAR: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jobject o = env->GetObjectArrayElement(arr, i);
+ if (!o)
+ ret.push_back(Variant());
+ else {
+ int val = env->CallCharMethod(o, JavaClassWrapper::singleton->Character_characterValue);
+ ret.push_back(val);
+
+ }
+ env->DeleteLocalRef(o);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_ARRAY_BIT|ARG_TYPE_SHORT: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jobject o = env->GetObjectArrayElement(arr, i);
+ if (!o)
+ ret.push_back(Variant());
+ else {
+ int val = env->CallShortMethod(o, JavaClassWrapper::singleton->Short_shortValue);
+ ret.push_back(val);
+
+ }
+ env->DeleteLocalRef(o);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_ARRAY_BIT|ARG_TYPE_INT: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jobject o = env->GetObjectArrayElement(arr, i);
+ if (!o)
+ ret.push_back(Variant());
+ else {
+ int val = env->CallIntMethod(o, JavaClassWrapper::singleton->Integer_integerValue);
+ ret.push_back(val);
+
+ }
+ env->DeleteLocalRef(o);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_ARRAY_BIT|ARG_TYPE_LONG: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jobject o = env->GetObjectArrayElement(arr, i);
+ if (!o)
+ ret.push_back(Variant());
+ else {
+ int64_t val = env->CallLongMethod(o, JavaClassWrapper::singleton->Long_longValue);
+ ret.push_back(val);
+
+ }
+ env->DeleteLocalRef(o);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_ARRAY_BIT|ARG_TYPE_FLOAT: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jobject o = env->GetObjectArrayElement(arr, i);
+ if (!o)
+ ret.push_back(Variant());
+ else {
+ float val = env->CallFloatMethod(o, JavaClassWrapper::singleton->Float_floatValue);
+ ret.push_back(val);
+
+ }
+ env->DeleteLocalRef(o);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_NUMBER_CLASS_BIT|ARG_ARRAY_BIT|ARG_TYPE_DOUBLE: {
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jobject o = env->GetObjectArrayElement(arr, i);
+ if (!o)
+ ret.push_back(Variant());
+ else {
+ double val = env->CallDoubleMethod(o, JavaClassWrapper::singleton->Double_doubleValue);
+ ret.push_back(val);
+
+ }
+ env->DeleteLocalRef(o);
+ }
+
+ var=ret;
+ return true;
+ } break;
+
+ case ARG_ARRAY_BIT|ARG_TYPE_STRING: {
+
+ Array ret;
+ jobjectArray arr = (jobjectArray)obj;
+
+ int count = env->GetArrayLength(arr);
+
+ for (int i=0; i<count; i++) {
+
+ jobject o = env->GetObjectArrayElement(arr, i);
+ if (!o)
+ ret.push_back(Variant());
+ else {
+ String val = String::utf8(env->GetStringUTFChars( (jstring)o, NULL ));
+ ret.push_back(val);
+
+ }
+ env->DeleteLocalRef(o);
+ }
+
+ var=ret;
+ return true;
+ } break;
+ case ARG_ARRAY_BIT|ARG_TYPE_CLASS: {
+
+ } break;
+ }
+
+ return false;
+
+}
+
+
+Ref<JavaClass> JavaClassWrapper::wrap(const String& p_class) {
+
+ if (class_cache.has(p_class))
+ return class_cache[p_class];
+
+
+ JNIEnv *env = ThreadAndroid::get_env();
+
+ 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>());
+
+
+ Ref<JavaClass> java_class = memnew( JavaClass );
+
+ int count = env->GetArrayLength(methods);
+
+ for (int i=0; i<count; i++) {
+
+ jobject obj = env->GetObjectArrayElement(methods, i);
+ ERR_CONTINUE(!obj);
+
+
+ jstring name = (jstring)env->CallObjectMethod(obj, getName);
+ String str_method = env->GetStringUTFChars( name, NULL );
+ env->DeleteLocalRef(name);
+
+ Vector<String> params;
+
+ jint mods = env->CallIntMethod(obj,getModifiers);
+
+ if (!(mods&0x0001)) {
+ env->DeleteLocalRef(obj);
+ continue; //not public bye
+ }
+
+
+
+ jobjectArray param_types = (jobjectArray)env->CallObjectMethod(obj, getParameterTypes);
+ int count2=env->GetArrayLength(param_types);
+
+ if (!java_class->methods.has(str_method)) {
+ java_class->methods[str_method]=List<JavaClass::MethodInfo>();
+ }
+
+ JavaClass::MethodInfo mi;
+ mi._static = (mods&0x8)!=0;
+ bool valid=true;
+ String signature="(";
+
+ for(int j=0;j<count2;j++) {
+
+ jobject obj2 = env->GetObjectArrayElement(param_types, j);
+ String strsig;
+ uint32_t sig=0;
+ if (!_get_type_sig(env,obj2,sig,strsig)) {
+ valid=false;
+ env->DeleteLocalRef(obj2);
+ break;
+ }
+ signature+=strsig;
+ mi.param_types.push_back(sig);
+ mi.param_sigs.push_back(strsig);
+ env->DeleteLocalRef(obj2);
+
+ }
+
+ if (!valid) {
+ print_line("Method Can't be bound (unsupported arguments): "+p_class+"::"+str_method);
+ env->DeleteLocalRef(obj);
+ env->DeleteLocalRef(param_types);
+ continue;
+ }
+
+ signature+=")";
+
+ jobject return_type = (jobject)env->CallObjectMethod(obj, getReturnType);
+
+
+ String strsig;
+ uint32_t sig=0;
+ if (!_get_type_sig(env,return_type,sig,strsig)) {
+ print_line("Method Can't be bound (unsupported return type): "+p_class+"::"+str_method);
+ env->DeleteLocalRef(obj);
+ env->DeleteLocalRef(param_types);
+ env->DeleteLocalRef(return_type);
+ continue;
+ }
+
+ signature+=strsig;
+ mi.return_type=sig;
+
+ print_line("METHOD: "+str_method+" SIG: "+signature+" static: "+itos(mi._static));
+
+ bool discard=false;
+
+ for(List<JavaClass::MethodInfo>::Element *E=java_class->methods[str_method].front();E;E=E->next()) {
+
+ float new_likeliness=0;
+ float existing_likeliness=0;
+
+ 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;
+ float new_l;
+ Variant::Type existing;
+ float existing_l;
+ JavaClass::_convert_to_variant_type(E->get().param_types[j],existing,existing_l);
+ JavaClass::_convert_to_variant_type(mi.param_types[j],_new,new_l);
+ if (_new!=existing) {
+ valid=false;
+ break;
+ }
+ new_likeliness+=new_l;
+ existing_likeliness=existing_l;
+
+ }
+
+ if (!valid)
+ continue;
+
+ if (new_likeliness>existing_likeliness) {
+ java_class->methods[str_method].erase(E);
+ print_line("replace old");
+ break;
+ } else {
+ discard=true;
+ print_line("old is better");
+ }
+
+
+ }
+
+ if (!discard) {
+ if (mi._static)
+ mi.method = env->GetStaticMethodID(bclass, str_method.utf8().get_data(), signature.utf8().get_data());
+ else
+ mi.method = env->GetMethodID(bclass, str_method.utf8().get_data(), signature.utf8().get_data());
+
+ ERR_CONTINUE(!mi.method);
+
+ java_class->methods[str_method].push_back(mi);
+ }
+
+ env->DeleteLocalRef(obj);
+ env->DeleteLocalRef(param_types);
+ env->DeleteLocalRef(return_type);
+
+
+
+
+ //args[i] = _jobject_to_variant(env, obj);
+// print_line("\targ"+itos(i)+": "+Variant::get_type_name(args[i].get_type()));
+
+ };
+
+ env->DeleteLocalRef(methods);
+
+ jobjectArray fields = (jobjectArray)env->CallObjectMethod(bclass, getFields);
+
+ count = env->GetArrayLength(fields);
+
+ for (int i=0; i<count; i++) {
+
+ jobject obj = env->GetObjectArrayElement(fields, i);
+ ERR_CONTINUE(!obj);
+
+ jstring name = (jstring)env->CallObjectMethod(obj, Field_getName);
+ String str_field = env->GetStringUTFChars( name, NULL );
+ env->DeleteLocalRef(name);
+ print_line("FIELD: "+str_field);
+ int mods = env->CallIntMethod(obj,Field_getModifiers);
+ if ((mods&0x8) && (mods&0x10) && (mods&0x1)) { //static final public!
+
+ jobject objc = env->CallObjectMethod(obj, Field_get,NULL);
+ if (objc) {
+
+
+ uint32_t sig;
+ String strsig;
+ jclass cl = env->GetObjectClass(objc);
+ if (JavaClassWrapper::_get_type_sig(env,cl,sig,strsig)) {
+
+ if ((sig&JavaClass::ARG_TYPE_MASK)<=JavaClass::ARG_TYPE_STRING) {
+
+ Variant value;
+ if (JavaClass::_convert_object_to_variant(env,objc,value,sig)) {
+
+ java_class->constant_map[str_field]=value;
+ }
+ }
+ }
+
+ env->DeleteLocalRef(cl);
+ }
+
+
+ env->DeleteLocalRef(objc);
+
+ }
+ env->DeleteLocalRef(obj);
+ }
+
+ env->DeleteLocalRef(fields);
+
+
+ return Ref<JavaClass>();
+}
+
+JavaClassWrapper *JavaClassWrapper::singleton=NULL;
+
+JavaClassWrapper::JavaClassWrapper(jobject p_activity) {
+
+ singleton=this;
+
+ JNIEnv *env = ThreadAndroid::get_env();
+
+ jclass activityClass = env->FindClass("com/android/godot/Godot");
+ jmethodID getClassLoader = env->GetMethodID(activityClass,"getClassLoader", "()Ljava/lang/ClassLoader;");
+ classLoader = env->CallObjectMethod(p_activity, getClassLoader);
+ classLoader=(jclass)env->NewGlobalRef(classLoader);
+ jclass classLoaderClass = env->FindClass("java/lang/ClassLoader");
+ findClass = env->GetMethodID(classLoaderClass, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
+
+ jclass bclass = env->FindClass("java/lang/Class");
+ getDeclaredMethods = env->GetMethodID(bclass,"getDeclaredMethods", "()[Ljava/lang/reflect/Method;");
+ getFields = env->GetMethodID(bclass,"getFields", "()[Ljava/lang/reflect/Field;");
+ Class_getName = env->GetMethodID(bclass,"getName", "()Ljava/lang/String;");
+ //
+ bclass = env->FindClass("java/lang/reflect/Method");
+ getParameterTypes = env->GetMethodID(bclass,"getParameterTypes", "()[Ljava/lang/Class;");
+ getReturnType = env->GetMethodID(bclass,"getReturnType", "()Ljava/lang/Class;");
+ getName = env->GetMethodID(bclass,"getName", "()Ljava/lang/String;");
+ getModifiers = env->GetMethodID(bclass,"getModifiers", "()I");
+ ///
+ bclass = env->FindClass("java/lang/reflect/Field");
+ Field_getName = env->GetMethodID(bclass,"getName", "()Ljava/lang/String;");
+ Field_getModifiers = env->GetMethodID(bclass,"getModifiers", "()I");
+ Field_get = env->GetMethodID(bclass,"get", "(Ljava/lang/Object;)Ljava/lang/Object;");
+ // each
+ bclass = env->FindClass("java/lang/Boolean");
+ Boolean_booleanValue = env->GetMethodID(bclass, "booleanValue", "()Z");
+
+ bclass = env->FindClass("java/lang/Byte");
+ Byte_byteValue = env->GetMethodID(bclass, "byteValue", "()B");
+
+ bclass = env->FindClass("java/lang/Character");
+ Character_characterValue = env->GetMethodID(bclass, "charValue", "()C");
+
+ bclass = env->FindClass("java/lang/Short");
+ Short_shortValue = env->GetMethodID(bclass, "shortValue", "()S");
+
+ bclass = env->FindClass("java/lang/Integer");
+ Integer_integerValue = env->GetMethodID(bclass, "intValue", "()I");
+
+ bclass = env->FindClass("java/lang/Long");
+ Long_longValue = env->GetMethodID(bclass, "longValue", "()J");
+
+ bclass = env->FindClass("java/lang/Float");
+ Float_floatValue = env->GetMethodID(bclass, "floatValue", "()F");
+
+ bclass = env->FindClass("java/lang/Double");
+ Double_doubleValue = env->GetMethodID(bclass, "doubleValue", "()D");
+
+
+}
diff --git a/platform/android/java_class_wrapper.h b/platform/android/java_class_wrapper.h
new file mode 100644
index 0000000000..d5d8bd5be8
--- /dev/null
+++ b/platform/android/java_class_wrapper.h
@@ -0,0 +1,168 @@
+#ifndef JAVA_CLASS_WRAPPER_H
+#define JAVA_CLASS_WRAPPER_H
+
+#include "reference.h"
+#include <jni.h>
+#include <android/log.h>
+
+class JavaObject;
+
+class JavaClass : public Reference {
+
+ OBJ_TYPE(JavaClass,Reference);
+
+ enum ArgumentType {
+
+ ARG_TYPE_VOID,
+ ARG_TYPE_BOOLEAN,
+ ARG_TYPE_BYTE,
+ ARG_TYPE_CHAR,
+ ARG_TYPE_SHORT,
+ ARG_TYPE_INT,
+ ARG_TYPE_LONG,
+ ARG_TYPE_FLOAT,
+ ARG_TYPE_DOUBLE,
+ ARG_TYPE_STRING, //special case
+ ARG_TYPE_CLASS,
+ ARG_ARRAY_BIT=1<<16,
+ ARG_NUMBER_CLASS_BIT=1<<17,
+ ARG_TYPE_MASK=(1<<16)-1
+ };
+
+
+ Map<StringName,Variant> constant_map;
+
+ struct MethodInfo {
+
+ bool _static;
+ Vector<uint32_t> param_types;
+ Vector<StringName> param_sigs;
+ uint32_t return_type;
+ jmethodID method;
+
+ };
+
+ _FORCE_INLINE_ static void _convert_to_variant_type(int p_sig, Variant::Type& r_type, float& likelyhood) {
+
+ likelyhood=1.0;
+ r_type=Variant::NIL;
+
+ switch(p_sig) {
+
+ case ARG_TYPE_VOID: r_type=Variant::NIL; break;
+ case ARG_TYPE_BOOLEAN|ARG_NUMBER_CLASS_BIT:
+ case ARG_TYPE_BOOLEAN: r_type=Variant::BOOL; break;
+ case ARG_TYPE_BYTE|ARG_NUMBER_CLASS_BIT:
+ case ARG_TYPE_BYTE: r_type=Variant::INT; likelyhood=0.1; break;
+ case ARG_TYPE_CHAR|ARG_NUMBER_CLASS_BIT:
+ case ARG_TYPE_CHAR: r_type=Variant::INT; likelyhood=0.2; break;
+ case ARG_TYPE_SHORT|ARG_NUMBER_CLASS_BIT:
+ case ARG_TYPE_SHORT: r_type=Variant::INT; likelyhood=0.3; break;
+ case ARG_TYPE_INT|ARG_NUMBER_CLASS_BIT:
+ case ARG_TYPE_INT: r_type=Variant::INT; likelyhood=1.0; break;
+ case ARG_TYPE_LONG|ARG_NUMBER_CLASS_BIT:
+ case ARG_TYPE_LONG: r_type=Variant::INT; likelyhood=0.5; break;
+ case ARG_TYPE_FLOAT|ARG_NUMBER_CLASS_BIT:
+ case ARG_TYPE_FLOAT: r_type=Variant::REAL; likelyhood=1.0; break;
+ case ARG_TYPE_DOUBLE|ARG_NUMBER_CLASS_BIT:
+ case ARG_TYPE_DOUBLE: r_type=Variant::REAL; likelyhood=0.5; break;
+ case ARG_TYPE_STRING: r_type=Variant::STRING; break;
+ case ARG_TYPE_CLASS: r_type=Variant::OBJECT; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_VOID: r_type=Variant::NIL; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_BOOLEAN: r_type=Variant::ARRAY; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_BYTE: r_type=Variant::RAW_ARRAY; likelyhood=1.0; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_CHAR: r_type=Variant::RAW_ARRAY; likelyhood=0.5; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_SHORT: r_type=Variant::INT_ARRAY; likelyhood=0.3; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_INT: r_type=Variant::INT_ARRAY; likelyhood=1.0; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_LONG: r_type=Variant::INT_ARRAY; likelyhood=0.5; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_FLOAT: r_type=Variant::REAL_ARRAY; likelyhood=1.0; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_DOUBLE: r_type=Variant::REAL_ARRAY; likelyhood=0.5; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_STRING: r_type=Variant::STRING_ARRAY; break;
+ case ARG_ARRAY_BIT|ARG_TYPE_CLASS: r_type=Variant::ARRAY; break;
+ }
+ }
+
+ _FORCE_INLINE_ static bool _convert_object_to_variant(JNIEnv * env, jobject obj, Variant& var,uint32_t p_sig);
+
+
+
+ bool _call_method(JavaObject* p_instance,const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error,Variant& ret);
+
+friend class JavaClassWrapper;
+ Map<StringName,List<MethodInfo> > methods;
+ jclass _class;
+
+public:
+
+ virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error);
+
+ JavaClass();
+
+};
+
+
+class JavaObject : public Reference {
+
+ OBJ_TYPE(JavaObject,Reference);
+
+ Ref<JavaClass> base_class;
+friend class JavaClass;
+
+ jobject instance;
+
+public:
+
+ virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error);
+
+ JavaObject(const Ref<JavaClass>& p_base,jobject *p_instance);
+ ~JavaObject();
+
+};
+
+
+class JavaClassWrapper : public Object {
+
+ OBJ_TYPE(JavaClassWrapper,Object);
+
+
+ Map<String,Ref<JavaClass> > class_cache;
+friend class JavaClass;
+ jclass activityClass;
+ jmethodID findClass;
+ jmethodID getDeclaredMethods;
+ jmethodID getFields;
+ jmethodID getParameterTypes;
+ jmethodID getReturnType;
+ jmethodID getModifiers;
+ jmethodID getName;
+ jmethodID Class_getName;
+ jmethodID Field_getName;
+ jmethodID Field_getModifiers;
+ jmethodID Field_get;
+ jmethodID Boolean_booleanValue;
+ jmethodID Byte_byteValue;
+ jmethodID Character_characterValue;
+ jmethodID Short_shortValue;
+ jmethodID Integer_integerValue;
+ jmethodID Long_longValue;
+ jmethodID Float_floatValue;
+ jmethodID Double_doubleValue;
+ jobject classLoader;
+
+ bool _get_type_sig(JNIEnv *env, jobject obj, uint32_t& sig, String&strsig);
+
+ static JavaClassWrapper *singleton;
+
+protected:
+
+ static void _bind_methods();
+public:
+
+ static JavaClassWrapper *get_singleton() { return singleton; }
+
+ Ref<JavaClass> wrap(const String& p_class);
+
+ JavaClassWrapper(jobject p_activity=NULL);
+};
+
+#endif // JAVA_CLASS_WRAPPER_H
diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp
index ae8174c35a..fdc6f1207d 100644
--- a/platform/android/java_glue.cpp
+++ b/platform/android/java_glue.cpp
@@ -38,7 +38,10 @@
#include "globals.h"
#include "thread_jandroid.h"
#include "core/os/keyboard.h"
+#include "java_class_wrapper.h"
+
+static JavaClassWrapper *java_class_wrapper=NULL;
static OS_Android *os_android=NULL;
@@ -934,6 +937,8 @@ JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_step(JNIEnv * env, jobjec
// ugly hack to initialize the rest of the engine
// because of the way android forces you to do everything with threads
+ java_class_wrapper = memnew( JavaClassWrapper(_godot_instance ));
+ Globals::get_singleton()->add_singleton(Globals::Singleton("JavaClassWrapper",java_class_wrapper));
_initialize_java_modules();
Main::setup2();
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm
index 9ba95ff0c5..9877e09ade 100644
--- a/platform/iphone/app_delegate.mm
+++ b/platform/iphone/app_delegate.mm
@@ -257,18 +257,21 @@ static int frame_count = 0;
- (void)applicationDidEnterBackground:(UIApplication *)application
{
printf("********************* did enter background\n");
+ OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
[view_controller.view stopAnimation];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
printf("********************* did enter foreground\n");
+ //OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
[view_controller.view startAnimation];
}
- (void) applicationWillResignActive:(UIApplication *)application
{
printf("********************* will resign active\n");
+ //OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
[view_controller.view stopAnimation]; // FIXME: pause seems to be recommended elsewhere
}
@@ -279,6 +282,7 @@ static int frame_count = 0;
printf("********************* mobile app tracker found\n");
[MobileAppTracker measureSession];
#endif
+ OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
[view_controller.view startAnimation]; // FIXME: resume seems to be recommended elsewhere
}
diff --git a/platform/iphone/in_app_store.h b/platform/iphone/in_app_store.h
index dba1a1a5a1..656d126ead 100644
--- a/platform/iphone/in_app_store.h
+++ b/platform/iphone/in_app_store.h
@@ -49,6 +49,8 @@ public:
int get_pending_event_count();
Variant pop_pending_event();
+ void finish_transaction(String product_id);
+ void set_auto_finish_transaction(bool b);
void _post_event(Variant p_event);
void _record_purchase(String product_id);
diff --git a/platform/iphone/in_app_store.mm b/platform/iphone/in_app_store.mm
index 9b932d147b..f3640c3076 100644
--- a/platform/iphone/in_app_store.mm
+++ b/platform/iphone/in_app_store.mm
@@ -32,8 +32,12 @@
extern "C" {
#import <StoreKit/StoreKit.h>
+#import <Foundation/Foundation.h>
};
+bool auto_finish_transactions = true;
+NSMutableDictionary* pending_transactions = [NSMutableDictionary dictionary];
+
@interface SKProduct (LocalizedPrice)
@property (nonatomic, readonly) NSString *localizedPrice;
@end
@@ -63,6 +67,8 @@ void InAppStore::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_pending_event_count"),&InAppStore::get_pending_event_count);
ObjectTypeDB::bind_method(_MD("pop_pending_event"),&InAppStore::pop_pending_event);
+ ObjectTypeDB::bind_method(_MD("finish_transaction"),&InAppStore::finish_transaction);
+ ObjectTypeDB::bind_method(_MD("set_auto_finish_transaction"),&InAppStore::set_auto_finish_transaction);
};
@interface ProductsDelegate : NSObject<SKProductsRequestDelegate> {
@@ -162,11 +168,13 @@ Error InAppStore::request_product_info(Variant p_params) {
case SKPaymentTransactionStatePurchased: {
printf("status purchased!\n");
String pid = String::utf8([transaction.payment.productIdentifier UTF8String]);
+ String transactionId = String::utf8([transaction.transactionIdentifier UTF8String]);
InAppStore::get_singleton()->_record_purchase(pid);
Dictionary ret;
ret["type"] = "purchase";
ret["result"] = "ok";
ret["product_id"] = pid;
+ ret["transaction_id"] = transactionId;
NSData* receipt = nil;
int sdk_version = 6;
@@ -207,7 +215,13 @@ Error InAppStore::request_product_info(Variant p_params) {
ret["receipt"] = receipt_ret;
InAppStore::get_singleton()->_post_event(ret);
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
+
+ if (auto_finish_transactions){
+ [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
+ }
+ else{
+ [pending_transactions setObject:transaction forKey:transaction.payment.productIdentifier];
+ }
} break;
case SKPaymentTransactionStateFailed: {
printf("status transaction failed!\n");
@@ -290,11 +304,26 @@ InAppStore* InAppStore::get_singleton() {
InAppStore::InAppStore() {
ERR_FAIL_COND(instance != NULL);
instance = this;
+ auto_finish_transactions = false;
TransObserver* observer = [[TransObserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
+ //pending_transactions = [NSMutableDictionary dictionary];
};
+void InAppStore::finish_transaction(String product_id){
+ NSString* prod_id = [NSString stringWithCString:product_id.utf8().get_data() encoding:NSUTF8StringEncoding];
+
+ if ([pending_transactions objectForKey:prod_id]){
+ [[SKPaymentQueue defaultQueue] finishTransaction:[pending_transactions objectForKey:prod_id]];
+ [pending_transactions removeObjectForKey:prod_id];
+ }
+};
+
+void InAppStore::set_auto_finish_transaction(bool b){
+ auto_finish_transactions = b;
+}
+
InAppStore::~InAppStore() {
};
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 0e21540e13..b866dd2ec3 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -51,7 +51,7 @@ def get_flags():
return [
('freetype','builtin'), #use builtin freetype
- ('openssl','builtin'), #use builtin openssl
+ ('openssl','builtin'), #use builtin openssl
]
@@ -166,6 +166,7 @@ def configure(env):
env.Append(CCFLAGS=['-O3','-ffast-math','-fomit-frame-pointer','-msse2'])
env['OBJSUFFIX'] = "_opt"+env['OBJSUFFIX']
env['LIBSUFFIX'] = "_opt"+env['LIBSUFFIX']
+ env.Append(LINKFLAGS=['-Wl,--subsystem,windows'])
elif (env["target"]=="release_debug"):
env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED'])
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 778609950e..5e57827c68 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -206,6 +206,54 @@ bool OS_Windows::can_draw() const {
return !minimized;
};
+#define MI_WP_SIGNATURE 0xFF515700
+#define SIGNATURE_MASK 0xFFFFFF00
+#define IsPenEvent(dw) (((dw) & SIGNATURE_MASK) == MI_WP_SIGNATURE)
+
+
+void OS_Windows::_touch_event(int idx, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+
+ InputEvent event;
+ event.type = InputEvent::SCREEN_TOUCH;
+ event.ID=++last_id;
+ event.screen_touch.index = idx;
+
+ switch (uMsg) {
+ case WM_LBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_RBUTTONDOWN: {
+
+ event.screen_touch.pressed = true;
+ } break;
+
+ case WM_LBUTTONUP:
+ case WM_MBUTTONUP:
+ case WM_RBUTTONUP: {
+ event.screen_touch.pressed = false;
+ } break;
+ };
+
+ event.screen_touch.x=GET_X_LPARAM(lParam);
+ event.screen_touch.y=GET_Y_LPARAM(lParam);
+
+ if (main_loop) {
+ input->parse_input_event(event);
+ }
+};
+
+void OS_Windows::_drag_event(int idx,UINT uMsg, WPARAM wParam, LPARAM lParam) {
+
+ InputEvent event;
+ event.type = InputEvent::SCREEN_DRAG;
+ event.ID=++last_id;
+ event.screen_drag.index = idx;
+
+ event.screen_drag.x=GET_X_LPARAM(lParam);
+ event.screen_drag.y=GET_Y_LPARAM(lParam);
+
+ if (main_loop)
+ input->parse_input_event(event);
+};
LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) {
@@ -270,28 +318,41 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) {
}
case WM_MOUSELEAVE: {
- old_invalid=true;
- outside=true;
+ old_invalid=true;
+ outside=true;
} break;
case WM_MOUSEMOVE: {
- if (outside) {
+ if (outside) {
+
+ CursorShape c=cursor_shape;
+ cursor_shape=CURSOR_MAX;
+ set_cursor_shape(c);
+ outside=false;
- CursorShape c=cursor_shape;
- cursor_shape=CURSOR_MAX;
- set_cursor_shape(c);
- outside=false;
+ //Once-Off notification, must call again....
+ TRACKMOUSEEVENT tme;
+ tme.cbSize=sizeof(TRACKMOUSEEVENT);
+ tme.dwFlags=TME_LEAVE;
+ tme.hwndTrack=hWnd;
+ tme.dwHoverTime=HOVER_DEFAULT;
+ TrackMouseEvent(&tme);
+
+ }
+
+ LPARAM extra = GetMessageExtraInfo();
+ if (IsPenEvent(extra)) {
+
+ int idx = extra & 0x7f;
+ _drag_event(idx, uMsg, wParam, lParam);
+ if (idx != 0) {
+ return 0;
+ };
+ // fallthrough for mouse event
+ };
- //Once-Off notification, must call again....
- TRACKMOUSEEVENT tme;
- tme.cbSize=sizeof(TRACKMOUSEEVENT);
- tme.dwFlags=TME_LEAVE;
- tme.hwndTrack=hWnd;
- tme.dwHoverTime=HOVER_DEFAULT;
- TrackMouseEvent(&tme);
- }
InputEvent event;
event.type=InputEvent::MOUSE_MOTION;
event.ID=++last_id;
@@ -360,6 +421,17 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) {
/*case WM_XBUTTONDOWN:
case WM_XBUTTONUP: */{
+ LPARAM extra = GetMessageExtraInfo();
+ if (IsPenEvent(extra)) {
+
+ int idx = extra & 0x7f;
+ _touch_event(idx, uMsg, wParam, lParam);
+ if (idx != 0) {
+ return 0;
+ };
+ // fallthrough for mouse event
+ };
+
InputEvent event;
event.type=InputEvent::MOUSE_BUTTON;
event.ID=++last_id;
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index c9eb475e1a..1a41b9d77d 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -160,6 +160,10 @@ class OS_Windows : public OS {
void _post_dpad(DWORD p_dpad, int p_device, bool p_pressed);
+ void _drag_event(int idx,UINT uMsg, WPARAM wParam, LPARAM lParam);
+ void _touch_event(int idx, UINT uMsg, WPARAM wParam, LPARAM lParam);
+
+
// functions used by main to initialize/deintialize the OS
protected:
virtual int get_video_driver_count() const;