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