mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-22 12:41:21 +00:00
Use nanosleep() instead of a busy wait loop.
This cuts the cpu time requirements in half. Windows has no equivalent for nanosleep(), so keep the busy loop.
This commit is contained in:
parent
98683cbc31
commit
0ba7614739
1 changed files with 7 additions and 2 deletions
|
@ -26,9 +26,8 @@
|
|||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <locale.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../common/header/common.h"
|
||||
|
@ -40,6 +39,7 @@ main(int argc, char **argv)
|
|||
int time, oldtime, newtime;
|
||||
int verLen, i;
|
||||
const char* versionString;
|
||||
struct timespec t;
|
||||
|
||||
/* register signal handler */
|
||||
registerHandler();
|
||||
|
@ -123,6 +123,7 @@ main(int argc, char **argv)
|
|||
fcntl(fileno(stdin), F_SETFL, fcntl(fileno(stdin), F_GETFL, NULL) | FNDELAY);
|
||||
|
||||
oldtime = Sys_Milliseconds();
|
||||
t.tv_sec = 0;
|
||||
|
||||
/* The legendary Quake II mainloop */
|
||||
while (1)
|
||||
|
@ -130,6 +131,10 @@ main(int argc, char **argv)
|
|||
/* find time spent rendering last frame */
|
||||
do
|
||||
{
|
||||
/* Sleep 10 microseconds */
|
||||
t.tv_nsec = 10000;
|
||||
nanosleep(&t, NULL);
|
||||
|
||||
newtime = Sys_Milliseconds();
|
||||
time = newtime - oldtime;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue