Game Development Reference
In-Depth Information
Changes are also required to s_sound.c to insert a call to jni_set_music_volume (volume) to
send the background music volume back to Java (see Listing 5-21). Note that this function is
called within the game when the user changes the music volume from the options menu.
Listing 5-21. Changes Required to s_sound.c to Insert the Music JNI Callback
void S_SetMusicVolume(int volume)
{
// Return if music is not enabled
if (!mus_card || nomusicparm)
return;
if (volume < 0 || volume > 15)
I_Error("S_SetMusicVolume: Attempt to set music volume at %d", volume);
// JNI Changes: Send a volume request to Java
// volume = [0..100]
jni_set_music_volume (volume);
I_SetMusicVolume(volume);
snd_MusicVolume = volume;
}
Video Buffer Changes
This is where the toughest changes must be done. The i_video.c file is the one that renders
the video buffer and uses SDL heavily. All SDL references must be removed and replaced
with structures compatible with Android.
Down to the pipe, a video buffer is simply an array of packed colors represented as either
bytes indicating the index of a color in a color palette or integers specifying an RGB color.
SDL uses a structure called SDL_Surface to encapsulate the video buffer as an array of bytes
plus a palette used to map colors to the buffer. Consider the following fragment, which
replaces the SDL screen with a similar structure called XImage (actually taken from the X11
structure of the same name):
static SDL_Surface *screen; // OLD CODE
static XImage * image; // NEW CODE
In Doom, SDL_Surface will be replaced with the equivalent XImage that holds the array of
bytes for the video buffer. Note that the video buffer cannot be rendered directly to a display.
Instead, it must be cascaded back to Java using the C to Java callbacks, where Android will
take care of the actual rendering.
Because XImage doesn't exist, it must be written. This isn't difficult because XImage is
simply a C struct holding the width, height, and array of bytes for the video buffer, as
shown in Listing 5-22.
 
Search WWH ::




Custom Search