Merge remote-tracking branch 'origin/flats' into flats-png

This commit is contained in:
Jaime Passos 2019-06-25 16:04:24 -03:00
commit 8362710e50
5 changed files with 266 additions and 177 deletions

View File

@ -49,12 +49,6 @@ typedef struct
// for patchflats
UINT8 *flatpatch;
#ifdef ESLOPE
// rescaled version of the above
UINT8 *resizedflat;
UINT16 resizedwidth, resizedheight;
#endif
} levelflat_t;
extern size_t numlevelflats;

View File

@ -2205,36 +2205,3 @@ void R_TextureToFlat(size_t tex, UINT8 *flat)
}
}
}
void R_CropFlat(UINT8 *srcflat, UINT8 *destflat,
UINT16 srcwidth, UINT16 srcheight,
UINT16 resizewidth, UINT16 resizeheight,
UINT16 destwidth, UINT16 destheight)
{
UINT16 y;
UINT16 position = 0;
for (y = 0; y < destheight; y++)
{
if (position > (srcwidth * srcheight))
break;
if (srcwidth != resizewidth)
{
if (resizewidth > srcwidth)
{
UINT8 *pos2 = srcflat+position;
UINT8 lastpixel = *(pos2-1);
M_Memcpy(destflat, srcflat+position, destwidth);
memset(pos2, lastpixel, resizewidth-srcwidth);
}
else
M_Memcpy(destflat, srcflat+position, resizewidth);
}
else
M_Memcpy(destflat, srcflat+position, destwidth);
destflat += destwidth;
position += srcwidth;
}
while (y++ < min(resizeheight, srcheight))
memset(destflat + (y * destwidth), *(destflat - 1), destwidth);
}

View File

@ -53,11 +53,6 @@ typedef struct
{
UINT8 *flat;
INT16 width, height;
#ifdef ESLOPE
UINT8 *resizedflat;
INT16 resizedwidth, resizedheight;
#endif
} textureflat_t;
// all loaded and prepared textures from the start of the game
@ -110,10 +105,6 @@ UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b);
void R_PatchToFlat(patch_t *patch, UINT8 *flat);
void R_TextureToFlat(size_t tex, UINT8 *flat);
void R_CropFlat(UINT8 *srcflat, UINT8 *destflat,
UINT16 srcwidth, UINT16 srcheight,
UINT16 resizewidth, UINT16 resizeheight,
UINT16 destwidth, UINT16 destheight);
#ifndef NO_PNG_LUMPS
boolean R_IsLumpPNG(UINT8 *d, size_t s);

View File

@ -724,7 +724,24 @@ void R_DrawTiltedSpan_8(void)
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
*dest = colormap[source[((y * ds_flatwidth) + x)]];
}
else
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
dest++;
iz += ds_sz.x;
uz += ds_su.x;
@ -761,7 +778,24 @@ void R_DrawTiltedSpan_8(void)
for (i = SPANSIZE-1; i >= 0; i--)
{
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
*dest = colormap[source[((y * ds_flatwidth) + x)]];
}
else
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
dest++;
u += stepu;
v += stepv;
@ -777,7 +811,24 @@ void R_DrawTiltedSpan_8(void)
u = (INT64)(startu);
v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
*dest = colormap[source[((y * ds_flatwidth) + x)]];
}
else
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
}
else
{
@ -798,7 +849,24 @@ void R_DrawTiltedSpan_8(void)
for (; width != 0; width--)
{
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
*dest = colormap[source[((y * ds_flatwidth) + x)]];
}
else
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
dest++;
u += stepu;
v += stepv;
@ -859,7 +927,24 @@ void R_DrawTiltedTranslucentSpan_8(void)
v = (INT64)(vz*z) + viewy;
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest);
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dest);
}
else
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest);
dest++;
iz += ds_sz.x;
uz += ds_su.x;
@ -896,7 +981,24 @@ void R_DrawTiltedTranslucentSpan_8(void)
for (i = SPANSIZE-1; i >= 0; i--)
{
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest);
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dest);
}
else
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest);
dest++;
u += stepu;
v += stepv;
@ -912,7 +1014,24 @@ void R_DrawTiltedTranslucentSpan_8(void)
u = (INT64)(startu);
v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest);
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dest);
}
else
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest);
}
else
{
@ -933,7 +1052,24 @@ void R_DrawTiltedTranslucentSpan_8(void)
for (; width != 0; width--)
{
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest);
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dest);
}
else
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest);
dest++;
u += stepu;
v += stepv;
@ -994,9 +1130,28 @@ void R_DrawTiltedSplat_8(void)
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)];
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
val = source[((y * ds_flatwidth) + x)];
}
else
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)];
if (val != TRANSPARENTPIXEL)
*dest = colormap[val];
dest++;
iz += ds_sz.x;
uz += ds_su.x;
@ -1033,7 +1188,24 @@ void R_DrawTiltedSplat_8(void)
for (i = SPANSIZE-1; i >= 0; i--)
{
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)];
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
val = source[((y * ds_flatwidth) + x)];
}
else
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)];
if (val != TRANSPARENTPIXEL)
*dest = colormap[val];
dest++;
@ -1051,7 +1223,24 @@ void R_DrawTiltedSplat_8(void)
u = (INT64)(startu);
v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)];
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
val = source[((y * ds_flatwidth) + x)];
}
else
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)];
if (val != TRANSPARENTPIXEL)
*dest = colormap[val];
}
@ -1075,6 +1264,24 @@ void R_DrawTiltedSplat_8(void)
{
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)];
if (!ds_powersoftwo)
{
fixed_t x = ((u-viewx) >> FRACBITS);
fixed_t y = ((v-viewy) >> FRACBITS);
// Carefully align all of my Friends.
if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth);
if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight);
x %= ds_flatwidth;
y %= ds_flatheight;
val = source[((y * ds_flatwidth) + x)];
}
else
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)];
if (val != TRANSPARENTPIXEL)
*dest = colormap[val];
dest++;

