2017-03-11 16:01:30 +00:00
|
|
|
#include "textures/textures.h"
|
2016-04-28 16:17:18 +00:00
|
|
|
|
|
|
|
template<class TYPE>
|
2016-04-30 10:36:55 +00:00
|
|
|
void WarpBuffer(TYPE *Pixels, const TYPE *source, int width, int height, int xmul, int ymul, unsigned time, float Speed, int warptype)
|
2016-04-28 16:17:18 +00:00
|
|
|
{
|
|
|
|
int ymask = height - 1;
|
|
|
|
int x, y;
|
|
|
|
|
2016-04-30 10:36:55 +00:00
|
|
|
if (warptype == 1)
|
2016-04-28 16:17:18 +00:00
|
|
|
{
|
2016-04-30 10:36:55 +00:00
|
|
|
TYPE *buffer = (TYPE *)alloca(sizeof(TYPE) * MAX(width, height));
|
|
|
|
// [mxd] Rewrote to fix animation for NPo2 textures
|
|
|
|
unsigned timebase = unsigned(time * Speed * 32 / 28);
|
|
|
|
for (y = height - 1; y >= 0; y--)
|
|
|
|
{
|
|
|
|
int xf = (TexMan.sintable[((timebase + y*ymul) >> 2)&TexMan.SINMASK] >> 11) % width;
|
|
|
|
if (xf < 0) xf += width;
|
|
|
|
int xt = xf;
|
|
|
|
const TYPE *sourcep = source + y;
|
|
|
|
TYPE *dest = Pixels + y;
|
|
|
|
for (xt = width; xt; xt--, xf = (xf + 1) % width, dest += height)
|
|
|
|
*dest = sourcep[xf + ymask * xf];
|
|
|
|
}
|
|
|
|
timebase = unsigned(time * Speed * 23 / 28);
|
|
|
|
for (x = width - 1; x >= 0; x--)
|
|
|
|
{
|
|
|
|
int yf = (TexMan.sintable[((time + (x + 17)*xmul) >> 2)&TexMan.SINMASK] >> 11) % height;
|
|
|
|
if (yf < 0) yf += height;
|
|
|
|
int yt = yf;
|
|
|
|
const TYPE *sourcep = Pixels + (x + ymask * x);
|
|
|
|
TYPE *dest = buffer;
|
|
|
|
for (yt = height; yt; yt--, yf = (yf + 1) % height)
|
|
|
|
*dest++ = sourcep[yf];
|
|
|
|
memcpy(Pixels + (x + ymask*x), buffer, height * sizeof(TYPE));
|
|
|
|
}
|
2016-04-28 16:17:18 +00:00
|
|
|
}
|
2016-04-30 10:36:55 +00:00
|
|
|
else if (warptype == 2)
|
2016-04-28 16:17:18 +00:00
|
|
|
{
|
2016-04-30 10:36:55 +00:00
|
|
|
unsigned timebase = unsigned(time * Speed * 40 / 28);
|
|
|
|
// [mxd] Rewrote to fix animation for NPo2 textures
|
|
|
|
for (x = 0; x < width; x++)
|
2016-04-28 16:17:18 +00:00
|
|
|
{
|
2016-04-30 10:36:55 +00:00
|
|
|
TYPE *dest = Pixels + (x + ymask * x);
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
int xt = (x + 128
|
|
|
|
+ ((TexMan.sintable[((y*ymul + timebase * 5 + 900) >> 2) & TexMan.SINMASK]) >> 13)
|
|
|
|
+ ((TexMan.sintable[((x*xmul + timebase * 4 + 300) >> 2) & TexMan.SINMASK]) >> 13)) % width;
|
|
|
|
|
|
|
|
int yt = (y + 128
|
|
|
|
+ ((TexMan.sintable[((y*ymul + timebase * 3 + 700) >> 2) & TexMan.SINMASK]) >> 13)
|
|
|
|
+ ((TexMan.sintable[((x*xmul + timebase * 4 + 1200) >> 2) & TexMan.SINMASK]) >> 13)) % height;
|
|
|
|
|
|
|
|
*dest++ = source[(xt + ymask * xt) + yt];
|
|
|
|
}
|
2016-04-28 16:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-30 10:36:55 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// should never happen, just in case...
|
|
|
|
memcpy(Pixels, source, width*height * sizeof(TYPE));
|
|
|
|
}
|
2016-04-28 16:17:18 +00:00
|
|
|
}
|
|
|
|
|