Game Development Reference
In-Depth Information
For this purpose, Quake II defines the audio data structure dma as
// snd_loc.h
typedef struct
{
int channels;
int samples; // mono samples in buffer
int submission_chunk; // don't mix less than this #
int samplepos; // in mono samples
int samplebits;
int speed;
byte *buffer;
} dma_t;
extern dma_t dma;
When Quake II starts, it calls SNDDMA_Init to initialize the audio, and the following sequence
of events will take place to quickly start the audio playback:
When the user starts the game, the Java native method QuakeMain is
invoked, which translates the array of Java string arguments into a C
array and passes them to the Quake II engine.
1.
2.
Quake II starts up, processes the arguments, and at some point calls
SNDDMA_Init .
Once the audio and video are initialized, the C to Java callback jni_
init_video is called to send a message to the Java wrappers that
video is ready. At this point, the Java code starts the audio thread
declared in NativeAudio.java by invoking NativeAudio.start() .
3.
4.
Audio playback starts.
The jni_init_video callback is explained in detail in the section on video handling.
What to Do When Fatal Errors Occur
The user needs to be notified when a fatal error such as a crash or missing resource occurs.
For this purpose, you can use JNI to invoke a Java method, like so:
OnSysError(final String message)
This method could pop up a dialog box to notify the user of the error and then terminate the
program. Listing 7-6 presents such an implementation.
Listing 7-6. Handling Fatal Errors
// sys_linux.c
void Sys_Error (char *error, ...)
{
 
Search WWH ::




Custom Search