View File

@ -718,7 +718,6 @@ static void R_GetPatchFlat(levelflat_t *levelflat, boolean leveltexture, boolean
{
textureflat_t *texflat = &texflats[levelflat->texturenum];
patch_t *patch = NULL;
UINT8 *tex;
boolean texturechanged = (leveltexture ? (levelflat->texturenum != levelflat->lasttexturenum) : false);
// Check if the texture changed.
@ -738,11 +737,6 @@ static void R_GetPatchFlat(levelflat_t *levelflat, boolean leveltexture, boolean
// If the texture changed, or the patch doesn't exist, convert either of them to a flat.
if (levelflat->flatpatch == NULL || texturechanged)
{
#ifdef ESLOPE
INT32 resizewidth, resizeheight, newresize;
INT32 checkresizewidth, checkresizeheight;
#endif // ESLOPE
if (leveltexture)
{
texture_t *texture = textures[levelflat->texturenum];
@ -793,75 +787,6 @@ static void R_GetPatchFlat(levelflat_t *levelflat, boolean leveltexture, boolean
}
ds_source = levelflat->flatpatch;
}
#ifdef ESLOPE
// Crop the flat, if necessary.
if (!R_CheckPowersOfTwo())
{
// Scale up to nearest power of 2
resizewidth = resizeheight = 1;
while (resizewidth < ds_flatwidth)
resizewidth <<= 1;
while (resizeheight < ds_flatheight)
resizeheight <<= 1;
// Scale down to fit in 2048x2048
if (resizewidth > 2048)
resizewidth = 2048;
if (resizeheight > 2048)
resizeheight = 2048;
// A single pixel difference is negligible.
checkresizewidth = ds_flatwidth - 1;
if (checkresizewidth & (checkresizewidth - 1))
{
checkresizewidth += 2;
if (checkresizewidth & (checkresizewidth - 1))
{
while (resizewidth > ds_flatwidth)
resizewidth >>= 1;
}
else
resizewidth = checkresizewidth;
}
else
resizewidth = checkresizewidth;
checkresizeheight = ds_flatheight - 1;
if (checkresizeheight & (checkresizeheight - 1))
{
checkresizeheight += 2;
if (checkresizeheight & (checkresizeheight - 1))
{
while (resizeheight > ds_flatheight)
resizeheight >>= 1;
}
else
resizeheight = checkresizeheight;
}
else
resizeheight = checkresizeheight;
// Find smallest size.
newresize = min(resizewidth, resizeheight);
// Allocate texture.
tex = Z_Malloc(newresize * newresize, PU_LEVEL, NULL);
memset(tex, TRANSPARENTPIXEL, newresize * newresize);
R_CropFlat(ds_source, tex, ds_flatwidth, ds_flatheight, min(resizewidth, newresize), min(resizeheight, newresize), newresize, newresize);
if (leveltexture)
{
texflat->resizedflat = tex;
texflat->resizedwidth = texflat->resizedheight = newresize;
}
else
{
levelflat->resizedflat = tex;
levelflat->resizedwidth = levelflat->resizedheight = newresize;
}
}
#endif // ESLOPE
}
else
{
@ -873,28 +798,6 @@ static void R_GetPatchFlat(levelflat_t *levelflat, boolean leveltexture, boolean
yoffs += levelflat->topoffset;
}
#ifdef ESLOPE
if (currentplane->slope)
{
if (R_CheckPowersOfTwo())
{
if (leveltexture)
{
ds_source = texflat->resizedflat;
ds_flatwidth = texflat->resizedwidth;
ds_flatheight = texflat->resizedheight;
}
else
{
ds_source = levelflat->resizedflat;
ds_flatwidth = levelflat->resizedwidth;
ds_flatheight = levelflat->resizedheight;
}
}
R_CheckFlatLength(ds_flatwidth * ds_flatheight);
}
#endif // ESLOPE
levelflat->lasttexturenum = levelflat->texturenum;
}
@ -1085,22 +988,34 @@ void R_DrawSinglePlane(visplane_t *pl)
floatv3_t p, m, n;
float ang;
float vx, vy, vz;
float fudge;
float fudge = 0;
// compiler complains when P_GetZAt is used in FLOAT_TO_FIXED directly
// use this as a temp var to store P_GetZAt's return value each time
fixed_t temp;
xoffs &= ((1 << (32-nflatshiftup))-1);
yoffs &= ((1 << (32-nflatshiftup))-1);
if (ds_powersoftwo)
{
// But xoffs and yoffs are zero..... ???!?!?!???!?!?!
// (Except when flat alignment is involved)
xoffs &= ((1 << (32-nflatshiftup))-1);
yoffs &= ((1 << (32-nflatshiftup))-1);
xoffs -= (pl->slope->o.x + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1);
yoffs += (pl->slope->o.y + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1);
xoffs -= (pl->slope->o.x + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1);
yoffs += (pl->slope->o.y + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1);
// Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -Red
fudge = ((1<<nflatshiftup)+1.0f)/(1<<nflatshiftup);
// Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -Red
fudge = ((1<<nflatshiftup)+1.0f)/(1<<nflatshiftup);
xoffs = (fixed_t)(xoffs*fudge);
yoffs = (fixed_t)(yoffs/fudge);
xoffs = (fixed_t)(xoffs*fudge);
yoffs = (fixed_t)(yoffs/fudge);
}
else
{
// Whoops, this is actually incorrect behaviour.
// Keep xoffs and yoffs as they are if this flat has offsets
//xoffs = -pl->slope->o.x;
//yoffs = pl->slope->o.y;
}
vx = FIXED_TO_FLOAT(pl->viewx+xoffs);
vy = FIXED_TO_FLOAT(pl->viewy-yoffs);
@ -1135,13 +1050,16 @@ void R_DrawSinglePlane(visplane_t *pl)
temp = P_GetZAt(pl->slope, pl->viewx + FLOAT_TO_FIXED(cos(ang)), pl->viewy - FLOAT_TO_FIXED(sin(ang)));
n.y = FIXED_TO_FLOAT(temp) - zeroheight;
m.x /= fudge;
m.y /= fudge;
m.z /= fudge;
if (ds_powersoftwo)
{
m.x /= fudge;
m.y /= fudge;
m.z /= fudge;
n.x *= fudge;
n.y *= fudge;
n.z *= fudge;
n.x *= fudge;
n.y *= fudge;
n.z *= fudge;
}
// Eh. I tried making this stuff fixed-point and it exploded on me. Here's a macro for the only floating-point vector function I recall using.
#define CROSS(d, v1, v2) \
@ -1158,14 +1076,26 @@ void R_DrawSinglePlane(visplane_t *pl)
ds_sz.z *= focallengthf;
// Premultiply the texture vectors with the scale factors
if (ds_powersoftwo)
{
#define SFMULT 65536.f*(1<<nflatshiftup)
ds_su.x *= SFMULT;
ds_su.y *= SFMULT;
ds_su.z *= SFMULT;
ds_sv.x *= SFMULT;
ds_sv.y *= SFMULT;
ds_sv.z *= SFMULT;
ds_su.x *= SFMULT;
ds_su.y *= SFMULT;
ds_su.z *= SFMULT;
ds_sv.x *= SFMULT;
ds_sv.y *= SFMULT;
ds_sv.z *= SFMULT;
#undef SFMULT
}
else
{
ds_su.x *= 65536.f;
ds_su.y *= 65536.f;
ds_su.z *= 65536.f;
ds_sv.x *= 65536.f;
ds_sv.y *= 65536.f;
ds_sv.z *= 65536.f;
}
if (spanfunc == R_DrawTranslucentSpan_8)
spanfunc = R_DrawTiltedTranslucentSpan_8;