|
| 1 | +// WOLFHACK.C |
| 2 | + |
| 3 | +#include "3D_DEF.H" |
| 4 | + |
| 5 | +#define MAXVIEWHEIGHT 200 |
| 6 | +#define GAMESTATE_TEST (true) |
| 7 | + |
| 8 | + |
| 9 | +unsigned CeilingTile=126, FloorTile=126; |
| 10 | + |
| 11 | +void (*MapRowPtr)(); |
| 12 | + |
| 13 | +int far spanstart[MAXVIEWHEIGHT/2]; // jtr - far |
| 14 | + |
| 15 | +fixed stepscale[MAXVIEWHEIGHT/2]; |
| 16 | +fixed basedist[MAXVIEWHEIGHT/2]; |
| 17 | + |
| 18 | +extern char far planepics[8192]; // 4k of ceiling, 4k of floor |
| 19 | + |
| 20 | +int halfheight = 0; |
| 21 | + |
| 22 | +byte far *planeylookup[MAXVIEWHEIGHT/2]; |
| 23 | +unsigned far mirrorofs[MAXVIEWHEIGHT/2]; |
| 24 | + |
| 25 | +fixed psin, pcos; |
| 26 | + |
| 27 | +fixed FixedMul (fixed a, fixed b) |
| 28 | +{ |
| 29 | + return (a>>8)*(b>>8); |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +int mr_rowofs; |
| 34 | +int mr_count; |
| 35 | +int mr_xstep; |
| 36 | +int mr_ystep; |
| 37 | +int mr_xfrac; |
| 38 | +int mr_yfrac; |
| 39 | +int mr_dest; |
| 40 | + |
| 41 | + |
| 42 | +/* |
| 43 | +============== |
| 44 | += |
| 45 | += DrawSpans |
| 46 | += |
| 47 | += Height ranges from 0 (infinity) to viewheight/2 (nearest) |
| 48 | +============== |
| 49 | +*/ |
| 50 | +extern byte far * lightsource; |
| 51 | +extern byte far * shadingtable; |
| 52 | + |
| 53 | + |
| 54 | +void DrawSpans (int x1, int x2, int height) |
| 55 | +{ |
| 56 | + fixed length; |
| 57 | + int ofs; |
| 58 | + int prestep; |
| 59 | + fixed startxfrac, startyfrac; |
| 60 | + |
| 61 | + int x, startx, count, plane, startplane; |
| 62 | + byte far *toprow, far *dest; |
| 63 | + long i; |
| 64 | + |
| 65 | + toprow = planeylookup[height]+bufferofs; |
| 66 | + mr_rowofs = mirrorofs[height]; |
| 67 | + |
| 68 | + mr_xstep = (psin<<1)/height; |
| 69 | + mr_ystep = (pcos<<1)/height; |
| 70 | + |
| 71 | + length = basedist[height]; |
| 72 | + startxfrac = (viewx + FixedMul(length,pcos)); |
| 73 | + startyfrac = (viewy - FixedMul(length,psin)); |
| 74 | + |
| 75 | +// draw two spans simultaniously |
| 76 | + |
| 77 | + if (gamestate.flags & GS_LIGHTING) |
| 78 | + { |
| 79 | + |
| 80 | + i=shade_max-(63l*(unsigned long)height/(unsigned long)normalshade); |
| 81 | + if (i<0) |
| 82 | + i=0; |
| 83 | + else |
| 84 | + if (i>63) |
| 85 | + i = 63; |
| 86 | + shadingtable=lightsource+(i<<8); |
| 87 | + plane = startplane = x1&3; |
| 88 | + prestep = viewwidth/2 - x1; |
| 89 | + do |
| 90 | + { |
| 91 | + outportb (SC_INDEX+1,1<<plane); |
| 92 | + mr_xfrac = startxfrac - (mr_xstep>>2)*prestep; |
| 93 | + mr_yfrac = startyfrac - (mr_ystep>>2)*prestep; |
| 94 | + |
| 95 | + startx = x1>>2; |
| 96 | + mr_dest = (unsigned)toprow + startx; |
| 97 | + mr_count = ((x2-plane)>>2) - startx + 1; |
| 98 | + x1++; |
| 99 | + prestep--; |
| 100 | + |
| 101 | +#if GAMESTATE_TEST |
| 102 | + if (mr_count) |
| 103 | + MapRowPtr(); |
| 104 | +#else |
| 105 | + if (mr_count) |
| 106 | + MapLSRow (); |
| 107 | +#endif |
| 108 | + |
| 109 | + plane = (plane+1)&3; |
| 110 | + } while (plane != startplane); |
| 111 | + } |
| 112 | + else |
| 113 | + { |
| 114 | + plane = startplane = x1&3; |
| 115 | + prestep = viewwidth/2 - x1; |
| 116 | + do |
| 117 | + { |
| 118 | + outportb (SC_INDEX+1,1<<plane); |
| 119 | + mr_xfrac = startxfrac - (mr_xstep>>2)*prestep; |
| 120 | + mr_yfrac = startyfrac - (mr_ystep>>2)*prestep; |
| 121 | + |
| 122 | + startx = x1>>2; |
| 123 | + mr_dest = (unsigned)toprow + startx; |
| 124 | + mr_count = ((x2-plane)>>2) - startx + 1; |
| 125 | + x1++; |
| 126 | + prestep--; |
| 127 | + |
| 128 | +#if GAMESTATE_TEST |
| 129 | + if (mr_count) |
| 130 | + MapRowPtr(); |
| 131 | +#else |
| 132 | + if (mr_count) |
| 133 | + MapRow (); |
| 134 | +#endif |
| 135 | + |
| 136 | + plane = (plane+1)&3; |
| 137 | + } while (plane != startplane); |
| 138 | + } |
| 139 | +} |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | +/* |
| 145 | +=================== |
| 146 | += |
| 147 | += SetPlaneViewSize |
| 148 | += |
| 149 | +=================== |
| 150 | +*/ |
| 151 | + |
| 152 | +void SetPlaneViewSize (void) |
| 153 | +{ |
| 154 | + int x,y; |
| 155 | + byte far *dest, far *src; |
| 156 | + |
| 157 | + halfheight = viewheight>>1; |
| 158 | + |
| 159 | + |
| 160 | + for (y=0 ; y<halfheight ; y++) |
| 161 | + { |
| 162 | + planeylookup[y] = (byte far *)0xa0000000l + (halfheight-1-y)*SCREENBWIDE;; |
| 163 | + mirrorofs[y] = (y*2+1)*SCREENBWIDE; |
| 164 | + |
| 165 | + stepscale[y] = y*GLOBAL1/32; |
| 166 | + if (y>0) |
| 167 | + basedist[y] = GLOBAL1/2*scale/y; |
| 168 | + } |
| 169 | + |
| 170 | + src = PM_GetPage(CeilingTile); |
| 171 | + dest = planepics; |
| 172 | + for (x=0 ; x<4096 ; x++) |
| 173 | + { |
| 174 | + *dest = *src++; |
| 175 | + dest += 2; |
| 176 | + } |
| 177 | + src = PM_GetPage(FloorTile); |
| 178 | + dest = planepics+1; |
| 179 | + for (x=0 ; x<4096 ; x++) |
| 180 | + { |
| 181 | + *dest = *src++; |
| 182 | + dest += 2; |
| 183 | + } |
| 184 | + |
| 185 | +} |
| 186 | + |
| 187 | + |
| 188 | +/* |
| 189 | +=================== |
| 190 | += |
| 191 | += DrawPlanes |
| 192 | += |
| 193 | +=================== |
| 194 | +*/ |
| 195 | + |
| 196 | +void DrawPlanes (void) |
| 197 | +{ |
| 198 | + int height, lastheight; |
| 199 | + int x; |
| 200 | + |
| 201 | +#if IN_DEVELOPMENT |
| 202 | + if (!MapRowPtr) |
| 203 | + DRAW2_ERROR(NULL_FUNC_PTR_PASSED); |
| 204 | +#endif |
| 205 | + |
| 206 | + |
| 207 | + if (viewheight>>1 != halfheight) |
| 208 | + SetPlaneViewSize (); // screen size has changed |
| 209 | + |
| 210 | + |
| 211 | + psin = viewsin; |
| 212 | + if (psin < 0) |
| 213 | + psin = -(psin&0xffff); |
| 214 | + pcos = viewcos; |
| 215 | + if (pcos < 0) |
| 216 | + pcos = -(pcos&0xffff); |
| 217 | + |
| 218 | +// |
| 219 | +// loop over all columns |
| 220 | +// |
| 221 | + lastheight = halfheight; |
| 222 | + |
| 223 | + for (x=0 ; x<viewwidth ; x++) |
| 224 | + { |
| 225 | + height = wallheight[x]>>3; |
| 226 | + if (height < lastheight) |
| 227 | + { // more starts |
| 228 | + do |
| 229 | + { |
| 230 | + spanstart[--lastheight] = x; |
| 231 | + } while (lastheight > height); |
| 232 | + } |
| 233 | + else if (height > lastheight) |
| 234 | + { // draw spans |
| 235 | + if (height > halfheight) |
| 236 | + height = halfheight; |
| 237 | + for ( ; lastheight < height ; lastheight++) |
| 238 | + if (lastheight>0) |
| 239 | + DrawSpans (spanstart[lastheight], x-1, lastheight); |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + height = halfheight; |
| 244 | + for ( ; lastheight < height ; lastheight++) |
| 245 | + if (lastheight>0) |
| 246 | + DrawSpans (spanstart[lastheight], x-1, lastheight); |
| 247 | +} |
| 248 | + |
0 commit comments