summaryrefslogtreecommitdiffstats
path: root/core/input/input.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-25 18:31:06 +0200
committerwm4 <wm4@nowhere>2013-05-26 16:44:20 +0200
commite56d8a200d900066c3da571d92733f66ce6a13ab (patch)
treef43862ec12beee05380da82ebef23bcce83401e7 /core/input/input.c
parent51254a678c386cf48f2caa51e06ad34065c8693a (diff)
downloadmpv-e56d8a200d900066c3da571d92733f66ce6a13ab.tar.bz2
mpv-e56d8a200d900066c3da571d92733f66ce6a13ab.tar.xz
Replace all calls to GetTimer()/GetTimerMS()
GetTimer() is generally replaced with mp_time_us(). Both calls return microseconds, but the latter uses int64_t, us defined to never wrap, and never returns 0 or negative values. GetTimerMS() has no direct replacement. Instead the other functions are used. For some code, switch to mp_time_sec(), which returns the time as double float value in seconds. The returned time is offset to program start time, so there is enough precision left to deliver microsecond resolution for at least 100 years. Unless it's casted to a float (or the CPU reduces precision), which is why we still use mp_time_us() out of paranoia in places where precision is clearly needed. Always switch to the correct time. The whole point of the new timer calls is that they don't wrap, and storing microseconds in unsigned int variables would negate this. In some cases, remove wrap-around handling for time values.
Diffstat (limited to 'core/input/input.c')
-rw-r--r--core/input/input.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/core/input/input.c b/core/input/input.c
index c756efcbdc..3d8ba711b7 100644
--- a/core/input/input.c
+++ b/core/input/input.c
@@ -464,7 +464,7 @@ struct input_ctx {
// Autorepeat stuff
short ar_state;
mp_cmd_t *ar_cmd;
- unsigned int last_ar;
+ int64_t last_ar;
// Autorepeat config
unsigned int ar_delay;
unsigned int ar_rate;
@@ -475,7 +475,7 @@ struct input_ctx {
// these are the keys currently down
int key_down[MP_MAX_KEY_DOWN];
unsigned int num_key_down;
- unsigned int last_key_down;
+ int64_t last_key_down;
bool test;
@@ -491,7 +491,7 @@ struct input_ctx {
// events sources. If yes, the sources may have more queued.
bool got_new_events;
- unsigned int last_mouse_event;
+ unsigned int mouse_event_counter;
struct input_fd key_fds[MP_MAX_KEY_FD];
unsigned int num_key_fd;
@@ -1230,7 +1230,7 @@ static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code)
return NULL;
ictx->key_down[ictx->num_key_down] = code;
ictx->num_key_down++;
- ictx->last_key_down = GetTimer();
+ ictx->last_key_down = mp_time_us();
ictx->ar_state = 0;
ret = NULL;
if (!(code & MP_NO_REPEAT_KEY))
@@ -1287,7 +1287,7 @@ static mp_cmd_t *check_autorepeat(struct input_ctx *ictx)
// No input : autorepeat ?
if (ictx->ar_rate > 0 && ictx->ar_state >= 0 && ictx->num_key_down > 0
&& !(ictx->key_down[ictx->num_key_down - 1] & MP_NO_REPEAT_KEY)) {
- unsigned int t = GetTimer();
+ int64_t t = mp_time_us();
if (ictx->last_ar + 2000000 < t)
ictx->last_ar = t;
// First time : wait delay
@@ -1319,7 +1319,7 @@ void mp_input_feed_key(struct input_ctx *ictx, int code)
ictx->got_new_events = true;
int unmod = code & ~(MP_KEY_MODIFIER_MASK | MP_KEY_STATE_DOWN);
if (unmod >= MP_MOUSE_BASE && unmod <= MP_MOUSE_BTN_END)
- ictx->last_mouse_event = GetTimerMS();
+ ictx->mouse_event_counter++;
if (code == MP_INPUT_RELEASE_ALL) {
mp_msg(MSGT_INPUT, MSGL_V, "input: release all\n");
memset(ictx->key_down, 0, sizeof(ictx->key_down));
@@ -1483,7 +1483,7 @@ int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t *cmd)
if (!cmd)
return 0;
if (cmd->id == MP_CMD_SET_MOUSE_POS)
- ictx->last_mouse_event = GetTimerMS();
+ ictx->mouse_event_counter++;
queue_add(&ictx->control_cmd_queue, cmd, false);
return 1;
}
@@ -1914,7 +1914,7 @@ int mp_input_check_interrupt(struct input_ctx *ictx, int time)
}
}
-unsigned int mp_input_get_last_mouse_event_time(struct input_ctx *ictx)
+unsigned int mp_input_get_mouse_event_counter(struct input_ctx *ictx)
{
- return ictx->last_mouse_event;
+ return ictx->mouse_event_counter;
}