X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fmisc.c;h=657bc164f495b6f61e09fcbfcf9e4d6d53e6d99d;hb=4b0c6356359ee52f98cee8fa578179c6c41d4ef1;hp=b9127322837f809331da5a9450fa59356d47e5af;hpb=b7d31643c9c84104fb3ebef778e545928610ff65;p=rocksndiamonds.git diff --git a/src/misc.c b/src/misc.c index b9127322..657bc164 100644 --- a/src/misc.c +++ b/src/misc.c @@ -26,14 +26,31 @@ void microsleep(unsigned long usec) { - struct timeval delay; + if (usec < 5000) + { + /* we want to wait less than 5 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 */ - delay.tv_sec = usec / 1000000; - delay.tv_usec = usec % 1000000; + long base_counter = Counter2(), actual_counter = Counter2(); + long delay = usec/1000; - if (select(0,NULL,NULL,NULL,&delay)!=0) - fprintf(stderr,"%s: in function microsleep: select failed!\n", - progname); + while (actual_counter < base_counter+delay && + actual_counter >= base_counter) + actual_counter = Counter2(); + } + else + { + struct timeval delay; + + delay.tv_sec = usec / 1000000; + delay.tv_usec = usec % 1000000; + + if (select(0,NULL,NULL,NULL,&delay) != 0) + fprintf(stderr,"%s: in function microsleep: select failed!\n", + progname); + } } long mainCounter(int mode) @@ -167,3 +184,16 @@ char *GetLoginName() else return(pwd->pw_name); } + +void MarkTileDirty(int x, int y) +{ + int xx = redraw_x1 + x; + int yy = redraw_y1 + y; + + if (!redraw[xx][yy]) + { + redraw[xx][yy] = TRUE; + redraw_tiles++; + redraw_mask |= REDRAW_TILES; + } +}