Extract time functions into own module
parent
61657c97ba
commit
baad0ecd68
|
@ -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;
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
|
11
src/smooth.c
11
src/smooth.c
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue