X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2F3dengfx%2Fsrc%2Fgfx%2Ftimeline.cpp;fp=src%2F3dengfx%2Fsrc%2Fgfx%2Ftimeline.cpp;h=fbce4f36f86a0cb734e74dd905d73d9c7b2304a1;hb=6e23259dbabaeb1711a2a5ca25b9cb421f693759;hp=0000000000000000000000000000000000000000;hpb=fe068fa879814784c45e0cb2e65dac489e8f5594;p=summerhack diff --git a/src/3dengfx/src/gfx/timeline.cpp b/src/3dengfx/src/gfx/timeline.cpp new file mode 100644 index 0000000..fbce4f3 --- /dev/null +++ b/src/3dengfx/src/gfx/timeline.cpp @@ -0,0 +1,71 @@ +/* +This file is part of the graphics core library. + +Copyright (c) 2004, 2005 John Tsiombikas + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "timeline.hpp" + +template +static inline T wrap(T n, T low, T high) { + n -= low; + + while(n < 0) { + n += high; + } + if(high) n %= high; + + return n + low; +} + +template +static inline T bounce(T n, T low, T high) { + T interval = high - low; + T offs = n % interval; + + if((n / interval) % 2) { + // descent + return high - offs; + } else { + return low + offs; + } +} + + +unsigned long get_timeline_time(unsigned long time, unsigned long start, unsigned long end, TimelineMode mode) { + switch(mode) { + case TIME_WRAP: + time = wrap(time, start, end); + break; + + case TIME_BOUNCE: + time = bounce(time, start, end); + break; + + case TIME_CLAMP: + if(time < start) time = start; + if(time > end) time = end; + break; + + case TIME_FREE: + default: + break; + } + + return time; +} +