Advertisement
naf456

OUYAPlatform.cpp enterOuterspace (090913)

Sep 9th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. //this function loads are java helper class, which provides us
  2. //with needed functionality from the android OS.
  3. int enterOuterspace()
  4. {
  5.     // Ready are JNI interface.
  6.         ANativeActivity* activity = __state->activity;
  7.         JavaVM* jvm = __state->activity->vm;
  8.         JNIEnv* env = NULL;
  9.         jvm->GetEnv((void **)&env, JNI_VERSION_1_6);
  10.         jint res = jvm->AttachCurrentThread(&env, NULL);
  11.         if (res == JNI_ERR)
  12.         {
  13.             GP_ERROR("Failed to retrieve JVM environment when entering message pump.");
  14.             return -1;
  15.         }
  16.         GP_ASSERT(env);
  17.    
  18.         //Lets get an application context object using a special little trick.
  19.    
  20.         jclass activityClass = env->FindClass("android/app/NativeActivity");
  21.         GP_ASSERT(activityClass);
  22.    
  23.     jmethodID getClassLoader = env->GetMethodID(activityClass,"getClassLoader",
  24.         "()Ljava/lang/ClassLoader;");
  25.     GP_ASSERT(getClassLoader);
  26.    
  27.     jobject cls = env->CallObjectMethod(__state->activity->clazz, getClassLoader);
  28.     GP_ASSERT(cls);
  29.    
  30.     jclass classLoader = env->FindClass("java/lang/ClassLoader");
  31.     GP_ASSERT(classLoader);
  32.    
  33.     jmethodID findClass = env->GetMethodID(classLoader, "loadClass",
  34.         "(Ljava/lang/String;)Ljava/lang/Class;");
  35.     GP_ASSERT(findClass)
  36.    
  37.     jmethodID contextMethod = env->GetMethodID(activityClass, "getApplicationContext",
  38.         "()Landroid/content/Context;");
  39.     GP_ASSERT(contextMethod);
  40.    
  41.     jobject contextObj = env->CallObjectMethod(__state->activity->clazz, contextMethod);
  42.     GP_ASSERT(contextObj);
  43.    
  44.    
  45.     //We now call are java helper class methods.
  46.     jclass classHelper = env->FindClass("org/community/combat/engine/Gameplay3DHelper");
  47.         if(classHelper == 0)
  48.         {
  49.             print("Can't' Find Class! : org/community/combat/engine/Gameplay3DHelper");
  50.             GP_ASSERT();
  51.         }
  52.    
  53.         jmethodID methodHelperConstructor = env->GetMethodID(classHelper, "setupControllerAgent", "(android/content/Context)V");
  54.         if (methodHelperConstructor == NULL)
  55.     {
  56.             print("Can't Find MethodID! : setupControllerAgent");
  57.         GP_ASSERT();
  58.     }
  59.    
  60.         env->CallVoidMethod(classHelper, methodHelperConstructor,contextObj);
  61.         GP_ASSERT(helperObject);
  62.    
  63.         jvm->DetachCurrentThread();
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement