Game Development Reference
In-Depth Information
// Load doom.util.Natives.OnImageUpdate(char[])
jSendImageMethod = (*env)->GetStaticMethodID(env, jNativesCls
, CB_CLASS_IU_CB
, CB_CLASS_IU_SIG);
if ( jSendImageMethod == 0 ) {
jni_printf("Unable to find method OnImageUpdate(): %s"
, CB_CLASS);
return -1;
}
// Load OnStartSound(String name, int vol)
jStartSoundMethod = (*env)->GetStaticMethodID(env, jNativesCls
, CB_CLASS_SS_CB
, CB_CLASS_SS_SIG);
if ( jStartSoundMethod == 0 ) {
jni_printf("Unable to find method OnStartSound signature: %s "
, CB_CLASS_SS_SIG);
return -1;
}
// Invoke Doom's main sub. This will loop forever
doom_main (clen, args);
return 0;
}
Key and Motion Events
Key and motion events are posted via the extern symbol D_PostEvent , as shown in
Listing 5-14. The event type ( event_t ) is defined by the engine and consists of the following:
A type (0 for key down, 1 for key up, and 2 for mouse events).
An ASCII key stored in
event.data1 for key events.
A mouse button and x and y coordinates for mouse events, stored as
event.data1 = MOUSE BUTTON , event.data2 = x , and event.data3 = y .
Mouse buttons can be 1 for left, 2 for middle, or 3 for right.
Listing 5-14. Posting Key and Motion Events with JNI
/*
* Class: doom_util_Natives
* Method: keyEvent
* Signature: (II)V
*/
extern void D_PostEvent (event_t* ev);
 
Search WWH ::




Custom Search