Game Development Reference
In-Depth Information
jmethodID mid = (*env)->GetStaticMethodID(env, jNativesCls
, CB_CLASS_STOPM_CB
, CB_CLASS_STOPM_SIG);
if (mid) {
(*env)->CallStaticVoidMethod(env, jNativesCls
, mid
, (*env)->NewStringUTF(env, name)
);
}
}
/**
* Set bg msic vol callback
*/
void jni_set_music_volume (int vol) {
JNIEnv *env;
if ( !g_VM) {
return;
}
(*g_VM)->AttachCurrentThread (g_VM, (void **) &env, NULL);
jmethodID mid = (*env)->GetStaticMethodID(env, jNativesCls
, CB_CLASS_SETMV_CB
, CB_CLASS_SETMV_SIG);
if (mid) {
(*env)->CallStaticVoidMethod(env, jNativesCls
, mid
, (jint) vol
);
}
}
Fatal Errors
Fatal or unrecoverable errors occur in any type of software. In Doom, these errors are cascaded back to
Java, where a message is presented to the user, and then the application aborts. The next fragment from
jni_doom.h shows the callback name and signature for this task:
#define CB_CLASS_FATAL_CB "OnFatalError"
#define CB_CLASS_FATAL_SIG "(Ljava/lang/String;)V"
This callback is simple (see Listing 7-18). It works as follows:
It attaches to the current thread, aborting if no JNI environment is available.
Search WWH ::




Custom Search