Game Development Reference
In-Depth Information
if (mid) {
(*env)->CallStaticVoidMethod(env, jNativesCls
, mid
, (*env)->NewStringUTF(env, text) );
}
else {
printf("JNI FATAL: Unable to find method: %s, signature: %s\n"
, CB_CLASS_MSG_CB, CB_CLASS_MSG_SIG );
exit (-1);
}
}
Original Game Changes
In order for the JNI glue to work, changes are required to the original game engine. Some are
simple, such as inserting calls to the C to Java callbacks; some are not so simple, such as
removing invalid dependencies. Table 5-6 shows the original files and the changes required.
Considering that the engine has a total of 90,000 lines of code, these changes are not that bad.
Table 5-6. Changes Required to the Original Engine to Insert the JNI Glue
File
Changes
i_main.c
Rename the main subroutine to doom_main .
i_system.c
In I_Error , insert jni_fatal_error .
i_sound.c
Comment SDL dependencies. In I_StartSound , insert start sound callback
jni_start_sound .
s_sound.c
In S_SetMusicVolume , insert volume callback jni_set_music_volume .
i_video.c
Comment SDL dependencies. Insert code to build an Android ARBG pixel array
from the video buffer. In I_SetRes , add JNI callback to initialize graphics. In
I_FinishUpdate , send pixels to Java with jni_send_pixels .
These changes are explained in more detail in the following sections.
Renaming main
Let's start with the simplest change: renaming the main() subroutine in i_main.c so it can
be invoked from the Java native Java_doom_jni_Natives_DoomMain , which will start the game
from Java, as shown in the following fragment:
// In i_main.c
int main(int argc, char **argv)
int doom_main(int argc, char **argv)
 
 
Search WWH ::




Custom Search