From: havoc Date: Sun, 1 Feb 2004 22:30:51 +0000 (+0000) Subject: changed Sys_Sleep from (void) to (int milliseconds), now wastes a lot less cpu time... X-Git-Tag: xonotic-v0.1.0preview~6141 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=93ed14242647c8f0ca1ed8d5e3f3238e70671f07;p=xonotic%2Fdarkplaces.git changed Sys_Sleep from (void) to (int milliseconds), now wastes a lot less cpu time while waiting for the next frame git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3847 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_parse.c b/cl_parse.c index 90953375..dfe44a98 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -206,7 +206,7 @@ void CL_KeepaliveMessage (void) MSG_WriteChar(&msg, svc_nop); NetConn_SendUnreliableMessage(cls.netcon, &msg); // try not to utterly crush the computer with work, that's just rude - Sys_Sleep(); + Sys_Sleep(1); } } diff --git a/host.c b/host.c index f1943a74..09683f91 100644 --- a/host.c +++ b/host.c @@ -577,7 +577,7 @@ qboolean Host_FilterTime (double time) { // don't totally hog the CPU if (timeleft >= 0.02) - Sys_Sleep(); + Sys_Sleep(timeleft * 1000 - 5); return false; } } diff --git a/sys.h b/sys.h index 6b38df3e..73e2da0d 100644 --- a/sys.h +++ b/sys.h @@ -67,7 +67,7 @@ double Sys_DoubleTime (void); char *Sys_ConsoleInput (void); -void Sys_Sleep (void); +void Sys_Sleep(int milliseconds); // called to yield for a little bit so as // not to hog cpu when paused or debugging diff --git a/sys_linux.c b/sys_linux.c index 728ff5fd..c61e01b7 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -194,12 +194,14 @@ char *Sys_ConsoleInput(void) return NULL; } -void Sys_Sleep(void) +void Sys_Sleep(int milliseconds) { + if (milliseconds < 1) + milliseconds = 1; #ifdef WIN32 - Sleep (1); + Sleep(milliseconds); #else - usleep(1); + usleep(milliseconds * 1000); #endif } diff --git a/sys_sdl.c b/sys_sdl.c index bb236494..9c757167 100644 --- a/sys_sdl.c +++ b/sys_sdl.c @@ -195,13 +195,11 @@ char *Sys_ConsoleInput(void) return NULL; } -void Sys_Sleep(void) +void Sys_Sleep(int milliseconds) { -#ifdef WIN32 - Sleep (1); -#else - usleep(1); -#endif + if (milliseconds < 1) + milliseconds = 1; + SDL_Delay(milliseconds); } int SDL_main (int argc, char *argv[]) diff --git a/sys_win.c b/sys_win.c index 34f82380..f3ea0e28 100644 --- a/sys_win.c +++ b/sys_win.c @@ -271,9 +271,11 @@ char *Sys_ConsoleInput (void) return NULL; } -void Sys_Sleep (void) +void Sys_Sleep(int milliseconds) { - Sleep (1); + if (milliseconds < 1) + milliseconds = 1; + Sleep(milliseconds); }