Game Development Reference
In-Depth Information
onSurfaceChanged : This event fires whenever the surface changes, such
as when it is first created or when the orientation of the parent changes.
It can fire many times throughout the lifetime of the application.
onSurfaceCreated : This event fires only once when the surface is
first created. It receives a GL context ( GL10 ) and the GL configuration
( EGLConfig ). It is useful to adjust the graphics configuration such as
pixel, format, depth buffer, and more.
Natives : This is a user-defined interface class to all things native. It
contains the definitions of the native methods to be called from Java,
which are as follows:
QuakeMain(String[] argv) : This is the main entry point to the
engine. It essentially calls the main C function with an array of string
arguments.
RenderFrame() : This native function renders 1 frame of the game.
keyPress(int key) : This function sends an ASCII key-pressed event
to the engine.
keyRelease(int key) : This function sends an ASCII key-released
event to the engine.
mouseLook(int mouseX, int mouseY) : This native function is used to
send the XY delta coordinates of a touch event used to look around
3D space whenever a finger is dragged on screen.
PaintAudio(ByteBuffer buf) : This function is used to read a byte
buffer from the native audio buffer of the engine. The buffer is then
played from Java using the Android MediaTrack API.
Natives class also wraps a set of JNI-C callbacks that the engine
uses to send information back to the thin Java wrappers (see Listing 6-4).
These callbacks are as follows:
OnInitVideo(int w, int h) : This tells Java that the native video has
been initialized. It is used to start the Java audio thread.
OnSysError(String message) : This method is called by the engine
when a fatal system error occurs and the program needs to
terminate.
The
Listing 6-4. Java Class for Native Functions and C Callbacks
package quake.jni;
import java.nio.ByteBuffer;
import android.util.Log;
public class Natives {
public static final String TAG = "Natives";
private static EventListener listener;
 
Search WWH ::




Custom Search