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