project_files/Android-build/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp
author Xeli
Fri, 01 Jul 2011 21:30:33 +0200
branchhedgeroid
changeset 5389 b3cc5b4099f1
parent 5353 37b0fb82e22c
child 5934 9f05a0f43003
permissions -rw-r--r--
Changed package name from org.hedgewars to org.hedgewars.mobile


/* Include the SDL main definition header */
#include "SDL_main.h"

/*******************************************************************************
                 Functions called by JNI
*******************************************************************************/
#include <jni.h>

// Called before SDL_main() to initialize JNI bindings in SDL library
extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls);

// Library init
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    return JNI_VERSION_1_4;
}

// Start up the SDL app
extern "C" void Java_org_hedgewars_mobile_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobjectArray strArray)
{
    /* This interface could expand with ABI negotiation, calbacks, etc. */
    SDL_Android_Init(env, cls);

    //Get the String array from java
    int argc = env->GetArrayLength(strArray);
    char *argv[argc];
    jstring jstringArgv[argc];
    for(int i = 0; i < argc; i++){
        jstringArgv[i] = (jstring)env->GetObjectArrayElement(strArray, i);  //get the element
	argv[i] = (char*)malloc(sizeof(char) * env->GetStringLength(jstringArgv[i]));
	strcpy(argv[i], env->GetStringUTFChars(jstringArgv[i], JNI_FALSE)); //copy it to a mutable location
	//Don't release memory the JAVA GC will take care of it
        //env->ReleaseStringChars(jstringArgv[i], (jchar*)argv[i]);           
    }
    
    /* Run the application code! */
    int status;
    status = SDL_main(argc, argv);

    //Clean up argv
    for(int i = 0; i < argc; i++){
    }

    /* We exit here for consistency with other platforms. */
    exit(status);
}

/* vi: set ts=4 sw=4 expandtab: */