Game Development Reference
In-Depth Information
Listing 6-17. Rendering a Single Frame in Quake
// sys_android.c: This will be invoked from JNI on each renderer frame
// This code is taken from the main while loop
void RenderFrame()
{
double time, newtime;
static double oldtime;
// Init this var
if (oldtime == 0.0 )
oldtime = Sys_FloatTime () - 0.1;
// find time spent rendering last frame
newtime = Sys_FloatTime ();
time = newtime - oldtime;
if (cls.state == ca_dedicated)
{
if (time < sys_ticrate.value )
{
usleep(1);
return; // not time to run a server only tic yet
}
time = sys_ticrate.value;
}
if (time > sys_ticrate.value*2)
oldtime = newtime;
else
oldtime += time;
Host_Frame (time);
// graphic debugging aids
if (sys_linerefresh.value)
Sys_LineRefresh ();
}
The JNI-C companion that implements Natives.RenderFrame and calls RenderFrame is declared
in the file jni_quake.c (under the ch06.Quake/jni/Quake/android in the topic source).
extern void RenderFrame();
JNIEXPORT jint JNICALL Java_quake_jni_Natives_RenderFrame
(JNIEnv * env, jclass cls)
{
RenderFrame();
}
 
Search WWH ::




Custom Search