Game Development Reference
In-Depth Information
6.
Finally, invoke Quake II
main
sub with the arguments that you
just created.
// Invoke Quake's main sub.
main (clen, args);
Rendering a Single Frame
Both the Java and C implementations for
RenderFrame
are the same as Chapter 6. In
Natives.java
you declared the native method
RenderFrame()
, which is implemented as
shown in the following fragment:
extern void RenderFrame();
JNIEXPORT jint JNICALL Java_quake_jni_Natives_RenderFrame
(JNIEnv * env, jclass cls)
{
RenderFrame();
}
The C keyword
extern
next to
void RenderFrame()
tells the compiler that elsewhere
exists a function called
RenderFrame
, which will be invoked within the JNI implementation.
RenderFrame
is a new function and needs to be created.
Listing 7-1 shows the Quake II
main
function from the project source at
ch07.QuakeII/jni/
quake2-3.21/android/sys_linux.c
. You notice that it loops forever (by using a
while (1)
loop).
Listing 7-1. Quake II Main Function
int main (int argc, char **argv)
{
int time, oldtime, newtime;
// go back to real user for config loads
saved_euid = geteuid();
seteuid(getuid());
Qcommon_Init(argc, argv);
nostdout = Cvar_Get("nostdout", "0", 0);
if (!nostdout->value) {
printf ("Linux Quake -- Version %0.3f\n", LINUX_VERSION);
}
oldtime = Sys_Milliseconds ();
// main render loop
while (1) {
// find time spent rendering last frame
do {
newtime = Sys_Milliseconds ();