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