Game Development Reference
In-Depth Information
Most of the native access methods reside in the class Natives.java ; they are as follows:
native void QuakeMain(String[] argv) : This method calls the Quake
II main method. Its job is to convert the Java String arguments ( argv )
into a C array that can be fed into the engine. It also loads the Natives.
java class to fire up callbacks when the native engine needs to send a
message back to Java (for example, when a system/fatal error occurs
and the application needs to terminate). This method requires no change
to work with Quake II.
native void RenderFrame() : This native method renders a single frame
of the game. You must do so to play nice with the Android OpenGL
surface renderer, which uses a separate thread to render one frame at a
time. This method requires no change to work with Quake II.
native int keyPress(int key) and keyRelease(int key) : These two
are used to push ASCII keys into the key processor. Note that the
Android key codes will be translated into ASCII by the Java wrappers.
These methods need to be updated to work with Quake II.
native void mouseLook(int mouseX, int mouseY) : This method is used
to look around the 3D space when the player sweeps a finger across the
screen. It receives delta coordinates for yaw ( mouseX ) and pitch ( mouseY ).
This method requires no change.
native void mouseMove(int mouseX, int mouseY) : This method is used
to move the characters forward or sideways in 3D space. It receives
delta coordinates in the XY axis. This method requires no change.
native void PaintAudio( ByteBuffer buf ) : This method reads a byte
buffer of audio from the C engine into a Java buffer and writes it into the
device audio hardware using Android's MediaTrack API. This method
requires no change.
Game Startup
QuakeMain is the function that kicks things off. It starts the Quake II engine with a given
array of arguments. The following fragment shows its declaration and Natives.java and C
implementation in jni_quake.c :
Note The C implementations for all the native Java methods in Natives.java are located in the
project source under ch07.QuakeII/jni/quake2-3.21/android/jni_quake.c .
 
 
Search WWH ::




Custom Search