SDL
SDL copied to clipboard
[RFE] provide timestamp from backend event
This bug report was migrated from our old Bugzilla tracker.
Reported in version: HG 2.1 Reported for operating system, platform: All, All
Comments on the original bug report:
On 2013-08-05 14:40:00 +0000, Alexander Hirsch wrote:
Currently the SDL_*Event timestamp is not the time the event occurred, but the time the event was polled by SDL. It would be great if you could obtain the timestamp from the backend event, for events where the backend supports that. Otherwise you can still "fall back" to the time when the event was polled.
In the public API there should be a way of checking if the timestamp was provided by the backend event or SDL.
Since the backend and SDL probably use different methods of providing a time, they won't be comparable. I don't think clock skew can happen, since it is on the same computer, so it should be possible to convert the timestamp to something comparable with SDL_GetTicks(). Otherwise you'd also need a SDL_GetBackendTicks() or something.
I'm putting this in 2.0.18, because I think it would be neat, but this is almost certainly going to slide to 2.0.20 or later.
Just want to +1 this request: I'm a cognitive science researcher and we use SDL2 (via Python) for a lot of our experimental tasks, and one of our most commonly measured variables are people's reaction times to stimuli.
However, since we use VSync for timing precision and event timestamps only reflect the time the event was polled, that can add up to 16 ms of inaccuracy on each recorded response when the mean effect of an experimental manipulation across people can often be on the order of ~30 ms. This feature would help improve things quite a bit without requiring specialized hardware or trying to wrangle handling input polling in a separate thread (which I believe is a problem at least on macOS due to anti-keylogger security measures).
+1 for this, please! This feature would be super helpful for finer grained input that is framerate independent. Thanks!
This is implemented for SDL3 in https://github.com/libsdl-org/SDL/commit/0a3262e819edc695a764702e8127bbd1b09944ef. Currently Windows and Apple platforms have the OS event timestamps coming through for mouse, keyboard, and touch events. On Linux, X11 does not have an event timestamp, but Wayland does, and that will be plumbed through for the SDL 3.0 release.
Nice! For some of the (non-SDL) games I've worked on we've heavily used timestamps from gamepad thumbstick events for high precision and accuracy with some analog aiming controls. Now that this is implemented for some systems I think hooking it up for joysticks would be worthwhile in the future, if it hasn't already been considered.
For example Microsoft's GameInput API has a timestamp feature.
EDIT: oh, I didn't see #6737, my bad 😅