-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path3D_DRAW2.C
248 lines (194 loc) · 4.31 KB
/
3D_DRAW2.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// WOLFHACK.C
#include "3D_DEF.H"
#define MAXVIEWHEIGHT 200
#define GAMESTATE_TEST (true)
unsigned CeilingTile=126, FloorTile=126;
void (*MapRowPtr)();
int far spanstart[MAXVIEWHEIGHT/2]; // jtr - far
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 far 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)
==============
*/
extern byte far * lightsource;
extern byte far * shadingtable;
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;
long i;
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
if (gamestate.flags & GS_LIGHTING)
{
i=shade_max-(63l*(unsigned long)height/(unsigned long)normalshade);
if (i<0)
i=0;
else
if (i>63)
i = 63;
shadingtable=lightsource+(i<<8);
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 GAMESTATE_TEST
if (mr_count)
MapRowPtr();
#else
if (mr_count)
MapLSRow ();
#endif
plane = (plane+1)&3;
} while (plane != startplane);
}
else
{
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 GAMESTATE_TEST
if (mr_count)
MapRowPtr();
#else
if (mr_count)
MapRow ();
#endif
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(CeilingTile);
dest = planepics;
for (x=0 ; x<4096 ; x++)
{
*dest = *src++;
dest += 2;
}
src = PM_GetPage(FloorTile);
dest = planepics+1;
for (x=0 ; x<4096 ; x++)
{
*dest = *src++;
dest += 2;
}
}
/*
===================
=
= DrawPlanes
=
===================
*/
void DrawPlanes (void)
{
int height, lastheight;
int x;
#if IN_DEVELOPMENT
if (!MapRowPtr)
DRAW2_ERROR(NULL_FUNC_PTR_PASSED);
#endif
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++)
if (lastheight>0)
DrawSpans (spanstart[lastheight], x-1, lastheight);
}
}
height = halfheight;
for ( ; lastheight < height ; lastheight++)
if (lastheight>0)
DrawSpans (spanstart[lastheight], x-1, lastheight);
}