- Code:
/*
====================
= ApplyPatch2
= Partial Coverage Patches with transparency
= aka 3rd or 4th Index Walls
====================
*/
#ifdef Use_Patch2
byte patchedwall[PMPageSize];
int lastpatchnum;
#define FIRSTPATCHTILE 2000
#define NUMPATCHES 1 // This is the number of patch pairs (light/dark) in use.
#define PATCHSTART DOORWALL-NUMPATCHES*2
unsigned GetPatchNum(boolean useXspot)
{
// work off xspot/yspot, instead of xtile/ytile
unsigned spot, x, y;
(useXspot? spot=xspot : spot=yspot);
x = (unsigned)((spot+1)/64);
y = (unsigned)((spot+1)%64) -1;
spot = MAPSPOT(x,y,1); // adjust for *Planes Exp
// Restrict patch objects to the given range.
if (spot < FIRSTPATCHTILE || spot >= FIRSTPATCHTILE+NUMPATCHES )
return 0;
else
return spot;
}
boolean ApplyPatch(int wallpic, boolean useXspot)
{
byte *scan;
int pixel;
unsigned spot;
spot = GetPatchNum(useXspot);
if (spot > 0 && wallpic < DOORWALL) // Don't do door-related textures.
{
// Keep track of the patch in memory.
// The wall is already stored elsewhere.
lastpatchnum = spot;
spot -= FIRSTPATCHTILE;
// Adjust for light/dark patch sides
spot = spot * 2 + (lastside?1:0);
// Load the wall into the byte array first.
scan = PM_GetTexture(wallpic);
for (pixel=0; pixel>TEXTUREFROMFIXEDSHIFT)&TEXTUREMASK;
if (xtilestep == -1)
{
texture = TEXTUREMASK-texture;
xintercept += TILEGLOBAL;
}
#ifdef Use_Patch2
if(lastside==1 && lastintercept==xtile && lasttilehit==tilehit && !(lasttilehit & BIT_WALL) && GetPatchNum(true)==lastpatchnum)
#else
if(lastside==1 && lastintercept==xtile && lasttilehit==tilehit && !(lasttilehit & BIT_WALL))
#endif
{
if((pixx&3) && texture == lasttexture)
{
ScalePost();
postx = pixx;
wallheight[pixx] = wallheight[pixx-1];
return;
}
ScalePost();
wallheight[pixx] = CalcHeight();
postsource+=texture-lasttexture;
postwidth=1;
postx=pixx;
lasttexture=texture;
return;
}
if(lastside!=-1) ScalePost();
lastside=1;
lastintercept=xtile;
lasttilehit=tilehit;
lasttexture=texture;
wallheight[pixx] = CalcHeight();
postx = pixx;
postwidth = 1;
if (tilehit & BIT_WALL)
{ // check for adjacent doors
ytile = (short)(yintercept>>TILESHIFT);
if ( tilemap[xtile-xtilestep][ytile]&BIT_DOOR )
wallpic = DOORWALL+3;
else
wallpic = vertwall[tilehit &BIT_WALL]; // was ~BIT_WALL]; // *Mod *Max *Flag *!
}
else
wallpic = vertwall[tilehit];
#ifdef Use_Patch2
AssignWall (wallpic); // ?
if (ApplyPatch (wallpic, true))
postsource = patchedwall+texture;
else
postsource = PM_GetTexture(wallpic)+texture;
#else
postsource = PM_GetTexture(wallpic) + texture;
#endif
}
I don't know how or why that code got inserted here on this thread, but that was is not the code I am using in that section, and as far as I understand that code would not even compile.
___________________________________________________________
This is what I have in the relevant section of WL_Draw.cpp
(still semi broken, due to incompatibility with my implementation of removing the hard coded wall and door limits)
[why both... there are reasons]
/*
====================
= ApplyPatch2
= Partial Coverage Patches with transparency
= aka 3rd or 4th Index Walls
====================
*/
#ifdef Use_Patch2
byte patchedwall[PMPageSize];
int lastpatchnum;
#define FIRSTPATCHTILE 2000
#define NUMPATCHES 2 // This is the number of patch pairs (light/dark) in use.
#define PATCHSTART DOORWALL-NUMPATCHES*2
unsigned GetPatchNum(boolean useXspot)
{
// work off xspot/yspot, instead of xtile/ytile
unsigned spot, x, y;
(useXspot? spot=xspot : spot=yspot);
x = (unsigned)((spot+1)/64);
y = (unsigned)((spot+1)%64) -1;
spot = MAPSPOT(x,y,1); // adjust for *Planes Exp
// Restrict patch objects to the given range.
if (spot < FIRSTPATCHTILE || spot >= FIRSTPATCHTILE+NUMPATCHES )
return 0;
else
return spot;
}
boolean ApplyPatch(int wallpic, boolean useXspot)
{
byte *scan;
int pixel;
unsigned spot;
spot = GetPatchNum(useXspot);
if (spot > 0 && wallpic < DOORWALL) // Don't do door-related textures.
{
// Keep track of the patch in memory.
// The wall is already stored elsewhere.
lastpatchnum = spot;
spot -= FIRSTPATCHTILE;
// Adjust for light/dark patch sides
spot = spot * 2 + (lastside?1:0);
// Load the wall into the byte array first.
scan = PM_GetTexture(wallpic);
for (pixel=0; pixel>TEXTUREFROMFIXEDSHIFT)&TEXTUREMASK;
if (xtilestep == -1)
{
texture = TEXTUREMASK-texture;
xintercept += TILEGLOBAL;
}
#ifdef Use_Patch2
if(lastside==1 && lastintercept==xtile && lasttilehit==tilehit && !(lasttilehit & BIT_WALL) && GetPatchNum(true)==lastpatchnum)
#else
if(lastside==1 && lastintercept==xtile && lasttilehit==tilehit && !(lasttilehit & BIT_WALL))
#endif
{
if((pixx&3) && texture == lasttexture)
{
ScalePost();
postx = pixx;
wallheight[pixx] = wallheight[pixx-1];
return;
}
ScalePost();
wallheight[pixx] = CalcHeight();
postsource+=texture-lasttexture;
postwidth=1;
postx=pixx;
lasttexture=texture;
return;
}
if(lastside!=-1) ScalePost();
lastside=1;
lastintercept=xtile;
lasttilehit=tilehit;
lasttexture=texture;
wallheight[pixx] = CalcHeight();
postx = pixx;
postwidth = 1;
if (tilehit & BIT_WALL)
{ // check for adjacent doors
ytile = (short)(yintercept>>TILESHIFT);
if ( tilemap[xtile-xtilestep][ytile]&BIT_DOOR )
wallpic = DOORWALL+3;
else
#ifdef Ultra_Tex
wallpic = vertwall[tilehit &BIT_WALL];
#else
wallpic = vertwall[tilehit &~BIT_WALL];
#endif // Ultra_Tex
}
else
wallpic = vertwall[tilehit];
#ifdef Use_Patch2
// AssignWall (wallpic); // ?
if (ApplyPatch (wallpic, true))
postsource = patchedwall+texture;
else
postsource = PM_GetTexture(wallpic)+texture;
#else
postsource = PM_GetTexture(wallpic) + texture;
#endif
}
/*
====================
=
= HitHorizWall
=
= tilehit bit 7 is 0, because it's not a door tile
= if bit 6 is 1 and the adjacent tile is a door tile, use door side pic
=
====================
*/
void HitHorizWall (void)
{
int wallpic;
int texture;
texture = ((xintercept+texdelta)>>TEXTUREFROMFIXEDSHIFT)&TEXTUREMASK;
if (ytilestep == -1)
yintercept += TILEGLOBAL;
else
texture = TEXTUREMASK-texture;
#ifdef Use_Patch2
if(lastside==1 && lastintercept==ytile && lasttilehit==tilehit && !(lasttilehit & BIT_WALL) && lastpatchnum==GetPatchNum(false))
#else
if(lastside==0 && lastintercept==ytile && lasttilehit==tilehit && !(lasttilehit & BIT_WALL))
#endif
{
if((pixx&3) && texture == lasttexture)
{
ScalePost();
postx=pixx;
wallheight[pixx] = wallheight[pixx-1];
return;
}
ScalePost();
wallheight[pixx] = CalcHeight();
postsource+=texture-lasttexture;
postwidth=1;
postx=pixx;
lasttexture=texture;
return;
}
if(lastside!=-1) ScalePost();
lastside=0;
lastintercept=ytile;
lasttilehit=tilehit;
lasttexture=texture;
wallheight[pixx] = CalcHeight();
postx = pixx;
postwidth = 1;
if (tilehit & BIT_WALL)
{ // check for adjacent doors
xtile = (short)(xintercept>>TILESHIFT);
if ( tilemap[xtile][ytile-ytilestep]&BIT_DOOR)
wallpic = DOORWALL+2;
else
wallpic = horizwall[tilehit & ~BIT_WALL];
}
else
wallpic = horizwall[tilehit];
#ifdef Use_Patch2
// AssignWall (wallpic); // ?
if (ApplyPatch (wallpic, false))
postsource = patchedwall+texture;
else
postsource = PM_GetTexture(wallpic)+texture;
#else
postsource = PM_GetTexture(wallpic) + texture;
#endif
}