Extract time functions into own module

pull/1/head
Andri Yngvason 2019-12-29 10:06:25 +00:00
parent 61657c97ba
commit baad0ecd68
3 changed files with 19 additions and 17 deletions

View File

@ -0,0 +1,16 @@
#include <time.h>
#include <stdint.h>
static inline double gettime_s(void)
{
struct timespec ts = { 0 };
clock_gettime(CLOCK_MONOTONIC, &ts);
return (double)ts.tv_sec + (double)ts.tv_nsec / 1.0e-9;
}
static inline uint32_t gettime_ms(void)
{
struct timespec ts = { 0 };
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000UL + ts.tv_nsec / 1000000UL;
}

View File

@ -17,18 +17,11 @@
#include <stdint.h> #include <stdint.h>
#include <wayland-client-protocol.h> #include <wayland-client-protocol.h>
#include <wayland-client.h> #include <wayland-client.h>
#include <time.h>
#include <linux/input-event-codes.h> #include <linux/input-event-codes.h>
#include "pointer.h" #include "pointer.h"
#include "wlr-virtual-pointer-unstable-v1.h" #include "wlr-virtual-pointer-unstable-v1.h"
#include "time-util.h"
static inline uint32_t gettime_ms(void)
{
struct timespec ts = { 0 };
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000UL + ts.tv_nsec / 1000000UL;
}
int pointer_init(struct pointer* self) int pointer_init(struct pointer* self)
{ {

View File

@ -15,20 +15,13 @@
*/ */
#include "smooth.h" #include "smooth.h"
#include "time-util.h"
#include <math.h> #include <math.h>
#include <time.h>
static inline double smooth__gettime(void)
{
struct timespec ts = { 0 };
clock_gettime(CLOCK_MONOTONIC, &ts);
return (double)ts.tv_sec + (double)ts.tv_nsec / 1.0e-9;
}
double smooth(struct smooth* self, double input) double smooth(struct smooth* self, double input)
{ {
double now = smooth__gettime(); double now = gettime_s();
double dt = now - self->last_time; double dt = now - self->last_time;
self->last_time = now; self->last_time = now;