Game Development Reference
In-Depth Information
(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 7-5 shows the callbacks on the left side and the Java methods they invoke on the right. The
callbacks can be divided into the following types:
•
Graphics initialization (
jni_init_graphics
)
Video buffer (
jni_send_pixels
)
•
Sound and music (
jni_start_sound, jni_start_music, jni_stop_music
and
jni_set_music_volume
)
•
Fatal errors (
jni_fatal_error
)
•
Table 7-5.
C to Java Callbacks in jni_doom.c
C Method
Invoked Java Method
void jni_init_graphics(int width, int
height)
static void OnInitGraphics(int w, int h)
void jni_send_pixels(int * data)
static void OnImageUpdate(int[] pixels)