Debian Codegraph @

project_files/Android-build/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp

raw
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_hedgeroid_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 argv[i] = (char*)malloc(env->GetStringUTFLength(jstringArgv[i]) + 1);
32 const char *str = env->GetStringUTFChars(jstringArgv[i], NULL);
33 strcpy(argv[i], str); //copy it to a mutable location
34 env->ReleaseStringUTFChars(jstringArgv[i], str);
35 }
36
37 /* Run the application code! */
38 int status = SDL_main(argc, argv);
39
40 //Clean up argv
41 for(int i = 0; i < argc; i++){
42 free(argv[i]);
43 }
44 }
45
46 /* vi: set ts=4 sw=4 expandtab: */