Game Development Reference
In-Depth Information
Load the doom.jni.Natives.OnImageUpdate and doom.jni.natives.OnStartSound
Java methods. This is done for performance reasons, as these methods are called
many times.
Listing 7-13 shows the native game loop.
Listing 7-13. JNI Call to the Main Game Loop
/*
* Class: doom_jni_Natives
* Method: DoomMain
* Signature: ([Ljava/lang/String;)V
*/
JNIEXPORT jint JNICALL Java_doom_jni_Natives_DoomMain
(JNIEnv * env, jclass class, jobjectArray jargv)
{
// Obtain a global ref to the Java VM
(*env)->GetJavaVM(env, &g_VM);
// Extract char ** args from Java array
jsize clen = getArrayLen(env, jargv);
char * args[(int)clen];
int i;
jstring jrow;
for (i = 0; i < clen; i++)
{
jrow = (jstring)(*env)->GetObjectArrayElement(env, jargv, i);
const char *row = (*env)->GetStringUTFChars(env, jrow, 0);
args[i] = malloc( strlen(row) + 1);
strcpy (args[i], row);
jni_printf("Main argv[%d]=%s", i, args[i]);
// Free Java string jrow
(*env)->ReleaseStringUTFChars(env, jrow, row);
}
/*
* Load the Image update class (called many times)
*/
jNativesCls = (*env)->FindClass(env, CB_CLASS);
if ( jNativesCls == 0 ) {
jni_printf("Unable to find class: %s", CB_CLASS);
return -1;
}
Search WWH ::




Custom Search