summaryrefslogtreecommitdiff
path: root/platform/android/godot_android.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/godot_android.cpp')
-rw-r--r--platform/android/godot_android.cpp1022
1 files changed, 476 insertions, 546 deletions
diff --git a/platform/android/godot_android.cpp b/platform/android/godot_android.cpp
index 83d5a413c0..9d300940b0 100644
--- a/platform/android/godot_android.cpp
+++ b/platform/android/godot_android.cpp
@@ -28,139 +28,130 @@
/*************************************************************************/
#ifdef ANDROID_NATIVE_ACTIVITY
-#include <jni.h>
#include <errno.h>
+#include <jni.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
+#include "file_access_android.h"
+#include "global_config.h"
+#include "main/main.h"
+#include "os_android.h"
+#include <android/log.h>
#include <android/sensor.h>
#include <android/window.h>
-#include <android/log.h>
#include <android_native_app_glue.h>
-#include "file_access_android.h"
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <stdlib.h>
-#include "os_android.h"
-#include "global_config.h"
-#include "main/main.h"
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "godot", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "godot", __VA_ARGS__))
-
extern "C" {
- JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerSingleton(JNIEnv * env, jobject obj, jstring name,jobject p_object);
- JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerMethod(JNIEnv * env, jobject obj, jstring sname, jstring name, jstring ret, jobjectArray args);
- JNIEXPORT jstring JNICALL Java_org_godotengine_godot_Godot_getGlobal(JNIEnv * env, jobject obj, jstring path);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerSingleton(JNIEnv *env, jobject obj, jstring name, jobject p_object);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerMethod(JNIEnv *env, jobject obj, jstring sname, jstring name, jstring ret, jobjectArray args);
+JNIEXPORT jstring JNICALL Java_org_godotengine_godot_Godot_getGlobal(JNIEnv *env, jobject obj, jstring path);
};
class JNISingleton : public Object {
- GDCLASS( JNISingleton, Object );
-
+ GDCLASS(JNISingleton, Object);
struct MethodData {
-
jmethodID method;
Variant::Type ret_type;
Vector<Variant::Type> argtypes;
};
jobject instance;
- Map<StringName,MethodData> method_map;
+ Map<StringName, MethodData> method_map;
JNIEnv *env;
public:
+ void update_env(JNIEnv *p_env) { env = p_env; }
- void update_env(JNIEnv *p_env) { env=p_env; }
+ virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
- virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) {
+ print_line("attempt to call " + String(p_method));
- print_line("attempt to call "+String(p_method));
+ r_error.error = Variant::CallError::CALL_OK;
- r_error.error=Variant::CallError::CALL_OK;
-
- Map<StringName,MethodData >::Element *E=method_map.find(p_method);
+ Map<StringName, MethodData>::Element *E = method_map.find(p_method);
if (!E) {
print_line("no exists");
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return Variant();
}
-
int ac = E->get().argtypes.size();
- if (ac<p_argcount) {
+ if (ac < p_argcount) {
print_line("fewargs");
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=ac;
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = ac;
return Variant();
}
- if (ac>p_argcount) {
+ if (ac > p_argcount) {
print_line("manyargs");
- r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
- r_error.argument=ac;
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument = ac;
return Variant();
}
+ for (int i = 0; i < p_argcount; i++) {
+ if (!Variant::can_convert(p_args[i]->get_type(), E->get().argtypes[i])) {
- for(int i=0;i<p_argcount;i++) {
-
- if (!Variant::can_convert(p_args[i]->get_type(),E->get().argtypes[i])) {
-
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=i;
- r_error.expected=E->get().argtypes[i];
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = i;
+ r_error.expected = E->get().argtypes[i];
}
}
-
- jvalue *v=NULL;
+ jvalue *v = NULL;
if (p_argcount) {
- v=(jvalue*)alloca( sizeof(jvalue)*p_argcount );
+ v = (jvalue *)alloca(sizeof(jvalue) * p_argcount);
}
- for(int i=0;i<p_argcount;i++) {
-
+ for (int i = 0; i < p_argcount; i++) {
- switch(E->get().argtypes[i]) {
+ switch (E->get().argtypes[i]) {
case Variant::BOOL: {
- v[i].z=*p_args[i];
+ v[i].z = *p_args[i];
} break;
case Variant::INT: {
- v[i].i=*p_args[i];
+ v[i].i = *p_args[i];
} break;
case Variant::REAL: {
- v[i].f=*p_args[i];
+ v[i].f = *p_args[i];
} break;
case Variant::STRING: {
String s = *p_args[i];
jstring jStr = env->NewStringUTF(s.utf8().get_data());
- v[i].l=jStr;
+ v[i].l = jStr;
} break;
case Variant::STRING_ARRAY: {
PoolVector<String> sarray = *p_args[i];
- jobjectArray arr = env->NewObjectArray(sarray.size(),env->FindClass("java/lang/String"),env->NewStringUTF(""));
+ jobjectArray arr = env->NewObjectArray(sarray.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
- for(int j=0;j<sarray.size();j++) {
+ for (int j = 0; j < sarray.size(); j++) {
- env->SetObjectArrayElement(arr,j,env->NewStringUTF( sarray[i].utf8().get_data() ));
+ env->SetObjectArrayElement(arr, j, env->NewStringUTF(sarray[i].utf8().get_data()));
}
- v[i].l=arr;
+ v[i].l = arr;
} break;
case Variant::INT_ARRAY: {
@@ -168,8 +159,8 @@ public:
PoolVector<int> array = *p_args[i];
jintArray arr = env->NewIntArray(array.size());
PoolVector<int>::Read r = array.read();
- env->SetIntArrayRegion(arr,0,array.size(),r.ptr());
- v[i].l=arr;
+ env->SetIntArrayRegion(arr, 0, array.size(), r.ptr());
+ v[i].l = arr;
} break;
case Variant::REAL_ARRAY: {
@@ -177,15 +168,14 @@ public:
PoolVector<float> array = *p_args[i];
jfloatArray arr = env->NewFloatArray(array.size());
PoolVector<float>::Read r = array.read();
- env->SetFloatArrayRegion(arr,0,array.size(),r.ptr());
- v[i].l=arr;
+ env->SetFloatArrayRegion(arr, 0, array.size(), r.ptr());
+ v[i].l = arr;
} break;
default: {
ERR_FAIL_V(Variant());
} break;
-
}
}
@@ -193,78 +183,76 @@ public:
Variant ret;
- switch(E->get().ret_type) {
+ switch (E->get().ret_type) {
case Variant::NIL: {
-
print_line("call void");
- env->CallVoidMethodA(instance,E->get().method,v);
+ env->CallVoidMethodA(instance, E->get().method, v);
} break;
case Variant::BOOL: {
- ret = env->CallBooleanMethodA(instance,E->get().method,v);
+ ret = env->CallBooleanMethodA(instance, E->get().method, v);
print_line("call bool");
} break;
case Variant::INT: {
- ret = env->CallIntMethodA(instance,E->get().method,v);
+ ret = env->CallIntMethodA(instance, E->get().method, v);
print_line("call int");
} break;
case Variant::REAL: {
- ret = env->CallFloatMethodA(instance,E->get().method,v);
+ ret = env->CallFloatMethodA(instance, E->get().method, v);
} break;
case Variant::STRING: {
- jobject o = env->CallObjectMethodA(instance,E->get().method,v);
- String singname = env->GetStringUTFChars((jstring)o, NULL );
+ jobject o = env->CallObjectMethodA(instance, E->get().method, v);
+ String singname = env->GetStringUTFChars((jstring)o, NULL);
} break;
case Variant::STRING_ARRAY: {
- jobjectArray arr = (jobjectArray)env->CallObjectMethodA(instance,E->get().method,v);
+ jobjectArray arr = (jobjectArray)env->CallObjectMethodA(instance, E->get().method, v);
int stringCount = env->GetArrayLength(arr);
PoolVector<String> sarr;
- for (int i=0; i<stringCount; i++) {
- jstring string = (jstring) env->GetObjectArrayElement(arr, i);
+ for (int i = 0; i < stringCount; i++) {
+ jstring string = (jstring)env->GetObjectArrayElement(arr, i);
const char *rawString = env->GetStringUTFChars(string, 0);
sarr.push_back(String(rawString));
}
- ret=sarr;
+ ret = sarr;
} break;
case Variant::INT_ARRAY: {
- jintArray arr = (jintArray)env->CallObjectMethodA(instance,E->get().method,v);
+ jintArray arr = (jintArray)env->CallObjectMethodA(instance, E->get().method, v);
int fCount = env->GetArrayLength(arr);
PoolVector<int> sarr;
sarr.resize(fCount);
PoolVector<int>::Write w = sarr.write();
- env->GetIntArrayRegion(arr,0,fCount,w.ptr());
+ env->GetIntArrayRegion(arr, 0, fCount, w.ptr());
w = PoolVector<int>::Write();
- ret=sarr;
+ ret = sarr;
} break;
case Variant::REAL_ARRAY: {
- jfloatArray arr = (jfloatArray)env->CallObjectMethodA(instance,E->get().method,v);
+ jfloatArray arr = (jfloatArray)env->CallObjectMethodA(instance, E->get().method, v);
int fCount = env->GetArrayLength(arr);
PoolVector<float> sarr;
sarr.resize(fCount);
PoolVector<float>::Write w = sarr.write();
- env->GetFloatArrayRegion(arr,0,fCount,w.ptr());
+ env->GetFloatArrayRegion(arr, 0, fCount, w.ptr());
w = PoolVector<float>::Write();
- ret=sarr;
+ ret = sarr;
} break;
default: {
-
print_line("failure..");
ERR_FAIL_V(Variant());
} break;
@@ -275,270 +263,251 @@ public:
return ret;
}
-
jobject get_instance() const {
return instance;
}
void set_instance(jobject p_instance) {
- instance=p_instance;
+ instance = p_instance;
}
-
- void add_method(const StringName& p_name, jmethodID p_method,const Vector<Variant::Type>& p_args, Variant::Type p_ret_type) {
+ void add_method(const StringName &p_name, jmethodID p_method, const Vector<Variant::Type> &p_args, Variant::Type p_ret_type) {
MethodData md;
- md.method=p_method;
- md.argtypes=p_args;
- md.ret_type=p_ret_type;
- method_map[p_name]=md;
-
+ md.method = p_method;
+ md.argtypes = p_args;
+ md.ret_type = p_ret_type;
+ method_map[p_name] = md;
}
-
JNISingleton() {}
-
};
//JNIEnv *JNISingleton::env=NULL;
-static HashMap<String,JNISingleton*> jni_singletons;
-
+static HashMap<String, JNISingleton *> jni_singletons;
struct engine {
- struct android_app* app;
- OS_Android *os;
- JNIEnv *jni;
-
- ASensorManager* sensorManager;
- const ASensor* accelerometerSensor;
- const ASensor* magnetometerSensor;
- const ASensor* gyroscopeSensor;
- ASensorEventQueue* sensorEventQueue;
-
- bool display_active;
- bool requested_quit;
- int animating;
- EGLDisplay display;
- EGLSurface surface;
- EGLContext context;
- int32_t width;
- int32_t height;
-
+ struct android_app *app;
+ OS_Android *os;
+ JNIEnv *jni;
+
+ ASensorManager *sensorManager;
+ const ASensor *accelerometerSensor;
+ const ASensor *magnetometerSensor;
+ const ASensor *gyroscopeSensor;
+ ASensorEventQueue *sensorEventQueue;
+
+ bool display_active;
+ bool requested_quit;
+ int animating;
+ EGLDisplay display;
+ EGLSurface surface;
+ EGLContext context;
+ int32_t width;
+ int32_t height;
};
/**
* Initialize an EGL context for the current display.
*/
-static int engine_init_display(struct engine* engine,bool p_gl2) {
- // initialize OpenGL ES and EGL
+static int engine_init_display(struct engine *engine, bool p_gl2) {
+ // initialize OpenGL ES and EGL
- /*
+ /*
* Here specify the attributes of the desired configuration.
* Below, we select an EGLConfig with at least 8 bits per color
* component compatible with on-screen windows
*/
- const EGLint gl2_attribs[] = {
- // EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_BLUE_SIZE, 4,
- EGL_GREEN_SIZE, 4,
- EGL_RED_SIZE, 4,
- EGL_ALPHA_SIZE, 0,
- EGL_DEPTH_SIZE, 16,
- EGL_STENCIL_SIZE, EGL_DONT_CARE,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL_NONE
- };
-
- const EGLint gl1_attribs[] = {
- // EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_BLUE_SIZE, 4,
- EGL_GREEN_SIZE, 4,
- EGL_RED_SIZE, 4,
- EGL_ALPHA_SIZE, 0,
- EGL_DEPTH_SIZE, 16,
- EGL_STENCIL_SIZE, EGL_DONT_CARE,
- EGL_NONE
- };
-
- const EGLint *attribs=p_gl2?gl2_attribs:gl1_attribs;
-
-
- EGLint w, h, dummy, format;
- EGLint numConfigs;
- EGLConfig config;
- EGLSurface surface;
- EGLContext context;
-
- EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-
- eglInitialize(display, 0, 0);
-
-
- /* Here, the application chooses the configuration it desires. In this
+ const EGLint gl2_attribs[] = {
+ // EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_BLUE_SIZE, 4,
+ EGL_GREEN_SIZE, 4,
+ EGL_RED_SIZE, 4,
+ EGL_ALPHA_SIZE, 0,
+ EGL_DEPTH_SIZE, 16,
+ EGL_STENCIL_SIZE, EGL_DONT_CARE,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_NONE
+ };
+
+ const EGLint gl1_attribs[] = {
+ // EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_BLUE_SIZE, 4,
+ EGL_GREEN_SIZE, 4,
+ EGL_RED_SIZE, 4,
+ EGL_ALPHA_SIZE, 0,
+ EGL_DEPTH_SIZE, 16,
+ EGL_STENCIL_SIZE, EGL_DONT_CARE,
+ EGL_NONE
+ };
+
+ const EGLint *attribs = p_gl2 ? gl2_attribs : gl1_attribs;
+
+ EGLint w, h, dummy, format;
+ EGLint numConfigs;
+ EGLConfig config;
+ EGLSurface surface;
+ EGLContext context;
+
+ EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+
+ eglInitialize(display, 0, 0);
+
+ /* Here, the application chooses the configuration it desires. In this
* sample, we have a very simplified selection process, where we pick
* the first EGLConfig that matches our criteria */
- eglChooseConfig(display, attribs, &config, 1, &numConfigs);
+ eglChooseConfig(display, attribs, &config, 1, &numConfigs);
- LOGI("Num configs: %i\n",numConfigs);
+ LOGI("Num configs: %i\n", numConfigs);
- /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
+ /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
* As soon as we picked a EGLConfig, we can safely reconfigure the
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
- eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
+ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
- ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);
- //ANativeWindow_setFlags(engine->app->window, 0, 0, format|);
+ ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);
+ //ANativeWindow_setFlags(engine->app->window, 0, 0, format|);
- surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
+ surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
- const EGLint context_attribs[] = {
- EGL_CONTEXT_CLIENT_VERSION,2,
- EGL_NONE
- };
- context = eglCreateContext(display, config, EGL_NO_CONTEXT, p_gl2?context_attribs:NULL);
-
- if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
- LOGW("Unable to eglMakeCurrent");
- return -1;
- }
+ const EGLint context_attribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+ context = eglCreateContext(display, config, EGL_NO_CONTEXT, p_gl2 ? context_attribs : NULL);
- eglQuerySurface(display, surface, EGL_WIDTH, &w);
- eglQuerySurface(display, surface, EGL_HEIGHT, &h);
- print_line("INIT VIDEO MODE: "+itos(w)+","+itos(h));
+ if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
+ LOGW("Unable to eglMakeCurrent");
+ return -1;
+ }
- //engine->os->set_egl_extensions(eglQueryString(display,EGL_EXTENSIONS));
- engine->os->init_video_mode(w,h);
+ eglQuerySurface(display, surface, EGL_WIDTH, &w);
+ eglQuerySurface(display, surface, EGL_HEIGHT, &h);
+ print_line("INIT VIDEO MODE: " + itos(w) + "," + itos(h));
+ //engine->os->set_egl_extensions(eglQueryString(display,EGL_EXTENSIONS));
+ engine->os->init_video_mode(w, h);
- engine->display = display;
- engine->context = context;
- engine->surface = surface;
- engine->width = w;
- engine->height = h;
- engine->display_active=true;
+ engine->display = display;
+ engine->context = context;
+ engine->surface = surface;
+ engine->width = w;
+ engine->height = h;
+ engine->display_active = true;
- //engine->state.angle = 0;
+ //engine->state.angle = 0;
- // Initialize GL state.
- //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
- glEnable(GL_CULL_FACE);
- // glShadeModel(GL_SMOOTH);
- glDisable(GL_DEPTH_TEST);
- LOGI("GL Version: %s - %s %s\n", glGetString(GL_VERSION),glGetString(GL_VENDOR), glGetString(GL_RENDERER));
+ // Initialize GL state.
+ //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
+ glEnable(GL_CULL_FACE);
+ // glShadeModel(GL_SMOOTH);
+ glDisable(GL_DEPTH_TEST);
+ LOGI("GL Version: %s - %s %s\n", glGetString(GL_VERSION), glGetString(GL_VENDOR), glGetString(GL_RENDERER));
- return 0;
+ return 0;
}
+static void engine_draw_frame(struct engine *engine) {
+ if (engine->display == NULL) {
+ // No display.
+ return;
+ }
-static void engine_draw_frame(struct engine* engine) {
- if (engine->display == NULL) {
- // No display.
- return;
- }
-
- // Just fill the screen with a color.
- //glClearColor(0,1,0,1);
- //glClear(GL_COLOR_BUFFER_BIT);
- if (engine->os && engine->os->main_loop_iterate()==true) {
+ // Just fill the screen with a color.
+ //glClearColor(0,1,0,1);
+ //glClear(GL_COLOR_BUFFER_BIT);
+ if (engine->os && engine->os->main_loop_iterate() == true) {
- engine->requested_quit=true;
- return; //should exit instead
- }
+ engine->requested_quit = true;
+ return; //should exit instead
+ }
- eglSwapBuffers(engine->display, engine->surface);
+ eglSwapBuffers(engine->display, engine->surface);
}
-
-static void engine_term_display(struct engine* engine) {
- if (engine->display != EGL_NO_DISPLAY) {
- eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- if (engine->context != EGL_NO_CONTEXT) {
- eglDestroyContext(engine->display, engine->context);
- }
- if (engine->surface != EGL_NO_SURFACE) {
- eglDestroySurface(engine->display, engine->surface);
+static void engine_term_display(struct engine *engine) {
+ if (engine->display != EGL_NO_DISPLAY) {
+ eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ if (engine->context != EGL_NO_CONTEXT) {
+ eglDestroyContext(engine->display, engine->context);
+ }
+ if (engine->surface != EGL_NO_SURFACE) {
+ eglDestroySurface(engine->display, engine->surface);
+ }
+ eglTerminate(engine->display);
}
- eglTerminate(engine->display);
- }
-
- engine->animating = 0;
- engine->display = EGL_NO_DISPLAY;
- engine->context = EGL_NO_CONTEXT;
- engine->surface = EGL_NO_SURFACE;
- engine->display_active=false;
+ engine->animating = 0;
+ engine->display = EGL_NO_DISPLAY;
+ engine->context = EGL_NO_CONTEXT;
+ engine->surface = EGL_NO_SURFACE;
+ engine->display_active = false;
}
/**
* Process the next input event.
*/
-static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
- struct engine* engine = (struct engine*)app->userData;
+static int32_t engine_handle_input(struct android_app *app, AInputEvent *event) {
+ struct engine *engine = (struct engine *)app->userData;
if (!engine->os)
return 0;
- switch(AInputEvent_getType(event)) {
+ switch (AInputEvent_getType(event)) {
case AINPUT_EVENT_TYPE_KEY: {
int ac = AKeyEvent_getAction(event);
- switch(ac) {
+ switch (ac) {
case AKEY_EVENT_ACTION_DOWN: {
int32_t code = AKeyEvent_getKeyCode(event);
- if (code==AKEYCODE_BACK) {
+ if (code == AKEYCODE_BACK) {
//AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
if (engine->os)
engine->os->main_loop_request_quit();
return 1;
-
}
-
} break;
case AKEY_EVENT_ACTION_UP: {
-
} break;
}
-
} break;
case AINPUT_EVENT_TYPE_MOTION: {
-
Vector<OS_Android::TouchPos> touchvec;
int pc = AMotionEvent_getPointerCount(event);
touchvec.resize(pc);
- for(int i=0;i<pc;i++) {
+ for (int i = 0; i < pc; i++) {
- touchvec[i].pos.x=AMotionEvent_getX(event,i);
- touchvec[i].pos.y=AMotionEvent_getY(event,i);
- touchvec[i].id=AMotionEvent_getPointerId(event,i);
+ touchvec[i].pos.x = AMotionEvent_getX(event, i);
+ touchvec[i].pos.y = AMotionEvent_getY(event, i);
+ touchvec[i].id = AMotionEvent_getPointerId(event, i);
}
-
//System.out.printf("gaction: %d\n",event.getAction());
- int pidx=(AMotionEvent_getAction(event)&AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)>>8;
- switch(AMotionEvent_getAction(event)&AMOTION_EVENT_ACTION_MASK) {
+ int pidx = (AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> 8;
+ switch (AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK) {
case AMOTION_EVENT_ACTION_DOWN: {
- engine->os->process_touch(0,0,touchvec);
+ engine->os->process_touch(0, 0, touchvec);
//System.out.printf("action down at: %f,%f\n", event.getX(),event.getY());
} break;
case AMOTION_EVENT_ACTION_MOVE: {
- engine->os->process_touch(1,0,touchvec);
+ engine->os->process_touch(1, 0, touchvec);
/*
for(int i=0;i<event.getPointerCount();i++) {
System.out.printf("%d - moved to: %f,%f\n",i, event.getX(i),event.getY(i));
@@ -547,16 +516,16 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
} break;
case AMOTION_EVENT_ACTION_POINTER_UP: {
- engine->os->process_touch(4,pidx,touchvec);
+ engine->os->process_touch(4, pidx, touchvec);
//System.out.printf("%d - s.up at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx));
} break;
case AMOTION_EVENT_ACTION_POINTER_DOWN: {
- engine->os->process_touch(3,pidx,touchvec);
+ engine->os->process_touch(3, pidx, touchvec);
//System.out.printf("%d - s.down at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx));
} break;
case AMOTION_EVENT_ACTION_CANCEL:
case AMOTION_EVENT_ACTION_UP: {
- engine->os->process_touch(2,0,touchvec);
+ engine->os->process_touch(2, 0, touchvec);
/*
for(int i=0;i<event.getPointerCount();i++) {
System.out.printf("%d - up! %f,%f\n",i, event.getX(i),event.getY(i));
@@ -567,34 +536,33 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
return 1;
} break;
-
}
- return 0;
+ return 0;
}
/**
* Process the next main command.
*/
-static void _gfx_init(void *ud,bool p_gl2) {
+static void _gfx_init(void *ud, bool p_gl2) {
- struct engine* engine = (struct engine*)ud;
- engine_init_display(engine,p_gl2);
+ struct engine *engine = (struct engine *)ud;
+ engine_init_display(engine, p_gl2);
}
-static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
- struct engine* engine = (struct engine*)app->userData;
- // LOGI("**** CMD %i\n",cmd);
- switch (cmd) {
- case APP_CMD_SAVE_STATE:
- // The system has asked us to save our current state. Do so.
- //engine->app->savedState = malloc(sizeof(struct saved_state));
- //*((struct saved_state*)engine->app->savedState) = engine->state;
- //engine->app->savedStateSize = sizeof(struct saved_state);
- break;
- case APP_CMD_CONFIG_CHANGED:
- case APP_CMD_WINDOW_RESIZED: {
+static void engine_handle_cmd(struct android_app *app, int32_t cmd) {
+ struct engine *engine = (struct engine *)app->userData;
+ // LOGI("**** CMD %i\n",cmd);
+ switch (cmd) {
+ case APP_CMD_SAVE_STATE:
+ // The system has asked us to save our current state. Do so.
+ //engine->app->savedState = malloc(sizeof(struct saved_state));
+ //*((struct saved_state*)engine->app->savedState) = engine->state;
+ //engine->app->savedStateSize = sizeof(struct saved_state);
+ break;
+ case APP_CMD_CONFIG_CHANGED:
+ case APP_CMD_WINDOW_RESIZED: {
#if 0
// android blows
@@ -610,26 +578,22 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
}
#else
- if (engine->display_active) {
+ if (engine->display_active) {
-
- EGLint w,h;
- eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w);
- eglQuerySurface(engine->display, engine->surface, EGL_HEIGHT, &h);
- // if (w==engine->os->get_video_mode().width && h==engine->os->get_video_mode().height)
+ EGLint w, h;
+ eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w);
+ eglQuerySurface(engine->display, engine->surface, EGL_HEIGHT, &h);
+ // if (w==engine->os->get_video_mode().width && h==engine->os->get_video_mode().height)
// break;
- engine_term_display(engine);
-
-
- }
-
+ engine_term_display(engine);
+ }
- engine->os->reload_gfx();
- engine_draw_frame(engine);
- engine->animating=1;
+ engine->os->reload_gfx();
+ engine_draw_frame(engine);
+ engine->animating = 1;
- /*
+/*
EGLint w,h;
eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w);
eglQuerySurface(engine->display, engine->surface, EGL_HEIGHT, &h);
@@ -640,309 +604,285 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
#endif
- } break;
- case APP_CMD_INIT_WINDOW:
- //The window is being shown, get it ready.
- //LOGI("INIT WINDOW");
- if (engine->app->window != NULL) {
+ } break;
+ case APP_CMD_INIT_WINDOW:
+ //The window is being shown, get it ready.
+ //LOGI("INIT WINDOW");
+ if (engine->app->window != NULL) {
- if (engine->os==NULL) {
+ if (engine->os == NULL) {
- //do initialization here, when there's OpenGL! hackish but the only way
- engine->os = new OS_Android(_gfx_init,engine);
+ //do initialization here, when there's OpenGL! hackish but the only way
+ engine->os = new OS_Android(_gfx_init, engine);
- //char *args[]={"-test","gui",NULL};
- __android_log_print(ANDROID_LOG_INFO,"godot","pre asdasd setup...");
+ //char *args[]={"-test","gui",NULL};
+ __android_log_print(ANDROID_LOG_INFO, "godot", "pre asdasd setup...");
#if 0
Error err = Main::setup("apk",2,args);
#else
- Error err = Main::setup("apk",0,NULL);
-
- String modules = GlobalConfig::get_singleton()->get("android/modules");
- Vector<String> mods = modules.split(",",false);
- mods.push_back("GodotOS");
- __android_log_print(ANDROID_LOG_INFO,"godot","mod count: %i",mods.size());
-
- if (mods.size()) {
+ Error err = Main::setup("apk", 0, NULL);
- jclass activityClass = engine->jni->FindClass("android/app/NativeActivity");
+ String modules = GlobalConfig::get_singleton()->get("android/modules");
+ Vector<String> mods = modules.split(",", false);
+ mods.push_back("GodotOS");
+ __android_log_print(ANDROID_LOG_INFO, "godot", "mod count: %i", mods.size());
- jmethodID getClassLoader = engine->jni->GetMethodID(activityClass,"getClassLoader", "()Ljava/lang/ClassLoader;");
+ if (mods.size()) {
- jobject cls = engine->jni->CallObjectMethod(app->activity->clazz, getClassLoader);
+ jclass activityClass = engine->jni->FindClass("android/app/NativeActivity");
- jclass classLoader = engine->jni->FindClass("java/lang/ClassLoader");
+ jmethodID getClassLoader = engine->jni->GetMethodID(activityClass, "getClassLoader", "()Ljava/lang/ClassLoader;");
- jmethodID findClass = engine->jni->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
+ jobject cls = engine->jni->CallObjectMethod(app->activity->clazz, getClassLoader);
+ jclass classLoader = engine->jni->FindClass("java/lang/ClassLoader");
- static JNINativeMethod methods[] = {
- {"registerSingleton", "(Ljava/lang/String;Ljava/lang/Object;)V",(void *)&Java_org_godotengine_godot_Godot_registerSingleton},
- {"registerMethod", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V",(void *)&Java_org_godotengine_godot_Godot_registerMethod},
- {"getGlobal", "(Ljava/lang/String;)Ljava/lang/String;", (void *)&Java_org_godotengine_godot_Godot_getGlobal},
- };
+ jmethodID findClass = engine->jni->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
- jstring gstrClassName = engine->jni->NewStringUTF("org/godotengine/godot/Godot");
- jclass GodotClass = (jclass)engine->jni->CallObjectMethod(cls, findClass, gstrClassName);
+ static JNINativeMethod methods[] = {
+ { "registerSingleton", "(Ljava/lang/String;Ljava/lang/Object;)V", (void *)&Java_org_godotengine_godot_Godot_registerSingleton },
+ { "registerMethod", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V", (void *)&Java_org_godotengine_godot_Godot_registerMethod },
+ { "getGlobal", "(Ljava/lang/String;)Ljava/lang/String;", (void *)&Java_org_godotengine_godot_Godot_getGlobal },
+ };
- __android_log_print(ANDROID_LOG_INFO,"godot","godot ****^*^*?^*^*class data %x",GodotClass);
+ jstring gstrClassName = engine->jni->NewStringUTF("org/godotengine/godot/Godot");
+ jclass GodotClass = (jclass)engine->jni->CallObjectMethod(cls, findClass, gstrClassName);
- engine->jni->RegisterNatives(GodotClass,methods,sizeof(methods)/sizeof(methods[0]));
+ __android_log_print(ANDROID_LOG_INFO, "godot", "godot ****^*^*?^*^*class data %x", GodotClass);
- for (int i=0;i<mods.size();i++) {
+ engine->jni->RegisterNatives(GodotClass, methods, sizeof(methods) / sizeof(methods[0]));
- String m = mods[i];
- //jclass singletonClass = engine->jni->FindClass(m.utf8().get_data());
+ for (int i = 0; i < mods.size(); i++) {
- jstring strClassName = engine->jni->NewStringUTF(m.utf8().get_data());
- jclass singletonClass = (jclass)engine->jni->CallObjectMethod(cls, findClass, strClassName);
+ String m = mods[i];
+ //jclass singletonClass = engine->jni->FindClass(m.utf8().get_data());
- __android_log_print(ANDROID_LOG_INFO,"godot","****^*^*?^*^*class data %x",singletonClass);
- jmethodID initialize = engine->jni->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lorg/godotengine/godot/Godot$SingletonBase;");
-
-
- jobject obj = engine->jni->CallStaticObjectMethod(singletonClass,initialize,app->activity->clazz);
- __android_log_print(ANDROID_LOG_INFO,"godot","****^*^*?^*^*class instance %x",obj);
- jobject gob = engine->jni->NewGlobalRef(obj);
+ jstring strClassName = engine->jni->NewStringUTF(m.utf8().get_data());
+ jclass singletonClass = (jclass)engine->jni->CallObjectMethod(cls, findClass, strClassName);
+ __android_log_print(ANDROID_LOG_INFO, "godot", "****^*^*?^*^*class data %x", singletonClass);
+ jmethodID initialize = engine->jni->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lorg/godotengine/godot/Godot$SingletonBase;");
+ jobject obj = engine->jni->CallStaticObjectMethod(singletonClass, initialize, app->activity->clazz);
+ __android_log_print(ANDROID_LOG_INFO, "godot", "****^*^*?^*^*class instance %x", obj);
+ jobject gob = engine->jni->NewGlobalRef(obj);
+ }
}
- }
-
#endif
+ if (!Main::start())
+ return; //should exit instead and print the error
- if (!Main::start())
- return; //should exit instead and print the error
+ engine->os->main_loop_begin();
+ } else {
+ //i guess recreate resources?
+ engine->os->reload_gfx();
+ }
- engine->os->main_loop_begin();
- } else {
- //i guess recreate resources?
- engine->os->reload_gfx();
+ engine->animating = 1;
+ engine_draw_frame(engine);
}
-
-
- engine->animating=1;
+ break;
+ case APP_CMD_TERM_WINDOW:
+ // The window is being hidden or closed, clean it up.
+ //LOGI("TERM WINDOW");
+ engine_term_display(engine);
+ break;
+ case APP_CMD_GAINED_FOCUS:
+ // When our app gains focus, we start monitoring the accelerometer.
+ if (engine->accelerometerSensor != NULL) {
+ ASensorEventQueue_enableSensor(engine->sensorEventQueue,
+ engine->accelerometerSensor);
+ // We'd like to get 60 events per second (in us).
+ ASensorEventQueue_setEventRate(engine->sensorEventQueue,
+ engine->accelerometerSensor, (1000L / 60) * 1000);
+ }
+ // Also start monitoring the magnetometer.
+ if (engine->magnetometerSensor != NULL) {
+ ASensorEventQueue_enableSensor(engine->sensorEventQueue,
+ engine->magnetometerSensor);
+ // We'd like to get 60 events per second (in us).
+ ASensorEventQueue_setEventRate(engine->sensorEventQueue,
+ engine->magnetometerSensor, (1000L / 60) * 1000);
+ }
+ // And the gyroscope.
+ if (engine->gyroscopeSensor != NULL) {
+ ASensorEventQueue_enableSensor(engine->sensorEventQueue,
+ engine->gyroscopeSensor);
+ // We'd like to get 60 events per second (in us).
+ ASensorEventQueue_setEventRate(engine->sensorEventQueue,
+ engine->gyroscopeSensor, (1000L / 60) * 1000);
+ }
+ engine->animating = 1;
+ break;
+ case APP_CMD_LOST_FOCUS:
+ // When our app loses focus, we stop monitoring the sensors.
+ // This is to avoid consuming battery while not being used.
+ if (engine->accelerometerSensor != NULL) {
+ ASensorEventQueue_disableSensor(engine->sensorEventQueue,
+ engine->accelerometerSensor);
+ }
+ if (engine->magnetometerSensor != NULL) {
+ ASensorEventQueue_disableSensor(engine->sensorEventQueue,
+ engine->magnetometerSensor);
+ }
+ if (engine->gyroscopeSensor != NULL) {
+ ASensorEventQueue_disableSensor(engine->sensorEventQueue,
+ engine->gyroscopeSensor);
+ }
+ // Also stop animating.
+ engine->animating = 0;
engine_draw_frame(engine);
- }
- break;
- case APP_CMD_TERM_WINDOW:
- // The window is being hidden or closed, clean it up.
- //LOGI("TERM WINDOW");
- engine_term_display(engine);
- break;
- case APP_CMD_GAINED_FOCUS:
- // When our app gains focus, we start monitoring the accelerometer.
- if (engine->accelerometerSensor != NULL) {
- ASensorEventQueue_enableSensor(engine->sensorEventQueue,
- engine->accelerometerSensor);
- // We'd like to get 60 events per second (in us).
- ASensorEventQueue_setEventRate(engine->sensorEventQueue,
- engine->accelerometerSensor, (1000L/60)*1000);
-
- }
- // Also start monitoring the magnetometer.
- if (engine->magnetometerSensor != NULL) {
- ASensorEventQueue_enableSensor(engine->sensorEventQueue,
- engine->magnetometerSensor);
- // We'd like to get 60 events per second (in us).
- ASensorEventQueue_setEventRate(engine->sensorEventQueue,
- engine->magnetometerSensor, (1000L/60)*1000);
-
- }
- // And the gyroscope.
- if (engine->gyroscopeSensor != NULL) {
- ASensorEventQueue_enableSensor(engine->sensorEventQueue,
- engine->gyroscopeSensor);
- // We'd like to get 60 events per second (in us).
- ASensorEventQueue_setEventRate(engine->sensorEventQueue,
- engine->gyroscopeSensor, (1000L/60)*1000);
-
- }
- engine->animating = 1;
- break;
- case APP_CMD_LOST_FOCUS:
- // When our app loses focus, we stop monitoring the sensors.
- // This is to avoid consuming battery while not being used.
- if (engine->accelerometerSensor != NULL) {
- ASensorEventQueue_disableSensor(engine->sensorEventQueue,
- engine->accelerometerSensor);
- }
- if (engine->magnetometerSensor != NULL) {
- ASensorEventQueue_disableSensor(engine->sensorEventQueue,
- engine->magnetometerSensor);
- }
- if (engine->gyroscopeSensor != NULL) {
- ASensorEventQueue_disableSensor(engine->sensorEventQueue,
- engine->gyroscopeSensor);
- }
- // Also stop animating.
- engine->animating = 0;
- engine_draw_frame(engine);
- break;
- }
+ break;
+ }
}
-void android_main(struct android_app* state) {
- struct engine engine;
- // Make sure glue isn't stripped.
- app_dummy();
-
- memset(&engine, 0, sizeof(engine));
- state->userData = &engine;
- state->onAppCmd = engine_handle_cmd;
- state->onInputEvent = engine_handle_input;
- engine.app = state;
- engine.requested_quit=false;
- engine.os=NULL;
- engine.display_active=false;
-
- FileAccessAndroid::asset_manager=state->activity->assetManager;
-
- // Prepare to monitor sensors
- engine.sensorManager = ASensorManager_getInstance();
- engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
- ASENSOR_TYPE_ACCELEROMETER);
- engine.magnetometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
- ASENSOR_TYPE_MAGNETIC_FIELD);
- engine.gyroscopeSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
- ASENSOR_TYPE_GYROSCOPE);
- engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager,
- state->looper, LOOPER_ID_USER, NULL, NULL);
-
-
- ANativeActivity_setWindowFlags(state->activity,AWINDOW_FLAG_FULLSCREEN|AWINDOW_FLAG_KEEP_SCREEN_ON,0);
+void android_main(struct android_app *state) {
+ struct engine engine;
+ // Make sure glue isn't stripped.
+ app_dummy();
+
+ memset(&engine, 0, sizeof(engine));
+ state->userData = &engine;
+ state->onAppCmd = engine_handle_cmd;
+ state->onInputEvent = engine_handle_input;
+ engine.app = state;
+ engine.requested_quit = false;
+ engine.os = NULL;
+ engine.display_active = false;
+
+ FileAccessAndroid::asset_manager = state->activity->assetManager;
+
+ // Prepare to monitor sensors
+ engine.sensorManager = ASensorManager_getInstance();
+ engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
+ ASENSOR_TYPE_ACCELEROMETER);
+ engine.magnetometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
+ ASENSOR_TYPE_MAGNETIC_FIELD);
+ engine.gyroscopeSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
+ ASENSOR_TYPE_GYROSCOPE);
+ engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager,
+ state->looper, LOOPER_ID_USER, NULL, NULL);
+
+ ANativeActivity_setWindowFlags(state->activity, AWINDOW_FLAG_FULLSCREEN | AWINDOW_FLAG_KEEP_SCREEN_ON, 0);
state->activity->vm->AttachCurrentThread(&engine.jni, NULL);
+ // loop waiting for stuff to do.
+ while (1) {
+ // Read all pending events.
+ int ident;
+ int events;
+ struct android_poll_source *source;
- // loop waiting for stuff to do.
-
- while (1) {
- // Read all pending events.
- int ident;
- int events;
- struct android_poll_source* source;
-
- // If not animating, we will block forever waiting for events.
- // If animating, we loop until all events are read, then continue
- // to draw the next frame of animation.
-
- int nullmax=50;
- while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
- (void**)&source)) >= 0) {
+ // If not animating, we will block forever waiting for events.
+ // If animating, we loop until all events are read, then continue
+ // to draw the next frame of animation.
- // Process this event.
+ int nullmax = 50;
+ while ((ident = ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
+ (void **)&source)) >= 0) {
- if (source != NULL) {
- // LOGI("process\n");
- source->process(state, source);
- } else {
- nullmax--;
- if (nullmax<0)
- break;
- }
-
- // If a sensor has data, process it now.
- // LOGI("events\n");
- if (ident == LOOPER_ID_USER) {
- if (engine.accelerometerSensor != NULL || engine.magnetometerSensor != NULL || engine.gyroscopeSensor != NULL) {
- ASensorEvent event;
- while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
- &event, 1) > 0) {
-
-
- if (engine.os) {
- if (event.acceleration != NULL) {
- engine.os->process_accelerometer(Vector3(event.acceleration.x, event.acceleration.y,
- event.acceleration.z));
- }
- if (event.magnetic != NULL) {
- engine.os->process_magnetometer(Vector3(event.magnetic.x, event.magnetic.y,
- event.magnetic.z));
- }
- if (event.vector != NULL) {
- engine.os->process_gyroscope(Vector3(event.vector.x, event.vector.y,
- event.vector.z));
- }
- }
-
- }
- }
- }
-
- // Check if we are exiting.
- if (state->destroyRequested != 0) {
- if (engine.os) {
- engine.os->main_loop_request_quit();
- }
- state->destroyRequested=0;
- }
-
- if (engine.requested_quit) {
- engine_term_display(&engine);
- exit(0);
- return;
- }
+ // Process this event.
- // LOGI("end\n");
+ if (source != NULL) {
+ // LOGI("process\n");
+ source->process(state, source);
+ } else {
+ nullmax--;
+ if (nullmax < 0)
+ break;
+ }
+ // If a sensor has data, process it now.
+ // LOGI("events\n");
+ if (ident == LOOPER_ID_USER) {
+ if (engine.accelerometerSensor != NULL || engine.magnetometerSensor != NULL || engine.gyroscopeSensor != NULL) {
+ ASensorEvent event;
+ while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
+ &event, 1) > 0) {
+
+ if (engine.os) {
+ if (event.acceleration != NULL) {
+ engine.os->process_accelerometer(Vector3(event.acceleration.x, event.acceleration.y,
+ event.acceleration.z));
+ }
+ if (event.magnetic != NULL) {
+ engine.os->process_magnetometer(Vector3(event.magnetic.x, event.magnetic.y,
+ event.magnetic.z));
+ }
+ if (event.vector != NULL) {
+ engine.os->process_gyroscope(Vector3(event.vector.x, event.vector.y,
+ event.vector.z));
+ }
+ }
+ }
+ }
+ }
- }
+ // Check if we are exiting.
+ if (state->destroyRequested != 0) {
+ if (engine.os) {
+ engine.os->main_loop_request_quit();
+ }
+ state->destroyRequested = 0;
+ }
- // LOGI("engine animating? %i\n",engine.animating);
+ if (engine.requested_quit) {
+ engine_term_display(&engine);
+ exit(0);
+ return;
+ }
- if (engine.animating) {
- //do os render
+ // LOGI("end\n");
+ }
- engine_draw_frame(&engine);
- //LOGI("TERM WINDOW");
+ // LOGI("engine animating? %i\n",engine.animating);
- }
- }
+ if (engine.animating) {
+ //do os render
+ engine_draw_frame(&engine);
+ //LOGI("TERM WINDOW");
+ }
+ }
}
+JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerSingleton(JNIEnv *env, jobject obj, jstring name, jobject p_object) {
-
-
-JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerSingleton(JNIEnv * env, jobject obj, jstring name,jobject p_object){
-
- String singname = env->GetStringUTFChars( name, NULL );
- JNISingleton *s = memnew( JNISingleton );
+ String singname = env->GetStringUTFChars(name, NULL);
+ JNISingleton *s = memnew(JNISingleton);
s->update_env(env);
s->set_instance(env->NewGlobalRef(p_object));
- jni_singletons[singname]=s;
-
- GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton(singname,s));
+ jni_singletons[singname] = s;
+ GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton(singname, s));
}
-
-static Variant::Type get_jni_type(const String& p_type) {
+static Variant::Type get_jni_type(const String &p_type) {
static struct {
const char *name;
Variant::Type type;
- } _type_to_vtype[]={
- {"void",Variant::NIL},
- {"boolean",Variant::BOOL},
- {"int",Variant::INT},
- {"float",Variant::REAL},
- {"java.lang.String",Variant::STRING},
- {"[I",Variant::INT_ARRAY},
- {"[F",Variant::REAL_ARRAY},
- {"[Ljava.lang.String;",Variant::STRING_ARRAY},
- {NULL,Variant::NIL}
+ } _type_to_vtype[] = {
+ { "void", Variant::NIL },
+ { "boolean", Variant::BOOL },
+ { "int", Variant::INT },
+ { "float", Variant::REAL },
+ { "java.lang.String", Variant::STRING },
+ { "[I", Variant::INT_ARRAY },
+ { "[F", Variant::REAL_ARRAY },
+ { "[Ljava.lang.String;", Variant::STRING_ARRAY },
+ { NULL, Variant::NIL }
};
- int idx=0;
+ 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++;
@@ -951,88 +891,78 @@ static Variant::Type get_jni_type(const String& p_type) {
return Variant::NIL;
}
-
-static const char* get_jni_sig(const String& p_type) {
+static const char *get_jni_sig(const String &p_type) {
static struct {
const char *name;
const char *sig;
- } _type_to_vtype[]={
- {"void","V"},
- {"boolean","Z"},
- {"int","I"},
- {"float","F"},
- {"java.lang.String","Ljava/lang/String;"},
- {"[I","[I"},
- {"[F","[F"},
- {"[Ljava.lang.String;","[Ljava/lang/String;"},
- {NULL,"V"}
+ } _type_to_vtype[] = {
+ { "void", "V" },
+ { "boolean", "Z" },
+ { "int", "I" },
+ { "float", "F" },
+ { "java.lang.String", "Ljava/lang/String;" },
+ { "[I", "[I" },
+ { "[F", "[F" },
+ { "[Ljava.lang.String;", "[Ljava/lang/String;" },
+ { NULL, "V" }
};
- int idx=0;
+ 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++;
}
-
return "";
}
-JNIEXPORT jstring JNICALL Java_org_godotengine_godot_Godot_getGlobal(JNIEnv * env, jobject obj, jstring path) {
+JNIEXPORT jstring JNICALL Java_org_godotengine_godot_Godot_getGlobal(JNIEnv *env, jobject obj, jstring path) {
- String js = env->GetStringUTFChars( path, NULL );
+ String js = env->GetStringUTFChars(path, NULL);
return env->NewStringUTF(GlobalConfig::get_singleton()->get(js).operator String().utf8().get_data());
-
-
}
+JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerMethod(JNIEnv *env, jobject obj, jstring sname, jstring name, jstring ret, jobjectArray args) {
-
-JNIEXPORT void JNICALL Java_org_godotengine_godot_Godot_registerMethod(JNIEnv * env, jobject obj, jstring sname, jstring name, jstring ret, jobjectArray args){
-
- String singname = env->GetStringUTFChars( sname, NULL );
+ String singname = env->GetStringUTFChars(sname, NULL);
ERR_FAIL_COND(!jni_singletons.has(singname));
JNISingleton *s = jni_singletons.get(singname);
-
- String mname = env->GetStringUTFChars( name, NULL );
- String retval = env->GetStringUTFChars( ret, NULL );
+ String mname = env->GetStringUTFChars(name, NULL);
+ String retval = env->GetStringUTFChars(ret, NULL);
Vector<Variant::Type> types;
- String cs="(";
-
+ String cs = "(";
int stringCount = env->GetArrayLength(args);
- print_line("Singl: "+singname+" Method: "+mname+" RetVal: "+retval);
- for (int i=0; i<stringCount; i++) {
+ print_line("Singl: " + singname + " Method: " + mname + " RetVal: " + retval);
+ for (int i = 0; i < stringCount; i++) {
- jstring string = (jstring) env->GetObjectArrayElement(args, i);
+ jstring string = (jstring)env->GetObjectArrayElement(args, i);
const char *rawString = env->GetStringUTFChars(string, 0);
types.push_back(get_jni_type(String(rawString)));
- cs+=get_jni_sig(String(rawString));
+ cs += get_jni_sig(String(rawString));
}
- cs+=")";
- cs+=get_jni_sig(retval);
+ cs += ")";
+ cs += get_jni_sig(retval);
jclass cls = env->GetObjectClass(s->get_instance());
- print_line("METHOD: "+mname+" sig: "+cs);
+ print_line("METHOD: " + mname + " sig: " + cs);
jmethodID mid = env->GetMethodID(cls, mname.ascii().get_data(), cs.ascii().get_data());
if (!mid) {
- print_line("FAILED GETTING METHOID "+mname);
+ print_line("FAILED GETTING METHOID " + mname);
}
- s->add_method(mname,mid,types,get_jni_type(retval));
-
-
+ s->add_method(mname, mid, types, get_jni_type(retval));
}
#endif