Commit a8c256ed authored by Steven Fuller's avatar Steven Fuller

wl_draw.c, wl_main.c: cleanups

wl_main.c: fixed hard to find raycasting bug in BuildTables where in certain
circumstances a casted ray would miss the wall it should have hit.
parent 0f7a8ddd
......@@ -32,9 +32,8 @@ void Quit(char *error)
ShutdownId();
if (screen) {
printf("TODO: spiffy ansi screen goes here..\n");
/* doesn't look too good on console at the moment ...*/
//DisplayTextSplash(screen);
/* DisplayTextSplash(screen); */
}
if (error && *error) {
......
......@@ -11,12 +11,8 @@
static unsigned wallheight[MAXVIEWWIDTH];
/* refresh variables */
fixed viewx,viewy; /* the focal point */
fixed viewx, viewy; /* the focal point */
/* ray casting variables */
static int focaltx, focalty;
static unsigned xpartial, ypartial;
static int viewangle;
static unsigned tilehit;
......@@ -24,7 +20,6 @@ static unsigned tilehit;
static int xtile, ytile;
static int xtilestep, ytilestep;
static long xintercept, yintercept;
static long xstep, ystep;
static unsigned postx;
......@@ -219,16 +214,12 @@ static int CalcRotate(objtype *ob)
=
= DrawScaleds
=
= Draws all objects that are visable
= Draws all objects that are visible
=
=====================
*/
#ifdef DUMBTEST
#define MAXVISABLE 640
#else
#define MAXVISABLE 64
#endif
typedef struct {
int viewx;
......@@ -249,16 +240,14 @@ static void DrawScaleds()
visptr = &vislist[0];
//
// place static objects
//
/* place static objects */
for (statptr = &statobjlist[0]; statptr != laststatobj; statptr++)
{
if ((visptr->shapenum = statptr->shapenum) == -1)
continue; // object has been deleted
continue; /* object has been deleted */
if (!*statptr->visspot)
continue; // not visable
continue; /* not visable */
if (TransformTile(statptr->tilex, statptr->tiley
,&visptr->viewx,&visptr->viewheight) && statptr->flags & FL_BONUS)
......@@ -268,7 +257,7 @@ static void DrawScaleds()
}
if (!visptr->viewheight)
continue; // to close to the object
continue; /* too close to the object */
if (visptr < &vislist[MAXVISABLE-1]) /* don't let it overflow */
visptr++;
......@@ -397,18 +386,12 @@ static void DrawPlayerWeapon()
static void WallRefresh()
{
/*
set up variables for this view
*/
viewangle = player->angle;
viewsin = sintable[viewangle];
viewcos = costable[viewangle];
viewx = player->x - FixedByFrac(focallength,viewcos);
viewy = player->y + FixedByFrac(focallength,viewsin);
focaltx = viewx>>TILESHIFT;
focalty = viewy>>TILESHIFT;
viewx = player->x - FixedByFrac(focallength, viewcos);
viewy = player->y + FixedByFrac(focallength, viewsin);
AsmRefresh();
}
......@@ -450,10 +433,6 @@ static void MapRow()
//mr_yfrac += mr_ystep;
//mr_xfrac += mr_xstep;
/*
mr_dest[0] = planepics[0x1F00|(planepics[(ebx&0x1FFE)+0]&0xFF)];
mr_dest[mr_rowofs] = planepics[0x1F00|(planepics[(ebx&0x1FFE)+1]&0xFF)];
*/
mr_dest[0] = planepics[ebx+0];
mr_dest[mr_rowofs] = planepics[ebx+1];
mr_dest++;
......@@ -633,9 +612,6 @@ void ThreeDRefresh()
/* clear out the traced array */
memset(spotvis, 0, sizeof(spotvis));
/* follow the walls from there to the right, drawing as we go */
/* DrawPlayBorder(); */
#ifndef DRAWCEIL
ClearScreen();
#endif
......@@ -734,15 +710,15 @@ static void ScaleLineTrans(unsigned int height, byte *source, int x)
}
}
static unsigned char *spritegfx[SPR_TOTAL];
static byte *spritegfx[SPR_TOTAL];
static void DeCompileSprite(int shapenum)
{
unsigned char *ptr;
unsigned char *buf;
unsigned char *cmdptr;
unsigned char *pixels;
short int yoff; /* int16_t */
byte *ptr;
byte *buf;
byte *cmdptr;
byte *pixels;
int yoff;
int y, y0, y1;
int x, left, right;
int cmd;
......@@ -768,7 +744,7 @@ static void DeCompileSprite(int shapenum)
while (ptr[cmd+0]) {
/* y1 = (ptr[cmd+0] | (ptr[cmd+1] << 8)) / 2; */
y1 = ptr[cmd+0] / 2;
yoff = ptr[cmd+2] | (ptr[cmd+3] << 8);
yoff = (int16_t)(ptr[cmd+2] | (ptr[cmd+3] << 8));
/* y0 = (ptr[cmd+4] | (ptr[cmd+5] << 8)) / 2; */
y0 = ptr[cmd+4] / 2;
......@@ -1058,15 +1034,17 @@ static int samey(int intercept, int tile)
else
return 1;
}
}
}
static void AsmRefresh()
{
fixed doorxhit, dooryhit;
long xtemp, ytemp;
unsigned xpartialup, xpartialdown, ypartialup, ypartialdown;
unsigned xpartial, ypartial;
int doorhit;
int angle; /* ray angle through postx */
int midangle;
int focaltx, focalty;
int xstep, ystep;
midangle = viewangle*(FINEANGLES/ANGLES);
xpartialdown = viewx&(TILEGLOBAL-1);
......@@ -1074,6 +1052,9 @@ static void AsmRefresh()
ypartialdown = viewy&(TILEGLOBAL-1);
ypartialup = TILEGLOBAL-ypartialdown;
focaltx = viewx>>TILESHIFT;
focalty = viewy>>TILESHIFT;
for (postx = 0; postx < viewwidth; postx++) {
angle = midangle + pixelangle[postx];
......@@ -1120,6 +1101,7 @@ for (postx = 0; postx < viewwidth; postx++) {
goto entry90;
}
yintercept = viewy + xpartialbyystep();
xtile = focaltx + xtilestep;
......@@ -1128,40 +1110,40 @@ for (postx = 0; postx < viewwidth; postx++) {
/* CORE LOOP */
#define TILE(n) (n>>16)
#define TILE(n) ((n)>>16)
/* check intersections with vertical walls */
vertcheck:
vertcheck:
if (!samey(yintercept, ytile))
goto horizentry;
vertentry:
tilehit = tilemap[xtile][TILE(yintercept)];
if (tilehit != 0) {
if (tilehit) {
if (tilehit & 0x80) {
if (tilehit & 0x40) {
/* vertpushwall */
ytemp = yintercept + (signed)((signed)pwallpos * ystep) / 64;
doorhit = yintercept + (signed)((signed)pwallpos * ystep) / 64;
if (TILE(ytemp) != TILE(yintercept))
if (TILE(doorhit) != TILE(yintercept))
goto passvert;
yintercept = ytemp;
yintercept = doorhit;
xintercept = xtile << 16;
HitVertPWall();
} else {
/* vertdoor */
dooryhit = yintercept + ystep / 2;
doorhit = yintercept + ystep / 2;
if (TILE(dooryhit) != TILE(yintercept))
if (TILE(doorhit) != TILE(yintercept))
goto passvert;
/* check door position */
if ((dooryhit&0xFFFF) < doorposition[tilehit&0x7f])
if ((doorhit&0xFFFF) < doorposition[tilehit&0x7f])
goto passvert;
yintercept = dooryhit;
yintercept = doorhit;
xintercept = (xtile << 16) + 32768;
HitVertDoor();
}
......@@ -1186,29 +1168,29 @@ horizcheck:
horizentry:
tilehit = tilemap[TILE(xintercept)][ytile];
if (tilehit != 0) {
if (tilehit) {
if (tilehit & 0x80) {
if (tilehit & 0x40) {
xtemp = xintercept + (signed)((signed)pwallpos * xstep) / 64;
doorhit = xintercept + (signed)((signed)pwallpos * xstep) / 64;
/* horizpushwall */
if (TILE(xtemp) != TILE(xintercept))
if (TILE(doorhit) != TILE(xintercept))
goto passhoriz;
xintercept = xtemp;
xintercept = doorhit;
yintercept = ytile << 16;
HitHorizPWall();
} else {
doorxhit = xintercept + xstep / 2;
doorhit = xintercept + xstep / 2;
if (TILE(doorxhit) != TILE(xintercept))
if (TILE(doorhit) != TILE(xintercept))
goto passhoriz;
/* check door position */
if ((doorxhit&0xFFFF) < doorposition[tilehit&0x7f])
if ((doorhit&0xFFFF) < doorposition[tilehit&0x7f])
goto passhoriz;
xintercept = doorxhit;
xintercept = doorhit;
yintercept = (ytile << 16) + 32768;
HitHorizDoor();
}
......@@ -1224,7 +1206,4 @@ passhoriz:
xintercept += xstep;
goto horizcheck;
}
#ifdef DUMBTEST
memset(spotvis, 1, sizeof(spotvis));
#endif
}
......@@ -881,53 +881,47 @@ void InitDigiMap()
=
= BuildTables
=
= Calculates:
=
= scale projection constant
= sintable/costable overlapping fractional tables
=
==================
*/
static const float radtoint = (float)FINEANGLES/2.0f/PI;
static const double radtoint = (double)FINEANGLES/2.0/PI;
void BuildTables()
{
int i;
float angle,anglestep;
double tang;
double tang, angle, anglestep;
fixed value;
/* calculate fine tangents */
//
// calculate fine tangents
//
for (i=0;i<FINEANGLES/8;i++)
{
tang = tan((i+0.5)/radtoint);
for (i = 0; i < FINEANGLES/8; i++) {
tang = tan((double)i/radtoint);
finetangent[i] = tang*TILEGLOBAL;
finetangent[FINEANGLES/4-1-i] = 1/tang*TILEGLOBAL;
}
/* fight off asymptotic behaviour at 90 degrees */
finetangent[FINEANGLES/4-1] = finetangent[FINEANGLES/4-2];
//
// costable overlays sintable with a quarter phase shift
// ANGLES is assumed to be divisable by four
//
angle = 0;
anglestep = PI/2/ANGLEQUAD;
for (i=0;i<=ANGLEQUAD;i++)
{
value=GLOBAL1*sin(angle);
sintable[i]=
sintable[i+ANGLES]=
angle = 0.0;
anglestep = PI/2.0/ANGLEQUAD;
for (i = 0; i <= ANGLEQUAD; i++) {
value = GLOBAL1*sin(angle);
sintable[i] =
sintable[i+ANGLES] =
sintable[ANGLES/2-i] = value;
sintable[ANGLES-i]=
sintable[ANGLES-i] =
sintable[ANGLES/2+i] = -value;
angle += anglestep;
}
}
/*
......@@ -942,10 +936,8 @@ void CalcProjection(long focal)
{
int i;
long intang;
float angle;
double tang;
double angle, tang, facedist;
int halfview;
double facedist;
focallength = focal;
facedist = focal+MINDIST;
......@@ -967,10 +959,8 @@ void CalcProjection(long focal)
// calculate the angle offset from view angle of each pixel's ray
//
for (i=0;i<halfview;i++)
{
// start 1/2 pixel over, so viewangle bisects two middle pixels
tang = (long)i*VIEWGLOBAL/viewwidth/facedist;
for (i = 0; i < halfview; i++) {
tang = ((double)i)*VIEWGLOBAL/viewwidth/facedist;
angle = atan(tang);
intang = angle*radtoint;
pixelangle[halfview-1-i] = intang;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment