X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fmisc.c;h=253a8d7fcee20e336a05b27b9b68843987a34c32;hp=944458f5669d0bd63d486123b3978d773c5aa8cc;hb=b2a0ff1ddd4430110b331129469dabb8ea7b6ba7;hpb=c4baa69cc8d5e8398425e67498b49f4b77f8e477 diff --git a/src/misc.c b/src/misc.c index 944458f5..253a8d7f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1,22 +1,16 @@ /*********************************************************** * Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* ©1995 Artsoft Development * -* Holger Schemel * -* 33659 Bielefeld-Senne * -* Telefon: (0521) 493245 * -* eMail: aeglos@valinor.owl.de * -* aeglos@uni-paderborn.de * -* q99492@pbhrzx.uni-paderborn.de * +* (c) 1995-98 Artsoft Entertainment * +* Holger Schemel * +* Oststrasse 11a * +* 33604 Bielefeld * +* phone: ++49 +521 290471 * +* email: aeglos@valinor.owl.de * *----------------------------------------------------------* * misc.c * ***********************************************************/ -#include "misc.h" -#include "tools.h" -#include "sound.h" -#include "random.h" - #include #include #include @@ -24,6 +18,11 @@ #include #include +#include "misc.h" +#include "tools.h" +#include "sound.h" +#include "random.h" + static unsigned long mainCounter(int mode) { static struct timeval base_time = { 0, 0 }; @@ -53,9 +52,9 @@ unsigned long Counter() /* get milliseconds since last call of InitCounter() */ static void sleep_milliseconds(unsigned long milliseconds_delay) { - if (milliseconds_delay < 5 || !cpu_friendly) + if (milliseconds_delay < 5) { - /* we want to wait less than 5 ms -- if we assume that we have a + /* we want to wait only a few ms -- if we assume that we have a kernel timer resolution of 10 ms, we would wait far to long; therefore it's better to do a short interval of busy waiting to get our sleeping time more accurate */ @@ -110,10 +109,18 @@ BOOL DelayReached(unsigned long *counter_var, unsigned long delay) void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay) { - unsigned long actual_counter = Counter(); + unsigned long actual_counter; - if (actual_counter < *counter_var + delay && actual_counter >= *counter_var) - sleep_milliseconds(*counter_var + delay - actual_counter); + while(1) + { + actual_counter = Counter(); + + if (actual_counter < *counter_var + delay && + actual_counter >= *counter_var) + sleep_milliseconds((*counter_var + delay - actual_counter) / 2); + else + break; + } *counter_var = actual_counter; }