Game Development Reference
In-Depth Information
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 following 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.
Sound System Changes
Other changes are required to i_sound.c to insert a call to jni_start_sound , as shown in
Listing 5-20. The global variable S_sfx[id].name provides the sound name, which will be
sent back to Java and loaded from the file system, along with its volume.
Listing 5-20. Changes Required to i_sound.c to Insert the jni_start_sound Callback
int I_StartSound(int id, int channel, int vol, int sep, int pitch, int priority)
{
const unsigned char* data;
int lump;
size_t len;
// ...
// The entries DSBSPWLK, DSBSPACT, DSSWTCHN
// and DSSWTCHX are all zero-length sounds
if (len<=8) return -1;
/* Find padded length */
len -= 8;
// Do the lump caching outside the SDL_LockAudio/SDL_UnlockAudio pair
// Use locking which makes sure the sound data is in a malloced area and
// not in a memory mapped one
data = W_LockLumpNum(lump);
// JNI changes: Send a sound request to Java
// id is the sound index, S_sfx[id].name (soundname)
// vol = volume
jni_start_sound(S_sfx[id].name , vol);
// ...
return channel;
}
 
Search WWH ::




Custom Search