- merged FWarpTexture and FWarp2Texture, making the choice of effect a parameter of the WarpBuffer function.

Ideally the warping shouldn't be a property of the texture class itself but an effect processor that can get added to a texture. Unfortunately the current setup will not allow this, requiring some significant refactoring of texture access first.
This commit is contained in:
Christoph Oelckers 2016-04-30 12:36:55 +02:00
parent a95c6b9644
commit c3759646e7
4 changed files with 57 additions and 93 deletions

View file

@ -219,7 +219,7 @@ void FTextureManager::InitAnimated (void)
// SMMU-style swirly hack? Don't apply on already-warping texture
if (animspeed > 65535 && tex1 != NULL && !tex1->bWarped)
{
FTexture *warper = new FWarp2Texture (tex1);
FTexture *warper = new FWarpTexture (tex1, 2);
ReplaceTexture (pic1, warper, false);
}
// These tests were not really relevant for swirling textures, or even potentially
@ -617,9 +617,7 @@ void FTextureManager::ParseWarp(FScanner &sc)
// don't warp a texture more than once
if (!warper->bWarped)
{
if (type2) warper = new FWarp2Texture (warper);
else warper = new FWarpTexture (warper);
warper = new FWarpTexture (warper, type2? 2:1);
ReplaceTexture (picnum, warper, false);
}

View file

@ -469,7 +469,7 @@ public:
class FWarpTexture : public FTexture
{
public:
FWarpTexture (FTexture *source);
FWarpTexture (FTexture *source, int warptype);
~FWarpTexture ();
virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL);
@ -496,16 +496,6 @@ protected:
void SetupMultipliers (int width, int height); // [mxd]
};
// [GRB] Eternity-like warping
class FWarp2Texture : public FWarpTexture
{
public:
FWarp2Texture (FTexture *source);
protected:
void MakeTexture (DWORD time);
};
// A texture that can be drawn to.
class DSimpleCanvas;
class AActor;

View file

@ -1,61 +1,63 @@
template<class TYPE>
void WarpBufferType1(TYPE *Pixels, const TYPE *source, int width, int height, int xmul, int ymul, unsigned time, float Speed)
{
TYPE *buffer = (TYPE *)alloca(sizeof(TYPE) * MAX(width, height));
int ymask = height - 1;
int x, y;
// [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));
}
}
template<class TYPE>
void WarpBufferType2(TYPE *Pixels, const TYPE *source, int width, int height, int xmul, int ymul, unsigned time, float Speed)
void WarpBuffer(TYPE *Pixels, const TYPE *source, int width, int height, int xmul, int ymul, unsigned time, float Speed, int warptype)
{
int ymask = height - 1;
int x, y;
unsigned timebase = unsigned(time * Speed * 40 / 28);
// [mxd] Rewrote to fix animation for NPo2 textures
for (x = 0; x < width; x++)
if (warptype == 1)
{
TYPE *dest = Pixels + (x + ymask * x);
for (y = 0; y < height; y++)
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 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];
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));
}
}
else if (warptype == 2)
{
unsigned timebase = unsigned(time * Speed * 40 / 28);
// [mxd] Rewrote to fix animation for NPo2 textures
for (x = 0; x < width; x++)
{
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];
}
}
}
else
{
// should never happen, just in case...
memcpy(Pixels, source, width*height * sizeof(TYPE));
}
}

View file

@ -41,12 +41,12 @@
#include "warpbuffer.h"
FWarpTexture::FWarpTexture (FTexture *source)
FWarpTexture::FWarpTexture (FTexture *source, int warptype)
: GenTime (0), SourcePic (source), Pixels (0), Spans (0), Speed (1.f)
{
CopyInfo(source);
SetupMultipliers(128, 128); // [mxd]
bWarped = 1;
bWarped = warptype;
}
FWarpTexture::~FWarpTexture ()
@ -137,7 +137,7 @@ void FWarpTexture::MakeTexture(DWORD time)
}
GenTime = time;
WarpBufferType1(Pixels, otherpix, Width, Height, WidthOffsetMultiplier, HeightOffsetMultiplier, time, Speed);
WarpBuffer(Pixels, otherpix, Width, Height, WidthOffsetMultiplier, HeightOffsetMultiplier, time, Speed, bWarped);
}
// [mxd] Non power of 2 textures need different offset multipliers, otherwise warp animation won't sync across texture
@ -162,32 +162,6 @@ int FWarpTexture::NextPo2 (int v)
return ++v;
}
// [GRB] Eternity-like warping
FWarp2Texture::FWarp2Texture (FTexture *source)
: FWarpTexture (source)
{
SetupMultipliers(256, 128); // [mxd]
bWarped = 2;
}
void FWarp2Texture::MakeTexture (DWORD time)
{
const BYTE *otherpix = SourcePic->GetPixels ();
if (Pixels == NULL)
{
Pixels = new BYTE[Width * Height];
}
if (Spans != NULL)
{
FreeSpans (Spans);
Spans = NULL;
}
GenTime = time;
WarpBufferType2(Pixels, otherpix, Width, Height, WidthOffsetMultiplier, HeightOffsetMultiplier, time, Speed);
}
//==========================================================================
//
// FMultiPatchTexture :: TexPart :: TexPart