mirror of
https://github.com/Blzut3/Wolf3D-Mac.git
synced 2025-02-19 21:31:11 +00:00
1 line
12 KiB
C
1 line
12 KiB
C
|
#include "WolfDef.h"
static Word checkcoord[11][4] = { /* Indexs to the bspcoord table */
{3,0,2,1},
{3,0,2,0},
{3,1,2,0},
{0,0,0,0},
{2,0,2,1},
{0,0,0,0}, /* Not valid */
{3,1,3,0},
{0,0,0,0},
{2,0,3,1},
{2,1,3,1},
{2,1,3,0}};
/**********************************
Draw a 3-D textured polygon, must be done FAST!
**********************************/
void RenderWallLoop(Word x1,Word x2,Word distance)
{
fixed_t texturecolumn;
Word tile,scaler, angle;
/* calculate and draw each column */
if (rw_downside) {
while (x1 < x2) { /* Time to draw? */
scaler = rw_scale >> FRACBITS; /* Get the draw scale */
xscale[x1] = scaler; /* Save the scale factor */
angle = xtoviewangle[x1]+rw_centerangle;
texturecolumn = rw_midpoint - SUFixedMul(finetangent[angle],distance); /* Which texture to use? */
if ((Word)texturecolumn < rw_mintex) {
texturecolumn = rw_mintex;
} else if ((Word)texturecolumn >= rw_maxtex) {
texturecolumn = rw_maxtex-1;
}
tile = rw_texture[texturecolumn>>8]; /* Get the tile to use */
IO_ScaleWallColumn(x1,scaler,tile,(texturecolumn>>1)&127); /* Draw the line */
++x1; /* Next x */
rw_scale+=rw_scalestep; /* Step the scale factor for the wall */
}
return;
}
while (x1 < x2) { /* Time to draw? */
scaler = rw_scale >> FRACBITS; /* Get the draw scale */
xscale[x1] = scaler; /* Save the scale factor */
angle = xtoviewangle[x1]+rw_centerangle;
texturecolumn = SUFixedMul(finetangent[angle],distance)+rw_midpoint; /* Which texture to use? */
if ((Word)texturecolumn < rw_mintex) {
texturecolumn = rw_mintex;
} else if ((Word)texturecolumn >= rw_maxtex) {
texturecolumn = rw_maxtex-1;
}
tile = rw_texture[texturecolumn>>8]; /* Get the tile to use */
if (!(WallListPtr[tile+1] & 0x4000)) {
texturecolumn^=0xff; /* Reverse the tile for N,W walls */
}
IO_ScaleWallColumn(x1,scaler,tile,(texturecolumn>>1)&127); /* Draw the line */
++x1; /* Next x */
rw_scale+=rw_scalestep; /* Step the scale factor for the wall */
}
}
/*
=====================
=
= RenderWallRange
=
= Draw a wall segment between start and stop angles (inclusive) (short angles)
= No clipping is needed
=
======================
*/
void RenderWallRange (Word start,Word stop,saveseg_t *seg,Word distance)
{
LongWord scale2;
Word vangle;
Word x1,x2;
/* mark the segment as visible for auto map*/
seg->dir |= DIR_SEENFLAG; /* for automap*/
areavis[seg->area] = 1; /* for sprite drawing*/
start -= ANGLE180; /* Adjust the start angle */
stop -= ANGLE180; /* Adjust the stop angle */
vangle = (Word)(start+ANGLE90)>>ANGLETOFINESHIFT;
x1 = viewangletox[vangle];
vangle = (Word)(stop+ANGLE90-1)>>ANGLETOFINESHIFT; /* make non inclusive*/
x2 = viewangletox[vangle];
if (x2 == x1) {
return; /* less than one column wide*/
}
rw_scale = (long) ScaleFromGlobalAngle(start+centershort,distance)<<FRACBITS;
if (x2>x1+1) {
scale2 = (long) ScaleFromGlobalAngle(stop+centershort,distance)<<FRACBITS;
rw_scalestep = (long)(scale2-rw_scale)/(long)(x2-x1);
}
RenderWallLoop(x1,x2,distance);
}
/*
===============================================================================
=
= ClipWallSegment
=
= Clips the given screenpost and includes it in newcolumn
===============================================================================
*/
/* a screenpost_t is a solid range of visangles, used to clip and detect*/
/* span exposures / hidings*/
typedef struct {
Word top, bottom;
} screenpost_t;
#define MAXSEGS 16
screenpost_t solidsegs[MAXSEGS], *newend; /* newend is one past the last valid seg */
void ClipWallSegment(Word top,Word bottom,saveseg_t *seg,Word distance)
{
screenpost_t *next, *start;
/* find the first clippost that touches the source post (adjacent pixels are touching)*/
start = solidsegs;
while (start->bottom > top+1) {
start++;
}
if (top > start->top) {
if (bottom > start->top+1) { /* post is entirely visible (above start), so insert a new clippost*/
RenderWallRange(top, bottom,seg,distance);
next = newend;
newend++;
while (next !
|