Game Development Reference
In-Depth Information
Message Updates
The message updates handler receives native messages, which are very helpful for
debugging. Listing 5-8 shows this handler, which logs the text to the Android console.
Listing 5-8. Message Update Handler
/**
* Fires on DSO message
*/
public void OnMessage(String text, int level) {
Log.d(TAG, "**Doom Message: " + text);
}
Fatal Error Handler
The fatal error handler deals with unrecoverable errors. This means displaying a message to
the user and exiting gracefully. There are many things that can cause unrecoverable errors,
such as code bugs, corrupted game files, I/O errors, and network failures.
Listing 5-9 shows how Doom deals with this situation. It uses a message handler to display
a message box to the user (remember that this method fires from a non-UI thread, where all
UI widget access must go through an OS handler). It then waits for a while so the user can
read the message and finally exits gracefully.
Listing 5-9. Fatal Error Handler
public void OnFatalError(final String text) {
mHandler.post(new Runnable() {
public void run() {
MessageBox("Fatal Error",
text + " - Please report this error.");
}
});
// Wait for the user to read the box
try {
Thread.sleep(8000);
} catch (InterruptedException e) {
}
// Must quit here or the LIB will crash
DoomTools.hardExit(-1);
}
Audio Request Handlers
The native Doom engine cannot access the sound device directly. This is due to the
nonstandard audio library used by Android (Enhanced Audio System [EAS] by SoniVOX,
and in Ice Cream Sandwich, Vorbis). To overcome this serious limitation, audio requests are
cascaded back to these handlers, which start sound events at a given volume, start and
stop background music events, and set the background music.
 
Search WWH ::




Custom Search