This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3d_scale.c
294 lines (222 loc) · 6.13 KB
/
3d_scale.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// 3D_SCALE.C
//
// These functions are FULL of bugs in Blake;
// just use Wolf4SDL's stuff for now
//
#include "3d_def.h"
/*
===================
=
= DrawColumn
=
===================
*/
void DrawColumn (int count, int src, byte *dest)
{
while (count--)
{
*dest = src;
dest += screen.buffer->pitch;
}
}
/*
===================
=
= DrawTranslucentColumn
=
===================
*/
void DrawTranslucentColumn (int count, byte *dest)
{
byte *shade = &lightsource[0xa00];
while (count--)
{
*dest = shade[shadingtable[*dest]];
dest += screen.buffer->pitch;
}
}
/*
===================
=
= ScaleLine
=
= Reconstruct a sprite and draw it
=
= each vertical line of the shape has a pointer to segment data:
= end of segment pixel*2 (0 terminates line)
= top of virtual line with segment in proper place
= start of segment pixel*2
= <repeat>
=
= [top] must be cast to signed short because of the silly way it was
= calculated during sprite building
=
===================
*/
void ScaleLine (compline_t *sline, int ycenter)
{
byte *src,*dest;
byte *linecmds;
int count;
int start,end,top;
int startpix,endpix;
fixed screenscale;
linecmds = sline->commandtable;
for (end = ReadShort(linecmds) / 2; end; end = ReadShort(linecmds) / 2)
{
top = (int16_t)ReadShort(linecmds + 2);
start = ReadShort(linecmds + 4) / 2;
screenscale = start * sline->stepscale;
endpix = (screenscale >> FRACBITS) + ycenter;
for (src = &sline->source[top + start]; start != end; start++, src++)
{
startpix = endpix;
if (startpix >= viewheight)
break; // off the bottom of the view area
screenscale += sline->stepscale;
endpix = (screenscale >> FRACBITS) + ycenter;
if (endpix < 0)
continue; // not into the view area
if (startpix < 0)
startpix = 0; // clip upper boundary
if (endpix > viewheight)
endpix = viewheight; // clip lower boundary
count = endpix - startpix;
if (count)
{
dest = vbuf + ylookup[startpix] + sline->x;
if (sline->cloaked)
DrawTranslucentColumn (count,dest);
else
DrawColumn (count,shadingtable[*src],dest);
}
}
linecmds += 6; // next segment list
}
}
/*
===================
=
= ScaleShape
=
= Draws a compiled shape at [height] pixels high
=
===================
*/
void ScaleShape (visobj_t *sprite)
{
int i;
compline_t sline;
compshape_t *shape;
int height,ycenter;
int x1,x2,xcenter;
fixed screenscale;
height = sprite->viewheight >> 3; // low three bits are fractional
if (!height)
return; // too close or far away
sline.source = PM_GetSpritePage(sprite->shapenum);
sline.stepscale = FixedDiv(height,TEXTURESIZE / 2);
sline.cloaked = sprite->cloaked;
SetShading (height,sprite->lighting);
shape = (compshape_t *)sline.source;
xcenter = sprite->viewx - height;
ycenter = centery - height;
screenscale = shape->leftpix * sline.stepscale;
x2 = (screenscale >> FRACBITS) + xcenter;
for (i = shape->leftpix; i <= shape->rightpix; i++)
{
//
// calculate edges of the shape
//
x1 = x2;
if (x1 >= viewwidth)
break; // off the right side of the view area
screenscale += sline.stepscale;
x2 = (screenscale >> FRACBITS) + xcenter;
if (x2 < 0)
continue; // not into the view area
if (x1 < 0)
x1 = 0; // clip left boundary
if (x2 > viewwidth)
x2 = viewwidth; // clip right boundary
sline.commandtable = &sline.source[shape->dataofs[i - shape->leftpix]];
while (x1 < x2)
{
if (wallheight[x1] < sprite->viewheight)
{
sline.x = x1;
ScaleLine (&sline,ycenter);
}
x1++;
}
}
}
/*
===================
=
= SimpleScaleShape
=
= NO CLIPPING, height in pixels
=
= Draws a compiled shape at [height] pixels high
=
===================
*/
void SimpleScaleShape (int dispx, int dispy, int dispheight, int shapenum, int shade)
{
int i;
compline_t sline;
compshape_t *shape;
int height,ycenter;
int x1,x2,xcenter;
fixed screenscale;
height = dispheight >> 1;
sline.source = PM_GetSpritePage(shapenum);
sline.stepscale = FixedDiv(height,TEXTURESIZE / 2);
sline.cloaked = false;
SetShading (height,shade);
shape = (compshape_t *)sline.source;
xcenter = dispx - height;
ycenter = dispy - height;
if (useBounceOffset)
ycenter += bounceOffset >> (FRACBITS + 1);
screenscale = shape->leftpix * sline.stepscale;
x2 = (screenscale >> FRACBITS) + xcenter;
for (i = shape->leftpix; i <= shape->rightpix; i++)
{
//
// calculate edges of the shape
//
x1 = x2;
screenscale += sline.stepscale;
x2 = (screenscale >> FRACBITS) + xcenter;
sline.commandtable = &sline.source[shape->dataofs[i - shape->leftpix]];
while (x1 < x2)
{
sline.x = x1;
ScaleLine (&sline,ycenter);
x1++;
}
}
}
/*
===================
=
= MegaSimpleScaleShape
=
= Adjusts viewheight to draw anywhere on the screen
=
===================
*/
void MegaSimpleScaleShape (int dispx, int dispy, int dispheight, int shapenum, int shade)
{
int oldviewheight = viewheight;
viewheight = screen.height;
vbuf = VW_LockSurface(screen.buffer);
if (!vbuf)
Quit ("Unable to lock surface: %s\n",SDL_GetError());
SimpleScaleShape (dispx,dispy,dispheight,shapenum,shade);
VW_UnlockSurface (screen.buffer);
vbuf = NULL;
viewheight = oldviewheight;
}