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 <wayland-client-protocol.h>
#include <wayland-client.h>
#include <time.h>
#include <linux/input-event-codes.h>
#include "pointer.h"
#include "wlr-virtual-pointer-unstable-v1.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;
}
#include "time-util.h"
int pointer_init(struct pointer* self)
{

View File

@ -15,20 +15,13 @@
*/
#include "smooth.h"
#include "time-util.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 now = smooth__gettime();
double now = gettime_s();
double dt = now - self->last_time;
self->last_time = now;