diff --git a/src/p_tick.c b/src/p_tick.c index 708ed6ca8..ad83abca6 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -44,6 +44,14 @@ INT32 P_AltFlip(INT32 n, tic_t tics) return leveltime % (2 * tics) < tics ? n : -(n); } +// Please read p_tick.h +INT32 P_LerpFlip(INT32 n, tic_t tics) +{ + const tic_t w = 2 * tics; + + return P_AltFlip(((leveltime % w) - tics) * n, w); +} + // // THINKERS // All thinkers should be allocated by Z_Calloc diff --git a/src/p_tick.h b/src/p_tick.h index 7b10a5f28..f892942ea 100644 --- a/src/p_tick.h +++ b/src/p_tick.h @@ -35,4 +35,12 @@ mobj_t *P_SetTarget(mobj_t **mo, mobj_t *target); // killough 11/98 INT32 P_AltFlip(INT32 value, tic_t tics); #define P_RandomFlip(value) P_AltFlip(value, 1) +// Multiply value back and forth between -(tics) and +(tics). +// Example output P_ModulateFlip(2, 2): +// Tic: 0 1 2 3 4 5 6 7 8 +// Val: -4 -2 0 2 4 2 0 -2 -4 +// A half cycle (one direction) takes 2 * tics. +// A full cycle takes 4 * tics. +INT32 P_LerpFlip(INT32 value, tic_t tics); + #endif