From 6bb2c4cecb8a4e633fc0faf90c939fc180f7163b Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 23 May 2011 15:46:32 +0000 Subject: [PATCH] added LoopingFrameNumberFromDouble function to do this operation correctly (using divide, floor, and multiply), since doing it the lazy way (cast to int, use modulus operator) breaks down after a certain amount of time in the level git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11163 d7cf8633-e32d-0410-b094-e92efae38249 --- mathlib.c | 9 +++++++++ mathlib.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/mathlib.c b/mathlib.c index d6170d28..dae0de50 100644 --- a/mathlib.c +++ b/mathlib.c @@ -756,3 +756,12 @@ void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f) } } +// LordHavoc: this has to be done right or you get severe precision breakdown +int LoopingFrameNumberFromDouble(double t, int loopframes) +{ + if (loopframes) + return (int)(t - floor(t/loopframes)*loopframes); + else + return (int)t; +} + diff --git a/mathlib.h b/mathlib.h index b3a9f7ea..e1c7f647 100644 --- a/mathlib.h +++ b/mathlib.h @@ -291,5 +291,7 @@ int Math_atov(const char *s, vec3_t out); void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f); +int LoopingFrameNumberFromDouble(double t, int loopframes); + #endif -- 2.39.2