diff --git a/flecs.c b/flecs.c index ccafbc7c82..4f81aa0322 100644 --- a/flecs.c +++ b/flecs.c @@ -18260,9 +18260,10 @@ void ProgressTimers(ecs_iter_t *it) { t = 0; } - timer[i].time = t; /* Initialize with remainder */ + timer[i].time = t; /* Initialize with remainder */ tick_source[i].tick = true; - tick_source[i].time_elapsed = time_elapsed; + tick_source[i].time_elapsed = time_elapsed - timer[i].overshoot; + timer[i].overshoot = t; if (timer[i].single_shot) { timer[i].active = false; diff --git a/flecs.h b/flecs.h index 414c7dc747..f103047fb1 100644 --- a/flecs.h +++ b/flecs.h @@ -10067,6 +10067,7 @@ extern "C" { typedef struct EcsTimer { ecs_ftime_t timeout; /**< Timer timeout period */ ecs_ftime_t time; /**< Incrementing time value */ + ecs_ftime_t overshoot; /**< Used to correct returned interval time */ int32_t fired_count; /**< Number of times ticked */ bool active; /**< Is the timer active or not */ bool single_shot; /**< Is this a single shot timer */ diff --git a/include/flecs/addons/timer.h b/include/flecs/addons/timer.h index ceed6b9352..b84a37dd2a 100644 --- a/include/flecs/addons/timer.h +++ b/include/flecs/addons/timer.h @@ -35,6 +35,7 @@ extern "C" { typedef struct EcsTimer { ecs_ftime_t timeout; /**< Timer timeout period */ ecs_ftime_t time; /**< Incrementing time value */ + ecs_ftime_t overshoot; /**< Used to correct returned interval time */ int32_t fired_count; /**< Number of times ticked */ bool active; /**< Is the timer active or not */ bool single_shot; /**< Is this a single shot timer */ diff --git a/src/addons/timer.c b/src/addons/timer.c index df727a5360..281011020e 100644 --- a/src/addons/timer.c +++ b/src/addons/timer.c @@ -42,9 +42,10 @@ void ProgressTimers(ecs_iter_t *it) { t = 0; } - timer[i].time = t; /* Initialize with remainder */ + timer[i].time = t; /* Initialize with remainder */ tick_source[i].tick = true; - tick_source[i].time_elapsed = time_elapsed; + tick_source[i].time_elapsed = time_elapsed - timer[i].overshoot; + timer[i].overshoot = t; if (timer[i].single_shot) { timer[i].active = false;