/* Emacs style mode select -*- C++ -*- *----------------------------------------------------------------------------- * * * PrBoom a Doom port merged with LxDoom and LSDLDoom * based on BOOM, a modified and improved DOOM engine * Copyright (C) 1999 by * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman * Copyright (C) 1999-2000 by * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * DESCRIPTION: * The status bar widget code. * *-----------------------------------------------------------------------------*/ #include "doomdef.h" #include "doomstat.h" #include "v_video.h" #include "w_wad.h" #include "m_swap.h" #include "st_stuff.h" #include "st_lib.h" #include "r_main.h" int sts_always_red; //jff 2/18/98 control to disable status color changes int sts_pct_always_gray; // killough 2/21/98: always gray %'s? bug or feature? // // STlib_init() // void STlib_init(void) { // cph - no longer hold STMINUS pointer } // // STlib_initNum() // // Initializes an st_number_t widget // // Passed the widget, its position, the patches for the digits, a pointer // to the value displayed, a pointer to the on/off control, and the width // Returns nothing // void STlib_initNum ( st_number_t* n, int x, int y, const patchnum_t* pl, int* num, boolean* on, int width ) { n->x = x; n->y = y; n->oldnum = 0; n->width = width; n->num = num; n->on = on; n->p = pl; } /* * STlib_drawNum() * * A fairly efficient way to draw a number based on differences from the * old number. * * Passed a st_number_t widget, a color range for output, and a flag * indicating whether refresh is needed. * Returns nothing * * jff 2/16/98 add color translation to digit output * cphipps 10/99 - const pointer to colour trans table, made function static */ static void STlib_drawNum ( st_number_t* n, int cm, boolean refresh ) { int numdigits = n->width; int num = *n->num; int w = SHORT(n->p[0].width); int h = SHORT(n->p[0].height); int x = n->x; int neg; // leban 1/20/99: // strange that somebody went through all the work to draw only the // differences, and then went and constantly redrew all the numbers. // return without drawing if the number didn't change and the bar // isn't refreshing. if(n->oldnum == num && !refresh) return; // CPhipps - compact some code, use num instead of *n->num if ((neg = (n->oldnum = num) < 0)) { if (numdigits == 2 && num < -9) num = -9; else if (numdigits == 3 && num < -99) num = -99; num = -num; } // clear the area x = n->x - numdigits*w; #ifdef RANGECHECK if (n->y - ST_Y < 0) I_Error("STlib_drawNum: n->y - ST_Y < 0"); #endif V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG, VPT_STRETCH); // if non-number, do not draw it if (num == 1994) return; x = n->x; //jff 2/16/98 add color translation to digit output // in the special case of 0, you draw 0 if (!num) // CPhipps - patch drawing updated, reformatted V_DrawNumPatch(x - w, n->y, FG, n->p[0].lumpnum, cm, (((cm!=CR_DEFAULT) && !sts_always_red) ? VPT_TRANS : VPT_NONE) | VPT_STRETCH); // draw the new number //jff 2/16/98 add color translation to digit output while (num && numdigits--) { // CPhipps - patch drawing updated, reformatted x -= w; V_DrawNumPatch(x, n->y, FG, n->p[num % 10].lumpnum, cm, (((cm!=CR_DEFAULT) && !sts_always_red) ? VPT_TRANS : VPT_NONE) | VPT_STRETCH); num /= 10; } // draw a minus sign if necessary //jff 2/16/98 add color translation to digit output // cph - patch drawing updated, load by name instead of acquiring pointer earlier if (neg) V_DrawNamePatch(x - w, n->y, FG, "STTMINUS", cm, (((cm!=CR_DEFAULT) && !sts_always_red) ? VPT_TRANS : VPT_NONE) | VPT_STRETCH); } /* * STlib_updateNum() * * Draws a number conditionally based on the widget's enable * * Passed a number widget, the output color range, and a refresh flag * Returns nothing * * jff 2/16/98 add color translation to digit output * cphipps 10/99 - make that pointer const */ void STlib_updateNum ( st_number_t* n, int cm, boolean refresh ) { if (*n->on) STlib_drawNum(n, cm, refresh); } // // STlib_initPercent() // // Initialize a st_percent_t number with percent sign widget // // Passed a st_percent_t widget, the position, the digit patches, a pointer // to the number to display, a pointer to the enable flag, and patch // for the percent sign. // Returns nothing. // void STlib_initPercent ( st_percent_t* p, int x, int y, const patchnum_t* pl, int* num, boolean* on, const patchnum_t* percent ) { STlib_initNum(&p->n, x, y, pl, num, on, 3); p->p = percent; } /* * STlib_updatePercent() * * Draws a number/percent conditionally based on the widget's enable * * Passed a precent widget, the output color range, and a refresh flag * Returns nothing * * jff 2/16/98 add color translation to digit output * cphipps - const for pointer to the colour translation table */ void STlib_updatePercent ( st_percent_t* per, int cm, int refresh ) { if (*per->n.on && (refresh || (per->n.oldnum != *per->n.num))) { // killough 2/21/98: fix percents not updated; /* CPhipps - make %'s only be updated if number changed */ // CPhipps - patch drawing updated V_DrawNumPatch(per->n.x, per->n.y, FG, per->p->lumpnum, sts_pct_always_gray ? CR_GRAY : cm, (sts_always_red ? VPT_NONE : VPT_TRANS) | VPT_STRETCH); } STlib_updateNum(&per->n, cm, refresh); } // // STlib_initMultIcon() // // Initialize a st_multicon_t widget, used for a multigraphic display // like the status bar's keys. // // Passed a st_multicon_t widget, the position, the graphic patches, a pointer // to the numbers representing what to display, and pointer to the enable flag // Returns nothing. // void STlib_initMultIcon ( st_multicon_t* i, int x, int y, const patchnum_t* il, int* inum, boolean* on ) { i->x = x; i->y = y; i->oldinum = -1; i->inum = inum; i->on = on; i->p = il; } // // STlib_updateMultIcon() // // Draw a st_multicon_t widget, used for a multigraphic display // like the status bar's keys. Displays each when the control // numbers change or refresh is true // // Passed a st_multicon_t widget, and a refresh flag // Returns nothing. // void STlib_updateMultIcon ( st_multicon_t* mi, boolean refresh ) { int w; int h; int x; int y; if (*mi->on && (mi->oldinum != *mi->inum || refresh)) { if (mi->oldinum != -1) { x = mi->x - SHORT(mi->p[mi->oldinum].leftoffset); y = mi->y - SHORT(mi->p[mi->oldinum].topoffset); w = SHORT(mi->p[mi->oldinum].width); h = SHORT(mi->p[mi->oldinum].height); #ifdef RANGECHECK if (y - ST_Y < 0) I_Error("STlib_updateMultIcon: y - ST_Y < 0"); #endif V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG, VPT_STRETCH); } if (*mi->inum != -1) // killough 2/16/98: redraw only if != -1 V_DrawNumPatch(mi->x, mi->y, FG, mi->p[*mi->inum].lumpnum, CR_DEFAULT, VPT_STRETCH); mi->oldinum = *mi->inum; } } // // STlib_initBinIcon() // // Initialize a st_binicon_t widget, used for a multinumber display // like the status bar's weapons, that are present or not. // // Passed a st_binicon_t widget, the position, the digit patches, a pointer // to the flags representing what is displayed, and pointer to the enable flag // Returns nothing. // void STlib_initBinIcon ( st_binicon_t* b, int x, int y, const patchnum_t* i, boolean* val, boolean* on ) { b->x = x; b->y = y; b->oldval = 0; b->val = val; b->on = on; b->p = i; } // // STlib_updateBinIcon() // // DInitialize a st_binicon_t widget, used for a multinumber display // like the status bar's weapons, that are present or not. // // Draw a st_binicon_t widget, used for a multinumber display // like the status bar's weapons that are present or not. Displays each // when the control flag changes or refresh is true // // Passed a st_binicon_t widget, and a refresh flag // Returns nothing. // void STlib_updateBinIcon ( st_binicon_t* bi, boolean refresh ) { int x; int y; int w; int h; if (*bi->on && (bi->oldval != (signed)*bi->val || refresh)) { x = bi->x - SHORT(bi->p->leftoffset); y = bi->y - SHORT(bi->p->topoffset); w = SHORT(bi->p->width); h = SHORT(bi->p->height); #ifdef RANGECHECK if (y - ST_Y < 0) I_Error("STlib_updateBinIcon: y - ST_Y < 0"); #endif if (*bi->val) V_DrawNumPatch(bi->x, bi->y, FG, bi->p->lumpnum, CR_DEFAULT, VPT_STRETCH); else V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG, VPT_STRETCH); bi->oldval = *bi->val; } } '>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 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
/* Emacs style mode select -*- C++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2000 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* DESCRIPTION:
* Refresh of things, i.e. objects represented by sprites.
*
*-----------------------------------------------------------------------------*/
#include "doomdef.h"
#include "m_swap.h"
#include "doomstat.h"
#include "w_wad.h"
#include "r_main.h"
#include "r_bsp.h"
#include "r_segs.h"
#include "r_draw.h"
#include "r_things.h"
#include "i_system.h"
//#include "lprintf.h"
#include "rockmacros.h"
#define MINZ (FRACUNIT*4)
#define BASEYCENTER 100
typedef struct {
int x1;
int x2;
int column;
int topclip;
int bottomclip;
}
maskdraw_t;
//
// Sprite rotation 0 is facing the viewer,
// rotation 1 is one angle turn CLOCKWISE around the axis.
// This is not the same as the angle,
// which increases counter clockwise (protractor).
// There was a lot of stuff grabbed wrong, so I changed it...
//
fixed_t pspritescale;
fixed_t pspriteiscale;
// proff 11/06/98: Added for high-res
fixed_t pspriteyscale;
static lighttable_t** spritelights;
// constant arrays
// used for psprite clipping and initializing clipping
short negonearray[SCREENWIDTH];
short screenheightarray[SCREENWIDTH];
//
// INITIALIZATION FUNCTIONS
//
// variables used to look up and range check thing_t sprites patches
spritedef_t* sprites;
int numsprites;
#define MAX_SPRITE_FRAMES 29 /* Macroized -- killough 1/25/98 */
static spriteframe_t sprtemp[MAX_SPRITE_FRAMES];
static int maxframe;
//
// R_InstallSpriteLump
// Local function for R_InitSprites.
//
static void R_InstallSpriteLump(int lump, unsigned frame,
unsigned rotation, boolean flipped)
{
if (frame >= MAX_SPRITE_FRAMES || rotation > 8)
I_Error("R_InstallSpriteLump: Bad frame characters in lump %i", lump);
if ((int)frame > maxframe)
maxframe = frame;
if (rotation == 0)
{ // the lump should be used for all rotations
int r;
for (r=0 ; r<8 ; r++)
if (sprtemp[frame].lump[r]==-1)
{
sprtemp[frame].lump[r] = lump - firstspritelump;
sprtemp[frame].flip[r] = (byte) flipped;
sprtemp[frame].rotate = false; //jff 4/24/98 if any subbed, rotless
}
return;
}
// the lump is only used for one rotation
if (sprtemp[frame].lump[--rotation] == -1)
{
sprtemp[frame].lump[rotation] = lump - firstspritelump;
sprtemp[frame].flip[rotation] = (byte) flipped;
sprtemp[frame].rotate = true; //jff 4/24/98 only change if rot used
}
}
//
// R_InitSpriteDefs
// Pass a null terminated list of sprite names
// (4 chars exactly) to be used.
//
// Builds the sprite rotation matrixes to account
// for horizontally flipped sprites.
//
// Will report an error if the lumps are inconsistent.
// Only called at startup.
//
// Sprite lump names are 4 characters for the actor,
// a letter for the frame, and a number for the rotation.
//
// A sprite that is flippable will have an additional
// letter/number appended.
//
// The rotation character can be 0 to signify no rotations.
//
// 1/25/98, 1/31/98 killough : Rewritten for performance
//
// Empirically verified to have excellent hash
// properties across standard Doom sprites:
#define R_SpriteNameHash(s) ((unsigned)((s)[0]-((s)[1]*3-(s)[3]*2-(s)[2])*2))
void R_InitSpriteDefs(const char * const * namelist)
{
size_t numentries = lastspritelump-firstspritelump+1;
struct {
int index, next;
}
*hash;
int i;
if (!numentries || !*namelist)
return;
// count the number of sprite names
for (i=0; namelist[i]; i++)
;
numsprites = i;
sprites = Z_Malloc(numsprites *sizeof(*sprites), PU_STATIC, NULL);
// Create hash table based on just the first four letters of each sprite
// killough 1/31/98
hash = malloc(sizeof(*hash)*numentries); // allocate hash table
for (i=0; (size_t)i<numentries; i++) // initialize hash table as empty
hash[i].index = -1;
for (i=0; (size_t)i<numentries; i++) // Prepend each sprite to hash chain
{ // prepend so that later ones win
int j = R_SpriteNameHash(lumpinfo[i+firstspritelump].name) % numentries;
hash[i].next = hash[j].index;
hash[j].index = i;
}
// scan all the lump names for each of the names,
// noting the highest frame letter.
for (i=0 ; i<numsprites ; i++)
{
const char *spritename = namelist[i];
int j = hash[R_SpriteNameHash(spritename) % numentries].index;
if (j >= 0)
{
memset(sprtemp, -1, sizeof(sprtemp));
maxframe = -1;
do
{
register lumpinfo_t *lump = lumpinfo + j + firstspritelump;
// Fast portable comparison -- killough
// (using int pointer cast is nonportable):
if (!((lump->name[0] ^ spritename[0]) |
(lump->name[1] ^ spritename[1]) |
(lump->name[2] ^ spritename[2]) |
(lump->name[3] ^ spritename[3])))
{
R_InstallSpriteLump(j+firstspritelump,
lump->name[4] - 'A',
lump->name[5] - '0',
false);
if (lump->name[6])
R_InstallSpriteLump(j+firstspritelump,
lump->name[6] - 'A',
lump->name[7] - '0',
true);
}
}
while ((j = hash[j].next) >= 0)
;
// check the frames that were found for completeness
if ((sprites[i].numframes = ++maxframe)) // killough 1/31/98
{
int frame;
for (frame = 0; frame < maxframe; frame++)
switch ((int) sprtemp[frame].rotate)
{
case -1:
// no rotations were found for that frame at all
I_Error ("R_InitSprites: No patches found "
"for %.8s frame %c", namelist[i], frame+'A');
break;
case 0:
// only the first rotation is needed
break;
case 1:
// must have all 8 frames
{
int rotation;
for (rotation=0 ; rotation<8 ; rotation++)
if (sprtemp[frame].lump[rotation] == -1)
I_Error ("R_InitSprites: Sprite %.8s frame %c "
"is missing rotations",
namelist[i], frame+'A');
break;
}
}
// allocate space for the frames present and copy sprtemp to it
sprites[i].spriteframes =
Z_Malloc (maxframe * sizeof(spriteframe_t), PU_STATIC, NULL);
memcpy (sprites[i].spriteframes, sprtemp,
maxframe*sizeof(spriteframe_t));
}
}
}
free(hash); // free hash table
}
//
// GAME FUNCTIONS
//
static vissprite_t *vissprites, **vissprite_ptrs; // killough
static size_t num_vissprite, num_vissprite_alloc, num_vissprite_ptrs;
//
// R_InitSprites
// Called at program start.
//
void R_InitSprites(const char * const *namelist)
{
int i;
for (i=0 ; i<SCREENWIDTH ; i++)
negonearray[i] = -1;
R_InitSpriteDefs (namelist);
}
void R_ClearSprites (void)
{
num_vissprite = 0; // killough
}
//
// R_NewVisSprite
//
vissprite_t *R_NewVisSprite(void)
{
if (num_vissprite >= num_vissprite_alloc) // killough
{
num_vissprite_alloc = num_vissprite_alloc ? num_vissprite_alloc*2 : 128;
vissprites = realloc(vissprites,num_vissprite_alloc*sizeof(*vissprites));
}
return vissprites + num_vissprite++;
}
//
// R_DrawMaskedColumn
// Used for sprites and masked mid textures.
// Masked means: partly transparent, i.e. stored
// in posts/runs of opaque pixels.
//
short* mfloorclip;
short* mceilingclip;
fixed_t spryscale;
fixed_t sprtopscreen;
void R_DrawMaskedColumn(const column_t *column)
{
int topscreen;
int bottomscreen;
fixed_t basetexturemid = dc_texturemid;
dc_texheight = 0; // killough 11/98
while (column->topdelta != 0xff)
{
// calculate unclipped screen coordinates for post
topscreen = sprtopscreen + spryscale*column->topdelta;
bottomscreen = topscreen + spryscale*column->length;
dc_yl = (topscreen+FRACUNIT-1)>>FRACBITS;
dc_yh = (bottomscreen-1)>>FRACBITS;
if (dc_yh >= mfloorclip[dc_x])
dc_yh = mfloorclip[dc_x]-1;
if (dc_yl <= mceilingclip[dc_x])
dc_yl = mceilingclip[dc_x]+1;
// killough 3/2/98, 3/27/98: Failsafe against overflow/crash:
if (dc_yl <= dc_yh && dc_yh < viewheight)
{
dc_source = (byte *)column + 3;
dc_texturemid = basetexturemid - (column->topdelta<<FRACBITS);
// Drawn by either R_DrawColumn
// or (SHADOW) R_DrawFuzzColumn.
colfunc ();
}
column = (const column_t *)( (byte *)column + column->length + 4);
}
dc_texturemid = basetexturemid;
}
//
// R_DrawVisSprite
// mfloorclip and mceilingclip should also be set.
//
// CPhipps - new wad lump handling, *'s to const*'s
void R_DrawVisSprite(vissprite_t *vis, int x1, int x2)
{
(void)x1;
(void)x2;
const column_t *column;
int texturecolumn;
fixed_t frac;
const patch_t *patch = W_CacheLumpNum (vis->patch+firstspritelump);
dc_colormap = vis->colormap;
// killough 4/11/98: rearrange and handle translucent sprites
// mixed with translucent/non-translucenct 2s normals
if (!dc_colormap) // NULL colormap = shadow draw
colfunc = R_DrawFuzzColumn; // killough 3/14/98
else
if (vis->mobjflags & MF_TRANSLATION)
{
colfunc = R_DrawTranslatedColumn;
dc_translation = translationtables - 256 +
((vis->mobjflags & MF_TRANSLATION) >> (MF_TRANSSHIFT-8) );
}
else
if (vis->mobjflags & MF_TRANSLUCENT && general_translucency) // phares
{
colfunc = R_DrawTLColumn;
tranmap = main_tranmap; // killough 4/11/98
}
else
colfunc = R_DrawColumn; // killough 3/14/98, 4/11/98
// proff 11/06/98: Changed for high-res
dc_iscale = FixedDiv (FRACUNIT, vis->scale);
dc_texturemid = vis->texturemid;
frac = vis->startfrac;
spryscale = vis->scale;
sprtopscreen = centeryfrac - FixedMul(dc_texturemid,spryscale);
for (dc_x=vis->x1 ; dc_x<=vis->x2 ; dc_x++, frac += vis->xiscale)
{
texturecolumn = frac>>FRACBITS;
#ifdef RANGECHECK
if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width))
I_Error ("R_DrawSpriteRange: Bad texturecolumn");
#endif
column = (const column_t *)((const byte *) patch +
LONG(patch->columnofs[texturecolumn]));
R_DrawMaskedColumn (column);
}
colfunc = R_DrawColumn; // killough 3/14/98
W_UnlockLumpNum(vis->patch+firstspritelump); // cph - release lump
}
//
// R_ProjectSprite
// Generates a vissprite for a thing if it might be visible.
//
void R_ProjectSprite (mobj_t* thing)
{
fixed_t gzt; // killough 3/27/98
fixed_t tx;
fixed_t xscale;
int x1;
int x2;
spritedef_t *sprdef;
spriteframe_t *sprframe;
int lump;
boolean flip;
vissprite_t *vis;
#ifndef GL_DOOM
fixed_t iscale;
#endif
int heightsec; // killough 3/27/98
// transform the origin point
fixed_t tr_x = thing->x - viewx;
fixed_t tr_y = thing->y - viewy;
fixed_t gxt = FixedMul(tr_x,viewcos);
fixed_t gyt = -FixedMul(tr_y,viewsin);
fixed_t tz = gxt-gyt;
// thing is behind view plane?
if (tz < MINZ)
return;
xscale = FixedDiv(projection, tz);
gxt = -FixedMul(tr_x,viewsin);
gyt = FixedMul(tr_y,viewcos);
tx = -(gyt+gxt);
// too far off the side?
if (D_abs(tx)>(tz<<2))
return;
// decide which patch to use for sprite relative to player
#ifdef RANGECHECK
if ((unsigned) thing->sprite >= (unsigned)numsprites)
I_Error ("R_ProjectSprite: Invalid sprite number %i", thing->sprite);
#endif
sprdef = &sprites[thing->sprite];
#ifdef RANGECHECK
if ((thing->frame&FF_FRAMEMASK) >= sprdef->numframes)
I_Error ("R_ProjectSprite: Invalid sprite frame %i : %i", thing->sprite,
thing->frame);
#endif
sprframe = &sprdef->spriteframes[thing->frame & FF_FRAMEMASK];
if (sprframe->rotate)
{
// choose a different rotation based on player view
angle_t ang = R_PointToAngle(thing->x, thing->y);
unsigned rot = (ang-thing->angle+(unsigned)(ANG45/2)*9)>>29;
lump = sprframe->lump[rot];
flip = (boolean) sprframe->flip[rot];
}
else
{
// use single rotation for all views
lump = sprframe->lump[0];
flip = (boolean) sprframe->flip[0];
}
/* calculate edges of the shape
* cph 2003/08/1 - fraggle points out that this offset must be flipped if the
* sprite is flipped; e.g. FreeDoom imp is messed up by this. */
tx -= flip ? spritewidth[lump] - spriteoffset[lump] : spriteoffset[lump];
x1 = (centerxfrac + FixedMul(tx,xscale)) >>FRACBITS;
// off the right side?
if (x1 > viewwidth)
return;
tx += spritewidth[lump];
x2 = ((centerxfrac + FixedMul (tx,xscale) ) >>FRACBITS) - 1;
// off the left side
if (x2 < 0)
return;
gzt = thing->z + spritetopoffset[lump];
// killough 4/9/98: clip things which are out of view due to height
if (thing->z > viewz + FixedDiv(centeryfrac, xscale) ||
gzt < viewz - FixedDiv(centeryfrac-viewheight, xscale))
return;
// killough 3/27/98: exclude things totally separated
// from the viewer, by either water or fake ceilings
// killough 4/11/98: improve sprite clipping for underwater/fake ceilings
heightsec = thing->subsector->sector->heightsec;
if (heightsec != -1) // only clip things which are in special sectors
{
int phs = viewplayer->mo->subsector->sector->heightsec;
if (phs != -1 && viewz < sectors[phs].floorheight ?
thing->z >= sectors[heightsec].floorheight :
gzt < sectors[heightsec].floorheight)
return;
if (phs != -1 && viewz > sectors[phs].ceilingheight ?
gzt < sectors[heightsec].ceilingheight &&
viewz >= sectors[heightsec].ceilingheight :
thing->z >= sectors[heightsec].ceilingheight)
return;
}
// store information in a vissprite
vis = R_NewVisSprite ();
// killough 3/27/98: save sector for special clipping later
vis->heightsec = heightsec;
vis->mobjflags = thing->flags;
// proff 11/06/98: Changed for high-res
vis->scale = FixedDiv(projectiony, tz);
vis->gx = thing->x;
vis->gy = thing->y;
vis->gz = thing->z;
vis->gzt = gzt; // killough 3/27/98
vis->texturemid = vis->gzt - viewz;
vis->x1 = x1 < 0 ? 0 : x1;
vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2;
iscale = FixedDiv (FRACUNIT, xscale);
if (flip)
{
vis->startfrac = spritewidth[lump]-1;
vis->xiscale = -iscale;
}
else
{
vis->startfrac = 0;
vis->xiscale = iscale;
}
if (vis->x1 > x1)
vis->startfrac += vis->xiscale*(vis->x1-x1);
vis->patch = lump;
// get light level
if (thing->flags & MF_SHADOW)
vis->colormap = NULL; // shadow draw
else if (fixedcolormap)
vis->colormap = fixedcolormap; // fixed map
else if (thing->frame & FF_FULLBRIGHT)
vis->colormap = fullcolormap; // full bright // killough 3/20/98
else
{ // diminished light
int index = xscale>>LIGHTSCALESHIFT;
if (index >= MAXLIGHTSCALE)
index = MAXLIGHTSCALE-1;
vis->colormap = spritelights[index];
}
}
//
// R_AddSprites
// During BSP traversal, this adds sprites by sector.
//
// killough 9/18/98: add lightlevel as parameter, fixing underwater lighting
void R_AddSprites(subsector_t* subsec, int lightlevel)
{
sector_t* sec=subsec->sector;
mobj_t *thing;
int lightnum;
// BSP is traversed by subsector.
// A sector might have been split into several
// subsectors during BSP building.
// Thus we check whether its already added.
if (sec->validcount == validcount)
return;
// Well, now it will be done.
sec->validcount = validcount;
lightnum = (lightlevel >> LIGHTSEGSHIFT)+extralight;
if (lightnum < 0)
spritelights = scalelight[0];
else if (lightnum >= LIGHTLEVELS)
spritelights = scalelight[LIGHTLEVELS-1];
else
spritelights = scalelight[lightnum];
// Handle all things in sector.
for (thing = sec->thinglist; thing; thing = thing->snext)
R_ProjectSprite(thing);
}
//
// R_DrawPSprite
//
void R_DrawPSprite (pspdef_t *psp)
{
fixed_t tx;
int x1, x2;
spritedef_t *sprdef;
spriteframe_t *sprframe;
int lump;
boolean flip;
vissprite_t *vis;
vissprite_t avis;
// decide which patch to use
#ifdef RANGECHECK
if ( (unsigned)psp->state->sprite >= (unsigned)numsprites)
I_Error ("R_ProjectSprite: Invalid sprite number %i", psp->state->sprite);
#endif
sprdef = &sprites[psp->state->sprite];
#ifdef RANGECHECK
if ( (psp->state->frame & FF_FRAMEMASK) >= sprdef->numframes)
I_Error ("R_ProjectSprite: Invalid sprite frame %i : %li",
psp->state->sprite, psp->state->frame);
#endif
sprframe = &sprdef->spriteframes[psp->state->frame & FF_FRAMEMASK];
lump = sprframe->lump[0];
flip = (boolean) sprframe->flip[0];
// calculate edges of the shape
tx = psp->sx-160*FRACUNIT;
tx -= spriteoffset[lump];
x1 = (centerxfrac + FixedMul (tx,pspritescale))>>FRACBITS;
// off the right side
if (x1 > viewwidth)
return;
tx += spritewidth[lump];
x2 = ((centerxfrac + FixedMul (tx, pspritescale) ) >>FRACBITS) - 1;
// off the left side
if (x2 < 0)
return;
// store information in a vissprite
vis = &avis;
vis->mobjflags = 0;
// killough 12/98: fix psprite positioning problem
vis->texturemid = (BASEYCENTER<<FRACBITS) /* + FRACUNIT/2 */ -
(psp->sy-spritetopoffset[lump]);
vis->x1 = x1 < 0 ? 0 : x1;
vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2;
// proff 11/06/98: Added for high-res
vis->scale = pspriteyscale;
if (flip)
{
vis->xiscale = -pspriteiscale;
vis->startfrac = spritewidth[lump]-1;
}
else
{
vis->xiscale = pspriteiscale;
vis->startfrac = 0;
}
if (vis->x1 > x1)
vis->startfrac += vis->xiscale*(vis->x1-x1);
vis->patch = lump;
if (viewplayer->powers[pw_invisibility] > 4*32
|| viewplayer->powers[pw_invisibility] & 8)
vis->colormap = NULL; // shadow draw
else if (fixedcolormap)
vis->colormap = fixedcolormap; // fixed color
else if (psp->state->frame & FF_FULLBRIGHT)
vis->colormap = fullcolormap; // full bright // killough 3/20/98
else
vis->colormap = spritelights[MAXLIGHTSCALE-1]; // local light
R_DrawVisSprite(vis, vis->x1, vis->x2);
}
//
// R_DrawPlayerSprites