Advertisement
Selzier

Untitled

Oct 15th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. void onIncrementAchievement(unsigned char _iArgumentCount, const void *_pArguments, void *_pUserData){
  2.     JNIEnv *pJNIEnv = GetJNIEnv();
  3.     if (pJNIEnv){
  4.         if ( _pArguments && ( _iArgumentCount > 0 ) ){
  5.         const S3DX::AIVariable *pVariables = (const S3DX::AIVariable *)_pArguments ;
  6.         for ( uint8_t i = 0 ; i < _iArgumentCount ; i++ ){
  7.             //We only want strings
  8.             if(pVariables[i].GetType() == S3DX::AIVariable::eTypeString){
  9.                 //LOGI( "incrementAchievement returned string: %s", pVariables[i].GetStringValue() );
  10.                 //Find our main class so we can call the incrementAchievement function.  For me, my package name is:
  11.                 //com.hypercanestudios.acceleroketer
  12.                 //within that package I have a class called accelerocketer
  13.                 //so <package name>/<class name> and replace "." with "/"
  14.                 // CHANGE ME!
  15.                 jclass pJNIActivityClass = pJNIEnv->FindClass ( "com/nurfacegames/testgame01/TestGame01" );
  16.  
  17.                 if(pJNIActivityClass == NULL)
  18.                     LOGI("jclass was null!?!");
  19.                     else{
  20.                     //Now we have to find the function we're trying to call. We use the class defined above since the function
  21.                     //is a member of that class.  (Ljava/lang/String;) is the set of arguments that the function takes, a single String
  22.                     //V means that the function returns void
  23.                     //void incrementAchievement(String blah)
  24.                     //See table 3-2 http://docs.oracle.com/javase/1.3/docs/guide/jni/spec/types.doc.html#597
  25.  
  26.                     jmethodID pJNIMethodID = pJNIEnv->GetStaticMethodID(pJNIActivityClass, "onIncrementAchievement", "(Ljava/lang/String;)V", "(Ljava/lang/Integer;)V" );
  27.  
  28.                     if(pJNIMethodID == NULL)
  29.                         LOGI("jmethodID was null!?!?");
  30.                     else{
  31.                         //Create a new string
  32.                         jstring arg;
  33.                         arg = pJNIEnv->NewStringUTF(pVariables[i].GetStringValue());
  34.  
  35.                         jint arg2 = pVariables[1].GetNumberValue();
  36.                         if(arg2 == NULL)
  37.                             LOGI("ARGUMENT MISSING!!");
  38.                         else{
  39.                             //Call the method and pass the string parameter along
  40.                             pJNIEnv->CallStaticVoidMethod(pJNIActivityClass, pJNIMethodID, arg, arg2);
  41.                             //Free the string
  42.                             pJNIEnv->DeleteLocalRef(arg);
  43.                         }
  44.                     }
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement