Game Development Reference
In-Depth Information
, "OnImageUpdate"
, "([IIIII)V");
if ( jSendImageMethod == 0 ) {
jni_printf("Unable to find method wolf.jni.OnImageUpdate(byte[])");
return -1;
}
// Load OnStartSound(int id)
jStartSoundMethod = (*env)->GetStaticMethodID(env, jNativesCls
, "OnStartSound"
, "(I)V");
if ( jStartSoundMethod == 0 ) {
jni_printf("Unable to find method wolf.jni.OnStartSound sig: ([BI)V");
return -1;
}
// Print args
for (i = 0; i < clen; i++) {
jni_printf("WolfMain args[%d]=%s", clen, args[i]);
}
// Invoke Quake's main sub. This will loop forever
wolf_main (clen, args);
return 0;
}
Cascading Messages with C to Java Callbacks
C to Java callbacks are used to cascade native events such as video and sound events back to the Java
activity. The callbacks require a JNI implementation plus some tiny changes to the original C files. There
are three types of callbacks in Wolf 3D:
Graphics initialization : It is the very first callback that should fire to notify the
main activity of the size (width and height) of the video buffer. The main activity
will in turn use this information to create a bitmap to be displayed on the device.
Video buffer update : This callback must fire after graphics initialization and send
an Android packed ARGB bitmap back to the main activity for display.
Sound and music requests : These are used to tell the main activity that a sound or
background music must be played.
Initializing Graphics
Listing 6-15 shows the way graphics are initialized in the game. There are two functions in two different
files: jni_init_graphics (int width, int height) in jni_wolf.c and VL_Startup() in vi_null.c .
jni_init_graphics implements the C to Java callback that tells the main activity that graphics are
ready. It sends the width and height of the video buffer, and they are used to create a Java bitmap that
Search WWH ::




Custom Search