示例#1
0
s3eResult ODKInit_platform()
{
    // Get the environment from the pointer
    JNIEnv* env = s3eEdkJNIGetEnv();

    jobject obj = NULL;
	jfieldID field = NULL;

    // Get the extension class
    jclass cls = s3eEdkAndroidFindClass("com/ODK/ODK");
    if (!cls)
        goto fail;

	IwTrace(ODK, ("ODK init Found: com/ODK/ODK"));

    field = env->GetStaticFieldID(cls, "m_Activity", "Lcom/ODK/ODK;");
    if (!field)
        goto fail;

	IwTrace(ODK, ("ODK init Found: GetStaticFieldID"));

    obj = env->GetStaticObjectField(cls,field);
	if (!obj)
        goto fail;

	IwTrace(ODK, ("ODK init Found: GetStaticObjectField "));
/*
    // Get its constructor
    cons = env->GetMethodID(cls, "<init>", "()V");
    if (!cons)
        goto fail;

    // Construct the java class
    obj = env->NewObject(cls, cons);
    if (!obj)
        goto fail;
*/
    // Get all the extension methods
    g_OuyaController_startOfFrame = env->GetMethodID(cls, "OuyaController_startOfFrame", "()V");
    if (!g_OuyaController_startOfFrame)
        goto fail;

    g_OuyaController_selectControllerByPlayer = env->GetMethodID(cls, "OuyaController_selectControllerByPlayer", "(I)Z");
    if (!g_OuyaController_selectControllerByPlayer)
        goto fail;

    g_OuyaController_selectControllerByDeviceID = env->GetMethodID(cls, "OuyaController_selectControllerByDeviceID", "(I)Z");
    if (!g_OuyaController_selectControllerByDeviceID)
        goto fail;

    g_OuyaController_getAxisValue = env->GetMethodID(cls, "OuyaController_getAxisValue", "(I)I");
    if (!g_OuyaController_getAxisValue)
        goto fail;

    g_OuyaController_getButton = env->GetMethodID(cls, "OuyaController_getButton", "(I)Z");
    if (!g_OuyaController_getButton)
        goto fail;

    g_OuyaController_buttonPressedThisFrame = env->GetMethodID(cls, "OuyaController_buttonPressedThisFrame", "(I)Z");
    if (!g_OuyaController_buttonPressedThisFrame)
        goto fail;

    g_OuyaController_buttonReleasedThisFrame = env->GetMethodID(cls, "OuyaController_buttonReleasedThisFrame", "(I)Z");
    if (!g_OuyaController_buttonReleasedThisFrame)
        goto fail;

    g_OuyaController_buttonChangedThisFrame = env->GetMethodID(cls, "OuyaController_buttonChangedThisFrame", "(I)Z");
    if (!g_OuyaController_buttonChangedThisFrame)
        goto fail;

    g_OuyaController_getPlayerNum = env->GetMethodID(cls, "OuyaController_getPlayerNum", "()I");
    if (!g_OuyaController_getPlayerNum)
        goto fail;



    IwTrace(ODK, ("ODK init success"));
    g_Obj = env->NewGlobalRef(obj);
    env->DeleteLocalRef(obj);
    env->DeleteGlobalRef(cls);

    // cache class references
    g_pluginOuya.CacheClasses(env);

    // Add any platform-specific initialisation code here
    return S3E_RESULT_SUCCESS;

fail:
    jthrowable exc = env->ExceptionOccurred();
    if (exc)
    {
        env->ExceptionDescribe();
        env->ExceptionClear();
        IwTrace(ODK, ("One or more java methods could not be found"));
    }
    return S3E_RESULT_ERROR;

}
s3eResult ODKInit_platform()
{
    __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Marmalade Plugin Native Version: 0.0.1");
    IwTrace(ODK, ("Marmalade Plugin Native Version: 0.0.1"));


    // Get the environment from the pointer
    JNIEnv* env = s3eEdkJNIGetEnv();

    for (int index = 0; index < MAX_CONTROLLERS; ++index)
    {
        g_axis.push_back(std::map<int, float>());
        g_button.push_back(std::map<int, bool>());
        g_buttonDown.push_back(std::map<int, bool>());
        g_buttonUp.push_back(std::map<int, bool>());
        g_lastButtonDown.push_back(std::map<int, bool>());
        g_lastButtonUp.push_back(std::map<int, bool>());
    }

    __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Find OuyaInputView...");
    jclass clazz = env->FindClass("tv/ouya/sdk/marmalade/OuyaInputView");
    if (clazz)
    {
        jint ret = env->RegisterNatives(clazz, method_table, method_table_size);
        ret = env->RegisterNatives(clazz, method_table2, method_table_size2);

        const char* strField = "sNativeInitialized";
        jfieldID fieldNativeInitialized = env->GetStaticFieldID(clazz, strField, "Z");
        env->SetStaticBooleanField(clazz, fieldNativeInitialized, true);
        env->DeleteLocalRef(clazz);
        __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Loaded Native Plugin: 003");
    }
    else
    {
        IwTrace(ODK, ("*********************Failed to find OuyaInputView"));
        goto fail;
    }

    if (JSONArray::InitJNI(env) == JNI_ERR)
    {
        goto fail;
    }

    if (JSONObject::InitJNI(env) == JNI_ERR)
    {
        goto fail;
    }

    if (OuyaController::InitJNI(env) == JNI_ERR)
    {
        goto fail;
    }

    // cache class references
    g_pluginOuya.CacheClasses(env);

    // Add any platform-specific initialization code here
    return S3E_RESULT_SUCCESS;

fail:
    jthrowable exc = env->ExceptionOccurred();
    if (exc)
    {
        env->ExceptionDescribe();
        env->ExceptionClear();
        IwTrace(ODK, ("One or more java methods could not be found"));
    }
    return S3E_RESULT_ERROR;

}