Game Development Reference
In-Depth Information
time = newtime - oldtime;
} while (time < 1);
Qcommon_Frame (time);
oldtime = newtime;
}
}
This infinite loop does not work well with Android because Android's rendering thread
already has a loop of its own. Calling an infinite loop within another loop will deadlock the
rendering thread and will make your application crash. Therefore, you must comment the
infinite loop. You can also see that within the loop, one frame is rendered at a time using
Qcommon_Frame(time) . This is what you need; you can just extract what is inside this loop
and put it in RenderFrame() . Thus, the code in Listing 7-1 becomes the code in Listing 7-2.
Listing 7-2. Modified Quake II Main Function to Render a Single Frame
void RenderFrame()
{
int time, newtime;
static int oldtime;
// Init this var
if (oldtime == 0 )
oldtime = Sys_Milliseconds ();
do {
newtime = Sys_Milliseconds ();
time = newtime - oldtime;
} while (time < 1);
Qcommon_Frame (time);
oldtime = newtime;
}
int main (int argc, char **argv)
{
// ...
// main render loop?
#ifndef ANDROID
while (1) {
// find time spent rendering last frame
do {
newtime = Sys_Milliseconds ();
time = newtime - oldtime;
} while (time < 1);
Qcommon_Frame (time);
oldtime = newtime;
}
#endif
}
 
Search WWH ::




Custom Search