|
1 |
|
2 /* Include the SDL main definition header */ |
|
3 #include "SDL_main.h" |
|
4 |
|
5 /******************************************************************************* |
|
6 Functions called by JNI |
|
7 *******************************************************************************/ |
|
8 #include <jni.h> |
|
9 |
|
10 // Called before SDL_main() to initialize JNI bindings in SDL library |
|
11 extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls); |
|
12 |
|
13 // Library init |
|
14 extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) |
|
15 { |
|
16 return JNI_VERSION_1_4; |
|
17 } |
|
18 |
|
19 // Start up the SDL app |
|
20 extern "C" void Java_org_hedgewars_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobjectArray strArray) |
|
21 { |
|
22 /* This interface could expand with ABI negotiation, calbacks, etc. */ |
|
23 SDL_Android_Init(env, cls); |
|
24 |
|
25 //Get the String array from java |
|
26 int argc = env->GetArrayLength(strArray); |
|
27 char* argv[argc]; |
|
28 jstring jstringArgv[argc]; |
|
29 for(int i = 0; i < argc; i++){ |
|
30 jstringArgv[i] = (jstring)env->GetObjectArrayElement(strArray, i); //get the element |
|
31 strcpy(argv[i], env->GetStringUTFChars(jstringArgv[i], JNI_FALSE)); //copy it to a mutable location |
|
32 env->ReleaseStringChars(jstringArgv[i], (jchar*)argv[i]); //release mem |
|
33 } |
|
34 |
|
35 /* Run the application code! */ |
|
36 int status; |
|
37 status = SDL_main(argc, argv); |
|
38 |
|
39 //Clean up argv |
|
40 for(int i = 0; i < argc; i++){ |
|
41 } |
|
42 |
|
43 /* We exit here for consistency with other platforms. */ |
|
44 exit(status); |
|
45 } |
|
46 |
|
47 /* vi: set ts=4 sw=4 expandtab: */ |