Game Development Reference
In-Depth Information
// In jni_doom.c
extern int doom_main(int argc, char **argv);
JNIEXPORT jint JNICALL Java_doom_jni_Natives_DoomMain
(JNIEnv * env, jclass class, jobjectArray jargv)
{
...
doom_main (clen, args);
...
}
Once main is renamed to doom_main , simply add the extern symbol extern int doom_
main(int argc, char **argv) to jni_doom.c and invoke it from the game starter function.
Inserting the Fatal Error Callback
Another simple change is to insert the C to Java callback jni_fatal_error whenever an
unrecoverable error occurs. The changes occur in the I_Error function in the i_system.c file,
as shown in Listing 5-19.
Listing 5-19. Changes Required to i_system.c
void I_Error (char *error, ...)
{
va_list argptr;
static char string[1024];
// Message first.
va_start (argptr,error);
vsprintf (string, error ,argptr);
va_end (argptr);
// Shutdown. Here might be other errors.
if (demorecording)
G_CheckDemoStatus();
D_QuitNetGame ();
I_ShutdownGraphics();
// Send the error back to JNI layer
jni_fatal_error(string);
// Something wrong has happened
// OLD CODE -> exit(-1);
}
 
Search WWH ::




Custom Search