Game Development Reference
In-Depth Information
JNIEXPORT jint JNICALL Java_doom_jni_Natives_keyEvent
(JNIEnv * env, jclass cls, jint type, jint key)
{
event_t event;
event.type = (int)type;
event.data1 = (int)key;
D_PostEvent(&event);
return type + key;
}
/*
* Class: doom_util_Natives
* Method: motionEvent
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_doom_jni_Natives_motionEvent
(JNIEnv * env, jclass cls, jint x, jint y, jint z)
{
event_t event;
event.type = ev_mouse;
event.data1 = x;
event.data2 = y;
event.data3 = z;
D_PostEvent(&event);
return 0;
}
C to Java Callbacks
Table
5-5
shows the callbacks and the Java methods they invoke. The callbacks can be
divided into the following types:
Graphics initialization (
jni_init_graphics
)
jni_send_pixels
)
Sound and music (
Video buffer (
jni_start_sound
,
jni_start_music
,
jni_stop_music
,
and
jni_set_music_volume
)
Fatal errors (
jni_fatal_error
)