summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2014-12-16 18:51:06 +0100
committerBardur Arantsson <bardur@scientician.net>2014-12-16 18:54:55 +0100
commit4d351b8d07c25415d5848e9486eb5cb52f02d72e (patch)
tree0b8045630e146eaa870280e2d3e7f13e50499ad2 /src
parentff252acf7f2f38e33017e82881c95825b54c7cee (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')
-rw-r--r--src/cmd2.cc22
-rw-r--r--src/externs.h5
-rw-r--r--src/h-config.h8
-rw-r--r--src/main-gcu.c5
-rw-r--r--src/main-gtk2.c10
-rw-r--r--src/main-sdl.c19
-rw-r--r--src/main-x11.c5
-rw-r--r--src/modules.cc10
-rw-r--r--src/spells1.cc13
-rw-r--r--src/spells2.cc11
-rw-r--r--src/util.cc61
-rw-r--r--src/z-term.h2
12 files changed, 45 insertions, 126 deletions
diff --git a/src/cmd2.cc b/src/cmd2.cc
index f85f90fe..261207d4 100644
--- a/src/cmd2.cc
+++ b/src/cmd2.cc
@@ -13,6 +13,12 @@
#include "angband.h"
#include "hooks.h"
+#include <chrono>
+#include <thread>
+
+using std::this_thread::sleep_for;
+using std::chrono::milliseconds;
+
void do_cmd_immovable_special(void);
/*
@@ -3240,7 +3246,7 @@ void do_cmd_fire(void)
print_rel(missile_char, missile_attr, y, x);
move_cursor_relative(y, x);
Term_fresh();
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
lite_spot(y, x);
Term_fresh();
}
@@ -3249,7 +3255,7 @@ void do_cmd_fire(void)
else
{
/* Pause anyway, for consistancy */
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
}
@@ -3656,7 +3662,7 @@ void do_cmd_throw(void)
print_rel(missile_char, missile_attr, y, x);
move_cursor_relative(y, x);
Term_fresh();
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
lite_spot(y, x);
Term_fresh();
}
@@ -3665,7 +3671,7 @@ void do_cmd_throw(void)
else
{
/* Pause anyway, for consistancy */
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
}
@@ -3983,7 +3989,7 @@ void do_cmd_boomerang(void)
print_rel(missile_char, missile_attr, y, x);
move_cursor_relative(y, x);
Term_fresh();
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
lite_spot(y, x);
Term_fresh();
}
@@ -3992,7 +3998,7 @@ void do_cmd_boomerang(void)
else
{
/* Pause anyway, for consistancy */
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
}
@@ -4159,7 +4165,7 @@ void do_cmd_boomerang(void)
print_rel(missile_char, missile_attr, y, x);
move_cursor_relative(y, x);
Term_fresh();
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
lite_spot(y, x);
Term_fresh();
}
@@ -4168,7 +4174,7 @@ void do_cmd_boomerang(void)
else
{
/* Pause anyway, for consistancy */
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
}
}
}
diff --git a/src/externs.h b/src/externs.h
index 93120286..d29fefa1 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -2178,11 +2178,6 @@ extern void automatizer_load(cptr file_name);
extern void user_name(char *buf, int id);
#endif
-#ifndef HAS_USLEEP
-/* util.c */
-extern int usleep(huge usecs);
-#endif
-
/* util.c */
extern void repeat_push(int what);
extern bool_ repeat_pull(int *what);
diff --git a/src/h-config.h b/src/h-config.h
index aa323e72..fc2721ef 100644
--- a/src/h-config.h
+++ b/src/h-config.h
@@ -104,14 +104,6 @@ extern "C" {
#endif
-/*
- * OPTION: Define "HAS_USLEEP" only if "usleep()" exists.
- * Note that this is only relevant for "SET_UID" machines
- */
-#ifdef SET_UID
-# define HAS_USLEEP
-#endif
-
#ifdef __cplusplus
} // extern "C"
#endif
diff --git a/src/main-gcu.c b/src/main-gcu.c
index 34589e85..a07f216d 100644
--- a/src/main-gcu.c
+++ b/src/main-gcu.c
@@ -675,11 +675,6 @@ static errr Term_xtra_gcu(int n, int v)
while (!Term_xtra_gcu_event(FALSE));
return (0);
- /* Delay */
- case TERM_XTRA_DELAY:
- usleep(1000 * v);
- return (0);
-
/* React to events */
case TERM_XTRA_REACT:
Term_xtra_gcu_react();
diff --git a/src/main-gtk2.c b/src/main-gtk2.c
index f5c89897..10e7d9f0 100644
--- a/src/main-gtk2.c
+++ b/src/main-gtk2.c
@@ -511,16 +511,6 @@ static errr Term_xtra_gtk(int n, int v)
case TERM_XTRA_CLEAR:
return (Term_clear_gtk());
- /* Delay for some milliseconds */
- case TERM_XTRA_DELAY:
- {
- /* sleep for v milliseconds */
- usleep(v * 1000);
-
- /* Done */
- return (0);
- }
-
/* Rename main window */
case TERM_XTRA_RENAME_MAIN_WIN: gtk_window_set_title(GTK_WINDOW(data[0].window), angband_term_name[0]); return (0);
diff --git a/src/main-sdl.c b/src/main-sdl.c
index 07715aa0..907fbcf3 100644
--- a/src/main-sdl.c
+++ b/src/main-sdl.c
@@ -661,25 +661,6 @@ static errr Term_xtra_sdl(int n, int v)
return (1);
}
- case TERM_XTRA_DELAY:
- {
- /*
- * Delay for some milliseconds XXX XXX XXX
- *
- * This action is useful for proper "timing" of certain
- * visual effects, such as breath attacks.
- *
- * This action is optional, but may be required by this file,
- * especially if special "macro sequences" must be supported.
- */
-
- /* I think that this command is system independent... */
- /*sleep(v/1000);*/
- /* main-x11 uses usleep(1000*v); */
- /* main-win uses Sleep(v); */
- return (1);
- }
-
}
/* Unknown or Unhandled action */
diff --git a/src/main-x11.c b/src/main-x11.c
index 30f67173..41d629cd 100644
--- a/src/main-x11.c
+++ b/src/main-x11.c
@@ -2163,11 +2163,6 @@ static errr Term_xtra_x11(int n, int v)
/* Clear the screen, and redraw any selection later. */
case TERM_XTRA_CLEAR: Infowin_wipe(); s_ptr->drawn = FALSE; return (0);
- /* Delay for some milliseconds */
- case TERM_XTRA_DELAY:
- usleep(1000 * v);
- return (0);
-
/* React to changes */
case TERM_XTRA_REACT: return (Term_xtra_x11_react());
diff --git a/src/modules.cc b/src/modules.cc
index b152fa0b..2e16adbc 100644
--- a/src/modules.cc
+++ b/src/modules.cc
@@ -9,6 +9,12 @@
#include "angband.h"
#include "hooks.h"
+#include <chrono>
+#include <thread>
+
+using std::this_thread::sleep_for;
+using std::chrono::milliseconds;
+
static void module_reset_dir_aux(char **dir, cptr new_path)
{
char buf[1024];
@@ -311,7 +317,7 @@ static bool_ dleft(byte c, cptr str, int y, int o)
time = time + 1;
if (time >= 4)
{
- Term_xtra(TERM_XTRA_DELAY, 1);
+ sleep_for(milliseconds(1));
time = 0;
}
Term_redraw_section(a - 1, y, a, y);
@@ -344,7 +350,7 @@ static bool_ dright(byte c, cptr str, int y, int o)
Term_putch(a, y, c, str[i-1]);
time = time + 1;
if (time >= 4) {
- Term_xtra(TERM_XTRA_DELAY, 1);
+ sleep_for(milliseconds(1));
time = 0;
}
Term_redraw_section(a, y, a + 1, y);
diff --git a/src/spells1.cc b/src/spells1.cc
index 1c53fa8e..0f5e83c9 100644
--- a/src/spells1.cc
+++ b/src/spells1.cc
@@ -11,9 +11,14 @@
*/
#include "angband.h"
-
#include "spell_type.h"
+#include <chrono>
+#include <thread>
+
+using std::this_thread::sleep_for;
+using std::chrono::milliseconds;
+
/* 1/x chance of reducing stats (for elemental attacks) */
#define HURT_CHANCE 32
@@ -8436,7 +8441,7 @@ bool_ project(int who, int rad, int y, int x, int dam, int typ, int flg)
print_rel(c, a, y, x);
move_cursor_relative(y, x);
if (fresh_before) Term_fresh();
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
lite_spot(y, x);
if (fresh_before) Term_fresh();
@@ -8462,7 +8467,7 @@ bool_ project(int who, int rad, int y, int x, int dam, int typ, int flg)
else if (visual)
{
/* Delay for consistency */
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
}
}
}
@@ -8580,7 +8585,7 @@ bool_ project(int who, int rad, int y, int x, int dam, int typ, int flg)
/* Delay (efficiently) */
if (visual || drawn)
{
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
}
}
diff --git a/src/spells2.cc b/src/spells2.cc
index 4e502d8e..2dbfff43 100644
--- a/src/spells2.cc
+++ b/src/spells2.cc
@@ -13,8 +13,13 @@
#include "angband.h"
#include "hooks.h"
+#include <chrono>
+#include <thread>
#include <vector>
+using std::this_thread::sleep_for;
+using std::chrono::milliseconds;
+
#define WEIRD_LUCK 12
#define BIAS_LUCK 20
/*
@@ -5080,7 +5085,7 @@ bool_ invoke(int dam, int typee)
Term_fresh();
/* Delay */
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
/* Take note */
result = TRUE;
@@ -5156,7 +5161,7 @@ bool_ genocide_aux(bool_ player_cast, char typ)
Term_fresh();
/* Delay */
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
/* Take note */
result = TRUE;
@@ -5281,7 +5286,7 @@ bool_ mass_genocide(bool_ player_cast)
Term_fresh();
/* Delay */
- Term_xtra(TERM_XTRA_DELAY, msec);
+ sleep_for(milliseconds(msec));
/* Note effect */
result = TRUE;
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));
}
}
diff --git a/src/z-term.h b/src/z-term.h
index 6ada1905..dae3200a 100644
--- a/src/z-term.h
+++ b/src/z-term.h
@@ -199,7 +199,6 @@ struct term
* The "TERM_XTRA_SHAPE" action uses "v" to "show" the cursor
* The "TERM_XTRA_ALIVE" action uses "v" to "activate" (or "close")
* The "TERM_XTRA_LEVEL" action uses "v" to "resume" (or "suspend")
- * The "TERM_XTRA_DELAY" action uses "v" as a "millisecond" value
*
* The other actions do not need a "v" code, so "zero" is used.
*/
@@ -213,7 +212,6 @@ struct term
#define TERM_XTRA_REACT 10 /* React to global changes (optional) */
#define TERM_XTRA_ALIVE 11 /* Change the "hard" level (optional) */
#define TERM_XTRA_LEVEL 12 /* Change the "soft" level (optional) */
-#define TERM_XTRA_DELAY 13 /* Delay some milliseconds (optional) */
#define TERM_XTRA_RENAME_MAIN_WIN 16 /* Rename the main game window */