|
|
@ -3166,10 +3166,12 @@ void |
|
|
|
run(void) { |
|
|
|
run(void) { |
|
|
|
XEvent ev; |
|
|
|
XEvent ev; |
|
|
|
fd_set rfd; |
|
|
|
fd_set rfd; |
|
|
|
int xfd = XConnectionNumber(xw.dpy), i; |
|
|
|
int xfd = XConnectionNumber(xw.dpy); |
|
|
|
struct timeval drawtimeout, *tv = NULL; |
|
|
|
struct timeval drawtimeout, *tv = NULL, now, last; |
|
|
|
|
|
|
|
|
|
|
|
for(i = 0;; i++) { |
|
|
|
gettimeofday(&last, NULL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(;;) { |
|
|
|
FD_ZERO(&rfd); |
|
|
|
FD_ZERO(&rfd); |
|
|
|
FD_SET(cmdfd, &rfd); |
|
|
|
FD_SET(cmdfd, &rfd); |
|
|
|
FD_SET(xfd, &rfd); |
|
|
|
FD_SET(xfd, &rfd); |
|
|
@ -3179,35 +3181,44 @@ run(void) { |
|
|
|
die("select failed: %s\n", SERRNO); |
|
|
|
die("select failed: %s\n", SERRNO); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
gettimeofday(&now, NULL); |
|
|
|
* Stop after a certain number of reads so the user does not |
|
|
|
/* usecs until (next) frame */ |
|
|
|
* feel like the system is stuttering. |
|
|
|
drawtimeout.tv_sec = 0; |
|
|
|
*/ |
|
|
|
drawtimeout.tv_usec = \
|
|
|
|
if(i < 1000 && FD_ISSET(cmdfd, &rfd)) { |
|
|
|
((1000/framespersecond) - TIMEDIFF(now, last)) * 1000; |
|
|
|
ttyread(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/* Let us draw a frame. */ |
|
|
|
* Just wait a bit so it isn't disturbing the |
|
|
|
if(drawtimeout.tv_usec <= 0) { |
|
|
|
* user and the system is able to write something. |
|
|
|
draw(); |
|
|
|
*/ |
|
|
|
XFlush(xw.dpy); |
|
|
|
drawtimeout.tv_sec = 0; |
|
|
|
|
|
|
|
drawtimeout.tv_usec = 5; |
|
|
|
last = now; |
|
|
|
tv = &drawtimeout; |
|
|
|
tv = NULL; |
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
i = 0; |
|
|
|
|
|
|
|
tv = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(XPending(xw.dpy)) { |
|
|
|
if(FD_ISSET(cmdfd, &rfd)) |
|
|
|
XNextEvent(xw.dpy, &ev); |
|
|
|
ttyread(); |
|
|
|
if(XFilterEvent(&ev, None)) |
|
|
|
|
|
|
|
continue; |
|
|
|
if(FD_ISSET(xfd, &rfd)) { |
|
|
|
if(handler[ev.type]) |
|
|
|
while(XPending(xw.dpy)) { |
|
|
|
(handler[ev.type])(&ev); |
|
|
|
XNextEvent(xw.dpy, &ev); |
|
|
|
|
|
|
|
if(XFilterEvent(&ev, None)) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
if(handler[ev.type]) |
|
|
|
|
|
|
|
(handler[ev.type])(&ev); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(drawtimeout.tv_usec <= 0) { |
|
|
|
|
|
|
|
draw(); |
|
|
|
|
|
|
|
XFlush(xw.dpy); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
draw(); |
|
|
|
/* There is still some time to wait until next frame. */ |
|
|
|
XFlush(xw.dpy); |
|
|
|
if(drawtimeout.tv_usec > 0) { |
|
|
|
|
|
|
|
tv = &drawtimeout; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|