WOLFHACK.C (3068B)
1 // WOLFHACK.C 2 3 #include "WL_DEF.H" 4 5 #define MAXVIEWHEIGHT 200 6 7 int spanstart[MAXVIEWHEIGHT/2]; 8 9 fixed stepscale[MAXVIEWHEIGHT/2]; 10 fixed basedist[MAXVIEWHEIGHT/2]; 11 12 extern char far planepics[8192]; // 4k of ceiling, 4k of floor 13 14 int halfheight = 0; 15 16 byte far *planeylookup[MAXVIEWHEIGHT/2]; 17 unsigned mirrorofs[MAXVIEWHEIGHT/2]; 18 19 fixed psin, pcos; 20 21 fixed FixedMul (fixed a, fixed b) 22 { 23 return (a>>8)*(b>>8); 24 } 25 26 27 int mr_rowofs; 28 int mr_count; 29 int mr_xstep; 30 int mr_ystep; 31 int mr_xfrac; 32 int mr_yfrac; 33 int mr_dest; 34 35 36 /* 37 ============== 38 = 39 = DrawSpans 40 = 41 = Height ranges from 0 (infinity) to viewheight/2 (nearest) 42 ============== 43 */ 44 45 void DrawSpans (int x1, int x2, int height) 46 { 47 fixed length; 48 int ofs; 49 int prestep; 50 fixed startxfrac, startyfrac; 51 52 int x, startx, count, plane, startplane; 53 byte far *toprow, far *dest; 54 55 toprow = planeylookup[height]+bufferofs; 56 mr_rowofs = mirrorofs[height]; 57 58 mr_xstep = (psin<<1)/height; 59 mr_ystep = (pcos<<1)/height; 60 61 length = basedist[height]; 62 startxfrac = (viewx + FixedMul(length,pcos)); 63 startyfrac = (viewy - FixedMul(length,psin)); 64 65 // draw two spans simultaniously 66 67 plane = startplane = x1&3; 68 prestep = viewwidth/2 - x1; 69 do 70 { 71 outportb (SC_INDEX+1,1<<plane); 72 mr_xfrac = startxfrac - (mr_xstep>>2)*prestep; 73 mr_yfrac = startyfrac - (mr_ystep>>2)*prestep; 74 75 startx = x1>>2; 76 mr_dest = (unsigned)toprow + startx; 77 mr_count = ((x2-plane)>>2) - startx + 1; 78 x1++; 79 prestep--; 80 if (mr_count) 81 MapRow (); 82 plane = (plane+1)&3; 83 } while (plane != startplane); 84 85 } 86 87 88 89 90 /* 91 =================== 92 = 93 = SetPlaneViewSize 94 = 95 =================== 96 */ 97 98 void SetPlaneViewSize (void) 99 { 100 int x,y; 101 byte far *dest, far *src; 102 103 halfheight = viewheight>>1; 104 105 106 for (y=0 ; y<halfheight ; y++) 107 { 108 planeylookup[y] = (byte far *)0xa0000000l + (halfheight-1-y)*SCREENBWIDE;; 109 mirrorofs[y] = (y*2+1)*SCREENBWIDE; 110 111 stepscale[y] = y*GLOBAL1/32; 112 if (y>0) 113 basedist[y] = GLOBAL1/2*scale/y; 114 } 115 116 src = PM_GetPage(0); 117 dest = planepics; 118 for (x=0 ; x<4096 ; x++) 119 { 120 *dest = *src++; 121 dest += 2; 122 } 123 src = PM_GetPage(1); 124 dest = planepics+1; 125 for (x=0 ; x<4096 ; x++) 126 { 127 *dest = *src++; 128 dest += 2; 129 } 130 131 } 132 133 134 /* 135 =================== 136 = 137 = DrawPlanes 138 = 139 =================== 140 */ 141 142 void DrawPlanes (void) 143 { 144 int height, lastheight; 145 int x; 146 147 if (viewheight>>1 != halfheight) 148 SetPlaneViewSize (); // screen size has changed 149 150 151 psin = viewsin; 152 if (psin < 0) 153 psin = -(psin&0xffff); 154 pcos = viewcos; 155 if (pcos < 0) 156 pcos = -(pcos&0xffff); 157 158 // 159 // loop over all columns 160 // 161 lastheight = halfheight; 162 163 for (x=0 ; x<viewwidth ; x++) 164 { 165 height = wallheight[x]>>3; 166 if (height < lastheight) 167 { // more starts 168 do 169 { 170 spanstart[--lastheight] = x; 171 } while (lastheight > height); 172 } 173 else if (height > lastheight) 174 { // draw spans 175 if (height > halfheight) 176 height = halfheight; 177 for ( ; lastheight < height ; lastheight++) 178 DrawSpans (spanstart[lastheight], x-1, lastheight); 179 } 180 } 181 182 height = halfheight; 183 for ( ; lastheight < height ; lastheight++) 184 DrawSpans (spanstart[lastheight], x-1, lastheight); 185 } 186