|
|
1.1 ! root 1: /* r_main.c */ ! 2: ! 3: #include "doomdef.h" ! 4: #include "r_local.h" ! 5: ! 6: /*===================================== */ ! 7: ! 8: /* */ ! 9: /* subsectors */ ! 10: /* */ ! 11: subsector_t *vissubsectors[MAXVISSSEC], **lastvissubsector; ! 12: ! 13: /* */ ! 14: /* walls */ ! 15: /* */ ! 16: viswall_t viswalls[MAXWALLCMDS], *lastwallcmd; ! 17: ! 18: /* */ ! 19: /* planes */ ! 20: /* */ ! 21: visplane_t visplanes[MAXVISPLANES], *lastvisplane; ! 22: ! 23: /* */ ! 24: /* sprites */ ! 25: /* */ ! 26: vissprite_t vissprites[MAXVISSPRITES], *lastsprite_p, *vissprite_p; ! 27: ! 28: /* */ ! 29: /* openings / misc refresh memory */ ! 30: /* */ ! 31: unsigned short openings[MAXOPENINGS], *lastopening; ! 32: ! 33: ! 34: /*===================================== */ ! 35: ! 36: boolean phase1completed; ! 37: ! 38: pixel_t *workingscreen; ! 39: ! 40: ! 41: fixed_t viewx, viewy, viewz; ! 42: angle_t viewangle; ! 43: fixed_t viewcos, viewsin; ! 44: player_t *viewplayer; ! 45: ! 46: int validcount = 1; /* increment every time a check is made */ ! 47: int framecount; /* incremented every frame */ ! 48: ! 49: ! 50: boolean fixedcolormap; ! 51: ! 52: int lightlevel; /* fixed light level */ ! 53: int extralight; /* bumped light from gun blasts */ ! 54: ! 55: /* */ ! 56: /* sky mapping */ ! 57: /* */ ! 58: int skytexture; ! 59: ! 60: ! 61: /* */ ! 62: /* precalculated math */ ! 63: /* */ ! 64: angle_t clipangle,doubleclipangle; ! 65: fixed_t *finecosine = &finesine[FINEANGLES/4]; ! 66: ! 67: /* ! 68: =============================================================================== ! 69: = ! 70: = R_PointToAngle ! 71: = ! 72: =============================================================================== ! 73: */ ! 74: ! 75: ! 76: extern int tantoangle[SLOPERANGE+1]; ! 77: ! 78: int SlopeDiv (unsigned num, unsigned den) ! 79: { ! 80: unsigned ans; ! 81: if (den < 512) ! 82: return SLOPERANGE; ! 83: ans = (num<<3)/(den>>8); ! 84: return ans <= SLOPERANGE ? ans : SLOPERANGE; ! 85: } ! 86: ! 87: angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2) ! 88: { ! 89: int x; ! 90: int y; ! 91: ! 92: x = x2 - x1; ! 93: y = y2 - y1; ! 94: ! 95: if ( (!x) && (!y) ) ! 96: return 0; ! 97: if (x>= 0) ! 98: { /* x >=0 */ ! 99: if (y>= 0) ! 100: { /* y>= 0 */ ! 101: if (x>y) ! 102: return tantoangle[ SlopeDiv(y,x)]; /* octant 0 */ ! 103: else ! 104: return ANG90-1-tantoangle[ SlopeDiv(x,y)]; /* octant 1 */ ! 105: } ! 106: else ! 107: { /* y<0 */ ! 108: y = -y; ! 109: if (x>y) ! 110: return -tantoangle[SlopeDiv(y,x)]; /* octant 8 */ ! 111: else ! 112: return ANG270+tantoangle[ SlopeDiv(x,y)]; /* octant 7 */ ! 113: } ! 114: } ! 115: else ! 116: { /* x<0 */ ! 117: x = -x; ! 118: if (y>= 0) ! 119: { /* y>= 0 */ ! 120: if (x>y) ! 121: return ANG180-1-tantoangle[ SlopeDiv(y,x)]; /* octant 3 */ ! 122: else ! 123: return ANG90+ tantoangle[ SlopeDiv(x,y)]; /* octant 2 */ ! 124: } ! 125: else ! 126: { /* y<0 */ ! 127: y = -y; ! 128: if (x>y) ! 129: return ANG180+tantoangle[ SlopeDiv(y,x)]; /* octant 4 */ ! 130: else ! 131: return ANG270-1-tantoangle[ SlopeDiv(x,y)]; /* octant 5 */ ! 132: } ! 133: } ! 134: #ifndef LCC ! 135: return 0; ! 136: #endif ! 137: } ! 138: ! 139: ! 140: /* ! 141: =============================================================================== ! 142: = ! 143: = R_PointOnSide ! 144: = ! 145: = Returns side 0 (front) or 1 (back) ! 146: =============================================================================== ! 147: */ ! 148: ! 149: static int R_PointOnSide (int x, int y, node_t *node) ! 150: { ! 151: fixed_t dx,dy; ! 152: fixed_t left, right; ! 153: ! 154: if (!node->dx) ! 155: { ! 156: if (x <= node->x) ! 157: return node->dy > 0; ! 158: return node->dy < 0; ! 159: } ! 160: if (!node->dy) ! 161: { ! 162: if (y <= node->y) ! 163: return node->dx < 0; ! 164: return node->dx > 0; ! 165: } ! 166: ! 167: dx = (x - node->x); ! 168: dy = (y - node->y); ! 169: ! 170: left = (node->dy>>16) * (dx>>16); ! 171: right = (dy>>16) * (node->dx>>16); ! 172: ! 173: if (right < left) ! 174: return 0; /* front side */ ! 175: return 1; /* back side */ ! 176: } ! 177: ! 178: ! 179: ! 180: /* ! 181: ============== ! 182: = ! 183: = R_PointInSubsector ! 184: = ! 185: ============== ! 186: */ ! 187: ! 188: struct subsector_s *R_PointInSubsector (fixed_t x, fixed_t y) ! 189: { ! 190: node_t *node; ! 191: int side, nodenum; ! 192: ! 193: if (!numnodes) /* single subsector is a special case */ ! 194: return subsectors; ! 195: ! 196: nodenum = numnodes-1; ! 197: ! 198: while (! (nodenum & NF_SUBSECTOR) ) ! 199: { ! 200: node = &nodes[nodenum]; ! 201: side = R_PointOnSide (x, y, node); ! 202: nodenum = node->children[side]; ! 203: } ! 204: ! 205: return &subsectors[nodenum & ~NF_SUBSECTOR]; ! 206: ! 207: } ! 208: ! 209: /*============================================================================= */ ! 210: ! 211: ! 212: /* ! 213: ============== ! 214: = ! 215: = R_Init ! 216: = ! 217: ============== ! 218: */ ! 219: ! 220: void R_Init (void) ! 221: { ! 222: D_printf ("R_InitData\n"); ! 223: R_InitData (); ! 224: D_printf ("Done\n"); ! 225: ! 226: clipangle = xtoviewangle[0]; ! 227: doubleclipangle = clipangle*2; ! 228: ! 229: framecount = 0; ! 230: viewplayer = &players[0]; ! 231: } ! 232: ! 233: /*============================================================================= */ ! 234: ! 235: extern int ticsinframe; ! 236: ! 237: extern int checkpostics, shoottics; ! 238: extern int lasttics; ! 239: ! 240: extern int playertics, thinkertics, sighttics, basetics, latetics; ! 241: extern int tictics; ! 242: ! 243: extern int soundtics; ! 244: ! 245: /* ! 246: =================== ! 247: = ! 248: = R_DebugScreen ! 249: = ! 250: =================== ! 251: */ ! 252: ! 253: void R_DebugScreen (void) ! 254: { ! 255: #ifdef JAGUAR ! 256: ! 257: #if 1 ! 258: PrintNumber (15,1, vblsinframe); ! 259: ! 260: PrintNumber (15,2, phasetime[8] - phasetime[0]); ! 261: PrintNumber (15,3, tictics); ! 262: PrintNumber (15,4, soundtics); ! 263: #endif ! 264: ! 265: #if 1 ! 266: PrintNumber (15,6, playertics); ! 267: PrintNumber (15,7, thinkertics); ! 268: PrintNumber (15,8, sighttics); ! 269: PrintNumber (15,9, basetics); ! 270: PrintNumber (15,10, latetics); ! 271: #endif ! 272: ! 273: #if 0 ! 274: int i; ! 275: ! 276: PrintNumber (15,1, phasetime[8] - phasetime[0]); ! 277: for (i=0 ; i < 8 ; i++) ! 278: PrintNumber (15,3+i,phasetime[i+1]-phasetime[i]); ! 279: #endif ! 280: ! 281: ! 282: #endif ! 283: ! 284: } ! 285: /*============================================================================= */ ! 286: ! 287: int shadepixel; ! 288: extern int workpage; ! 289: extern pixel_t *screens[2]; /* [SCREENWIDTH*SCREENHEIGHT]; */ ! 290: ! 291: /* ! 292: ================== ! 293: = ! 294: = R_Setup ! 295: = ! 296: ================== ! 297: */ ! 298: ! 299: void R_Setup (void) ! 300: { ! 301: int damagecount, bonuscount; ! 302: player_t *player; ! 303: int shadex, shadey, shadei; ! 304: ! 305: /* */ ! 306: /* set up globals for new frame */ ! 307: /* */ ! 308: workingscreen = screens[workpage]; ! 309: ! 310: #ifdef JAGUAR ! 311: *(pixel_t **)0xf02224 = workingscreen; /* a2 base pointer */ ! 312: *(int *)0xf02234 = 0x10000; /* a2 outer loop add (+1 y) */ ! 313: *(int *)0xf0226c = *(int *)0xf02268 = 0; /* pattern compare */ ! 314: #endif ! 315: ! 316: framecount++; ! 317: validcount++; ! 318: ! 319: viewplayer = player = &players[displayplayer]; ! 320: viewx = player->mo->x; ! 321: viewy = player->mo->y; ! 322: viewz = player->viewz; ! 323: viewangle = player->mo->angle; ! 324: ! 325: viewsin = finesine[viewangle>>ANGLETOFINESHIFT]; ! 326: viewcos = finecosine[viewangle>>ANGLETOFINESHIFT]; ! 327: ! 328: extralight = player->extralight << 6; ! 329: fixedcolormap = player->fixedcolormap; ! 330: ! 331: /* */ ! 332: /* calc shadepixel */ ! 333: /* */ ! 334: player = &players[consoleplayer]; ! 335: ! 336: damagecount = player->damagecount; ! 337: bonuscount = player->bonuscount; ! 338: ! 339: if (damagecount) ! 340: damagecount += 10; ! 341: if (bonuscount) ! 342: bonuscount += 2; ! 343: damagecount >>= 2; ! 344: shadex = (bonuscount>>1) + damagecount; ! 345: shadey = (bonuscount>>1) - damagecount; ! 346: shadei = (bonuscount + damagecount)<<2; ! 347: ! 348: shadei += player->extralight<<3; ! 349: ! 350: /* */ ! 351: /* pwerups */ ! 352: /* */ ! 353: if (player->powers[pw_invulnerability] > 60 ! 354: || (player->powers[pw_invulnerability]&4) ) ! 355: { ! 356: shadex -= 8; ! 357: shadei += 32; ! 358: } ! 359: ! 360: if (player->powers[pw_ironfeet] > 60 ! 361: || (player->powers[pw_ironfeet]&4) ) ! 362: shadey += 7; ! 363: ! 364: if (player->powers[pw_strength] ! 365: && (player->powers[pw_strength]< 64) ) ! 366: shadex += (8 - (player->powers[pw_strength]>>3) ); ! 367: ! 368: ! 369: /* */ ! 370: /* bound and store shades */ ! 371: /* */ ! 372: if (shadex > 7) ! 373: shadex = 7; ! 374: else if (shadex < -8) ! 375: shadex = -8; ! 376: if (shadey > 7) ! 377: shadey = 7; ! 378: else if (shadey < -8) ! 379: shadey = -8; ! 380: if (shadei > 127) ! 381: shadei = 127; ! 382: else if (shadei < -128) ! 383: shadei = -128; ! 384: ! 385: shadepixel = ((shadex<<12)&0xf000) + ((shadey<<8)&0xf00) + (shadei&0xff); ! 386: ! 387: ! 388: /* */ ! 389: /* plane filling */ ! 390: /* */ ! 391: lastvisplane = visplanes+1; /* visplanes[0] is left empty */ ! 392: lastwallcmd = viswalls; /* no walls added yet */ ! 393: lastvissubsector = vissubsectors; /* no subsectors visible yet */ ! 394: ! 395: /* */ ! 396: /* clear sprites */ ! 397: /* */ ! 398: vissprite_p = vissprites; ! 399: lastopening = openings; ! 400: ! 401: phasetime[0] = samplecount; ! 402: } ! 403: ! 404: ! 405: void R_BSP (void); ! 406: void R_WallPrep (void); ! 407: void R_SpritePrep (void); ! 408: boolean R_LatePrep (void); ! 409: void R_Cache (void); ! 410: void R_SegCommands (void); ! 411: void R_DrawPlanes (void); ! 412: void R_Sprites (void); ! 413: void R_Update (void); ! 414: ! 415: ! 416: /* ! 417: ============== ! 418: = ! 419: = R_RenderView ! 420: = ! 421: ============== ! 422: */ ! 423: ! 424: int phasetime[9] = {1,2,3,4,5,6,7,8,9}; ! 425: ! 426: extern ref1_start; ! 427: extern ref2_start; ! 428: extern ref3_start; ! 429: extern ref4_start; ! 430: extern ref5_start; ! 431: extern ref6_start; ! 432: extern ref7_start; ! 433: extern ref8_start; ! 434: ! 435: ! 436: extern boolean debugscreenactive; ! 437: ! 438: void R_RenderPlayerView (void) ! 439: { ! 440: ! 441: /* make sure its done now */ ! 442: #ifdef JAGUAR ! 443: while (!I_RefreshCompleted ()) ! 444: ; ! 445: #endif ! 446: ! 447: /* */ ! 448: /* initial setup */ ! 449: /* */ ! 450: if (debugscreenactive) ! 451: R_DebugScreen (); ! 452: ! 453: R_Setup (); ! 454: ! 455: #ifndef JAGUAR ! 456: R_BSP (); ! 457: R_WallPrep (); ! 458: R_SpritePrep (); ! 459: /* the rest of the refresh can be run in parallel with the next game tic */ ! 460: if (R_LatePrep ()) ! 461: R_Cache (); ! 462: R_SegCommands (); ! 463: R_DrawPlanes (); ! 464: R_Sprites (); ! 465: R_Update (); ! 466: #else ! 467: ! 468: /* start the gpu running the refresh */ ! 469: phasetime[1] = 0; ! 470: phasetime[2] = 0; ! 471: phasetime[3] = 0; ! 472: phasetime[4] = 0; ! 473: phasetime[5] = 0; ! 474: phasetime[6] = 0; ! 475: phasetime[7] = 0; ! 476: phasetime[8] = 0; ! 477: gpufinished = zero; ! 478: gpucodestart = (int)&ref1_start; ! 479: ! 480: #if 0 ! 481: while (!I_RefreshCompleted () ) ! 482: ; /* wait for refresh to latch all needed data before */ ! 483: /* running the next tick */ ! 484: #endif ! 485: ! 486: #endif ! 487: } ! 488:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.