Game Development Reference
In-Depth Information
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 7-19.
Listing 7-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);
}
Commenting SDL Occurrences
The Doom engine is built on top of SDL, which is an open framework to access system resources such as
sound and video hardware. Doom uses SDL to display video and play music. This is a relatively hard
problem, as Android has no support for SDL. Thus, any SDL occurrence must be commented or
removed and replaced by a JNI equivalent. This happens in two files:
i_sound.c
and
i_video.c
.
Changes to
i_sound.c
are simple and consist of commenting the
sdl.h
header file and inserting
jni_doom.h
instead, as shown in the next fragment:
#include <sdl.h>
#include "include/jni_doom.h"
Furthermore, any function that starts with
SDL_
must be commented. Luckily, these functions do
not affect the game flow itself, and thus they can be safely commented.