|
|
1.1.1.2 ! root 1: // R_main.c 1.1 root 2: 1.1.1.2 ! root 3: #include <math.h> ! 4: #include "DoomDef.h" ! 5: #include "R_local.h" ! 6: /* 1.1 root 7: 1.1.1.2 ! root 8: */ 1.1 root 9: 1.1.1.2 ! root 10: int viewangleoffset; 1.1 root 11: 1.1.1.2 ! root 12: #ifdef __WATCOMC__ ! 13: int newViewAngleOff; ! 14: #endif 1.1 root 15: 1.1.1.2 ! root 16: int validcount = 1; // increment every time a check is made 1.1 root 17: 1.1.1.2 ! root 18: lighttable_t *fixedcolormap; ! 19: extern lighttable_t **walllights; 1.1 root 20: 1.1.1.2 ! root 21: int centerx, centery; ! 22: fixed_t centerxfrac, centeryfrac; ! 23: fixed_t projection; 1.1 root 24: 1.1.1.2 ! root 25: int framecount; // just for profiling purposes 1.1 root 26: 1.1.1.2 ! root 27: int sscount, linecount, loopcount; 1.1 root 28: 29: fixed_t viewx, viewy, viewz; 30: angle_t viewangle; 31: fixed_t viewcos, viewsin; 32: player_t *viewplayer; 33: 1.1.1.2 ! root 34: int detailshift; // 0 = high, 1 = low ! 35: ! 36: // ! 37: // precalculated math tables ! 38: // ! 39: angle_t clipangle; ! 40: ! 41: // The viewangletox[viewangle + FINEANGLES/4] lookup maps the visible view ! 42: // angles to screen X coordinates, flattening the arc to a flat projection ! 43: // plane. There will be many angles mapped to the same X. ! 44: int viewangletox[FINEANGLES/2]; ! 45: ! 46: // The xtoviewangleangle[] table maps a screen pixel to the lowest viewangle ! 47: // that maps back to x ranges from clipangle to -clipangle ! 48: angle_t xtoviewangle[SCREENWIDTH+1]; ! 49: ! 50: // the finetangentgent[angle+FINEANGLES/4] table holds the fixed_t tangent ! 51: // values for view angles, ranging from MININT to 0 to MAXINT. ! 52: // fixed_t finetangent[FINEANGLES/2]; ! 53: ! 54: // fixed_t finesine[5*FINEANGLES/4]; ! 55: fixed_t *finecosine = &finesine[FINEANGLES/4]; ! 56: 1.1 root 57: 1.1.1.2 ! root 58: lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; ! 59: lighttable_t *scalelightfixed[MAXLIGHTSCALE]; ! 60: lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; ! 61: ! 62: int extralight; // bumped light from gun blasts ! 63: ! 64: void (*colfunc) (void); ! 65: void (*basecolfunc) (void); ! 66: void (*fuzzcolfunc) (void); ! 67: void (*transcolfunc) (void); ! 68: void (*spanfunc) (void); 1.1 root 69: 1.1.1.2 ! root 70: /* ! 71: =================== ! 72: = ! 73: = R_AddPointToBox ! 74: = ! 75: =================== ! 76: */ 1.1 root 77: 1.1.1.2 ! root 78: void R_AddPointToBox (int x, int y, fixed_t *box) ! 79: { ! 80: if (x< box[BOXLEFT]) ! 81: box[BOXLEFT] = x; ! 82: if (x> box[BOXRIGHT]) ! 83: box[BOXRIGHT] = x; ! 84: if (y< box[BOXBOTTOM]) ! 85: box[BOXBOTTOM] = y; ! 86: if (y> box[BOXTOP]) ! 87: box[BOXTOP] = y; ! 88: } 1.1 root 89: 90: 91: 1.1.1.2 ! root 92: /* ! 93: =============================================================================== ! 94: = ! 95: = R_PointOnSide ! 96: = ! 97: = Returns side 0 (front) or 1 (back) ! 98: =============================================================================== ! 99: */ ! 100: ! 101: int R_PointOnSide (fixed_t x, fixed_t y, node_t *node) ! 102: { ! 103: fixed_t dx,dy; ! 104: fixed_t left, right; ! 105: ! 106: if (!node->dx) ! 107: { ! 108: if (x <= node->x) ! 109: return node->dy > 0; ! 110: return node->dy < 0; ! 111: } ! 112: if (!node->dy) ! 113: { ! 114: if (y <= node->y) ! 115: return node->dx < 0; ! 116: return node->dx > 0; ! 117: } ! 118: ! 119: dx = (x - node->x); ! 120: dy = (y - node->y); ! 121: ! 122: // try to quickly decide by looking at sign bits ! 123: if ( (node->dy ^ node->dx ^ dx ^ dy)&0x80000000 ) ! 124: { ! 125: if ( (node->dy ^ dx) & 0x80000000 ) ! 126: return 1; // (left is negative) ! 127: return 0; ! 128: } ! 129: ! 130: left = FixedMul ( node->dy>>FRACBITS , dx ); ! 131: right = FixedMul ( dy , node->dx>>FRACBITS ); ! 132: ! 133: if (right < left) ! 134: return 0; // front side ! 135: return 1; // back side ! 136: } ! 137: ! 138: ! 139: int R_PointOnSegSide (fixed_t x, fixed_t y, seg_t *line) ! 140: { ! 141: fixed_t lx, ly; ! 142: fixed_t ldx, ldy; ! 143: fixed_t dx,dy; ! 144: fixed_t left, right; ! 145: ! 146: lx = line->v1->x; ! 147: ly = line->v1->y; ! 148: ! 149: ldx = line->v2->x - lx; ! 150: ldy = line->v2->y - ly; ! 151: ! 152: if (!ldx) ! 153: { ! 154: if (x <= lx) ! 155: return ldy > 0; ! 156: return ldy < 0; ! 157: } ! 158: if (!ldy) ! 159: { ! 160: if (y <= ly) ! 161: return ldx < 0; ! 162: return ldx > 0; ! 163: } ! 164: ! 165: dx = (x - lx); ! 166: dy = (y - ly); ! 167: ! 168: // try to quickly decide by looking at sign bits ! 169: if ( (ldy ^ ldx ^ dx ^ dy)&0x80000000 ) ! 170: { ! 171: if ( (ldy ^ dx) & 0x80000000 ) ! 172: return 1; // (left is negative) ! 173: return 0; ! 174: } ! 175: ! 176: left = FixedMul ( ldy>>FRACBITS , dx ); ! 177: right = FixedMul ( dy , ldx>>FRACBITS ); ! 178: ! 179: if (right < left) ! 180: return 0; // front side ! 181: return 1; // back side ! 182: } ! 183: 1.1 root 184: 185: /* 186: =============================================================================== 187: = 188: = R_PointToAngle 189: = 190: =============================================================================== 191: */ 192: 1.1.1.2 ! root 193: // to get a global angle from cartesian coordinates, the coordinates are ! 194: // flipped until they are in the first octant of the coordinate system, then ! 195: // the y (<=x) is scaled and divided by x to get a tangent (slope) value ! 196: // which is looked up in the tantoangle[] table. The +1 size is to handle ! 197: // the case when x==y without additional checking. ! 198: #define SLOPERANGE 2048 ! 199: #define SLOPEBITS 11 ! 200: #define DBITS (FRACBITS-SLOPEBITS) ! 201: 1.1 root 202: 1.1.1.2 ! root 203: extern int tantoangle[SLOPERANGE+1]; // get from tables.c ! 204: ! 205: // int tantoangle[SLOPERANGE+1]; 1.1 root 206: 207: int SlopeDiv (unsigned num, unsigned den) 208: { 209: unsigned ans; 210: if (den < 512) 211: return SLOPERANGE; 212: ans = (num<<3)/(den>>8); 213: return ans <= SLOPERANGE ? ans : SLOPERANGE; 214: } 215: 1.1.1.2 ! root 216: angle_t R_PointToAngle (fixed_t x, fixed_t y) ! 217: { ! 218: x -= viewx; ! 219: y -= viewy; 1.1 root 220: if ( (!x) && (!y) ) 221: return 0; 222: if (x>= 0) 1.1.1.2 ! root 223: { // x >=0 1.1 root 224: if (y>= 0) 1.1.1.2 ! root 225: { // y>= 0 1.1 root 226: if (x>y) 1.1.1.2 ! root 227: return tantoangle[ SlopeDiv(y,x)]; // octant 0 1.1 root 228: else 1.1.1.2 ! root 229: return ANG90-1-tantoangle[ SlopeDiv(x,y)]; // octant 1 1.1 root 230: } 231: else 1.1.1.2 ! root 232: { // y<0 1.1 root 233: y = -y; 234: if (x>y) 1.1.1.2 ! root 235: return -tantoangle[SlopeDiv(y,x)]; // octant 8 1.1 root 236: else 1.1.1.2 ! root 237: return ANG270+tantoangle[ SlopeDiv(x,y)]; // octant 7 1.1 root 238: } 239: } 240: else 1.1.1.2 ! root 241: { // x<0 1.1 root 242: x = -x; 243: if (y>= 0) 1.1.1.2 ! root 244: { // y>= 0 1.1 root 245: if (x>y) 1.1.1.2 ! root 246: return ANG180-1-tantoangle[ SlopeDiv(y,x)]; // octant 3 1.1 root 247: else 1.1.1.2 ! root 248: return ANG90+ tantoangle[ SlopeDiv(x,y)]; // octant 2 1.1 root 249: } 250: else 1.1.1.2 ! root 251: { // y<0 1.1 root 252: y = -y; 253: if (x>y) 1.1.1.2 ! root 254: return ANG180+tantoangle[ SlopeDiv(y,x)]; // octant 4 1.1 root 255: else 1.1.1.2 ! root 256: return ANG270-1-tantoangle[ SlopeDiv(x,y)]; // octant 5 1.1 root 257: } 1.1.1.2 ! root 258: } ! 259: 1.1 root 260: return 0; 261: } 262: 263: 1.1.1.2 ! root 264: angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2) ! 265: { ! 266: viewx = x1; ! 267: viewy = y1; ! 268: return R_PointToAngle (x2, y2); ! 269: } ! 270: ! 271: ! 272: fixed_t R_PointToDist (fixed_t x, fixed_t y) ! 273: { ! 274: int angle; ! 275: fixed_t dx, dy, temp; ! 276: fixed_t dist; ! 277: ! 278: dx = abs(x - viewx); ! 279: dy = abs(y - viewy); ! 280: ! 281: if (dy>dx) ! 282: { ! 283: temp = dx; ! 284: dx = dy; ! 285: dy = temp; ! 286: } ! 287: ! 288: angle = (tantoangle[ FixedDiv(dy,dx)>>DBITS ]+ANG90) >> ANGLETOFINESHIFT; ! 289: ! 290: dist = FixedDiv (dx, finesine[angle] ); // use as cosine ! 291: ! 292: return dist; ! 293: } ! 294: ! 295: ! 296: 1.1 root 297: /* 1.1.1.2 ! root 298: ================= 1.1 root 299: = 1.1.1.2 ! root 300: = R_InitPointToAngle 1.1 root 301: = 1.1.1.2 ! root 302: ================= 1.1 root 303: */ 304: 1.1.1.2 ! root 305: void R_InitPointToAngle (void) 1.1 root 306: { 1.1.1.2 ! root 307: // now getting from tables.c ! 308: #if 0 ! 309: int i; ! 310: long t; ! 311: float f; ! 312: // ! 313: // slope (tangent) to angle lookup ! 314: // ! 315: for (i=0 ; i<=SLOPERANGE ; i++) 1.1 root 316: { 1.1.1.2 ! root 317: f = atan( (float)i/SLOPERANGE )/(3.141592657*2); ! 318: t = 0xffffffff*f; ! 319: tantoangle[i] = t; 1.1 root 320: } 1.1.1.2 ! root 321: #endif ! 322: } ! 323: ! 324: //============================================================================= ! 325: ! 326: /* ! 327: ================ ! 328: = ! 329: = R_ScaleFromGlobalAngle ! 330: = ! 331: = Returns the texture mapping scale for the current line at the given angle ! 332: = rw_distance must be calculated first ! 333: ================ ! 334: */ ! 335: ! 336: fixed_t R_ScaleFromGlobalAngle (angle_t visangle) ! 337: { ! 338: fixed_t scale; ! 339: int anglea, angleb; ! 340: int sinea, sineb; ! 341: fixed_t num,den; ! 342: ! 343: #if 0 ! 344: { ! 345: fixed_t dist,z; ! 346: fixed_t sinv, cosv; ! 347: ! 348: sinv = finesine[(visangle-rw_normalangle)>>ANGLETOFINESHIFT]; ! 349: dist = FixedDiv (rw_distance, sinv); ! 350: cosv = finecosine[(viewangle-visangle)>>ANGLETOFINESHIFT]; ! 351: z = abs(FixedMul (dist, cosv)); ! 352: scale = FixedDiv(projection, z); ! 353: return scale; ! 354: } ! 355: #endif ! 356: ! 357: anglea = ANG90 + (visangle-viewangle); ! 358: angleb = ANG90 + (visangle-rw_normalangle); ! 359: // bothe sines are allways positive ! 360: sinea = finesine[anglea>>ANGLETOFINESHIFT]; ! 361: sineb = finesine[angleb>>ANGLETOFINESHIFT]; ! 362: num = FixedMul(projection,sineb)<<detailshift; ! 363: den = FixedMul(rw_distance,sinea); ! 364: if (den > num>>16) 1.1 root 365: { 1.1.1.2 ! root 366: scale = FixedDiv (num, den); ! 367: if (scale > 64*FRACUNIT) ! 368: scale = 64*FRACUNIT; ! 369: else if (scale < 256) ! 370: scale = 256; 1.1 root 371: } 1.1.1.2 ! root 372: else ! 373: scale = 64*FRACUNIT; ! 374: ! 375: return scale; 1.1 root 376: } 377: 378: 379: 380: /* 1.1.1.2 ! root 381: ================= 1.1 root 382: = 1.1.1.2 ! root 383: = R_InitTables 1.1 root 384: = 1.1.1.2 ! root 385: ================= 1.1 root 386: */ 387: 1.1.1.2 ! root 388: void R_InitTables (void) 1.1 root 389: { 1.1.1.2 ! root 390: // now getting from tables.c ! 391: #if 0 ! 392: int i; ! 393: float a, fv; ! 394: int t; ! 395: ! 396: // ! 397: // viewangle tangent table ! 398: // ! 399: for (i=0 ; i<FINEANGLES/2 ; i++) ! 400: { ! 401: a = (i-FINEANGLES/4+0.5)*PI*2/FINEANGLES; ! 402: fv = FRACUNIT*tan (a); ! 403: t = fv; ! 404: finetangent[i] = t; ! 405: } 1.1 root 406: 1.1.1.2 ! root 407: // ! 408: // finesine table ! 409: // ! 410: for (i=0 ; i<5*FINEANGLES/4 ; i++) 1.1 root 411: { 1.1.1.2 ! root 412: // OPTIMIZE: mirror... ! 413: a = (i+0.5)*PI*2/FINEANGLES; ! 414: t = FRACUNIT*sin (a); ! 415: finesine[i] = t; 1.1 root 416: } 1.1.1.2 ! root 417: #endif 1.1 root 418: 1.1.1.2 ! root 419: } 1.1 root 420: 421: 422: /* 1.1.1.2 ! root 423: ================= 1.1 root 424: = 1.1.1.2 ! root 425: = R_InitTextureMapping 1.1 root 426: = 1.1.1.2 ! root 427: ================= 1.1 root 428: */ 429: 1.1.1.2 ! root 430: void R_InitTextureMapping (void) 1.1 root 431: { 1.1.1.2 ! root 432: int i; ! 433: int x; ! 434: int t; ! 435: fixed_t focallength; 1.1 root 436: 437: 1.1.1.2 ! root 438: // ! 439: // use tangent table to generate viewangletox ! 440: // viewangletox will give the next greatest x after the view angle ! 441: // ! 442: // calc focallength so FIELDOFVIEW angles covers SCREENWIDTH ! 443: focallength = FixedDiv (centerxfrac ! 444: , finetangent[FINEANGLES/4+FIELDOFVIEW/2] ); ! 445: ! 446: for (i=0 ; i<FINEANGLES/2 ; i++) ! 447: { ! 448: if (finetangent[i] > FRACUNIT*2) ! 449: t = -1; ! 450: else if (finetangent[i] < -FRACUNIT*2) ! 451: t = viewwidth+1; ! 452: else ! 453: { ! 454: t = FixedMul (finetangent[i], focallength); ! 455: t = (centerxfrac - t+FRACUNIT-1)>>FRACBITS; ! 456: if (t < -1) ! 457: t = -1; ! 458: else if (t>viewwidth+1) ! 459: t = viewwidth+1; ! 460: } ! 461: viewangletox[i] = t; ! 462: } 1.1 root 463: 1.1.1.2 ! root 464: // ! 465: // scan viewangletox[] to generate xtoviewangleangle[] ! 466: // ! 467: // xtoviewangle will give the smallest view angle that maps to x ! 468: for (x=0;x<=viewwidth;x++) ! 469: { ! 470: i = 0; ! 471: while (viewangletox[i]>x) ! 472: i++; ! 473: xtoviewangle[x] = (i<<ANGLETOFINESHIFT)-ANG90; ! 474: } 1.1 root 475: 1.1.1.2 ! root 476: // ! 477: // take out the fencepost cases from viewangletox ! 478: // ! 479: for (i=0 ; i<FINEANGLES/2 ; i++) ! 480: { ! 481: t = FixedMul (finetangent[i], focallength); ! 482: t = centerx - t; ! 483: if (viewangletox[i] == -1) ! 484: viewangletox[i] = 0; ! 485: else if (viewangletox[i] == viewwidth+1) ! 486: viewangletox[i] = viewwidth; ! 487: } 1.1 root 488: 1.1.1.2 ! root 489: clipangle = xtoviewangle[0]; ! 490: } 1.1 root 491: 1.1.1.2 ! root 492: //============================================================================= 1.1 root 493: 494: /* 1.1.1.2 ! root 495: ==================== 1.1 root 496: = 1.1.1.2 ! root 497: = R_InitLightTables 1.1 root 498: = 1.1.1.2 ! root 499: = Only inits the zlight table, because the scalelight table changes ! 500: = with view size ! 501: = ! 502: ==================== 1.1 root 503: */ 504: 1.1.1.2 ! root 505: #define DISTMAP 2 1.1 root 506: 1.1.1.2 ! root 507: void R_InitLightTables (void) ! 508: { ! 509: int i,j, level, startmap; ! 510: int scale; 1.1 root 511: 1.1.1.2 ! root 512: // ! 513: // Calculate the light levels to use for each level / distance combination ! 514: // ! 515: for (i=0 ; i< LIGHTLEVELS ; i++) ! 516: { ! 517: startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS; ! 518: for (j=0 ; j<MAXLIGHTZ ; j++) ! 519: { ! 520: scale = FixedDiv ((SCREENWIDTH/2*FRACUNIT), (j+1)<<LIGHTZSHIFT); ! 521: scale >>= LIGHTSCALESHIFT; ! 522: level = startmap - scale/DISTMAP; ! 523: if (level < 0) ! 524: level = 0; ! 525: if (level >= NUMCOLORMAPS) ! 526: level = NUMCOLORMAPS-1; ! 527: zlight[i][j] = colormaps + level*256; ! 528: } ! 529: } ! 530: } 1.1 root 531: 532: 1.1.1.2 ! root 533: /* ! 534: ============== ! 535: = ! 536: = R_SetViewSize ! 537: = ! 538: = Don't really change anything here, because i might be in the middle of ! 539: = a refresh. The change will take effect next refresh. ! 540: = ! 541: ============== ! 542: */ 1.1 root 543: 1.1.1.2 ! root 544: boolean setsizeneeded; ! 545: int setblocks, setdetail; 1.1 root 546: 1.1.1.2 ! root 547: void R_SetViewSize (int blocks, int detail) ! 548: { ! 549: setsizeneeded = true; ! 550: setblocks = blocks; ! 551: setdetail = detail; 1.1 root 552: } 553: 554: /* 1.1.1.2 ! root 555: ============== 1.1 root 556: = 1.1.1.2 ! root 557: = R_ExecuteSetViewSize 1.1 root 558: = 1.1.1.2 ! root 559: ============== 1.1 root 560: */ 561: 1.1.1.2 ! root 562: void R_ExecuteSetViewSize (void) 1.1 root 563: { 1.1.1.2 ! root 564: fixed_t cosadj, dy; ! 565: int i,j, level, startmap; 1.1 root 566: 1.1.1.2 ! root 567: setsizeneeded = false; 1.1 root 568: 1.1.1.2 ! root 569: if (setblocks == 11) ! 570: { ! 571: scaledviewwidth = SCREENWIDTH; ! 572: viewheight = SCREENHEIGHT; ! 573: } ! 574: else ! 575: { ! 576: scaledviewwidth = setblocks*32; ! 577: viewheight = (setblocks*158/10); ! 578: } 1.1 root 579: 1.1.1.2 ! root 580: detailshift = setdetail; ! 581: viewwidth = scaledviewwidth>>detailshift; ! 582: ! 583: centery = viewheight/2; ! 584: centerx = viewwidth/2; ! 585: centerxfrac = centerx<<FRACBITS; ! 586: centeryfrac = centery<<FRACBITS; ! 587: projection = centerxfrac; ! 588: ! 589: if (!detailshift) ! 590: { ! 591: colfunc = basecolfunc = R_DrawColumn; ! 592: fuzzcolfunc = R_DrawFuzzColumn; ! 593: transcolfunc = R_DrawTranslatedColumn; ! 594: spanfunc = R_DrawSpan; ! 595: } ! 596: else ! 597: { ! 598: colfunc = basecolfunc = R_DrawColumnLow; ! 599: fuzzcolfunc = R_DrawFuzzColumn; ! 600: transcolfunc = R_DrawTranslatedColumn; ! 601: spanfunc = R_DrawSpanLow; ! 602: } ! 603: ! 604: R_InitBuffer (scaledviewwidth, viewheight); ! 605: ! 606: R_InitTextureMapping (); ! 607: ! 608: // ! 609: // psprite scales ! 610: // ! 611: pspritescale = FRACUNIT*viewwidth/SCREENWIDTH; ! 612: pspriteiscale = FRACUNIT*SCREENWIDTH/viewwidth; ! 613: ! 614: // ! 615: // thing clipping ! 616: // ! 617: for (i=0 ; i<viewwidth ; i++) ! 618: screenheightarray[i] = viewheight; ! 619: ! 620: // ! 621: // planes ! 622: // ! 623: for (i=0 ; i<viewheight ; i++) ! 624: { ! 625: dy = ((i-viewheight/2)<<FRACBITS)+FRACUNIT/2; ! 626: dy = abs(dy); ! 627: yslope[i] = FixedDiv ( (viewwidth<<detailshift)/2*FRACUNIT, dy); ! 628: } 1.1 root 629: 1.1.1.2 ! root 630: for (i=0 ; i<viewwidth ; i++) ! 631: { ! 632: cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]); ! 633: distscale[i] = FixedDiv (FRACUNIT,cosadj); ! 634: } ! 635: ! 636: // ! 637: // Calculate the light levels to use for each level / scale combination ! 638: // ! 639: for (i=0 ; i< LIGHTLEVELS ; i++) ! 640: { ! 641: startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS; ! 642: for (j=0 ; j<MAXLIGHTSCALE ; j++) ! 643: { ! 644: level = startmap - j*SCREENWIDTH/(viewwidth<<detailshift)/DISTMAP; ! 645: if (level < 0) ! 646: level = 0; ! 647: if (level >= NUMCOLORMAPS) ! 648: level = NUMCOLORMAPS-1; ! 649: scalelight[i][j] = colormaps + level*256; ! 650: } ! 651: } 1.1 root 652: 1.1.1.2 ! root 653: // ! 654: // draw the border ! 655: // ! 656: R_DrawViewBorder (); // erase old menu stuff ! 657: } 1.1 root 658: 659: 660: /* 661: ============== 662: = 1.1.1.2 ! root 663: = R_Init 1.1 root 664: = 665: ============== 666: */ 667: 1.1.1.2 ! root 668: int detailLevel; ! 669: int screenblocks; 1.1 root 670: 1.1.1.2 ! root 671: void R_Init (void) ! 672: { ! 673: tprintf("R_InitData ",1); ! 674: R_InitData (); ! 675: //printf ("."); ! 676: tprintf("R_InitPointToAngle\n",0); ! 677: R_InitPointToAngle (); ! 678: //printf ("."); ! 679: tprintf("R_InitTables ",0); ! 680: R_InitTables (); ! 681: // viewwidth / viewheight / detailLevel are set by the defaults ! 682: //printf ("."); ! 683: R_SetViewSize (screenblocks, detailLevel); ! 684: tprintf("R_InitPlanes\n",0); ! 685: R_InitPlanes (); ! 686: //printf ("."); ! 687: tprintf("R_InitLightTables ",0); ! 688: R_InitLightTables (); ! 689: //printf ("."); ! 690: tprintf("R_InitSkyMap\n",0); ! 691: R_InitSkyMap (); ! 692: //printf ("."); ! 693: R_InitTranslationTables(); ! 694: framecount = 0; ! 695: } 1.1 root 696: 697: 1.1.1.2 ! root 698: /* ! 699: ============== ! 700: = ! 701: = R_PointInSubsector ! 702: = ! 703: ============== ! 704: */ 1.1 root 705: 1.1.1.2 ! root 706: subsector_t *R_PointInSubsector (fixed_t x, fixed_t y) 1.1 root 707: { 1.1.1.2 ! root 708: node_t *node; ! 709: int side, nodenum; 1.1 root 710: 1.1.1.2 ! root 711: if (!numnodes) // single subsector is a special case ! 712: return subsectors; 1.1 root 713: 1.1.1.2 ! root 714: nodenum = numnodes-1; 1.1 root 715: 1.1.1.2 ! root 716: while (! (nodenum & NF_SUBSECTOR) ) ! 717: { ! 718: node = &nodes[nodenum]; ! 719: side = R_PointOnSide (x, y, node); ! 720: nodenum = node->children[side]; ! 721: } ! 722: ! 723: return &subsectors[nodenum & ~NF_SUBSECTOR]; ! 724: ! 725: } ! 726: ! 727: //---------------------------------------------------------------------------- ! 728: // ! 729: // PROC R_SetupFrame ! 730: // ! 731: //---------------------------------------------------------------------------- ! 732: ! 733: void R_SetupFrame(player_t *player) ! 734: { ! 735: int i; ! 736: int tableAngle; ! 737: int tempCentery; ! 738: ! 739: //drawbsp = 1; ! 740: viewplayer = player; ! 741: #ifdef __WATCOMC__ ! 742: viewangleoffset = newViewAngleOff<<ANGLETOFINESHIFT; ! 743: #endif ! 744: viewangle = player->mo->angle+viewangleoffset; ! 745: tableAngle = viewangle>>ANGLETOFINESHIFT; ! 746: if(player->chickenTics && player->chickenPeck) ! 747: { // Set chicken attack view position ! 748: viewx = player->mo->x+player->chickenPeck*finecosine[tableAngle]; ! 749: viewy = player->mo->y+player->chickenPeck*finesine[tableAngle]; ! 750: } ! 751: else ! 752: { // Normal view position ! 753: viewx = player->mo->x; ! 754: viewy = player->mo->y; ! 755: } ! 756: extralight = player->extralight; ! 757: viewz = player->viewz; ! 758: ! 759: tempCentery = viewheight/2+(player->lookdir)*screenblocks/10; ! 760: if(centery != tempCentery) ! 761: { ! 762: centery = tempCentery; ! 763: centeryfrac = centery<<FRACBITS; ! 764: for(i = 0; i < viewheight; i++) ! 765: { ! 766: yslope[i] = FixedDiv ((viewwidth<<detailshift)/2*FRACUNIT, ! 767: abs(((i-centery)<<FRACBITS)+FRACUNIT/2)); ! 768: } ! 769: } ! 770: viewsin = finesine[tableAngle]; ! 771: viewcos = finecosine[tableAngle]; ! 772: sscount = 0; ! 773: if(player->fixedcolormap) ! 774: { ! 775: fixedcolormap = colormaps+player->fixedcolormap ! 776: *256*sizeof(lighttable_t); ! 777: walllights = scalelightfixed; ! 778: for(i = 0; i < MAXLIGHTSCALE; i++) ! 779: { ! 780: scalelightfixed[i] = fixedcolormap; ! 781: } ! 782: } ! 783: else ! 784: { ! 785: fixedcolormap = 0; ! 786: } ! 787: framecount++; ! 788: validcount++; ! 789: if(BorderNeedRefresh) ! 790: { ! 791: if(setblocks < 10) ! 792: { ! 793: R_DrawViewBorder(); ! 794: } ! 795: BorderNeedRefresh = false; ! 796: BorderTopRefresh = false; ! 797: UpdateState |= I_FULLSCRN; ! 798: } ! 799: if(BorderTopRefresh) ! 800: { ! 801: if(setblocks < 10) ! 802: { ! 803: R_DrawTopBorder(); ! 804: } ! 805: BorderTopRefresh = false; ! 806: UpdateState |= I_MESSAGES; ! 807: } ! 808: ! 809: #ifdef __NeXT__ ! 810: RD_ClearMapWindow (); ! 811: #endif ! 812: #ifdef __WATCOMC__ ! 813: destview = destscreen+(viewwindowx>>2)+viewwindowy*80; 1.1 root 814: #endif 815: 1.1.1.2 ! root 816: #if 0 ! 817: { ! 818: static int frame; ! 819: memset (screen, frame, SCREENWIDTH*SCREENHEIGHT); ! 820: frame++; ! 821: } 1.1 root 822: #endif 823: } 824: 1.1.1.2 ! root 825: /* ! 826: ============== ! 827: = ! 828: = R_RenderView ! 829: = ! 830: ============== ! 831: */ ! 832: ! 833: void R_RenderPlayerView (player_t *player) ! 834: { ! 835: R_SetupFrame (player); ! 836: R_ClearClipSegs (); ! 837: R_ClearDrawSegs (); ! 838: R_ClearPlanes (); ! 839: R_ClearSprites (); ! 840: NetUpdate (); // check for new console commands ! 841: R_RenderBSPNode (numnodes-1); // the head node is the last node output ! 842: NetUpdate (); // check for new console commands ! 843: R_DrawPlanes (); ! 844: NetUpdate (); // check for new console commands ! 845: R_DrawMasked (); ! 846: NetUpdate (); // check for new console commands ! 847: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.