Game Development Reference
In-Depth Information
boolean SD_PlaySoundSOD(soundnamesSOD sound)
{
// New code for Android
jni_start_sound (sound);
return true;
}
Listing 6-18 also shows the changes required to the native sound handlers (in sd_null.c ) to call the
C to Java callbacks:
SD_PlaySoundWL6 (soundnamesWL6 sound) : This is the handler for the Wolf 3D
chapter of the game. soundnamesWL6 s a C enumeration described in audiowl6.h ,
which defines the IDs for sounds and music.
SD_PlaySoundSOD (soundnamesSOD sound) : This is the handler for the Spear of
Destiny (SOD) chapter of the game. soundnamesSOD s a C enumeration described in
audiosod.h which defines the IDs for sounds and music.
Finally, you are ready to compile the code and see how it works on the device. Here is how.
Compiling the Native Library
The native library (or Dynamic Shared Object - DSO) contains all the native code and interacts with the
Java side of Wolf 3D. Before we can test the game in the emulator, this library must be compiled. Here
are the steps required to do this:
1.
Write a Makefile to compile the native code.
2.
Generate the JNI headers required by the JNI interface.
3.
Compile the native code into the dynamic shared library (DSO):
libwolf_jni.so .
Place the DSO under the libs/armeabi folder of the main project.
4.
5.
Start the project in the emulator.
Writing the Makefile
The Makefile for Wolf 3D uses the agcc and ald scripts for compiling and linking defined in Chapter 1.
Some interesting features of this file are described in Listing 6-19:
Compilation : We use -wall to display all warnings and -O2 to define a level of
optimization.
Linking : The linking step is performed by the script: ald -shared -o
libwolf_jni.so $(OBJS) , where -shared tells the compiler to build a shared library
and -o defines the name of the output library ( libwolf_jni.so ).
Search WWH ::




Custom Search