| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2000 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: |
| 30 |
* Here is a core component: drawing the floors and ceilings, |
| 31 |
* while maintaining a per column clipping list only. |
| 32 |
* Moreover, the sky areas have to be determined. |
| 33 |
* |
| 34 |
* MAXVISPLANES is no longer a limit on the number of visplanes, |
| 35 |
* but a limit on the number of hash slots; larger numbers mean |
| 36 |
* better performance usually but after a point they are wasted, |
| 37 |
* and memory and time overheads creep in. |
| 38 |
* |
| 39 |
* For more information on visplanes, see: |
| 40 |
* |
| 41 |
* http://classicgaming.com/doom/editing/ |
| 42 |
* |
| 43 |
* Lee Killough |
| 44 |
* |
| 45 |
*-----------------------------------------------------------------------------*/ |
| 46 |
|
| 47 |
#ifdef HAVE_CONFIG_H |
| 48 |
#include "config.h" |
| 49 |
#endif |
| 50 |
|
| 51 |
#include "z_zone.h" /* memory allocation wrappers -- killough */ |
| 52 |
|
| 53 |
#include "doomstat.h" |
| 54 |
#include "w_wad.h" |
| 55 |
#include "r_main.h" |
| 56 |
#include "r_draw.h" |
| 57 |
#include "r_things.h" |
| 58 |
#include "r_sky.h" |
| 59 |
#include "r_plane.h" |
| 60 |
#include "r_main.h" |
| 61 |
#include "v_video.h" |
| 62 |
#include "lprintf.h" |
| 63 |
|
| 64 |
#include "dsda/map_format.h" |
| 65 |
#include "dsda/render_stats.h" |
| 66 |
#include "dsda/configuration.h" |
| 67 |
|
| 68 |
int Sky1Texture; |
| 69 |
int Sky2Texture; |
| 70 |
fixed_t Sky1ColumnOffset; |
| 71 |
fixed_t Sky2ColumnOffset; |
| 72 |
dboolean DoubleSky; |
| 73 |
|
| 74 |
#define MAXVISPLANES 256 /* must be a power of 2 */ |
| 75 |
|
| 76 |
static visplane_t *visplanes[MAXVISPLANES]; // killough |
| 77 |
static visplane_t *freetail; // killough |
| 78 |
static visplane_t **freehead = &freetail; // killough |
| 79 |
visplane_t *floorplane, *ceilingplane; |
| 80 |
|
| 81 |
// [FG] linear horizontal sky scrolling |
| 82 |
static angle_t *xtoskyangle; |
| 83 |
|
| 84 |
// killough -- hash function for visplanes |
| 85 |
// Empirically verified to be fairly uniform: |
| 86 |
|
| 87 |
#define visplane_hash(picnum,lightlevel,height) \ |
| 88 |
((unsigned)((picnum)*3+(lightlevel)+(height)*7) & (MAXVISPLANES-1)) |
| 89 |
|
| 90 |
size_t maxopenings; |
| 91 |
int *openings,*lastopening; // dropoff overflow |
| 92 |
|
| 93 |
// Clip values are the solid pixel bounding the range. |
| 94 |
// floorclip starts out SCREENHEIGHT |
| 95 |
// ceilingclip starts out -1 |
| 96 |
|
| 97 |
// dropoff overflow |
| 98 |
// e6y: resolution limitation is removed |
| 99 |
int *floorclip = NULL; |
| 100 |
int *ceilingclip = NULL; |
| 101 |
|
| 102 |
// spanstart holds the start of a plane span; initialized to 0 at start |
| 103 |
|
| 104 |
// e6y: resolution limitation is removed |
| 105 |
static int *spanstart = NULL; // killough 2/8/98 |
| 106 |
|
| 107 |
// |
| 108 |
// texture mapping |
| 109 |
// |
| 110 |
|
| 111 |
// killough 2/8/98: make variables static |
| 112 |
|
| 113 |
static fixed_t *cachedheight = NULL; |
| 114 |
|
| 115 |
// e6y: resolution limitation is removed |
| 116 |
fixed_t *yslope = NULL; |
| 117 |
fixed_t *distscale = NULL; |
| 118 |
|
| 119 |
void R_InitPlanesRes(void) |
| 120 |
{ |
| 121 |
if (floorclip) Z_Free(floorclip); |
| 122 |
if (ceilingclip) Z_Free(ceilingclip); |
| 123 |
if (spanstart) Z_Free(spanstart); |
| 124 |
|
| 125 |
if (cachedheight) Z_Free(cachedheight); |
| 126 |
|
| 127 |
if (yslope) Z_Free(yslope); |
| 128 |
if (distscale) Z_Free(distscale); |
| 129 |
|
| 130 |
floorclip = Z_Calloc(1, SCREENWIDTH * sizeof(*floorclip)); |
| 131 |
ceilingclip = Z_Calloc(1, SCREENWIDTH * sizeof(*ceilingclip)); |
| 132 |
spanstart = Z_Calloc(1, SCREENHEIGHT * sizeof(*spanstart)); |
| 133 |
|
| 134 |
cachedheight = Z_Calloc(1, SCREENHEIGHT * sizeof(*cachedheight)); |
| 135 |
|
| 136 |
yslope = Z_Calloc(1, SCREENHEIGHT * sizeof(*yslope)); |
| 137 |
distscale = Z_Calloc(1, SCREENWIDTH * sizeof(*distscale)); |
| 138 |
|
| 139 |
xtoskyangle = dsda_IntConfig(dsda_config_render_linearsky) ? linearskyangle : xtoviewangle; |
| 140 |
} |
| 141 |
|
| 142 |
void R_InitVisplanesRes(void) |
| 143 |
{ |
| 144 |
int i; |
| 145 |
|
| 146 |
freetail = NULL; |
| 147 |
freehead = &freetail; |
| 148 |
|
| 149 |
for (i = 0; i < MAXVISPLANES; i++) |
| 150 |
{ |
| 151 |
visplanes[i] = 0; |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
// |
| 156 |
// R_InitPlanes |
| 157 |
// Only at game startup. |
| 158 |
// |
| 159 |
void R_InitPlanes (void) |
| 160 |
{ |
| 161 |
} |
| 162 |
|
| 163 |
// Refresh "Linear Sky" |
| 164 |
void dsda_RefreshLinearSky (void) |
| 165 |
{ |
| 166 |
xtoskyangle = dsda_IntConfig(dsda_config_render_linearsky) ? linearskyangle : xtoviewangle; |
| 167 |
} |
| 168 |
|
| 169 |
// |
| 170 |
// R_MapPlane |
| 171 |
// |
| 172 |
|
| 173 |
static void R_MapPlane(int y, int x1, int x2, draw_span_vars_t *dsvars) |
| 174 |
{ |
| 175 |
int64_t den; |
| 176 |
fixed_t distance; |
| 177 |
unsigned index; |
| 178 |
|
| 179 |
#ifdef RANGECHECK |
| 180 |
if (x2 < x1 || x1<0 || x2>=viewwidth || (unsigned)y>(unsigned)viewheight) |
| 181 |
I_Error ("R_MapPlane: %i, %i at %i",x1,x2,y); |
| 182 |
#endif |
| 183 |
|
| 184 |
// [RH]Instead of using the xtoviewangle array, I calculated the fractional values |
| 185 |
// at the middle of the screen, then used the calculated ds_xstep and ds_ystep |
| 186 |
// to step from those to the proper texture coordinate to start drawing at. |
| 187 |
// That way, the texture coordinate is always calculated by its position |
| 188 |
// on the screen and not by its position relative to the edge of the visplane. |
| 189 |
// |
| 190 |
// Visplanes with the same texture now match up far better than before. |
| 191 |
// |
| 192 |
// See cchest2.wad/map02/room with sector #265 |
| 193 |
if (centery == y) |
| 194 |
return; |
| 195 |
den = (int64_t)FRACUNIT * FRACUNIT * D_abs(centery - y); |
| 196 |
distance = FixedMul(dsvars->planeheight, yslope[y]); |
| 197 |
|
| 198 |
dsvars->xstep = (fixed_t)((int64_t)dsvars->sine * dsvars->planeheight * viewfocratio / den); |
| 199 |
dsvars->ystep = (fixed_t)((int64_t)dsvars->cosine * dsvars->planeheight * viewfocratio / den); |
| 200 |
|
| 201 |
// killough 2/28/98: Add offsets |
| 202 |
dsvars->xfrac = dsvars->xoffs + FixedMul(dsvars->cosine, distance) + (x1 - centerx) * dsvars->xstep; |
| 203 |
dsvars->yfrac = dsvars->yoffs - FixedMul(dsvars->sine, distance) + (x1 - centerx) * dsvars->ystep; |
| 204 |
|
| 205 |
dsvars->xstep = FixedMul(dsvars->xstep, dsvars->xscale); |
| 206 |
dsvars->ystep = FixedMul(dsvars->ystep, dsvars->yscale); |
| 207 |
|
| 208 |
dsvars->xfrac = FixedMul(dsvars->xfrac, dsvars->xscale); |
| 209 |
dsvars->yfrac = FixedMul(dsvars->yfrac, dsvars->yscale); |
| 210 |
|
| 211 |
if (!(dsvars->colormap = fixedcolormap)) |
| 212 |
{ |
| 213 |
dsvars->z = distance; |
| 214 |
index = distance >> LIGHTZSHIFT; |
| 215 |
if (index >= MAXLIGHTZ ) |
| 216 |
index = MAXLIGHTZ-1; |
| 217 |
dsvars->colormap = dsvars->planezlight[index]; |
| 218 |
} |
| 219 |
else |
| 220 |
{ |
| 221 |
dsvars->z = 0; |
| 222 |
} |
| 223 |
|
| 224 |
dsvars->y = y; |
| 225 |
dsvars->x1 = x1; |
| 226 |
dsvars->x2 = x2; |
| 227 |
|
| 228 |
if (V_IsSoftwareMode()) |
| 229 |
R_DrawSpan(dsvars); |
| 230 |
} |
| 231 |
|
| 232 |
// |
| 233 |
// R_ClearPlanes |
| 234 |
// At begining of frame. |
| 235 |
// |
| 236 |
|
| 237 |
void R_ClearPlanes(void) |
| 238 |
{ |
| 239 |
int i; |
| 240 |
|
| 241 |
// opening / clipping determination |
| 242 |
for (i=0 ; i<viewwidth ; i++) |
| 243 |
floorclip[i] = viewheight, ceilingclip[i] = -1; |
| 244 |
|
| 245 |
for (i=0;i<MAXVISPLANES;i++) // new code -- killough |
| 246 |
for (*freehead = visplanes[i], visplanes[i] = NULL; *freehead; ) |
| 247 |
freehead = &(*freehead)->next; |
| 248 |
|
| 249 |
lastopening = openings; |
| 250 |
|
| 251 |
// texture calculation |
| 252 |
memset (cachedheight, 0, SCREENHEIGHT * sizeof(*cachedheight)); |
| 253 |
} |
| 254 |
|
| 255 |
// New function, by Lee Killough |
| 256 |
|
| 257 |
static visplane_t *new_visplane(unsigned hash) |
| 258 |
{ |
| 259 |
visplane_t *check = freetail; |
| 260 |
if (!check) |
| 261 |
{ |
| 262 |
// e6y: resolution limitation is removed |
| 263 |
check = Z_Calloc(1, sizeof(*check) + sizeof(*check->top) * (SCREENWIDTH * 2)); |
| 264 |
check->bottom = &check->top[SCREENWIDTH + 2]; |
| 265 |
} |
| 266 |
else |
| 267 |
if (!(freetail = freetail->next)) |
| 268 |
freehead = &freetail; |
| 269 |
check->next = visplanes[hash]; |
| 270 |
visplanes[hash] = check; |
| 271 |
return check; |
| 272 |
} |
| 273 |
|
| 274 |
/* |
| 275 |
* R_DupPlane |
| 276 |
* |
| 277 |
* cph 2003/04/18 - create duplicate of existing visplane and set initial range |
| 278 |
*/ |
| 279 |
visplane_t *R_DupPlane(const visplane_t *pl, int start, int stop) |
| 280 |
{ |
| 281 |
int i; |
| 282 |
unsigned hash = visplane_hash(pl->picnum, pl->lightlevel, pl->height); |
| 283 |
visplane_t *new_pl = new_visplane(hash); |
| 284 |
|
| 285 |
new_pl->height = pl->height; |
| 286 |
new_pl->picnum = pl->picnum; |
| 287 |
new_pl->lightlevel = pl->lightlevel; |
| 288 |
new_pl->special = pl->special; |
| 289 |
new_pl->xoffs = pl->xoffs; // killough 2/28/98 |
| 290 |
new_pl->yoffs = pl->yoffs; |
| 291 |
new_pl->rotation = pl->rotation; |
| 292 |
new_pl->xscale = pl->xscale; |
| 293 |
new_pl->yscale = pl->yscale; |
| 294 |
new_pl->minx = start; |
| 295 |
new_pl->maxx = stop; |
| 296 |
for (i = 0; i != SCREENWIDTH; i++) |
| 297 |
new_pl->top[i] = SHRT_MAX; |
| 298 |
return new_pl; |
| 299 |
} |
| 300 |
// |
| 301 |
// R_FindPlane |
| 302 |
// |
| 303 |
// killough 2/28/98: Add offsets |
| 304 |
|
| 305 |
visplane_t *R_FindPlane(fixed_t height, int picnum, int lightlevel, int special, |
| 306 |
fixed_t xoffs, fixed_t yoffs, angle_t rotation, fixed_t xscale, fixed_t yscale) |
| 307 |
{ |
| 308 |
visplane_t *check; |
| 309 |
unsigned hash; // killough |
| 310 |
|
| 311 |
if (map_format.hexen && special < 150) |
| 312 |
{ |
| 313 |
special = 0; |
| 314 |
} |
| 315 |
|
| 316 |
if (picnum == skyflatnum || picnum & PL_SKYFLAT) |
| 317 |
height = lightlevel = 0; // killough 7/19/98: most skies map together |
| 318 |
|
| 319 |
// New visplane algorithm uses hash table -- killough |
| 320 |
hash = visplane_hash(picnum,lightlevel,height); |
| 321 |
|
| 322 |
for (check=visplanes[hash]; check; check=check->next) // killough |
| 323 |
if (height == check->height && |
| 324 |
picnum == check->picnum && |
| 325 |
lightlevel == check->lightlevel && |
| 326 |
special == check->special && |
| 327 |
xoffs == check->xoffs && // killough 2/28/98: Add offset checks |
| 328 |
yoffs == check->yoffs && |
| 329 |
rotation == check->rotation && |
| 330 |
xscale == check->xscale && |
| 331 |
yscale == check->yscale) |
| 332 |
return check; |
| 333 |
|
| 334 |
check = new_visplane(hash); // killough |
| 335 |
|
| 336 |
check->height = height; |
| 337 |
check->picnum = picnum; |
| 338 |
check->lightlevel = lightlevel; |
| 339 |
check->special = special; |
| 340 |
check->xoffs = xoffs; // killough 2/28/98: Save offsets |
| 341 |
check->yoffs = yoffs; |
| 342 |
check->rotation = rotation; |
| 343 |
check->xscale = xscale; |
| 344 |
check->yscale = yscale; |
| 345 |
|
| 346 |
if (V_IsSoftwareMode()) |
| 347 |
{ |
| 348 |
int i; |
| 349 |
check->minx = viewwidth; // Was SCREENWIDTH -- killough 11/98 |
| 350 |
check->maxx = -1; |
| 351 |
|
| 352 |
for (i = 0; i != SCREENWIDTH; i++) |
| 353 |
check->top[i] = SHRT_MAX; |
| 354 |
} |
| 355 |
|
| 356 |
return check; |
| 357 |
} |
| 358 |
|
| 359 |
// |
| 360 |
// R_CheckPlane |
| 361 |
// |
| 362 |
visplane_t *R_CheckPlane(visplane_t *pl, int start, int stop) |
| 363 |
{ |
| 364 |
int intrl, intrh, unionl, unionh, x; |
| 365 |
|
| 366 |
if (start < pl->minx) |
| 367 |
intrl = pl->minx, unionl = start; |
| 368 |
else |
| 369 |
unionl = pl->minx, intrl = start; |
| 370 |
|
| 371 |
if (stop > pl->maxx) |
| 372 |
intrh = pl->maxx, unionh = stop; |
| 373 |
else |
| 374 |
unionh = pl->maxx, intrh = stop; |
| 375 |
|
| 376 |
for (x=intrl ; x <= intrh && pl->top[x] == SHRT_MAX; x++) // dropoff overflow |
| 377 |
; |
| 378 |
|
| 379 |
if (x > intrh) { /* Can use existing plane; extend range */ |
| 380 |
pl->minx = unionl; pl->maxx = unionh; |
| 381 |
return pl; |
| 382 |
} else /* Cannot use existing plane; create a new one */ |
| 383 |
return R_DupPlane(pl,start,stop); |
| 384 |
} |
| 385 |
|
| 386 |
// |
| 387 |
// R_MakeSpans |
| 388 |
// |
| 389 |
|
| 390 |
static void R_MakeSpans(int x, unsigned int t1, unsigned int b1, |
| 391 |
unsigned int t2, unsigned int b2, |
| 392 |
draw_span_vars_t *dsvars) |
| 393 |
{ |
| 394 |
for (; t1 < t2 && t1 <= b1; t1++) |
| 395 |
R_MapPlane(t1, spanstart[t1], x-1, dsvars); |
| 396 |
for (; b1 > b2 && b1 >= t1; b1--) |
| 397 |
R_MapPlane(b1, spanstart[b1] ,x-1, dsvars); |
| 398 |
while (t2 < t1 && t2 <= b2) |
| 399 |
spanstart[t2++] = x; |
| 400 |
while (b2 > b1 && b2 >= t2) |
| 401 |
spanstart[b2--] = x; |
| 402 |
} |
| 403 |
|
| 404 |
// heretic has a hack: sky textures are defined with 128 height, but the patches are 200 |
| 405 |
// heretic textures with only one patch point their columns to the original patch data |
| 406 |
// when drawing skies, it used this to "overrun" into the lower patch pixels |
| 407 |
const rpatch_t *R_HackedSkyPatch(texture_t *texture) |
| 408 |
{ |
| 409 |
if (heretic && texture->patchcount == 1) |
| 410 |
{ |
| 411 |
const rpatch_t *patch; |
| 412 |
|
| 413 |
patch = (const rpatch_t*) R_PatchByNum(texture->patches[0].patch); |
| 414 |
|
| 415 |
if (patch->height == 200) |
| 416 |
{ |
| 417 |
return patch; |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
return NULL; |
| 422 |
} |
| 423 |
|
| 424 |
// New function, by Lee Killough |
| 425 |
|
| 426 |
static void R_DoDrawPlane(visplane_t *pl) |
| 427 |
{ |
| 428 |
register int x; |
| 429 |
draw_column_vars_t dcvars; |
| 430 |
R_DrawColumn_f colfunc = R_GetDrawColumnFunc(RDC_PIPELINE_STANDARD, RDRAW_FILTER_POINT); |
| 431 |
|
| 432 |
R_SetDefaultDrawColumnVars(&dcvars); |
| 433 |
|
| 434 |
if (pl->minx <= pl->maxx) { |
| 435 |
// hexen_note: Skies |
| 436 |
// if (pl->picnum == skyflatnum) |
| 437 |
// { // Sky flat |
| 438 |
// #define SKYTEXTUREMIDSHIFTED 200 |
| 439 |
// |
| 440 |
// byte *source; |
| 441 |
// byte *source2; |
| 442 |
// int offset; |
| 443 |
// int skyTexture; |
| 444 |
// int offset2; |
| 445 |
// int skyTexture2; |
| 446 |
// |
| 447 |
// if (DoubleSky) |
| 448 |
// { // Render 2 layers, sky 1 in front |
| 449 |
// offset = Sky1ColumnOffset >> 16; |
| 450 |
// skyTexture = texturetranslation[Sky1Texture]; |
| 451 |
// offset2 = Sky2ColumnOffset >> 16; |
| 452 |
// skyTexture2 = texturetranslation[Sky2Texture]; |
| 453 |
// for (x = pl->minx; x <= pl->maxx; x++) |
| 454 |
// { |
| 455 |
// dc_yl = pl->top[x]; |
| 456 |
// dc_yh = pl->bottom[x]; |
| 457 |
// if (dc_yl <= dc_yh) |
| 458 |
// { |
| 459 |
// count = dc_yh - dc_yl; |
| 460 |
// if (count < 0) |
| 461 |
// { |
| 462 |
// return; |
| 463 |
// } |
| 464 |
// angle = (viewangle + xtoviewangle[x]) |
| 465 |
// >> ANGLETOSKYSHIFT; |
| 466 |
// source = R_GetColumn(skyTexture, angle + offset); |
| 467 |
// source2 = R_GetColumn(skyTexture2, angle + offset2); |
| 468 |
// dest = ylookup[dc_yl] + columnofs[x]; |
| 469 |
// frac = SKYTEXTUREMIDSHIFTED * FRACUNIT + (dc_yl - centery) * fracstep; |
| 470 |
// do |
| 471 |
// { |
| 472 |
// if (source[frac >> FRACBITS]) |
| 473 |
// { |
| 474 |
// *dest = source[frac >> FRACBITS]; |
| 475 |
// frac += fracstep; |
| 476 |
// } |
| 477 |
// else |
| 478 |
// { |
| 479 |
// *dest = source2[frac >> FRACBITS]; |
| 480 |
// frac += fracstep; |
| 481 |
// } |
| 482 |
// dest += SCREENWIDTH; |
| 483 |
// } |
| 484 |
// while (count--); |
| 485 |
// } |
| 486 |
// } |
| 487 |
// continue; // Next visplane |
| 488 |
// } |
| 489 |
// else |
| 490 |
// { // Render single layer |
| 491 |
// if (pl->special == 200) |
| 492 |
// { // Use sky 2 |
| 493 |
// offset = Sky2ColumnOffset >> 16; |
| 494 |
// skyTexture = texturetranslation[Sky2Texture]; |
| 495 |
// } |
| 496 |
// else |
| 497 |
// { // Use sky 1 |
| 498 |
// offset = Sky1ColumnOffset >> 16; |
| 499 |
// skyTexture = texturetranslation[Sky1Texture]; |
| 500 |
// } |
| 501 |
// for (x = pl->minx; x <= pl->maxx; x++) |
| 502 |
// { |
| 503 |
// dc_yl = pl->top[x]; |
| 504 |
// dc_yh = pl->bottom[x]; |
| 505 |
// if (dc_yl <= dc_yh) |
| 506 |
// { |
| 507 |
// count = dc_yh - dc_yl; |
| 508 |
// if (count < 0) |
| 509 |
// { |
| 510 |
// return; |
| 511 |
// } |
| 512 |
// angle = (viewangle + xtoviewangle[x]) |
| 513 |
// >> ANGLETOSKYSHIFT; |
| 514 |
// source = R_GetColumn(skyTexture, angle + offset); |
| 515 |
// dest = ylookup[dc_yl] + columnofs[x]; |
| 516 |
// frac = SKYTEXTUREMIDSHIFTED * FRACUNIT + (dc_yl - centery) * fracstep; |
| 517 |
// do |
| 518 |
// { |
| 519 |
// *dest = source[frac >> FRACBITS]; |
| 520 |
// dest += SCREENWIDTH; |
| 521 |
// frac += fracstep; |
| 522 |
// } |
| 523 |
// while (count--); |
| 524 |
// } |
| 525 |
// } |
| 526 |
// continue; // Next visplane |
| 527 |
// } |
| 528 |
// } |
| 529 |
|
| 530 |
if (pl->picnum == skyflatnum || pl->picnum & PL_SKYFLAT) { // sky flat |
| 531 |
int texture; |
| 532 |
const rpatch_t *tex_patch; |
| 533 |
angle_t an, flip; |
| 534 |
|
| 535 |
// killough 10/98: allow skies to come from sidedefs. |
| 536 |
// Allows scrolling and/or animated skies, as well as |
| 537 |
// arbitrary multiple skies per level without having |
| 538 |
// to use info lumps. |
| 539 |
|
| 540 |
an = viewangle; |
| 541 |
|
| 542 |
if (pl->picnum & PL_SKYFLAT_LINE) |
| 543 |
{ |
| 544 |
// Sky Linedef |
| 545 |
const line_t *l = &lines[pl->picnum & ~PL_SKYFLAT_LINE]; |
| 546 |
|
| 547 |
// Sky transferred from first sidedef |
| 548 |
const side_t *s = *l->sidenum + sides; |
| 549 |
|
| 550 |
// Texture comes from upper texture of reference sidedef |
| 551 |
texture = texturetranslation[s->toptexture]; |
| 552 |
|
| 553 |
// Horizontal offset is turned into an angle offset, |
| 554 |
// to allow sky rotation as well as careful positioning. |
| 555 |
// However, the offset is scaled very small, so that it |
| 556 |
// allows a long-period of sky rotation. |
| 557 |
|
| 558 |
an += s->textureoffset; |
| 559 |
|
| 560 |
// Vertical offset allows careful sky positioning. |
| 561 |
|
| 562 |
dcvars.texturemid = s->rowoffset - 28*FRACUNIT; |
| 563 |
|
| 564 |
// We sometimes flip the picture horizontally. |
| 565 |
// |
| 566 |
// Doom always flipped the picture, so we make it optional, |
| 567 |
// to make it easier to use the new feature, while to still |
| 568 |
// allow old sky textures to be used. |
| 569 |
|
| 570 |
flip = l->special==272 ? 0u : ~0u; |
| 571 |
|
| 572 |
if (skystretch) |
| 573 |
{ |
| 574 |
int skyheight = textureheight[texture]>>FRACBITS; |
| 575 |
dcvars.texturemid = (int)((int64_t)dcvars.texturemid * skyheight / SKYSTRETCH_HEIGHT); |
| 576 |
} |
| 577 |
} |
| 578 |
else if (pl->picnum & PL_SKYFLAT_SECTOR) |
| 579 |
{ |
| 580 |
dcvars.texturemid = skytexturemid; |
| 581 |
texture = pl->picnum & ~PL_SKYFLAT_SECTOR; |
| 582 |
flip = 0; |
| 583 |
} |
| 584 |
else |
| 585 |
{ // Normal Doom sky, only one allowed per level |
| 586 |
dcvars.texturemid = skytexturemid; // Default y-offset |
| 587 |
texture = texturetranslation[skytexture]; // Default texture |
| 588 |
flip = 0; // Doom flips it |
| 589 |
} |
| 590 |
|
| 591 |
/* Sky is always drawn full bright, i.e. colormaps[0] is used. |
| 592 |
* Because of this hack, sky is not affected by INVUL inverse mapping. |
| 593 |
* Until Boom fixed this. Compat option added in MBF. */ |
| 594 |
|
| 595 |
if (comp[comp_skymap] || !(dcvars.colormap = fixedcolormap)) |
| 596 |
dcvars.colormap = fullcolormap; // killough 3/20/98 |
| 597 |
|
| 598 |
//dcvars.texturemid = skytexturemid; |
| 599 |
dcvars.texheight = textureheight[texture]>>FRACBITS; // killough |
| 600 |
|
| 601 |
// proff 09/21/98: Changed for high-res |
| 602 |
|
| 603 |
// e6y |
| 604 |
// disable sky texture scaling if status bar is used |
| 605 |
// old code: dcvars.iscale = FRACUNIT*200/viewheight; |
| 606 |
dcvars.iscale = skyiscale; |
| 607 |
|
| 608 |
{ |
| 609 |
const rpatch_t *patch; |
| 610 |
|
| 611 |
patch = R_HackedSkyPatch(textures[texture]); |
| 612 |
|
| 613 |
if (patch) |
| 614 |
{ |
| 615 |
dcvars.texheight = patch->height; |
| 616 |
dcvars.texturemid = 200 << FRACBITS; |
| 617 |
dcvars.iscale = (200 << FRACBITS) / SCREENHEIGHT; |
| 618 |
|
| 619 |
for (x = pl->minx; (dcvars.x = x) <= pl->maxx; x++) |
| 620 |
if ((dcvars.yl = pl->top[x]) != SHRT_MAX && dcvars.yl <= (dcvars.yh = pl->bottom[x])) // dropoff overflow |
| 621 |
{ |
| 622 |
dcvars.source = R_GetPatchColumn(patch, (an + xtoskyangle[x]) >> ANGLETOSKYSHIFT)->pixels; |
| 623 |
dcvars.prevsource = R_GetPatchColumn(patch, (an + xtoskyangle[x-1]) >> ANGLETOSKYSHIFT)->pixels; |
| 624 |
dcvars.nextsource = R_GetPatchColumn(patch, (an + xtoskyangle[x+1]) >> ANGLETOSKYSHIFT)->pixels; |
| 625 |
colfunc(&dcvars); |
| 626 |
} |
| 627 |
|
| 628 |
return; |
| 629 |
} |
| 630 |
} |
| 631 |
|
| 632 |
tex_patch = R_TextureCompositePatchByNum(texture); |
| 633 |
|
| 634 |
// killough 10/98: Use sky scrolling offset, and possibly flip picture |
| 635 |
for (x = pl->minx; (dcvars.x = x) <= pl->maxx; x++) |
| 636 |
if ((dcvars.yl = pl->top[x]) != SHRT_MAX && dcvars.yl <= (dcvars.yh = pl->bottom[x])) // dropoff overflow |
| 637 |
{ |
| 638 |
dcvars.source = R_GetTextureColumn(tex_patch, ((an + xtoskyangle[x])^flip) >> ANGLETOSKYSHIFT); |
| 639 |
dcvars.prevsource = R_GetTextureColumn(tex_patch, ((an + xtoskyangle[x-1])^flip) >> ANGLETOSKYSHIFT); |
| 640 |
dcvars.nextsource = R_GetTextureColumn(tex_patch, ((an + xtoskyangle[x+1])^flip) >> ANGLETOSKYSHIFT); |
| 641 |
colfunc(&dcvars); |
| 642 |
} |
| 643 |
} |
| 644 |
else { // regular flat |
| 645 |
|
| 646 |
int stop, light; |
| 647 |
draw_span_vars_t dsvars; |
| 648 |
|
| 649 |
dsvars.source = W_LumpByNum(firstflat + flattranslation[pl->picnum]); |
| 650 |
dsvars.xoffs = pl->xoffs; |
| 651 |
dsvars.yoffs = pl->yoffs; |
| 652 |
dsvars.xscale = pl->xscale; |
| 653 |
dsvars.yscale = pl->yscale; |
| 654 |
|
| 655 |
if (pl->rotation) |
| 656 |
{ |
| 657 |
fixed_t rotation_cos, rotation_sin; |
| 658 |
|
| 659 |
rotation_cos = finecosine[pl->rotation >> ANGLETOFINESHIFT]; |
| 660 |
rotation_sin = finesine[pl->rotation >> ANGLETOFINESHIFT]; |
| 661 |
|
| 662 |
dsvars.xoffs += FixedMul(rotation_cos, viewx) - FixedMul(rotation_sin, viewy); |
| 663 |
dsvars.yoffs -= FixedMul(rotation_sin, viewx) + FixedMul(rotation_cos, viewy); |
| 664 |
dsvars.sine = finesine[(viewangle + pl->rotation) >> ANGLETOFINESHIFT]; |
| 665 |
dsvars.cosine = finecosine[(viewangle + pl->rotation) >> ANGLETOFINESHIFT]; |
| 666 |
} |
| 667 |
else |
| 668 |
{ |
| 669 |
dsvars.xoffs += viewx; |
| 670 |
dsvars.yoffs -= viewy; |
| 671 |
dsvars.sine = viewsin; |
| 672 |
dsvars.cosine = viewcos; |
| 673 |
} |
| 674 |
|
| 675 |
if (map_format.hexen) |
| 676 |
{ |
| 677 |
int scrollOffset = leveltime >> 1 & 63; |
| 678 |
|
| 679 |
switch (pl->special) |
| 680 |
{ // Handle scrolling flats |
| 681 |
case 201: |
| 682 |
case 202: |
| 683 |
case 203: // Scroll_North_xxx |
| 684 |
dsvars.source = dsvars.source + ((scrollOffset |
| 685 |
<< (pl->special - 201) & 63) << 6); |
| 686 |
break; |
| 687 |
case 204: |
| 688 |
case 205: |
| 689 |
case 206: // Scroll_East_xxx |
| 690 |
dsvars.source = dsvars.source + ((63 - scrollOffset) |
| 691 |
<< (pl->special - 204) & 63); |
| 692 |
break; |
| 693 |
case 207: |
| 694 |
case 208: |
| 695 |
case 209: // Scroll_South_xxx |
| 696 |
dsvars.source = dsvars.source + (((63 - scrollOffset) |
| 697 |
<< (pl->special - 207) & 63) << 6); |
| 698 |
break; |
| 699 |
case 210: |
| 700 |
case 211: |
| 701 |
case 212: // Scroll_West_xxx |
| 702 |
dsvars.source = dsvars.source + (scrollOffset |
| 703 |
<< (pl->special - 210) & 63); |
| 704 |
break; |
| 705 |
case 213: |
| 706 |
case 214: |
| 707 |
case 215: // Scroll_NorthWest_xxx |
| 708 |
dsvars.source = dsvars.source + (scrollOffset |
| 709 |
<< (pl->special - 213) & 63) + |
| 710 |
((scrollOffset << (pl->special - 213) & 63) << 6); |
| 711 |
break; |
| 712 |
case 216: |
| 713 |
case 217: |
| 714 |
case 218: // Scroll_NorthEast_xxx |
| 715 |
dsvars.source = dsvars.source + ((63 - scrollOffset) |
| 716 |
<< (pl->special - 216) & 63) + |
| 717 |
((scrollOffset << (pl->special - 216) & 63) << 6); |
| 718 |
break; |
| 719 |
case 219: |
| 720 |
case 220: |
| 721 |
case 221: // Scroll_SouthEast_xxx |
| 722 |
dsvars.source = dsvars.source + ((63 - scrollOffset) |
| 723 |
<< (pl->special - 219) & 63) + |
| 724 |
(((63 - scrollOffset) << (pl->special - 219) & 63) << 6); |
| 725 |
break; |
| 726 |
case 222: |
| 727 |
case 223: |
| 728 |
case 224: // Scroll_SouthWest_xxx |
| 729 |
dsvars.source = dsvars.source + (scrollOffset |
| 730 |
<< (pl->special - 222) & 63) + |
| 731 |
(((63 - scrollOffset) << (pl->special - 222) & 63) << 6); |
| 732 |
break; |
| 733 |
default: |
| 734 |
break; |
| 735 |
} |
| 736 |
} |
| 737 |
else if (heretic) |
| 738 |
{ |
| 739 |
switch (pl->special) |
| 740 |
{ |
| 741 |
case 20: |
| 742 |
case 21: |
| 743 |
case 22: |
| 744 |
case 23: |
| 745 |
case 24: // Scroll_East |
| 746 |
dsvars.source = dsvars.source + |
| 747 |
((63 - ((leveltime >> 1) & 63)) << (pl->special - 20) & 63); |
| 748 |
break; |
| 749 |
case 4: // Scroll_EastLavaDamage |
| 750 |
dsvars.source = dsvars.source + |
| 751 |
(((63 - ((leveltime >> 1) & 63)) << 3) & 63); |
| 752 |
break; |
| 753 |
} |
| 754 |
} |
| 755 |
|
| 756 |
dsvars.planeheight = D_abs(pl->height-viewz); |
| 757 |
|
| 758 |
// SoM 10/19/02: deep water colormap fix |
| 759 |
if(fixedcolormap) |
| 760 |
light = (255 >> LIGHTSEGSHIFT); |
| 761 |
else |
| 762 |
light = (pl->lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); |
| 763 |
|
| 764 |
if(light >= LIGHTLEVELS) |
| 765 |
light = LIGHTLEVELS-1; |
| 766 |
|
| 767 |
if(light < 0) |
| 768 |
light = 0; |
| 769 |
|
| 770 |
stop = pl->maxx + 1; |
| 771 |
dsvars.planezlight = zlight[light]; |
| 772 |
pl->top[pl->minx-1] = pl->top[stop] = SHRT_MAX; // dropoff overflow |
| 773 |
|
| 774 |
for (x = pl->minx ; x <= stop ; x++) |
| 775 |
R_MakeSpans(x,pl->top[x-1],pl->bottom[x-1], |
| 776 |
pl->top[x],pl->bottom[x], &dsvars); |
| 777 |
} |
| 778 |
} |
| 779 |
} |
| 780 |
|
| 781 |
// |
| 782 |
// RDrawPlanes |
| 783 |
// At the end of each frame. |
| 784 |
// |
| 785 |
|
| 786 |
void R_DrawPlanes (void) |
| 787 |
{ |
| 788 |
visplane_t *pl; |
| 789 |
int i; |
| 790 |
for (i=0;i<MAXVISPLANES;i++) |
| 791 |
for (pl=visplanes[i]; pl; pl=pl->next) |
| 792 |
{ |
| 793 |
dsda_RecordVisPlane(); |
| 794 |
|
| 795 |
R_DoDrawPlane(pl); |
| 796 |
} |
| 797 |
} |