From 0ba7614739a3597c09d9a5fca598c14228f9dffc Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Sun, 14 Aug 2016 12:50:27 +0200 Subject: [PATCH] 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. --- src/backends/unix/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backends/unix/main.c b/src/backends/unix/main.c index 3388cea5..96ccd7e4 100644 --- a/src/backends/unix/main.c +++ b/src/backends/unix/main.c @@ -26,9 +26,8 @@ */ #include -#include #include -#include +#include #include #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; }