mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-23 04:59:10 +00:00
Don't assume evdev events and SDL_GetTicks() use the same time source
The evdev events are in the same time base as gettimeofday(), but SDL_GetTicks() might be using clock_gettime()
This commit is contained in:
parent
57d34f2e10
commit
75f1eb9216
3 changed files with 10 additions and 20 deletions
|
@ -38,7 +38,6 @@
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
|
|
||||||
#include "../../timer/SDL_timer_c.h"
|
|
||||||
#include "../../events/SDL_events_c.h"
|
#include "../../events/SDL_events_c.h"
|
||||||
#include "../../events/SDL_scancode_tables_c.h"
|
#include "../../events/SDL_scancode_tables_c.h"
|
||||||
#include "../../core/linux/SDL_evdev_capabilities.h"
|
#include "../../core/linux/SDL_evdev_capabilities.h"
|
||||||
|
@ -876,7 +875,9 @@ static int SDL_EVDEV_device_removed(const char *dev_path)
|
||||||
|
|
||||||
Uint64 SDL_EVDEV_GetEventTimestamp(struct input_event *event)
|
Uint64 SDL_EVDEV_GetEventTimestamp(struct input_event *event)
|
||||||
{
|
{
|
||||||
|
static Uint64 timestamp_offset;
|
||||||
Uint64 timestamp;
|
Uint64 timestamp;
|
||||||
|
Uint64 now = SDL_GetTicksNS();
|
||||||
|
|
||||||
/* The kernel internally has nanosecond timestamps, but converts it
|
/* The kernel internally has nanosecond timestamps, but converts it
|
||||||
to microseconds when delivering the events */
|
to microseconds when delivering the events */
|
||||||
|
@ -884,9 +885,15 @@ Uint64 SDL_EVDEV_GetEventTimestamp(struct input_event *event)
|
||||||
timestamp *= SDL_NS_PER_SECOND;
|
timestamp *= SDL_NS_PER_SECOND;
|
||||||
timestamp += SDL_US_TO_NS(event->time.tv_usec);
|
timestamp += SDL_US_TO_NS(event->time.tv_usec);
|
||||||
|
|
||||||
/* Let's assume for now that we're using the same time base */
|
if (!timestamp_offset) {
|
||||||
timestamp -= SDL_GetTickStartNS();
|
timestamp_offset = (now - timestamp);
|
||||||
|
}
|
||||||
|
timestamp += timestamp_offset;
|
||||||
|
|
||||||
|
if (timestamp > now) {
|
||||||
|
timestamp_offset -= (timestamp - now);
|
||||||
|
timestamp = now;
|
||||||
|
}
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -565,22 +565,6 @@ void SDL_TicksQuit(void)
|
||||||
tick_start = 0;
|
tick_start = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64
|
|
||||||
SDL_GetTickStartNS(void)
|
|
||||||
{
|
|
||||||
Uint64 starting_value, value;
|
|
||||||
|
|
||||||
if (!tick_start) {
|
|
||||||
SDL_TicksInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
starting_value = tick_start;
|
|
||||||
value = (starting_value * tick_numerator_ns);
|
|
||||||
SDL_assert(value >= starting_value);
|
|
||||||
value /= tick_denominator_ns;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint64
|
Uint64
|
||||||
SDL_GetTicksNS(void)
|
SDL_GetTicksNS(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,7 +33,6 @@ extern void SDL_TicksInit(void);
|
||||||
extern void SDL_TicksQuit(void);
|
extern void SDL_TicksQuit(void);
|
||||||
extern int SDL_TimerInit(void);
|
extern int SDL_TimerInit(void);
|
||||||
extern void SDL_TimerQuit(void);
|
extern void SDL_TimerQuit(void);
|
||||||
extern Uint64 SDL_GetTickStartNS(void);
|
|
||||||
|
|
||||||
#endif /* SDL_timer_c_h_ */
|
#endif /* SDL_timer_c_h_ */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue