diff options
author | Bardur Arantsson <bardur@scientician.net> | 2014-12-16 18:51:06 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2014-12-16 18:54:55 +0100 |
commit | 4d351b8d07c25415d5848e9486eb5cb52f02d72e (patch) | |
tree | 0b8045630e146eaa870280e2d3e7f13e50499ad2 /src/util.cc | |
parent | ff252acf7f2f38e33017e82881c95825b54c7cee (diff) |
Replace usleep with C++11 this_thread::sleep_for()
Also remove TERM_XTRA_DELAY. The terminal abstraction should
not be used for providing general platform independence. As a
side effect this reintroduces support for "delay" on SDL, not
sure if that's a good idea or not.
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 61 |
1 files changed, 6 insertions, 55 deletions
diff --git a/src/util.cc b/src/util.cc index 13a19ba2..a4c00a26 100644 --- a/src/util.cc +++ b/src/util.cc @@ -8,58 +8,12 @@ #include "quark.h" #include <boost/algorithm/string/predicate.hpp> +#include <chrono> +#include <thread> using boost::algorithm::iequals; - - -#ifdef SET_UID - -# ifndef HAS_USLEEP - -/* -* For those systems that don't have "usleep()" but need it. -* -* Fake "usleep()" function grabbed from the inl netrek server -cba -*/ -int usleep(huge usecs) -{ - struct timeval Timer; - - int nfds = 0; - -#ifdef FD_SET - fd_set *no_fds = NULL; -#else -int *no_fds = NULL; -#endif - - - /* Was: int readfds, writefds, exceptfds; */ - /* Was: readfds = writefds = exceptfds = 0; */ - - - /* Paranoia -- No excessive sleeping */ - if (usecs > 4000000L) { - usecs = 4000000L; - } - - /* Wait for it */ - Timer.tv_sec = (usecs / 1000000L); - Timer.tv_usec = (usecs % 1000000L); - - /* Wait for it */ - if (select(nfds, no_fds, no_fds, no_fds, &Timer) < 0) - { - /* Hack -- ignore interrupts */ - if (errno != EINTR) return -1; - } - - /* Success */ - return 0; -} - -# endif - +using std::this_thread::sleep_for; +using std::chrono::milliseconds; /* * Find a default user name from the system. @@ -83,9 +37,6 @@ void user_name(char *buf, int id) strcpy(buf, "PLAYER"); } -#endif /* SET_UID */ - - /* @@ -1458,7 +1409,7 @@ static char inkey_aux(void) if (w >= 100) break; /* Delay */ - Term_xtra(TERM_XTRA_DELAY, w); + sleep_for(milliseconds(w)); } } @@ -1706,7 +1657,7 @@ static char inkey_real(bool_ inkey_scan) if (w >= 100) break; /* Delay */ - Term_xtra(TERM_XTRA_DELAY, w); + sleep_for(milliseconds(w)); } } |