author | koda |
Tue, 21 Jan 2014 22:43:06 +0100 | |
changeset 10017 | de822cd3df3a |
parent 7554 | e50b266ed85a |
permissions | -rw-r--r-- |
5335 | 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 |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
5934
diff
changeset
|
20 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobjectArray strArray) |
5335 | 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); |
|
5353 | 27 |
char *argv[argc]; |
5335 | 28 |
jstring jstringArgv[argc]; |
29 |
for(int i = 0; i < argc; i++){ |
|
10017 | 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); |
|
5335 | 35 |
} |
10017 | 36 |
|
5335 | 37 |
/* Run the application code! */ |
7554
e50b266ed85a
Hedgeroid: Fixed memory handling issues
Medo <smaxein@googlemail.com>
parents:
6047
diff
changeset
|
38 |
int status = SDL_main(argc, argv); |
5335 | 39 |
|
40 |
//Clean up argv |
|
41 |
for(int i = 0; i < argc; i++){ |
|
10017 | 42 |
free(argv[i]); |
5335 | 43 |
} |
44 |
} |
|
45 |
||
46 |
/* vi: set ts=4 sw=4 expandtab: */ |