| 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 |
* Refresh of things, i.e. objects represented by sprites. |
| 31 |
* |
| 32 |
*-----------------------------------------------------------------------------*/ |
| 33 |
|
| 34 |
#include "doomstat.h" |
| 35 |
#include "w_wad.h" |
| 36 |
#include "r_main.h" |
| 37 |
#include "r_bsp.h" |
| 38 |
#include "r_segs.h" |
| 39 |
#include "r_draw.h" |
| 40 |
#include "r_things.h" |
| 41 |
#include "r_fps.h" |
| 42 |
#include "v_video.h" |
| 43 |
#include "p_pspr.h" |
| 44 |
#include "lprintf.h" |
| 45 |
#include "e6y.h"//e6y |
| 46 |
|
| 47 |
#include "dsda/configuration.h" |
| 48 |
#include "dsda/render_stats.h" |
| 49 |
#include "dsda/settings.h" |
| 50 |
|
| 51 |
#define BASEYCENTER 100 |
| 52 |
|
| 53 |
static int *clipbot = NULL; // killough 2/8/98: // dropoff overflow |
| 54 |
static int *cliptop = NULL; // change to MAX_* // dropoff overflow |
| 55 |
|
| 56 |
// |
| 57 |
// Sprite rotation 0 is facing the viewer, |
| 58 |
// rotation 1 is one angle turn CLOCKWISE around the axis. |
| 59 |
// This is not the same as the angle, |
| 60 |
// which increases counter clockwise (protractor). |
| 61 |
// There was a lot of stuff grabbed wrong, so I changed it... |
| 62 |
// |
| 63 |
|
| 64 |
fixed_t pspriteiscale; |
| 65 |
// proff 11/06/98: Added for high-res |
| 66 |
fixed_t pspritexscale; |
| 67 |
fixed_t pspriteyscale; |
| 68 |
fixed_t pspriteiyscale; |
| 69 |
|
| 70 |
static const lighttable_t **spritelights; // killough 1/25/98 made static |
| 71 |
|
| 72 |
//e6y: added for GL |
| 73 |
float pspriteyscale_f; |
| 74 |
float pspritexscale_f; |
| 75 |
|
| 76 |
typedef struct drawseg_xrange_item_s |
| 77 |
{ |
| 78 |
short x1, x2; |
| 79 |
drawseg_t *user; |
| 80 |
} drawseg_xrange_item_t; |
| 81 |
|
| 82 |
typedef struct drawsegs_xrange_s |
| 83 |
{ |
| 84 |
drawseg_xrange_item_t *items; |
| 85 |
int count; |
| 86 |
} drawsegs_xrange_t; |
| 87 |
|
| 88 |
#define DS_RANGES_COUNT 3 |
| 89 |
static drawsegs_xrange_t drawsegs_xranges[DS_RANGES_COUNT]; |
| 90 |
|
| 91 |
static drawseg_xrange_item_t *drawsegs_xrange; |
| 92 |
static unsigned int drawsegs_xrange_size = 0; |
| 93 |
static int drawsegs_xrange_count = 0; |
| 94 |
|
| 95 |
// constant arrays |
| 96 |
// used for psprite clipping and initializing clipping |
| 97 |
|
| 98 |
// e6y: resolution limitation is removed |
| 99 |
int *negonearray; // killough 2/8/98: // dropoff overflow |
| 100 |
int *screenheightarray; // change to MAX_* // dropoff overflow |
| 101 |
|
| 102 |
// |
| 103 |
// INITIALIZATION FUNCTIONS |
| 104 |
// |
| 105 |
|
| 106 |
// variables used to look up and range check thing_t sprites patches |
| 107 |
|
| 108 |
spritedef_t *sprites; |
| 109 |
|
| 110 |
#define MAX_SPRITE_FRAMES 30 /* Macroized -- killough 1/25/98 */ |
| 111 |
|
| 112 |
static spriteframe_t sprtemp[MAX_SPRITE_FRAMES]; |
| 113 |
static int maxframe; |
| 114 |
|
| 115 |
void R_InitSpritesRes(void) |
| 116 |
{ |
| 117 |
if (xtoviewangle) Z_Free(xtoviewangle); |
| 118 |
if (linearskyangle) Z_Free (linearskyangle); |
| 119 |
if (negonearray) Z_Free(negonearray); |
| 120 |
if (screenheightarray) Z_Free(screenheightarray); |
| 121 |
|
| 122 |
xtoviewangle = Z_Calloc(1, (SCREENWIDTH + 1) * sizeof(*xtoviewangle)); |
| 123 |
linearskyangle = Z_Calloc(1, (SCREENWIDTH + 1) * sizeof(*linearskyangle)); |
| 124 |
negonearray = Z_Calloc(1, SCREENWIDTH * sizeof(*negonearray)); |
| 125 |
screenheightarray = Z_Calloc(1, SCREENWIDTH * sizeof(*screenheightarray)); |
| 126 |
|
| 127 |
if (clipbot) Z_Free(clipbot); |
| 128 |
|
| 129 |
clipbot = Z_Calloc(1, 2 * SCREENWIDTH * sizeof(*clipbot)); |
| 130 |
cliptop = clipbot + SCREENWIDTH; |
| 131 |
} |
| 132 |
|
| 133 |
void R_UpdateVisSpriteTranMap(vissprite_t *vis, mobj_t *thing) |
| 134 |
{ |
| 135 |
if (thing && thing->tranmap) |
| 136 |
vis->tranmap = thing->tranmap; |
| 137 |
else if (vis->mobjflags & g_mf_translucent) |
| 138 |
vis->tranmap = main_tranmap; |
| 139 |
else |
| 140 |
vis->tranmap = NULL; |
| 141 |
} |
| 142 |
|
| 143 |
// |
| 144 |
// R_InstallSpriteLump |
| 145 |
// Local function for R_InitSprites. |
| 146 |
// |
| 147 |
|
| 148 |
static void R_InstallSpriteLump(int lump, unsigned frame, |
| 149 |
char rot, dboolean flipped) |
| 150 |
{ |
| 151 |
unsigned int rotation; |
| 152 |
|
| 153 |
if (rot >= '0' && rot <= '9') |
| 154 |
{ |
| 155 |
rotation = rot - '0'; |
| 156 |
} |
| 157 |
else if (rot >= 'A') |
| 158 |
{ |
| 159 |
rotation = rot - 'A' + 10; |
| 160 |
} |
| 161 |
else |
| 162 |
{ |
| 163 |
rotation = 17; |
| 164 |
} |
| 165 |
|
| 166 |
if (frame >= MAX_SPRITE_FRAMES || rotation > 16) |
| 167 |
I_Error("R_InstallSpriteLump: Bad frame characters in lump %i", lump); |
| 168 |
|
| 169 |
if ((int) frame > maxframe) |
| 170 |
maxframe = frame; |
| 171 |
|
| 172 |
if (rotation == 0) |
| 173 |
{ // the lump should be used for all rotations |
| 174 |
int r; |
| 175 |
for (r = 14; r >= 0; r -= 2) |
| 176 |
if (sprtemp[frame].lump[r] == -1) |
| 177 |
{ |
| 178 |
sprtemp[frame].lump[r] = lump - firstspritelump; |
| 179 |
if (flipped) |
| 180 |
{ |
| 181 |
sprtemp[frame].flip |= (1 << r); |
| 182 |
} |
| 183 |
sprtemp[frame].rotate = false; //jff 4/24/98 if any subbed, rotless |
| 184 |
} |
| 185 |
return; |
| 186 |
} |
| 187 |
|
| 188 |
// the lump is only used for one rotation |
| 189 |
|
| 190 |
if (rotation <= 8) |
| 191 |
{ |
| 192 |
rotation = (rotation - 1) * 2; |
| 193 |
} |
| 194 |
else |
| 195 |
{ |
| 196 |
rotation = (rotation - 9) * 2 + 1; |
| 197 |
} |
| 198 |
|
| 199 |
if (sprtemp[frame].lump[rotation] == -1) |
| 200 |
{ |
| 201 |
sprtemp[frame].lump[rotation] = lump - firstspritelump; |
| 202 |
if (flipped) |
| 203 |
{ |
| 204 |
sprtemp[frame].flip |= (1 << rotation); |
| 205 |
} |
| 206 |
sprtemp[frame].rotate = true; //jff 4/24/98 only change if rot used |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
// |
| 211 |
// R_InitSpriteDefs |
| 212 |
// Pass a null terminated list of sprite names |
| 213 |
// (4 chars exactly) to be used. |
| 214 |
// |
| 215 |
// Builds the sprite rotation matrixes to account |
| 216 |
// for horizontally flipped sprites. |
| 217 |
// |
| 218 |
// Will report an error if the lumps are inconsistent. |
| 219 |
// Only called at startup. |
| 220 |
// |
| 221 |
// Sprite lump names are 4 characters for the actor, |
| 222 |
// a letter for the frame, and a number for the rotation. |
| 223 |
// |
| 224 |
// A sprite that is flippable will have an additional |
| 225 |
// letter/number appended. |
| 226 |
// |
| 227 |
// The rotation character can be 0 to signify no rotations. |
| 228 |
// |
| 229 |
// 1/25/98, 1/31/98 killough : Rewritten for performance |
| 230 |
// |
| 231 |
// Empirically verified to have excellent hash |
| 232 |
// properties across standard Doom sprites: |
| 233 |
|
| 234 |
#define R_SpriteNameHash(s) ((unsigned)((s)[0]-((s)[1]*3-(s)[3]*2-(s)[2])*2)) |
| 235 |
|
| 236 |
static void R_InitSpriteDefs(const char * const * namelist) |
| 237 |
{ |
| 238 |
size_t numentries = lastspritelump-firstspritelump+1; |
| 239 |
struct { int index, next; } *hash; |
| 240 |
int i; |
| 241 |
|
| 242 |
if (!numentries || !*namelist) |
| 243 |
return; |
| 244 |
|
| 245 |
sprites = Z_Calloc(num_sprites, sizeof(*sprites)); |
| 246 |
|
| 247 |
// Create hash table based on just the first four letters of each sprite |
| 248 |
// killough 1/31/98 |
| 249 |
|
| 250 |
hash = Z_Malloc(sizeof(*hash)*numentries); // allocate hash table |
| 251 |
|
| 252 |
for (i=0; (size_t)i<numentries; i++) // initialize hash table as empty |
| 253 |
hash[i].index = -1; |
| 254 |
|
| 255 |
for (i=0; (size_t)i<numentries; i++) // Prepend each sprite to hash chain |
| 256 |
{ // prepend so that later ones win |
| 257 |
int j = R_SpriteNameHash(lumpinfo[i+firstspritelump].name) % numentries; |
| 258 |
hash[i].next = hash[j].index; |
| 259 |
hash[j].index = i; |
| 260 |
} |
| 261 |
|
| 262 |
// scan all the lump names for each of the names, |
| 263 |
// noting the highest frame letter. |
| 264 |
|
| 265 |
for (i=0 ; i<num_sprites ; i++) |
| 266 |
{ |
| 267 |
int k; |
| 268 |
int rot; |
| 269 |
const char *spritename; |
| 270 |
int j; |
| 271 |
|
| 272 |
spritename = namelist[i]; |
| 273 |
if (!spritename) |
| 274 |
continue; |
| 275 |
|
| 276 |
j = hash[R_SpriteNameHash(spritename) % numentries].index; |
| 277 |
if (j >= 0) |
| 278 |
{ |
| 279 |
memset(sprtemp, -1, sizeof(sprtemp)); |
| 280 |
for (k = 0; k < MAX_SPRITE_FRAMES; k++) |
| 281 |
{ |
| 282 |
sprtemp[k].flip = 0; |
| 283 |
} |
| 284 |
|
| 285 |
maxframe = -1; |
| 286 |
do |
| 287 |
{ |
| 288 |
register lumpinfo_t *lump = lumpinfo + j + firstspritelump; |
| 289 |
|
| 290 |
// Fast portable comparison -- killough |
| 291 |
// (using int pointer cast is nonportable): |
| 292 |
|
| 293 |
if (!((lump->name[0] ^ spritename[0]) | |
| 294 |
(lump->name[1] ^ spritename[1]) | |
| 295 |
(lump->name[2] ^ spritename[2]) | |
| 296 |
(lump->name[3] ^ spritename[3]))) |
| 297 |
{ |
| 298 |
R_InstallSpriteLump(j+firstspritelump, |
| 299 |
lump->name[4] - 'A', |
| 300 |
lump->name[5], |
| 301 |
false); |
| 302 |
if (lump->name[6]) |
| 303 |
R_InstallSpriteLump(j+firstspritelump, |
| 304 |
lump->name[6] - 'A', |
| 305 |
lump->name[7], |
| 306 |
true); |
| 307 |
} |
| 308 |
} |
| 309 |
while ((j = hash[j].next) >= 0); |
| 310 |
|
| 311 |
// check the frames that were found for completeness |
| 312 |
if ((sprites[i].numframes = ++maxframe)) // killough 1/31/98 |
| 313 |
{ |
| 314 |
int frame; |
| 315 |
for (frame = 0; frame < maxframe; frame++) |
| 316 |
{ |
| 317 |
switch (sprtemp[frame].rotate) |
| 318 |
{ |
| 319 |
case -1: |
| 320 |
// no rotations were found for that frame at all |
| 321 |
//I_Error ("R_InitSprites: No patches found " |
| 322 |
// "for %.8s frame %c", namelist[i], frame+'A'); |
| 323 |
break; |
| 324 |
|
| 325 |
case 0: |
| 326 |
// only the first rotation is needed |
| 327 |
for (rot = 1; rot < 16; rot++) |
| 328 |
{ |
| 329 |
sprtemp[frame].lump[rot] = sprtemp[frame].lump[0]; |
| 330 |
} |
| 331 |
// If the frame is flipped, they all should be |
| 332 |
if (sprtemp[frame].flip & 1) |
| 333 |
{ |
| 334 |
sprtemp[frame].flip = 0xFFFF; |
| 335 |
} |
| 336 |
break; |
| 337 |
|
| 338 |
case 1: |
| 339 |
// must have all 8 frames |
| 340 |
for (rot = 0; rot < 8; rot++) |
| 341 |
{ |
| 342 |
if (sprtemp[frame].lump[rot * 2 + 1] == -1) |
| 343 |
{ |
| 344 |
sprtemp[frame].lump[rot * 2 + 1] = sprtemp[frame].lump[rot * 2]; |
| 345 |
if (sprtemp[frame].flip & (1 << (rot * 2))) |
| 346 |
{ |
| 347 |
sprtemp[frame].flip |= 1 << (rot * 2 + 1); |
| 348 |
} |
| 349 |
} |
| 350 |
if (sprtemp[frame].lump[rot * 2] == -1) |
| 351 |
{ |
| 352 |
sprtemp[frame].lump[rot * 2] = sprtemp[frame].lump[rot * 2 + 1]; |
| 353 |
if (sprtemp[frame].flip & (1 << (rot * 2 + 1))) |
| 354 |
{ |
| 355 |
sprtemp[frame].flip |= 1 << (rot * 2); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
} |
| 360 |
for (rot = 0; rot < 16; rot++) |
| 361 |
{ |
| 362 |
if (sprtemp[frame].lump[rot] == -1) |
| 363 |
I_Error ("R_InitSprites: Sprite %.8s frame %c " |
| 364 |
"is missing rotations", |
| 365 |
namelist[i], frame+'A'); |
| 366 |
} |
| 367 |
break; |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
for (frame = 0; frame < maxframe; frame++) |
| 372 |
{ |
| 373 |
if (sprtemp[frame].rotate == -1) |
| 374 |
{ |
| 375 |
memset(&sprtemp[frame].lump, 0, sizeof(sprtemp[0].lump)); |
| 376 |
sprtemp[frame].flip = 0; |
| 377 |
sprtemp[frame].rotate = 0; |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
// allocate space for the frames present and copy sprtemp to it |
| 382 |
sprites[i].spriteframes = |
| 383 |
Z_Malloc (maxframe * sizeof(spriteframe_t)); |
| 384 |
memcpy (sprites[i].spriteframes, sprtemp, |
| 385 |
maxframe*sizeof(spriteframe_t)); |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
Z_Free(hash); // free hash table |
| 390 |
} |
| 391 |
|
| 392 |
// |
| 393 |
// GAME FUNCTIONS |
| 394 |
// |
| 395 |
|
| 396 |
static vissprite_t *vissprites, **vissprite_ptrs; // killough |
| 397 |
static int num_vissprite, num_vissprite_alloc, num_vissprite_ptrs; |
| 398 |
|
| 399 |
// |
| 400 |
// R_InitSprites |
| 401 |
// Called at program start. |
| 402 |
// |
| 403 |
|
| 404 |
void R_InitSprites(const char * const *namelist) |
| 405 |
{ |
| 406 |
int i; |
| 407 |
for (i=0; i<SCREENWIDTH; i++) // killough 2/8/98 |
| 408 |
negonearray[i] = -1; |
| 409 |
R_InitSpriteDefs(namelist); |
| 410 |
} |
| 411 |
|
| 412 |
// |
| 413 |
// R_ClearSprites |
| 414 |
// Called at frame start. |
| 415 |
// |
| 416 |
|
| 417 |
void R_ClearSprites (void) |
| 418 |
{ |
| 419 |
num_vissprite = 0; // killough |
| 420 |
} |
| 421 |
|
| 422 |
// |
| 423 |
// R_NewVisSprite |
| 424 |
// |
| 425 |
|
| 426 |
static vissprite_t *R_NewVisSprite(void) |
| 427 |
{ |
| 428 |
if (num_vissprite >= num_vissprite_alloc) // killough |
| 429 |
{ |
| 430 |
size_t num_vissprite_alloc_prev = num_vissprite_alloc; |
| 431 |
|
| 432 |
num_vissprite_alloc = num_vissprite_alloc ? num_vissprite_alloc*2 : 128; |
| 433 |
vissprites = Z_Realloc(vissprites,num_vissprite_alloc*sizeof(*vissprites)); |
| 434 |
|
| 435 |
//e6y: set all fields to zero |
| 436 |
memset(vissprites + num_vissprite_alloc_prev, 0, |
| 437 |
(num_vissprite_alloc - num_vissprite_alloc_prev)*sizeof(*vissprites)); |
| 438 |
} |
| 439 |
return vissprites + num_vissprite++; |
| 440 |
} |
| 441 |
|
| 442 |
// |
| 443 |
// R_DrawMaskedColumn |
| 444 |
// Used for sprites and masked mid textures. |
| 445 |
// Masked means: partly transparent, i.e. stored |
| 446 |
// in posts/runs of opaque pixels. |
| 447 |
// |
| 448 |
|
| 449 |
int *mfloorclip; // dropoff overflow |
| 450 |
int *mceilingclip; // dropoff overflow |
| 451 |
fixed_t spryscale; |
| 452 |
int64_t sprtopscreen; // R_WiggleFix |
| 453 |
int colheight; // Scaled software fuzz |
| 454 |
|
| 455 |
void R_DrawMaskedColumn( |
| 456 |
const rpatch_t *patch, |
| 457 |
R_DrawColumn_f colfunc, |
| 458 |
draw_column_vars_t *dcvars, |
| 459 |
const rcolumn_t *column, |
| 460 |
const rcolumn_t *prevcolumn, |
| 461 |
const rcolumn_t *nextcolumn |
| 462 |
) |
| 463 |
{ |
| 464 |
int i; |
| 465 |
int64_t topscreen; // R_WiggleFix |
| 466 |
int64_t bottomscreen; // R_WiggleFix |
| 467 |
fixed_t basetexturemid = dcvars->texturemid; |
| 468 |
|
| 469 |
colheight = 0; |
| 470 |
|
| 471 |
dcvars->texheight = patch->height; // killough 11/98 |
| 472 |
for (i=0; i<column->numPosts; i++) { |
| 473 |
const rpost_t *post = &column->posts[i]; |
| 474 |
|
| 475 |
// calculate unclipped screen coordinates for post |
| 476 |
topscreen = sprtopscreen + spryscale*post->topdelta; |
| 477 |
bottomscreen = topscreen + spryscale*post->length; |
| 478 |
|
| 479 |
dcvars->yl = (int)((topscreen+FRACUNIT-1)>>FRACBITS); |
| 480 |
dcvars->yh = (int)((bottomscreen-1)>>FRACBITS); |
| 481 |
|
| 482 |
if (dcvars->yh >= mfloorclip[dcvars->x]) |
| 483 |
dcvars->yh = mfloorclip[dcvars->x]-1; |
| 484 |
|
| 485 |
if (dcvars->yl <= mceilingclip[dcvars->x]) |
| 486 |
dcvars->yl = mceilingclip[dcvars->x]+1; |
| 487 |
|
| 488 |
if (dcvars->yh >= dcvars->baseclip && dcvars->baseclip != -1) |
| 489 |
dcvars->yh = dcvars->baseclip; |
| 490 |
|
| 491 |
// killough 3/2/98, 3/27/98: Failsafe against overflow/crash: |
| 492 |
if (dcvars->yl >= 0 && dcvars->yl <= dcvars->yh && dcvars->yh < viewheight) |
| 493 |
{ |
| 494 |
dcvars->source = column->pixels + post->topdelta; |
| 495 |
dcvars->prevsource = prevcolumn->pixels + post->topdelta; |
| 496 |
dcvars->nextsource = nextcolumn->pixels + post->topdelta; |
| 497 |
|
| 498 |
dcvars->texturemid = basetexturemid - (post->topdelta<<FRACBITS); |
| 499 |
|
| 500 |
dcvars->edgeslope = post->slope; |
| 501 |
// Drawn by either R_DrawColumn |
| 502 |
// or (SHADOW) R_DrawFuzzColumn. |
| 503 |
dcvars->drawingmasked = 1; // POPE |
| 504 |
colfunc (dcvars); |
| 505 |
dcvars->drawingmasked = 0; // POPE |
| 506 |
|
| 507 |
colheight += dcvars->yh - dcvars->yl + 1; |
| 508 |
} |
| 509 |
} |
| 510 |
dcvars->texturemid = basetexturemid; |
| 511 |
} |
| 512 |
|
| 513 |
static void R_SetSpritelights(int lightlevel) |
| 514 |
{ |
| 515 |
int lightnum = (lightlevel >> LIGHTSEGSHIFT) + (extralight * LIGHTBRIGHT); |
| 516 |
spritelights = scalelight[BETWEEN(0, LIGHTLEVELS - 1, lightnum)]; |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
// |
| 521 |
// R_DrawVisSprite |
| 522 |
// mfloorclip and mceilingclip should also be set. |
| 523 |
// |
| 524 |
// CPhipps - new wad lump handling, *'s to const*'s |
| 525 |
static void R_DrawVisSprite(vissprite_t *vis) |
| 526 |
{ |
| 527 |
int texturecolumn; |
| 528 |
fixed_t frac; |
| 529 |
const rpatch_t *patch = R_PatchByNum(vis->patch+firstspritelump); |
| 530 |
R_DrawColumn_f colfunc; |
| 531 |
draw_column_vars_t dcvars; |
| 532 |
|
| 533 |
R_SetDefaultDrawColumnVars(&dcvars); |
| 534 |
|
| 535 |
dcvars.colormap = vis->colormap; |
| 536 |
|
| 537 |
// hexen_note: colfunc: No idea how to merge this right now... |
| 538 |
// if (vis->mobjflags & (MF_SHADOW | MF_ALTSHADOW)) |
| 539 |
// { |
| 540 |
// if (vis->mobjflags & MF_TRANSLATION) |
| 541 |
// { |
| 542 |
// colfunc = R_DrawTranslatedTLColumn; |
| 543 |
// dc_translation = translationtables - 256 |
| 544 |
// + (vis->pclass - 1) * ((g_maxplayers - 1) * 256) + |
| 545 |
// ((vis->mobjflags & MF_TRANSLATION) >> (MF_TRANSSHIFT - 8)); |
| 546 |
// } |
| 547 |
// else if (vis->mobjflags & MF_SHADOW) |
| 548 |
// { // Draw using shadow column function |
| 549 |
// colfunc = tlcolfunc; |
| 550 |
// } |
| 551 |
// else |
| 552 |
// { |
| 553 |
// colfunc = R_DrawAltTLColumn; |
| 554 |
// } |
| 555 |
// } |
| 556 |
// else if (vis->mobjflags & MF_TRANSLATION) |
| 557 |
// { |
| 558 |
// // Draw using translated column function |
| 559 |
// colfunc = R_DrawTranslatedColumn; |
| 560 |
// dc_translation = translationtables - 256 |
| 561 |
// + (vis->pclass - 1) * ((g_maxplayers - 1) * 256) + |
| 562 |
// ((vis->mobjflags & MF_TRANSLATION) >> (MF_TRANSSHIFT - 8)); |
| 563 |
// } |
| 564 |
|
| 565 |
// killough 4/11/98: rearrange and handle translucent sprites |
| 566 |
// mixed with translucent/non-translucenct 2s normals |
| 567 |
|
| 568 |
if (!dcvars.colormap) // NULL colormap = shadow draw |
| 569 |
{ |
| 570 |
R_ResetFuzzCol(colheight); // Reset fuzz column for new sprite |
| 571 |
colfunc = R_GetDrawColumnFunc(RDC_PIPELINE_FUZZ, RDRAW_FILTER_POINT); // killough 3/14/98 |
| 572 |
} |
| 573 |
else if (vis->color) |
| 574 |
{ |
| 575 |
colfunc = R_GetDrawColumnFunc(RDC_PIPELINE_TRANSLATED, RDRAW_FILTER_POINT); |
| 576 |
dcvars.translation = colrngs[vis->color]; |
| 577 |
} |
| 578 |
else if (vis->mobjflags & MF_TRANSLATION) |
| 579 |
{ |
| 580 |
colfunc = R_GetDrawColumnFunc(RDC_PIPELINE_TRANSLATED, RDRAW_FILTER_POINT); |
| 581 |
dcvars.translation = translationtables - 256 + |
| 582 |
((vis->mobjflags & MF_TRANSLATION) >> (MF_TRANSSHIFT-8) ); |
| 583 |
} |
| 584 |
else if (vis->tranmap) // phares |
| 585 |
{ |
| 586 |
colfunc = R_GetDrawColumnFunc(RDC_PIPELINE_TRANSLUCENT, RDRAW_FILTER_POINT); |
| 587 |
tranmap = vis->tranmap; |
| 588 |
} |
| 589 |
else |
| 590 |
{ |
| 591 |
colfunc = R_GetDrawColumnFunc(RDC_PIPELINE_STANDARD, RDRAW_FILTER_POINT); // killough 3/14/98, 4/11/98 |
| 592 |
} |
| 593 |
|
| 594 |
// proff 11/06/98: Changed for high-res |
| 595 |
dcvars.iscale = FixedDiv (FRACUNIT, vis->scale); |
| 596 |
dcvars.texturemid = vis->texturemid; |
| 597 |
frac = vis->startfrac; |
| 598 |
spryscale = vis->scale; |
| 599 |
sprtopscreen = centeryfrac - FixedMul(dcvars.texturemid,spryscale); |
| 600 |
|
| 601 |
// check to see if weapon is a vissprite |
| 602 |
if(vis->mobjflags & MF_PLAYERSPRITE) |
| 603 |
{ |
| 604 |
// [FG] fix garbage lines at the top of weapon sprites |
| 605 |
dcvars.iscale = pspriteiyscale; |
| 606 |
dcvars.texturemid += FixedMul(((centery - viewheight/2)<<FRACBITS), dcvars.iscale); |
| 607 |
sprtopscreen += (viewheight/2 - centery)<<FRACBITS; |
| 608 |
} |
| 609 |
|
| 610 |
if (vis->floorclip && !(vis->mobjflags & MF_PLAYERSPRITE)) |
| 611 |
{ |
| 612 |
fixed_t sprbotscreen = sprtopscreen + FixedMul(LittleShort(patch->height) << FRACBITS, spryscale); |
| 613 |
dcvars.baseclip = (sprbotscreen - FixedMul(vis->floorclip, spryscale)) >> FRACBITS; |
| 614 |
} |
| 615 |
|
| 616 |
for (dcvars.x=vis->x1 ; dcvars.x<=vis->x2 ; dcvars.x++, frac += vis->xiscale) |
| 617 |
{ |
| 618 |
texturecolumn = frac>>FRACBITS; |
| 619 |
|
| 620 |
if (!dcvars.colormap) R_CheckFuzzCol(dcvars.x, colheight); |
| 621 |
|
| 622 |
R_DrawMaskedColumn( |
| 623 |
patch, |
| 624 |
colfunc, |
| 625 |
&dcvars, |
| 626 |
R_GetPatchColumnClamped(patch, texturecolumn), |
| 627 |
R_GetPatchColumnClamped(patch, texturecolumn-1), |
| 628 |
R_GetPatchColumnClamped(patch, texturecolumn+1) |
| 629 |
); |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
int r_near_clip_plane = MINZ; |
| 634 |
|
| 635 |
void R_SetClipPlanes(void) |
| 636 |
{ |
| 637 |
// thing is behind view plane? |
| 638 |
if ((V_IsOpenGLMode()) && (HaveMouseLook() || (gl_render_fov > FOV90))) |
| 639 |
{ |
| 640 |
r_near_clip_plane = -(FRACUNIT * 80); |
| 641 |
} |
| 642 |
else |
| 643 |
{ |
| 644 |
r_near_clip_plane = MINZ; |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
// |
| 649 |
// R_ProjectSprite |
| 650 |
// Generates a vissprite for a thing if it might be visible. |
| 651 |
// |
| 652 |
|
| 653 |
dboolean LevelUseFullBright = true; |
| 654 |
|
| 655 |
static void R_ProjectSprite (mobj_t* thing, int lightlevel) |
| 656 |
{ |
| 657 |
fixed_t gzt, gzb; // killough 3/27/98 |
| 658 |
fixed_t tx; |
| 659 |
fixed_t xscale; |
| 660 |
int x1; |
| 661 |
int x2; |
| 662 |
spritedef_t *sprdef; |
| 663 |
spriteframe_t *sprframe; |
| 664 |
int lump; |
| 665 |
dboolean flip; |
| 666 |
vissprite_t *vis; |
| 667 |
fixed_t iscale; |
| 668 |
int heightsec; // killough 3/27/98 |
| 669 |
|
| 670 |
// transform the origin point |
| 671 |
//e6y |
| 672 |
fixed_t tr_x, tr_y; |
| 673 |
fixed_t fx, fy, fz; |
| 674 |
fixed_t gxt, gyt; |
| 675 |
fixed_t tz, tz2; |
| 676 |
int width; |
| 677 |
|
| 678 |
if (thing->flags2 & MF2_DONTDRAW) |
| 679 |
{ |
| 680 |
return; |
| 681 |
} |
| 682 |
|
| 683 |
if (V_IsOpenGLMode()) |
| 684 |
{ |
| 685 |
gld_ProjectSprite(thing, lightlevel); |
| 686 |
return; |
| 687 |
} |
| 688 |
|
| 689 |
if (R_ViewInterpolation()) |
| 690 |
{ |
| 691 |
fx = thing->PrevX + FixedMul (tic_vars.frac, thing->x - thing->PrevX); |
| 692 |
fy = thing->PrevY + FixedMul (tic_vars.frac, thing->y - thing->PrevY); |
| 693 |
fz = thing->PrevZ + FixedMul (tic_vars.frac, thing->z - thing->PrevZ); |
| 694 |
} |
| 695 |
else |
| 696 |
{ |
| 697 |
fx = thing->x; |
| 698 |
fy = thing->y; |
| 699 |
fz = thing->z; |
| 700 |
} |
| 701 |
|
| 702 |
tr_x = fx - viewx; |
| 703 |
tr_y = fy - viewy; |
| 704 |
|
| 705 |
gxt = FixedMul(tr_x,viewcos); |
| 706 |
gyt = -FixedMul(tr_y,viewsin); |
| 707 |
|
| 708 |
tz = gxt-gyt; |
| 709 |
|
| 710 |
// thing is behind view plane? |
| 711 |
if (tz < r_near_clip_plane) |
| 712 |
return; |
| 713 |
|
| 714 |
xscale = FixedDiv(projection, tz); |
| 715 |
|
| 716 |
gxt = -FixedMul(tr_x,viewsin); |
| 717 |
gyt = FixedMul(tr_y,viewcos); |
| 718 |
tx = -(gyt+gxt); |
| 719 |
|
| 720 |
// too far off the side? |
| 721 |
if (D_abs(tx) > ((int64_t) tz << 2)) |
| 722 |
return; |
| 723 |
|
| 724 |
// decide which patch to use for sprite relative to player |
| 725 |
#ifdef RANGECHECK |
| 726 |
if ((unsigned) thing->sprite >= (unsigned)num_sprites) |
| 727 |
I_Error ("R_ProjectSprite: Invalid sprite number %i", thing->sprite); |
| 728 |
#endif |
| 729 |
|
| 730 |
sprdef = &sprites[thing->sprite]; |
| 731 |
|
| 732 |
#ifdef RANGECHECK |
| 733 |
if ((thing->frame&FF_FRAMEMASK) >= sprdef->numframes) |
| 734 |
I_Error ("R_ProjectSprite: Invalid sprite frame %i : %i", thing->sprite, |
| 735 |
thing->frame); |
| 736 |
#endif |
| 737 |
|
| 738 |
if (!sprdef->spriteframes) |
| 739 |
I_Error ("R_ProjectSprite: Missing spriteframes %i : %i", thing->sprite, |
| 740 |
thing->frame); |
| 741 |
|
| 742 |
sprframe = &sprdef->spriteframes[thing->frame & FF_FRAMEMASK]; |
| 743 |
|
| 744 |
if (sprframe->rotate) |
| 745 |
{ |
| 746 |
// choose a different rotation based on player view |
| 747 |
angle_t rot; |
| 748 |
angle_t ang = R_PointToAngle2(viewx, viewy, fx, fy); |
| 749 |
if (sprframe->lump[0] == sprframe->lump[1]) |
| 750 |
{ |
| 751 |
rot = (ang - thing->angle + (angle_t)(ANG45/2)*9) >> 28; |
| 752 |
} |
| 753 |
else |
| 754 |
{ |
| 755 |
rot = (ang - thing->angle + (angle_t)(ANG45 / 2) * 9 - |
| 756 |
(angle_t)(ANG180 / 16)) >> 28; |
| 757 |
} |
| 758 |
lump = sprframe->lump[rot]; |
| 759 |
flip = (dboolean)(sprframe->flip & (1 << rot)); |
| 760 |
} |
| 761 |
else |
| 762 |
{ |
| 763 |
// use single rotation for all views |
| 764 |
lump = sprframe->lump[0]; |
| 765 |
flip = (dboolean)(sprframe->flip & 1); |
| 766 |
} |
| 767 |
|
| 768 |
{ |
| 769 |
const rpatch_t* patch = R_PatchByNum(lump+firstspritelump); |
| 770 |
thing->patch_width = patch->width; |
| 771 |
|
| 772 |
/* calculate edges of the shape |
| 773 |
* cph 2003/08/1 - fraggle points out that this offset must be flipped |
| 774 |
* if the sprite is flipped; e.g. FreeDoom imp is messed up by this. */ |
| 775 |
if (flip) { |
| 776 |
tx -= (patch->width - patch->leftoffset) << FRACBITS; |
| 777 |
} else { |
| 778 |
tx -= patch->leftoffset << FRACBITS; |
| 779 |
} |
| 780 |
x1 = (centerxfrac + FixedMul(tx,xscale)) >> FRACBITS; |
| 781 |
|
| 782 |
tx += patch->width<<FRACBITS; |
| 783 |
x2 = ((centerxfrac + FixedMul (tx,xscale) - FRACUNIT/2) >> FRACBITS); |
| 784 |
|
| 785 |
gzt = fz + (patch->topoffset << FRACBITS); |
| 786 |
gzb = gzt - (patch->height << FRACBITS); |
| 787 |
width = patch->width; |
| 788 |
} |
| 789 |
|
| 790 |
// off the side? |
| 791 |
if (x1 > viewwidth || x2 < 0) |
| 792 |
return; |
| 793 |
|
| 794 |
// [RH] Reject sprites that are off the top or bottom of the screen |
| 795 |
tz2 = FixedMul(tr_x, viewtancos) + FixedMul(tr_y, viewtansin); |
| 796 |
if (FixedMul(globaluclip, tz2) > viewz - gzb || |
| 797 |
FixedMul(globaldclip, tz2) < viewz - gzt) |
| 798 |
{ |
| 799 |
return; |
| 800 |
} |
| 801 |
|
| 802 |
// killough 3/27/98: exclude things totally separated |
| 803 |
// from the viewer, by either water or fake ceilings |
| 804 |
// killough 4/11/98: improve sprite clipping for underwater/fake ceilings |
| 805 |
|
| 806 |
heightsec = thing->subsector->sector->heightsec; |
| 807 |
|
| 808 |
if (heightsec != -1) // only clip things which are in special sectors |
| 809 |
{ |
| 810 |
int phs = viewplayer->mo->subsector->sector->heightsec; |
| 811 |
if (phs != -1 && viewz < sectors[phs].floorheight ? |
| 812 |
fz >= sectors[heightsec].floorheight : |
| 813 |
gzt < sectors[heightsec].floorheight) |
| 814 |
return; |
| 815 |
if (phs != -1 && viewz > sectors[phs].ceilingheight ? |
| 816 |
gzt < sectors[heightsec].ceilingheight && |
| 817 |
viewz >= sectors[heightsec].ceilingheight : |
| 818 |
fz >= sectors[heightsec].ceilingheight) |
| 819 |
return; |
| 820 |
} |
| 821 |
|
| 822 |
//e6y FIXME!!! |
| 823 |
if (thing == players[displayplayer].mo && walkcamera.type != 2) |
| 824 |
// if (thing->player && thing->player == &players[displayplayer] && walkcamera.type != 2) |
| 825 |
return; |
| 826 |
|
| 827 |
// store information in a vissprite |
| 828 |
vis = R_NewVisSprite (); |
| 829 |
|
| 830 |
vis->gx = fx; |
| 831 |
vis->gy = fy; |
| 832 |
vis->gz = fz; |
| 833 |
|
| 834 |
//vis->isplayersprite = false; // e6y |
| 835 |
|
| 836 |
// killough 3/27/98: save sector for special clipping later |
| 837 |
vis->heightsec = heightsec; |
| 838 |
|
| 839 |
vis->mobjflags = thing->flags; |
| 840 |
// proff 11/06/98: Changed for high-res |
| 841 |
vis->scale = FixedDiv(projectiony, tz); |
| 842 |
vis->gzt = gzt; // killough 3/27/98 |
| 843 |
|
| 844 |
if (heretic) |
| 845 |
{ |
| 846 |
if (thing->flags2 & MF2_FEETARECLIPPED |
| 847 |
&& vis->gz <= thing->subsector->sector->floorheight) |
| 848 |
{ |
| 849 |
vis->floorclip = 10 << FRACBITS; |
| 850 |
} |
| 851 |
else |
| 852 |
vis->floorclip = 0; |
| 853 |
} |
| 854 |
else if (hexen) |
| 855 |
{ |
| 856 |
if (thing->flags & MF_TRANSLATION) |
| 857 |
{ |
| 858 |
if (thing->player) |
| 859 |
{ |
| 860 |
vis->pclass = thing->player->pclass; |
| 861 |
} |
| 862 |
else |
| 863 |
{ |
| 864 |
vis->pclass = thing->special1.i; |
| 865 |
} |
| 866 |
if (vis->pclass > 3) |
| 867 |
{ |
| 868 |
vis->pclass = 1; |
| 869 |
} |
| 870 |
} |
| 871 |
// foot clipping |
| 872 |
vis->floorclip = thing->floorclip; |
| 873 |
} |
| 874 |
else |
| 875 |
{ |
| 876 |
vis->floorclip = 0; |
| 877 |
} |
| 878 |
|
| 879 |
vis->texturemid = vis->gzt - viewz - vis->floorclip; |
| 880 |
vis->x1 = x1 < 0 ? 0 : x1; |
| 881 |
vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; |
| 882 |
iscale = FixedDiv (FRACUNIT, xscale); |
| 883 |
vis->color = thing->color; |
| 884 |
|
| 885 |
if (flip) |
| 886 |
{ |
| 887 |
vis->startfrac = (width<<FRACBITS)-1; |
| 888 |
vis->xiscale = -iscale; |
| 889 |
} |
| 890 |
else |
| 891 |
{ |
| 892 |
vis->startfrac = 0; |
| 893 |
vis->xiscale = iscale; |
| 894 |
} |
| 895 |
|
| 896 |
if (vis->x1 > x1) |
| 897 |
vis->startfrac += vis->xiscale*(vis->x1-x1); |
| 898 |
vis->patch = lump; |
| 899 |
|
| 900 |
R_SetSpritelights(lightlevel); |
| 901 |
|
| 902 |
// get light level |
| 903 |
if (thing->flags & g_mf_shadow) |
| 904 |
vis->colormap = NULL; // shadow draw |
| 905 |
else if (fixedcolormap) |
| 906 |
vis->colormap = fixedcolormap; // fixed map |
| 907 |
else if (LevelUseFullBright && thing->frame & FF_FULLBRIGHT) |
| 908 |
vis->colormap = fullcolormap; // full bright // killough 3/20/98 |
| 909 |
else |
| 910 |
{ // diminished light |
| 911 |
int index = (int)(((int64_t)xscale * 160 / wide_centerx) >> LIGHTSCALESHIFT); |
| 912 |
if (index >= MAXLIGHTSCALE) |
| 913 |
index = MAXLIGHTSCALE - 1; |
| 914 |
vis->colormap = spritelights[index]; |
| 915 |
} |
| 916 |
|
| 917 |
R_UpdateVisSpriteTranMap(vis, thing); |
| 918 |
} |
| 919 |
|
| 920 |
// |
| 921 |
// R_AddSprites |
| 922 |
// During BSP traversal, this adds sprites by sector. |
| 923 |
// |
| 924 |
// killough 9/18/98: add lightlevel as parameter, fixing underwater lighting |
| 925 |
void R_AddSprites(subsector_t* subsec, int lightlevel) |
| 926 |
{ |
| 927 |
sector_t* sec=subsec->sector; |
| 928 |
mobj_t *thing; |
| 929 |
|
| 930 |
if (compatibility_level <= boom_202_compatibility) |
| 931 |
lightlevel = sec->lightlevel; |
| 932 |
|
| 933 |
// Handle all things in sector. |
| 934 |
|
| 935 |
if (dsda_ShowAliveMonsters() && V_IsOpenGLMode()) |
| 936 |
{ |
| 937 |
if (dsda_ShowAliveMonsters() == 1) |
| 938 |
{ |
| 939 |
for (thing = sec->thinglist; thing; thing = thing->snext) |
| 940 |
{ |
| 941 |
if (!ALIVE(thing)) |
| 942 |
R_ProjectSprite(thing, lightlevel); |
| 943 |
} |
| 944 |
} |
| 945 |
} |
| 946 |
else |
| 947 |
{ |
| 948 |
for (thing = sec->thinglist; thing; thing = thing->snext) |
| 949 |
{ |
| 950 |
R_ProjectSprite(thing, lightlevel); |
| 951 |
} |
| 952 |
} |
| 953 |
} |
| 954 |
|
| 955 |
// |
| 956 |
// R_AddAllAliveMonstersSprites |
| 957 |
// Add all alive monsters. |
| 958 |
// |
| 959 |
void R_AddAllAliveMonstersSprites(void) |
| 960 |
{ |
| 961 |
int i; |
| 962 |
sector_t* sec; |
| 963 |
mobj_t *thing; |
| 964 |
|
| 965 |
for (i = 0; i < numsectors; i++) |
| 966 |
{ |
| 967 |
sec = §ors[i]; |
| 968 |
for (thing = sec->thinglist; thing; thing = thing->snext) |
| 969 |
{ |
| 970 |
if (ALIVE(thing)) |
| 971 |
{ |
| 972 |
thing->flags |= MF_NO_DEPTH_TEST; |
| 973 |
R_ProjectSprite(thing, 255); |
| 974 |
thing->flags &= ~MF_NO_DEPTH_TEST; |
| 975 |
} |
| 976 |
} |
| 977 |
} |
| 978 |
} |
| 979 |
|
| 980 |
// [crispy] apply bobbing (or centering) to the player's weapon sprite |
| 981 |
static void R_ApplyWeaponBob (fixed_t *sx, dboolean bobx, fixed_t *sy, dboolean boby) |
| 982 |
{ |
| 983 |
const angle_t angle = (128 * leveltime) & FINEMASK; |
| 984 |
fixed_t bob = viewplayer->bob * dsda_WeaponBob() / 4; |
| 985 |
|
| 986 |
if (sx) |
| 987 |
{ |
| 988 |
*sx = FRACUNIT; |
| 989 |
|
| 990 |
if (bobx) |
| 991 |
{ |
| 992 |
*sx += FixedMul(bob, finecosine[angle]); |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
if (sy) |
| 997 |
{ |
| 998 |
*sy = 32 * FRACUNIT; // [crispy] WEAPONTOP |
| 999 |
|
| 1000 |
if (boby) |
| 1001 |
{ |
| 1002 |
*sy += FixedMul(bob, finesine[angle & (FINEANGLES / 2 - 1)]); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
} |
| 1006 |
|
| 1007 |
// |
| 1008 |
// R_DrawPSprite |
| 1009 |
// |
| 1010 |
|
| 1011 |
// heretic |
| 1012 |
static int PSpriteSY[NUMCLASSES][NUMWEAPONS] = { |
| 1013 |
{ |
| 1014 |
0, // staff |
| 1015 |
5 * FRACUNIT, // goldwand |
| 1016 |
15 * FRACUNIT, // crossbow |
| 1017 |
15 * FRACUNIT, // blaster |
| 1018 |
15 * FRACUNIT, // skullrod |
| 1019 |
15 * FRACUNIT, // phoenix rod |
| 1020 |
15 * FRACUNIT, // mace |
| 1021 |
15 * FRACUNIT, // gauntlets |
| 1022 |
15 * FRACUNIT // beak |
| 1023 |
}, |
| 1024 |
{0, -12 * FRACUNIT, -10 * FRACUNIT, 10 * FRACUNIT}, // Fighter |
| 1025 |
{-8 * FRACUNIT, 10 * FRACUNIT, 10 * FRACUNIT, 0}, // Cleric |
| 1026 |
{9 * FRACUNIT, 20 * FRACUNIT, 20 * FRACUNIT, 20 * FRACUNIT}, // Mage |
| 1027 |
{10 * FRACUNIT, 10 * FRACUNIT, 10 * FRACUNIT, 10 * FRACUNIT} // Pig |
| 1028 |
}; |
| 1029 |
|
| 1030 |
static void R_DrawPSprite (pspdef_t *psp) |
| 1031 |
{ |
| 1032 |
int x1, x2; |
| 1033 |
spritedef_t *sprdef; |
| 1034 |
spriteframe_t *sprframe; |
| 1035 |
int lump; |
| 1036 |
dboolean flip; |
| 1037 |
vissprite_t *vis; |
| 1038 |
vissprite_t avis; |
| 1039 |
int width; |
| 1040 |
fixed_t topoffset; |
| 1041 |
fixed_t psp_sx = psp->sx; |
| 1042 |
fixed_t psp_sy = psp->sy; |
| 1043 |
|
| 1044 |
// decide which patch to use |
| 1045 |
|
| 1046 |
#ifdef RANGECHECK |
| 1047 |
if ( (unsigned)psp->state->sprite >= (unsigned)num_sprites) |
| 1048 |
I_Error ("R_ProjectSprite: Invalid sprite number %i", psp->state->sprite); |
| 1049 |
#endif |
| 1050 |
|
| 1051 |
sprdef = &sprites[psp->state->sprite]; |
| 1052 |
|
| 1053 |
#ifdef RANGECHECK |
| 1054 |
if ( (psp->state->frame & FF_FRAMEMASK) >= sprdef->numframes) |
| 1055 |
I_Error ("R_ProjectSprite: Invalid sprite frame %i : %li", |
| 1056 |
psp->state->sprite, psp->state->frame); |
| 1057 |
#endif |
| 1058 |
|
| 1059 |
sprframe = &sprdef->spriteframes[psp->state->frame & FF_FRAMEMASK]; |
| 1060 |
|
| 1061 |
lump = sprframe->lump[0]; |
| 1062 |
flip = (dboolean)(sprframe->flip & 1); |
| 1063 |
|
| 1064 |
{ |
| 1065 |
int weapon_attack_alignment = dsda_IntConfig(dsda_config_weapon_attack_alignment); |
| 1066 |
|
| 1067 |
// [crispy] don't align swiping weapons |
| 1068 |
const dboolean swiping_weapon = hexen && (viewplayer->pclass == PCLASS_FIGHTER || |
| 1069 |
(viewplayer->pclass == PCLASS_CLERIC && |
| 1070 |
viewplayer->readyweapon == wp_first)); |
| 1071 |
|
| 1072 |
if (!dsda_WeaponBob() && !(swiping_weapon && viewplayer->attackdown)) |
| 1073 |
{ |
| 1074 |
static fixed_t last_sy = 32 * FRACUNIT; |
| 1075 |
|
| 1076 |
psp_sx = FRACUNIT; |
| 1077 |
|
| 1078 |
if (psp->state->action != A_Lower && psp->state->action != A_Raise) |
| 1079 |
{ |
| 1080 |
last_sy = psp->sy; |
| 1081 |
psp_sy = 32 * FRACUNIT; |
| 1082 |
} |
| 1083 |
else if (psp->state->action == A_Lower) |
| 1084 |
{ |
| 1085 |
// We want to move smoothly from where we were |
| 1086 |
psp_sy -= (last_sy - 32 * FRACUNIT); |
| 1087 |
} |
| 1088 |
} |
| 1089 |
else if (weapon_attack_alignment && viewplayer->attackdown && !psp->state->misc1) |
| 1090 |
{ // [crispy] center the weapon sprite horizontally and vertically |
| 1091 |
R_ApplyWeaponBob(&psp_sx, weapon_attack_alignment == CENTERWEAPON_BOB, NULL, false); |
| 1092 |
|
| 1093 |
// [crispy] don't center vertically during lowering and raising states |
| 1094 |
if (weapon_attack_alignment >= CENTERWEAPON_HORVER && |
| 1095 |
psp->state->action != A_Lower && psp->state->action != A_Raise && !swiping_weapon) |
| 1096 |
{ |
| 1097 |
R_ApplyWeaponBob(NULL, false, &psp_sy, weapon_attack_alignment == CENTERWEAPON_BOB); |
| 1098 |
} |
| 1099 |
} |
| 1100 |
else if (psp->state->action == A_WeaponReady && psp->state->tics > 1 && movement_smooth) |
| 1101 |
{ |
| 1102 |
// Interpolate bobbing for animated weapons (Chainsaw) |
| 1103 |
R_ApplyWeaponBob(&psp_sx, true, &psp_sy, true); |
| 1104 |
} |
| 1105 |
else if (psp->state->action == A_WeaponReady && dsda_WeaponBob() < 4) |
| 1106 |
{ |
| 1107 |
// Always apply Weaponbob when using bobbing increments |
| 1108 |
R_ApplyWeaponBob(&psp_sx, true, &psp_sy, true); |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
{ |
| 1113 |
const rpatch_t* patch = R_PatchByNum(lump+firstspritelump); |
| 1114 |
// calculate edges of the shape |
| 1115 |
fixed_t tx; |
| 1116 |
tx = psp_sx-160*FRACUNIT; |
| 1117 |
|
| 1118 |
tx -= patch->leftoffset<<FRACBITS; |
| 1119 |
x1 = (centerxfrac + FixedMul (tx,pspritexscale))>>FRACBITS; |
| 1120 |
|
| 1121 |
tx += patch->width<<FRACBITS; |
| 1122 |
x2 = ((centerxfrac + FixedMul (tx, pspritexscale) ) >>FRACBITS) - 1; |
| 1123 |
|
| 1124 |
width = patch->width; |
| 1125 |
topoffset = patch->topoffset<<FRACBITS; |
| 1126 |
} |
| 1127 |
|
| 1128 |
// off the side |
| 1129 |
if (x2 < 0 || x1 > viewwidth) |
| 1130 |
return; |
| 1131 |
|
| 1132 |
// store information in a vissprite |
| 1133 |
vis = &avis; |
| 1134 |
vis->mobjflags = MF_PLAYERSPRITE; |
| 1135 |
vis->pclass = 0; |
| 1136 |
vis->floorclip = 0; |
| 1137 |
// killough 12/98: fix psprite positioning problem |
| 1138 |
vis->texturemid = (BASEYCENTER<<FRACBITS) /* + FRACUNIT/2 */ - |
| 1139 |
(psp_sy-topoffset); |
| 1140 |
|
| 1141 |
if (R_FullView() && raven) |
| 1142 |
{ |
| 1143 |
vis->texturemid -= PSpriteSY[viewplayer->pclass][players[consoleplayer].readyweapon]; |
| 1144 |
} |
| 1145 |
|
| 1146 |
// Move the weapon down for 1280x1024. |
| 1147 |
vis->texturemid -= psprite_offset; |
| 1148 |
|
| 1149 |
vis->x1 = x1 < 0 ? 0 : x1; |
| 1150 |
vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; |
| 1151 |
// proff 11/06/98: Added for high-res |
| 1152 |
vis->scale = pspriteyscale; |
| 1153 |
vis->color = 0; |
| 1154 |
|
| 1155 |
if (flip) |
| 1156 |
{ |
| 1157 |
vis->xiscale = -pspriteiscale; |
| 1158 |
vis->startfrac = (width<<FRACBITS)-1; |
| 1159 |
} |
| 1160 |
else |
| 1161 |
{ |
| 1162 |
vis->xiscale = pspriteiscale; |
| 1163 |
vis->startfrac = 0; |
| 1164 |
} |
| 1165 |
|
| 1166 |
if (vis->x1 > x1) |
| 1167 |
vis->startfrac += vis->xiscale*(vis->x1-x1); |
| 1168 |
|
| 1169 |
vis->patch = lump; |
| 1170 |
|
| 1171 |
if (viewplayer->powers[pw_invisibility] > 4*32 |
| 1172 |
|| viewplayer->powers[pw_invisibility] & 8) |
| 1173 |
{ |
| 1174 |
if (heretic) |
| 1175 |
{ |
| 1176 |
vis->mobjflags |= MF_SHADOW; |
| 1177 |
vis->colormap = spritelights[MAXLIGHTSCALE-1]; |
| 1178 |
} |
| 1179 |
else |
| 1180 |
{ |
| 1181 |
vis->colormap = NULL; // shadow draw |
| 1182 |
} |
| 1183 |
} |
| 1184 |
else if (viewplayer->powers[pw_invulnerability] && viewplayer->pclass == PCLASS_CLERIC) |
| 1185 |
{ |
| 1186 |
vis->colormap = spritelights[MAXLIGHTSCALE - 1]; |
| 1187 |
if (viewplayer->powers[pw_invulnerability] > 4 * 32) |
| 1188 |
{ |
| 1189 |
if (viewplayer->mo->flags2 & MF2_DONTDRAW) |
| 1190 |
{ // don't draw the psprite |
| 1191 |
vis->mobjflags |= MF_SHADOW; |
| 1192 |
} |
| 1193 |
else if (viewplayer->mo->flags & MF_SHADOW) |
| 1194 |
{ |
| 1195 |
vis->mobjflags |= MF_ALTSHADOW; |
| 1196 |
} |
| 1197 |
} |
| 1198 |
else if (viewplayer->powers[pw_invulnerability] & 8) |
| 1199 |
{ |
| 1200 |
vis->mobjflags |= MF_SHADOW; |
| 1201 |
} |
| 1202 |
} |
| 1203 |
else if (fixedcolormap) |
| 1204 |
vis->colormap = fixedcolormap; // fixed color |
| 1205 |
else if (psp->state->frame & FF_FULLBRIGHT) |
| 1206 |
vis->colormap = fullcolormap; // full bright // killough 3/20/98 |
| 1207 |
else |
| 1208 |
// e6y: original code is restored |
| 1209 |
vis->colormap = spritelights[MAXLIGHTSCALE-1]; // local light |
| 1210 |
|
| 1211 |
R_UpdateVisSpriteTranMap(vis, NULL); |
| 1212 |
|
| 1213 |
//e6y: interpolation for weapon bobbing |
| 1214 |
if (movement_smooth) |
| 1215 |
{ |
| 1216 |
typedef struct interpolate_s |
| 1217 |
{ |
| 1218 |
int x1; |
| 1219 |
int x1_prev; |
| 1220 |
int texturemid; |
| 1221 |
int texturemid_prev; |
| 1222 |
int lump; |
| 1223 |
} psp_interpolate_t; |
| 1224 |
|
| 1225 |
static psp_interpolate_t psp_inter; |
| 1226 |
|
| 1227 |
if (realframe) |
| 1228 |
{ |
| 1229 |
psp_inter.x1 = psp_inter.x1_prev; |
| 1230 |
psp_inter.texturemid = psp_inter.texturemid_prev; |
| 1231 |
} |
| 1232 |
|
| 1233 |
psp_inter.x1_prev = vis->x1; |
| 1234 |
psp_inter.texturemid_prev = vis->texturemid; |
| 1235 |
|
| 1236 |
// Do not interpolate on the first tic of the level |
| 1237 |
if (leveltime > 1) |
| 1238 |
{ |
| 1239 |
if (lump == psp_inter.lump) |
| 1240 |
{ |
| 1241 |
int deltax = vis->x2 - vis->x1; |
| 1242 |
vis->x1 = psp_inter.x1 + FixedMul (tic_vars.frac, (vis->x1 - psp_inter.x1)); |
| 1243 |
vis->x2 = vis->x1 + deltax; |
| 1244 |
vis->texturemid = psp_inter.texturemid + FixedMul (tic_vars.frac, (vis->texturemid - psp_inter.texturemid)); |
| 1245 |
} |
| 1246 |
else |
| 1247 |
{ |
| 1248 |
psp_inter.x1 = vis->x1; |
| 1249 |
psp_inter.texturemid = vis->texturemid; |
| 1250 |
psp_inter.lump=lump; |
| 1251 |
} |
| 1252 |
} |
| 1253 |
} |
| 1254 |
|
| 1255 |
if (dsda_HideWeapon()) |
| 1256 |
return; |
| 1257 |
|
| 1258 |
// proff 11/99: don't use software stuff in OpenGL |
| 1259 |
if (V_IsSoftwareMode()) |
| 1260 |
{ |
| 1261 |
R_DrawVisSprite(vis); |
| 1262 |
} |
| 1263 |
else |
| 1264 |
{ |
| 1265 |
int lightlevel; |
| 1266 |
sector_t tmpsec; |
| 1267 |
int floorlightlevel, ceilinglightlevel; |
| 1268 |
|
| 1269 |
if ((vis->colormap==fixedcolormap) || (vis->colormap==fullcolormap)) |
| 1270 |
lightlevel=255; |
| 1271 |
else |
| 1272 |
{ |
| 1273 |
// lightlevel = (viewplayer->mo->subsector->sector->lightlevel) + (extralight << LIGHTSEGSHIFT); |
| 1274 |
R_FakeFlat( viewplayer->mo->subsector->sector, &tmpsec, |
| 1275 |
&floorlightlevel, &ceilinglightlevel, false); |
| 1276 |
lightlevel = ((floorlightlevel+ceilinglightlevel) >> 1) + (extralight << LIGHTSEGSHIFT); |
| 1277 |
|
| 1278 |
if (lightlevel < 0) |
| 1279 |
lightlevel = 0; |
| 1280 |
else if (lightlevel >= 255) |
| 1281 |
lightlevel = 255; |
| 1282 |
} |
| 1283 |
gld_DrawWeapon(lump,vis,lightlevel); |
| 1284 |
} |
| 1285 |
} |
| 1286 |
|
| 1287 |
// |
| 1288 |
// R_DrawPlayerSprites |
| 1289 |
// |
| 1290 |
|
| 1291 |
void R_DrawPlayerSprites(void) |
| 1292 |
{ |
| 1293 |
int i; |
| 1294 |
pspdef_t *psp; |
| 1295 |
|
| 1296 |
if (walkcamera.type != 0) |
| 1297 |
return; |
| 1298 |
|
| 1299 |
// get light level |
| 1300 |
R_SetSpritelights(viewplayer->mo->subsector->sector->lightlevel); |
| 1301 |
|
| 1302 |
// clip to screen bounds |
| 1303 |
mfloorclip = screenheightarray; |
| 1304 |
mceilingclip = negonearray; |
| 1305 |
|
| 1306 |
// add all active psprites |
| 1307 |
for (i=0, psp=viewplayer->psprites; i<NUMPSPRITES; i++,psp++) |
| 1308 |
if (psp->state) |
| 1309 |
R_DrawPSprite (psp); |
| 1310 |
} |
| 1311 |
|
| 1312 |
// |
| 1313 |
// R_SortVisSprites |
| 1314 |
// |
| 1315 |
// Rewritten by Lee Killough to avoid using unnecessary |
| 1316 |
// linked lists, and to use faster sorting algorithm. |
| 1317 |
// |
| 1318 |
|
| 1319 |
#ifdef DJGPP |
| 1320 |
|
| 1321 |
// killough 9/22/98: inlined memcpy of pointer arrays |
| 1322 |
// CPhipps - added memory as modified |
| 1323 |
#define bcopyp(d, s, n) asm(" cld; rep; movsl;" :: "D"(d), "S"(s), "c"(n) : "%cc", "%esi", "%edi", "%ecx", "memory") |
| 1324 |
|
| 1325 |
#else |
| 1326 |
|
| 1327 |
#define bcopyp(d, s, n) memcpy(d, s, (n) * sizeof(void *)) |
| 1328 |
|
| 1329 |
#endif |
| 1330 |
|
| 1331 |
// killough 9/2/98: merge sort |
| 1332 |
|
| 1333 |
static void msort(vissprite_t **s, vissprite_t **t, int n) |
| 1334 |
{ |
| 1335 |
if (n >= 16) |
| 1336 |
{ |
| 1337 |
int n1 = n/2, n2 = n - n1; |
| 1338 |
vissprite_t **s1 = s, **s2 = s + n1, **d = t; |
| 1339 |
|
| 1340 |
msort(s1, t, n1); |
| 1341 |
msort(s2, t, n2); |
| 1342 |
|
| 1343 |
while ((*s1)->scale > (*s2)->scale ? |
| 1344 |
(*d++ = *s1++, --n1) : (*d++ = *s2++, --n2)); |
| 1345 |
|
| 1346 |
if (n2) |
| 1347 |
bcopyp(d, s2, n2); |
| 1348 |
else |
| 1349 |
bcopyp(d, s1, n1); |
| 1350 |
|
| 1351 |
bcopyp(s, t, n); |
| 1352 |
} |
| 1353 |
else |
| 1354 |
{ |
| 1355 |
int i; |
| 1356 |
for (i = 1; i < n; i++) |
| 1357 |
{ |
| 1358 |
vissprite_t *temp = s[i]; |
| 1359 |
if (s[i-1]->scale < temp->scale) |
| 1360 |
{ |
| 1361 |
int j = i; |
| 1362 |
while ((s[j] = s[j-1])->scale < temp->scale && --j); |
| 1363 |
s[j] = temp; |
| 1364 |
} |
| 1365 |
} |
| 1366 |
} |
| 1367 |
} |
| 1368 |
|
| 1369 |
void R_SortVisSprites (void) |
| 1370 |
{ |
| 1371 |
if (num_vissprite) |
| 1372 |
{ |
| 1373 |
int i = num_vissprite; |
| 1374 |
|
| 1375 |
// If we need to allocate more pointers for the vissprites, |
| 1376 |
// allocate as many as were allocated for sprites -- killough |
| 1377 |
// killough 9/22/98: allocate twice as many |
| 1378 |
|
| 1379 |
if (num_vissprite_ptrs < num_vissprite*2) |
| 1380 |
{ |
| 1381 |
Z_Free(vissprite_ptrs); // better than realloc -- no preserving needed |
| 1382 |
vissprite_ptrs = Z_Malloc((num_vissprite_ptrs = num_vissprite_alloc*2) |
| 1383 |
* sizeof *vissprite_ptrs); |
| 1384 |
} |
| 1385 |
|
| 1386 |
while (--i>=0) |
| 1387 |
vissprite_ptrs[num_vissprite-i-1] = vissprites+i; |
| 1388 |
|
| 1389 |
// killough 9/22/98: replace qsort with merge sort, since the keys |
| 1390 |
// are roughly in order to begin with, due to BSP rendering. |
| 1391 |
|
| 1392 |
msort(vissprite_ptrs, vissprite_ptrs + num_vissprite, num_vissprite); |
| 1393 |
} |
| 1394 |
} |
| 1395 |
|
| 1396 |
// |
| 1397 |
// R_DrawSprite |
| 1398 |
// |
| 1399 |
|
| 1400 |
static void R_DrawSprite (vissprite_t* spr) |
| 1401 |
{ |
| 1402 |
drawseg_t *ds; |
| 1403 |
int x; |
| 1404 |
int r1; |
| 1405 |
int r2; |
| 1406 |
fixed_t scale; |
| 1407 |
fixed_t lowscale; |
| 1408 |
|
| 1409 |
for (x = spr->x1 ; x<=spr->x2 ; x++) |
| 1410 |
clipbot[x] = -2; |
| 1411 |
for (x = spr->x1 ; x<=spr->x2 ; x++) |
| 1412 |
cliptop[x] = -2; |
| 1413 |
|
| 1414 |
// Scan drawsegs from end to start for obscuring segs. |
| 1415 |
// The first drawseg that has a greater scale is the clip seg. |
| 1416 |
|
| 1417 |
// Modified by Lee Killough: |
| 1418 |
// (pointer check was originally nonportable |
| 1419 |
// and buggy, by going past LEFT end of array): |
| 1420 |
|
| 1421 |
// e6y: optimization |
| 1422 |
if (drawsegs_xrange_size) |
| 1423 |
{ |
| 1424 |
const drawseg_xrange_item_t *last = &drawsegs_xrange[drawsegs_xrange_count - 1]; |
| 1425 |
drawseg_xrange_item_t *curr = &drawsegs_xrange[-1]; |
| 1426 |
while (++curr <= last) |
| 1427 |
{ |
| 1428 |
// determine if the drawseg obscures the sprite |
| 1429 |
if (curr->x1 > spr->x2 || curr->x2 < spr->x1) |
| 1430 |
continue; // does not cover sprite |
| 1431 |
|
| 1432 |
ds = curr->user; |
| 1433 |
|
| 1434 |
if (ds->scale1 > ds->scale2) |
| 1435 |
{ |
| 1436 |
lowscale = ds->scale2; |
| 1437 |
scale = ds->scale1; |
| 1438 |
} |
| 1439 |
else |
| 1440 |
{ |
| 1441 |
lowscale = ds->scale1; |
| 1442 |
scale = ds->scale2; |
| 1443 |
} |
| 1444 |
|
| 1445 |
if (scale < spr->scale || (lowscale < spr->scale && |
| 1446 |
!R_PointOnSegSide (spr->gx, spr->gy, ds->curline))) |
| 1447 |
{ |
| 1448 |
if (ds->maskedtexturecol) // masked mid texture? |
| 1449 |
{ |
| 1450 |
r1 = ds->x1 < spr->x1 ? spr->x1 : ds->x1; |
| 1451 |
r2 = ds->x2 > spr->x2 ? spr->x2 : ds->x2; |
| 1452 |
R_RenderMaskedSegRange(ds, r1, r2); |
| 1453 |
} |
| 1454 |
continue; // seg is behind sprite |
| 1455 |
} |
| 1456 |
|
| 1457 |
r1 = ds->x1 < spr->x1 ? spr->x1 : ds->x1; |
| 1458 |
r2 = ds->x2 > spr->x2 ? spr->x2 : ds->x2; |
| 1459 |
|
| 1460 |
// clip this piece of the sprite |
| 1461 |
// killough 3/27/98: optimized and made much shorter |
| 1462 |
|
| 1463 |
if (ds->silhouette&SIL_BOTTOM && spr->gz < ds->bsilheight) //bottom sil |
| 1464 |
for (x=r1 ; x<=r2 ; x++) |
| 1465 |
if (clipbot[x] == -2) |
| 1466 |
clipbot[x] = ds->sprbottomclip[x]; |
| 1467 |
|
| 1468 |
if (ds->silhouette&SIL_TOP && spr->gzt > ds->tsilheight) // top sil |
| 1469 |
for (x=r1 ; x<=r2 ; x++) |
| 1470 |
if (cliptop[x] == -2) |
| 1471 |
cliptop[x] = ds->sprtopclip[x]; |
| 1472 |
} |
| 1473 |
} |
| 1474 |
|
| 1475 |
// killough 3/27/98: |
| 1476 |
// Clip the sprite against deep water and/or fake ceilings. |
| 1477 |
// killough 4/9/98: optimize by adding mh |
| 1478 |
// killough 4/11/98: improve sprite clipping for underwater/fake ceilings |
| 1479 |
// killough 11/98: fix disappearing sprites |
| 1480 |
|
| 1481 |
if (spr->heightsec != -1) // only things in specially marked sectors |
| 1482 |
{ |
| 1483 |
fixed_t h,mh; |
| 1484 |
int phs = viewplayer->mo->subsector->sector->heightsec; |
| 1485 |
if ((mh = sectors[spr->heightsec].floorheight) > spr->gz && |
| 1486 |
(h = centeryfrac - FixedMul(mh-=viewz, spr->scale)) >= 0 && |
| 1487 |
(h >>= FRACBITS) < viewheight) { |
| 1488 |
if (mh <= 0 || (phs != -1 && viewz > sectors[phs].floorheight)) |
| 1489 |
{ // clip bottom |
| 1490 |
for (x=spr->x1 ; x<=spr->x2 ; x++) |
| 1491 |
if (clipbot[x] == -2 || h < clipbot[x]) |
| 1492 |
clipbot[x] = h; |
| 1493 |
} |
| 1494 |
else // clip top |
| 1495 |
if (phs != -1 && viewz <= sectors[phs].floorheight) // killough 11/98 |
| 1496 |
for (x=spr->x1 ; x<=spr->x2 ; x++) |
| 1497 |
if (cliptop[x] == -2 || h > cliptop[x]) |
| 1498 |
cliptop[x] = h; |
| 1499 |
} |
| 1500 |
|
| 1501 |
if ((mh = sectors[spr->heightsec].ceilingheight) < spr->gzt && |
| 1502 |
(h = centeryfrac - FixedMul(mh-viewz, spr->scale)) >= 0 && |
| 1503 |
(h >>= FRACBITS) < viewheight) { |
| 1504 |
if (phs != -1 && viewz >= sectors[phs].ceilingheight) |
| 1505 |
{ // clip bottom |
| 1506 |
for (x=spr->x1 ; x<=spr->x2 ; x++) |
| 1507 |
if (clipbot[x] == -2 || h < clipbot[x]) |
| 1508 |
clipbot[x] = h; |
| 1509 |
} |
| 1510 |
else // clip top |
| 1511 |
for (x=spr->x1 ; x<=spr->x2 ; x++) |
| 1512 |
if (cliptop[x] == -2 || h > cliptop[x]) |
| 1513 |
cliptop[x] = h; |
| 1514 |
} |
| 1515 |
} |
| 1516 |
// killough 3/27/98: end special clipping for deep water / fake ceilings |
| 1517 |
|
| 1518 |
// all clipping has been performed, so draw the sprite |
| 1519 |
// check for unclipped columns |
| 1520 |
|
| 1521 |
for (x = spr->x1 ; x<=spr->x2 ; x++) |
| 1522 |
if (clipbot[x] == -2) |
| 1523 |
clipbot[x] = viewheight; |
| 1524 |
|
| 1525 |
for (x = spr->x1 ; x<=spr->x2 ; x++) |
| 1526 |
if (cliptop[x] == -2) |
| 1527 |
cliptop[x] = -1; |
| 1528 |
|
| 1529 |
mfloorclip = clipbot; |
| 1530 |
mceilingclip = cliptop; |
| 1531 |
R_DrawVisSprite (spr); |
| 1532 |
} |
| 1533 |
|
| 1534 |
// |
| 1535 |
// R_DrawMasked |
| 1536 |
// |
| 1537 |
|
| 1538 |
void R_DrawMasked(void) |
| 1539 |
{ |
| 1540 |
int i; |
| 1541 |
drawseg_t *ds; |
| 1542 |
int cx = SCREENWIDTH / 2; |
| 1543 |
|
| 1544 |
R_SortVisSprites(); |
| 1545 |
|
| 1546 |
// e6y |
| 1547 |
// Reducing of cache misses in the following R_DrawSprite() |
| 1548 |
// Makes sense for scenes with huge amount of drawsegs. |
| 1549 |
// ~12% of speed improvement on epic.wad map05 |
| 1550 |
for(i = 0; i < DS_RANGES_COUNT; i++) |
| 1551 |
drawsegs_xranges[i].count = 0; |
| 1552 |
|
| 1553 |
if (num_vissprite > 0) |
| 1554 |
{ |
| 1555 |
if (drawsegs_xrange_size < maxdrawsegs) |
| 1556 |
{ |
| 1557 |
drawsegs_xrange_size = 2 * maxdrawsegs; |
| 1558 |
for(i = 0; i < DS_RANGES_COUNT; i++) |
| 1559 |
{ |
| 1560 |
drawsegs_xranges[i].items = Z_Realloc( |
| 1561 |
drawsegs_xranges[i].items, |
| 1562 |
drawsegs_xrange_size * sizeof(drawsegs_xranges[i].items[0])); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
for (ds = ds_p; ds-- > drawsegs;) |
| 1566 |
{ |
| 1567 |
if (ds->silhouette || ds->maskedtexturecol) |
| 1568 |
{ |
| 1569 |
drawsegs_xranges[0].items[drawsegs_xranges[0].count].x1 = ds->x1; |
| 1570 |
drawsegs_xranges[0].items[drawsegs_xranges[0].count].x2 = ds->x2; |
| 1571 |
drawsegs_xranges[0].items[drawsegs_xranges[0].count].user = ds; |
| 1572 |
|
| 1573 |
// e6y: ~13% of speed improvement on sunder.wad map10 |
| 1574 |
if (ds->x1 < cx) |
| 1575 |
{ |
| 1576 |
drawsegs_xranges[1].items[drawsegs_xranges[1].count] = |
| 1577 |
drawsegs_xranges[0].items[drawsegs_xranges[0].count]; |
| 1578 |
drawsegs_xranges[1].count++; |
| 1579 |
} |
| 1580 |
if (ds->x2 >= cx) |
| 1581 |
{ |
| 1582 |
drawsegs_xranges[2].items[drawsegs_xranges[2].count] = |
| 1583 |
drawsegs_xranges[0].items[drawsegs_xranges[0].count]; |
| 1584 |
drawsegs_xranges[2].count++; |
| 1585 |
} |
| 1586 |
|
| 1587 |
drawsegs_xranges[0].count++; |
| 1588 |
} |
| 1589 |
} |
| 1590 |
} |
| 1591 |
|
| 1592 |
// draw all vissprites back to front |
| 1593 |
|
| 1594 |
dsda_RecordVisSprites(num_vissprite); |
| 1595 |
|
| 1596 |
for (i = num_vissprite ;--i>=0; ) |
| 1597 |
{ |
| 1598 |
vissprite_t* spr = vissprite_ptrs[i]; |
| 1599 |
|
| 1600 |
if (spr->x2 < cx) |
| 1601 |
{ |
| 1602 |
drawsegs_xrange = drawsegs_xranges[1].items; |
| 1603 |
drawsegs_xrange_count = drawsegs_xranges[1].count; |
| 1604 |
} |
| 1605 |
else if (spr->x1 >= cx) |
| 1606 |
{ |
| 1607 |
drawsegs_xrange = drawsegs_xranges[2].items; |
| 1608 |
drawsegs_xrange_count = drawsegs_xranges[2].count; |
| 1609 |
} |
| 1610 |
else |
| 1611 |
{ |
| 1612 |
drawsegs_xrange = drawsegs_xranges[0].items; |
| 1613 |
drawsegs_xrange_count = drawsegs_xranges[0].count; |
| 1614 |
} |
| 1615 |
|
| 1616 |
R_DrawSprite(vissprite_ptrs[i]); |
| 1617 |
} |
| 1618 |
|
| 1619 |
// render any remaining masked mid textures |
| 1620 |
|
| 1621 |
// Modified by Lee Killough: |
| 1622 |
// (pointer check was originally nonportable |
| 1623 |
// and buggy, by going past LEFT end of array): |
| 1624 |
|
| 1625 |
// for (ds=ds_p-1 ; ds >= drawsegs ; ds--) old buggy code |
| 1626 |
|
| 1627 |
for (ds=ds_p ; ds-- > drawsegs ; ) // new -- killough |
| 1628 |
if (ds->maskedtexturecol) |
| 1629 |
R_RenderMaskedSegRange(ds, ds->x1, ds->x2); |
| 1630 |
|
| 1631 |
// draw the psprites on top of everything |
| 1632 |
R_DrawPlayerSprites (); |
| 1633 |
} |