Game Development Reference
In-Depth Information
Listing 5-16. Sending Video Pixels
/**
* Image update Java callback. Gets called many times per sec.
* It must not look up JNI classes/methods or create any objects; otherwise
* the local JNI ref table will overflow & the app will crash
*/
void jni_send_pixels(int * data)
{
JNIEnv *env;
if ( !g_VM) {
return;
}
(*g_VM)->AttachCurrentThread (g_VM, (void **) &env, NULL);
// Send img back to Java.
if (jSendImageMethod) {
(*env)->SetIntArrayRegion(env, jImage, 0, iSize, (jint *) data);
// Call Java method
(*env)->CallStaticVoidMethod(env, jNativesCls
, jSendImageMethod
, jImage);
}
}
Sound and Music Callbacks
The sound and music callbacks fire from the engine when a sound or background music
must be played. In a perfect world, sound would be handled in the native layer; however,
due to the lack of documentation and support for open audio standards in Android, requests
are cascaded back to Java for processing.
There are four sound and music callbacks in Doom, with their names and signatures defined
in the header jni_doom.h :
// doom.jni.Natives.OnStartSound(byte[] name, int volume)
#define CB_CLASS_SS_CB "OnStartSound"
#define CB_CLASS_SS_SIG "([BI)V"
// doom.jni.Natives.OnStartMusic (String name , int loop)
#define CB_CLASS_SM_CB "OnStartMusic"
#define CB_CLASS_SM_SIG "(Ljava/lang/String;I)V"
// doom.jni.Natives.OnStopMusic (String name )
#define CB_CLASS_STOPM_CB "OnStopMusic"
#define CB_CLASS_STOPM_SIG "(Ljava/lang/String;)V"
// doom.jni.Natives.OnSetMusicVolume (int volume)
#define CB_CLASS_SETMV_CB "OnSetMusicVolume"
#define CB_CLASS_SETMV_SIG "(I)V"
 
Search WWH ::




Custom Search