2 //**************************************************************************
4 //** r_local.h : Heretic 2 : Raven Software, Corp.
11 //**************************************************************************
16 #define ANGLETOSKYSHIFT 22 // sky map is 256*128*4 maps
18 #define BASEYCENTER 100
23 #define PI 3.141592657
25 #define CENTERY (SCREENHEIGHT/2)
27 #define MINZ (FRACUNIT*4)
29 #define FIELDOFVIEW 2048 // fineangles in the SCREENWIDTH wide window
34 #define LIGHTLEVELS 16
35 #define LIGHTSEGSHIFT 4
36 #define MAXLIGHTSCALE 48
37 #define LIGHTSCALESHIFT 12
39 #define LIGHTZSHIFT 20
40 #define NUMCOLORMAPS 32 // number of diminishing
41 #define INVERSECOLORMAP 32
44 ==============================================================================
48 ==============================================================================
51 //================ used by play and refresh
62 fixed_t floorheight, ceilingheight;
63 short floorpic, ceilingpic;
67 int soundtraversed; // 0 = untraversed, 1,2 = sndlines -1
68 mobj_t *soundtarget; // thing that made a sound (or null)
69 seqtype_t seqType; // stone, metal, heavy, etc...
71 int blockbox[4]; // mapblock bounding box for height changes
72 degenmobj_t soundorg; // for any sounds played by the sector
73 int validcount; // if == validcount, already checked
74 mobj_t *thinglist; // list of mobjs in sector
75 void *specialdata; // thinker_t for reversable actions
77 struct line_s **lines; // [linecount] size
80 int flatoffx, flatoffy; // Scrolling flats.
81 int skyfix; // Offset to ceiling height rendering w/sky.
88 fixed_t textureoffset; // add this to the calculated texture col
89 fixed_t rowoffset; // add this to the calculated texture top
90 short toptexture, bottomtexture, midtexture;
103 typedef struct line_s
106 fixed_t dx,dy; // v2 - v1 for side checking
109 short sidenum[2]; // sidenum[1] will be -1 if one sided
111 slopetype_t slopetype; // to aid move clipping
112 sector_t *frontsector, *backsector;
113 int validcount; // if == validcount, already checked
114 void *specialdata; // thinker_t for reversable actions
118 typedef struct line_s
133 slopetype_t slopetype;
134 sector_t *frontsector;
135 sector_t *backsector;
147 sector_t *frontsector;
148 sector_t *backsector; // NULL for one sided lines
151 float len; // Length of the segment (v1 -> v2) for texture mapping.
156 // ===== Polyobj data =====
161 degenmobj_t startSpot;
162 vertex_t *originalPts; // used as the base for the rotations
163 vertex_t *prevPts; // use to restore the old point values
165 int tag; // reference tag assigned in HereticEd
168 boolean crush; // should the polyobj attempt to crush mobjs?
170 fixed_t size; // polyobj size (area of POLY_AREAUNIT == size of FRACUNIT)
171 void *specialdata; // pointer a thinker, if the poly is moving
174 typedef struct polyblock_s
177 struct polyblock_s *prev;
178 struct polyblock_s *next;
190 typedef struct subsector_s
198 // Sorted edge vertices for rendering floors and ceilings.
200 fvertex_t* edgeverts; // A list of edge vertices.
201 fvertex_t* origedgeverts; // Unmodified, accurate edge vertices.
202 fvertex_t bbox[2]; // Min and max points.
203 fvertex_t midpoint; // Center of bounding box.
210 fixed_t x,y,dx,dy; // partition line
211 fixed_t bbox[2][4]; // bounding box for each child
212 unsigned short children[2]; // if NF_SUBSECTOR its a subsector
217 ==============================================================================
221 ==============================================================================
224 typedef byte lighttable_t; // this could be wider for >8 bit display
226 #define MAXVISPLANES 160
227 #define MAXOPENINGS SCREENWIDTH*64
236 byte pad1; // leave pads for [minx-1]/[maxx+1]
237 byte top[SCREENWIDTH];
240 byte bottom[SCREENWIDTH];
244 typedef struct drawseg_s
248 fixed_t scale1, scale2, scalestep;
249 int silhouette; // 0=none, 1=bottom, 2=top, 3=both
250 fixed_t bsilheight; // don't clip sprites above this
251 fixed_t tsilheight; // don't clip sprites below this
252 // pointers to lists for sprite clipping
253 short *sprtopclip; // adjusted so [x1] is first value
254 short *sprbottomclip; // adjusted so [x1] is first value
255 short *maskedtexturecol; // adjusted so [x1] is first value
263 #define MAXDRAWSEGS 256
265 // A vissprite_t is a thing that will be drawn during a refresh
266 typedef struct vissprite_s
268 struct vissprite_s *prev, *next;
270 fixed_t gx, gy; // for line side calculation
271 fixed_t gz, gzt; // global bottom / top for silhouette clipping
272 fixed_t startfrac; // horizontal position of x1
274 fixed_t xiscale; // negative if flipped
279 float v1[2], v2[2]; // The vertices (v1 is the left one).
280 float secfloor, secceil;
282 lighttable_t *colormap;
284 int mobjflags; // for color translation and shadow draw
285 boolean psprite; // true if psprite
286 int class; // player class (used in translation)
291 extern visplane_t *floorplane, *ceilingplane;
293 // Sprites are patches with a special naming convention so they can be
294 // recognized by R_InitSprites. The sprite and frame specified by a
295 // thing_t is range checked at run time.
296 // a sprite is a patch_t that is assumed to represent a three dimensional
297 // object and may have multiple rotations pre drawn. Horizontal flipping
298 // is used to save space. Some sprites will only have one picture used
303 boolean rotate; // if false use 0 for any position
304 short lump[8]; // lump to use for view angles 0-7
305 byte flip[8]; // flip (1 = flip) to use for view angles 0-7
311 spriteframe_t *spriteframes;
314 extern spritedef_t *sprites;
315 extern int numsprites;
317 //=============================================================================
319 extern int numvertexes;
320 extern vertex_t *vertexes;
325 extern int numsectors;
326 extern sector_t *sectors;
328 extern int numsubsectors;
329 extern subsector_t *subsectors;
332 extern node_t *nodes;
335 extern line_t *lines;
338 extern side_t *sides;
342 extern fixed_t viewx, viewy, viewz;
343 extern angle_t viewangle;
344 extern player_t *viewplayer;
347 extern float viewpitch;
348 extern int sbarscale;
351 extern angle_t clipangle;
353 extern int viewangletox[FINEANGLES/2];
354 extern angle_t xtoviewangle[SCREENWIDTH+1];
355 extern fixed_t finetangent[FINEANGLES/2];
357 extern fixed_t rw_distance;
358 extern angle_t rw_normalangle;
363 extern int viewwidth, viewheight, viewwindowx, viewwindowy;
364 extern int centerx, centery;
365 extern int flyheight;
366 extern fixed_t centerxfrac;
367 extern fixed_t centeryfrac;
368 extern fixed_t projection;
370 extern int validcount;
372 extern int sscount, linecount, loopcount;
373 extern lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE];
374 extern lighttable_t *scalelightfixed[MAXLIGHTSCALE];
375 extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
377 extern int extralight;
378 extern lighttable_t *fixedcolormap;
380 extern fixed_t viewcos, viewsin;
382 extern int detailshift; // 0 = high, 1 = low
384 extern void (*colfunc) (void);
385 extern void (*basecolfunc) (void);
386 extern void (*fuzzcolfunc) (void);
387 extern void (*spanfunc) (void);
389 int R_PointOnSide (fixed_t x, fixed_t y, node_t *node);
390 int R_PointOnSegSide (fixed_t x, fixed_t y, seg_t *line);
391 angle_t R_PointToAngle (fixed_t x, fixed_t y);
392 angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2);
393 fixed_t R_PointToDist (fixed_t x, fixed_t y);
394 fixed_t R_ScaleFromGlobalAngle (angle_t visangle);
395 subsector_t *R_PointInSubsector (fixed_t x, fixed_t y);
396 //void R_AddPointToBox (int x, int y, fixed_t *box);
402 extern seg_t *curline;
403 extern side_t *sidedef;
404 extern line_t *linedef;
405 extern sector_t *frontsector, *backsector;
410 extern boolean segtextured;
411 extern boolean markfloor; // false if the back side is the same plane
412 extern boolean markceiling;
413 extern boolean skymap;
415 extern drawseg_t drawsegs[MAXDRAWSEGS], *ds_p;
417 extern lighttable_t **hscalelight, **vscalelight, **dscalelight;
419 typedef void (*drawfunc_t) (int start, int stop);
420 void R_ClearClipSegs (void);
422 void R_ClearDrawSegs (void);
423 void R_InitSkyMap (void);
424 void R_RenderBSPNode (int bspnum);
429 extern int rw_angle1; // angle to line origin
430 extern int TransTextureStart;
431 extern int TransTextureEnd;
433 void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2);
438 typedef void (*planefunction_t) (int top, int bottom);
439 extern planefunction_t floorfunc, ceilingfunc;
441 extern int skyflatnum;
443 extern short openings[MAXOPENINGS], *lastopening;
445 extern short floorclip[SCREENWIDTH];
446 extern short ceilingclip[SCREENWIDTH];
448 extern fixed_t yslope[SCREENHEIGHT];
449 extern fixed_t distscale[SCREENWIDTH];
451 void R_InitPlanes (void);
452 void R_ClearPlanes (void);
453 void R_MapPlane (int y, int x1, int x2);
454 void R_MakeSpans (int x, int t1, int b1, int t2, int b2);
455 void R_DrawPlanes (void);
457 visplane_t *R_FindPlane (fixed_t height, int picnum, int lightlevel,
459 visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop);
467 void RD_OpenMapWindow (void);
468 void RD_ClearMapWindow (void);
469 void RD_DisplayLine (int x1, int y1, int x2, int y2, float gray);
470 void RD_DrawNodeLine (node_t *node);
471 void RD_DrawLineCheck (seg_t *line);
472 void RD_DrawLine (seg_t *line);
473 void RD_DrawBBox (fixed_t *bbox);
482 int originx; // block origin (allways UL), which has allready
483 int originy; // accounted for the patch's internal origin
487 // a maptexturedef_t describes a rectangular texture, which is composed of one
488 // or more mappatch_t structures that arrange graphic patches
491 char name[8]; // for switch changing, etc
495 texpatch_t patches[1]; // [patchcount] drawn back to front
496 // into the cached texture
498 boolean masked; // from maptexture_t
503 extern fixed_t *textureheight; // needed for texture pegging
504 extern fixed_t *spritewidth; // needed for pre rendering (fracs)
505 extern fixed_t *spriteoffset;
506 extern fixed_t *spritetopoffset;
507 extern lighttable_t *colormaps;
508 extern int viewwidth, scaledviewwidth, viewheight;
509 extern int firstflat;
512 extern int *flattranslation; // for global animation
513 extern int *texturetranslation; // for global animation
515 extern int firstspritelump, lastspritelump, numspritelumps;
516 extern boolean LevelUseFullBright;
518 byte *R_GetColumn (int tex, int col);
519 void R_InitData (void);
520 void R_PrecacheLevel (void);
526 #define MAXVISSPRITES 192
528 extern vissprite_t vissprites[MAXVISSPRITES], *vissprite_p;
529 extern vissprite_t vsprsortedhead;
531 // constant arrays used for psprite clipping and initializing clipping
532 extern short negonearray[SCREENWIDTH];
533 extern short screenheightarray[SCREENWIDTH];
535 // vars for R_DrawMaskedColumn
536 extern short *mfloorclip;
537 extern short *mceilingclip;
538 extern fixed_t spryscale;
539 extern fixed_t sprtopscreen;
540 extern fixed_t sprbotscreen;
542 extern fixed_t pspritescale, pspriteiscale;
545 void R_DrawMaskedColumn (column_t *column, signed int baseclip);
548 void R_SortVisSprites (void);
550 void R_AddSprites (sector_t *sec);
551 void R_AddPSprites (void);
552 void R_DrawSprites (void);
553 void R_InitSprites (char **namelist);
554 void R_ClearSprites (void);
555 void R_DrawMasked (void);
556 void R_ClipVisSprite (vissprite_t *vis, int xl, int xh);
558 //=============================================================================
562 //=============================================================================
564 extern lighttable_t *dc_colormap;
568 extern fixed_t dc_iscale;
569 extern fixed_t dc_texturemid;
570 extern byte *dc_source; // first pixel in a column
572 void R_DrawColumn (void);
573 void R_DrawColumnLow (void);
574 void R_DrawFuzzColumn (void);
575 void R_DrawFuzzColumnLow (void);
576 void R_DrawTranslatedColumn (void);
577 void R_DrawTranslatedFuzzColumn (void);
578 void R_DrawTranslatedColumnLow (void);
579 void R_DrawAltFuzzColumn(void);
580 //void R_DrawTranslatedAltFuzzColumn(void);
585 extern lighttable_t *ds_colormap;
586 extern fixed_t ds_xfrac;
587 extern fixed_t ds_yfrac;
588 extern fixed_t ds_xstep;
589 extern fixed_t ds_ystep;
590 extern byte *ds_source; // start of a 64*64 tile image
592 extern byte *translationtables;
593 extern byte *dc_translation;
595 void R_DrawSpan (void);
596 void R_DrawSpanLow (void);
598 void R_InitBuffer (int width, int height);
599 void R_InitTranslationTables (void);
601 #endif // __R_LOCAL__