]> icculus.org git repositories - theoddone33/hhexen.git/blob - include/r_local.h
osezer patch 009
[theoddone33/hhexen.git] / include / r_local.h
1
2 //**************************************************************************
3 //**
4 //** r_local.h : Heretic 2 : Raven Software, Corp.
5 //**
6 //** $RCSfile$
7 //** $Revision$
8 //** $Date$
9 //** $Author$
10 //**
11 //**************************************************************************
12
13 #ifndef __R_LOCAL__
14 #define __R_LOCAL__
15
16 #define ANGLETOSKYSHIFT         22              // sky map is 256*128*4 maps
17
18 #define BASEYCENTER                     100
19
20 #define MAXWIDTH                        1120
21 #define MAXHEIGHT                       832
22
23 #define PI                                      3.141592657
24
25 #define CENTERY                         (SCREENHEIGHT/2)
26
27 #define MINZ                    (FRACUNIT*4)
28
29 #define FIELDOFVIEW             2048    // fineangles in the SCREENWIDTH wide window
30
31 //
32 // lighting constants
33 //
34 #define LIGHTLEVELS                     16
35 #define LIGHTSEGSHIFT           4
36 #define MAXLIGHTSCALE           48
37 #define LIGHTSCALESHIFT         12
38 #define MAXLIGHTZ                       128
39 #define LIGHTZSHIFT                     20
40 #define NUMCOLORMAPS            32              // number of diminishing
41 #define INVERSECOLORMAP         32
42
43 /*
44 ==============================================================================
45
46                                         INTERNAL MAP TYPES
47
48 ==============================================================================
49 */
50
51 //================ used by play and refresh
52
53 typedef struct
54 {
55         fixed_t         x,y;
56 } vertex_t;
57
58 struct line_s;
59
60 typedef struct
61 {
62         fixed_t floorheight, ceilingheight;
63         short   floorpic, ceilingpic;
64         short   lightlevel;
65         short   special, tag;
66
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...
70
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
76         int     linecount;
77         struct line_s **lines;        // [linecount] size
78
79 #ifdef RENDER3D
80     int     flatoffx, flatoffy;     // Scrolling flats.
81     int     skyfix;                 // Offset to ceiling height rendering w/sky.
82 #endif
83
84 } sector_t;
85
86 typedef struct
87 {
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;
91         sector_t        *sector;
92 } side_t;
93
94 typedef enum
95 {
96         ST_HORIZONTAL,
97         ST_VERTICAL,
98         ST_POSITIVE,
99         ST_NEGATIVE
100 } slopetype_t;
101
102 /*
103 typedef struct line_s
104 {
105         vertex_t        *v1, *v2;
106         fixed_t         dx,dy;                          // v2 - v1 for side checking
107         short           flags;
108         short           special, tag;
109         short           sidenum[2];                     // sidenum[1] will be -1 if one sided
110         fixed_t         bbox[4];
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
115 } line_t;
116 */
117
118 typedef struct line_s
119 {
120         vertex_t *v1;
121         vertex_t *v2;
122         fixed_t dx;
123         fixed_t dy;
124         short flags;
125         byte special;
126         byte arg1;
127         byte arg2;
128         byte arg3;
129         byte arg4;
130         byte arg5;
131         short sidenum[2];
132         fixed_t bbox[4];
133         slopetype_t slopetype;
134         sector_t *frontsector;
135         sector_t *backsector;
136         int validcount;
137         void *specialdata;
138 } line_t;
139
140 typedef struct
141 {
142         vertex_t        *v1, *v2;
143         fixed_t         offset;
144         angle_t         angle;
145         side_t          *sidedef;
146         line_t          *linedef;
147         sector_t        *frontsector;
148         sector_t        *backsector;            // NULL for one sided lines
149
150 #ifdef RENDER3D
151     float len;  // Length of the segment (v1 -> v2) for texture mapping.
152 #endif
153
154 } seg_t;
155
156 // ===== Polyobj data =====
157 typedef struct
158 {
159         int numsegs;
160         seg_t **segs;
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
164         angle_t angle;
165         int tag;                                                // reference tag assigned in HereticEd
166         int bbox[4];
167         int validcount;
168         boolean crush;                  // should the polyobj attempt to crush mobjs?
169         int seqType;
170         fixed_t size; // polyobj size (area of POLY_AREAUNIT == size of FRACUNIT)
171         void *specialdata; // pointer a thinker, if the poly is moving
172 } polyobj_t;
173
174 typedef struct polyblock_s
175 {
176         polyobj_t *polyobj;
177         struct polyblock_s *prev;
178         struct polyblock_s *next;
179 } polyblock_t;
180
181
182 #ifdef RENDER3D
183 typedef struct
184 {
185     float x, y;
186 } fvertex_t;
187 #endif
188
189
190 typedef struct subsector_s
191 {
192         sector_t        *sector;
193         short           numlines;
194         short           firstline;
195         polyobj_t *poly;
196     
197 #ifdef RENDER3D
198     // Sorted edge vertices for rendering floors and ceilings.
199     char numedgeverts;
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.
204 #endif
205
206 } subsector_t;
207
208 typedef struct
209 {
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
213 } node_t;
214
215
216 /*
217 ==============================================================================
218
219                                                 OTHER TYPES
220
221 ==============================================================================
222 */
223
224 typedef byte    lighttable_t;           // this could be wider for >8 bit display
225
226 #define MAXVISPLANES    160
227 #define MAXOPENINGS             SCREENWIDTH*64
228
229 typedef struct
230 {
231         fixed_t         height;
232         int                     picnum;
233         int                     lightlevel;
234         int                     special;
235         int                     minx, maxx;
236         byte            pad1;                                           // leave pads for [minx-1]/[maxx+1]
237         byte            top[SCREENWIDTH];
238         byte            pad2;
239         byte            pad3;
240         byte            bottom[SCREENWIDTH];
241         byte            pad4;
242 } visplane_t;
243
244 typedef struct drawseg_s
245 {
246         seg_t           *curline;
247         int                     x1, x2;
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
256 } drawseg_t;
257
258 #define SIL_NONE        0
259 #define SIL_BOTTOM      1
260 #define SIL_TOP         2
261 #define SIL_BOTH        3
262
263 #define MAXDRAWSEGS             256
264
265 // A vissprite_t is a thing that will be drawn during a refresh
266 typedef struct vissprite_s
267 {
268         struct vissprite_s      *prev, *next;
269         int                     x1, x2;
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
273         fixed_t         scale;
274         fixed_t         xiscale;                // negative if flipped
275         fixed_t         texturemid;
276         int                     patch;
277 #ifdef RENDER3D
278     int             lightlevel;
279     float           v1[2], v2[2];       // The vertices (v1 is the left one).
280     float           secfloor, secceil;
281 #else
282         lighttable_t    *colormap;
283 #endif
284         int             mobjflags;        // for color translation and shadow draw
285         boolean         psprite;                // true if psprite
286         int                             class;                  // player class (used in translation)
287         fixed_t         floorclip;               
288 } vissprite_t;
289
290
291 extern  visplane_t      *floorplane, *ceilingplane;
292
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
299 // for all views.
300
301 typedef struct
302 {
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
306 } spriteframe_t;
307
308 typedef struct
309 {
310         int                             numframes;
311         spriteframe_t   *spriteframes;
312 } spritedef_t;
313
314 extern  spritedef_t             *sprites;
315 extern  int                             numsprites;
316
317 //=============================================================================
318
319 extern  int                     numvertexes;
320 extern  vertex_t        *vertexes;
321
322 extern  int                     numsegs;
323 extern  seg_t           *segs;
324
325 extern  int                     numsectors;
326 extern  sector_t        *sectors;
327
328 extern  int                     numsubsectors;
329 extern  subsector_t     *subsectors;
330
331 extern  int                     numnodes;
332 extern  node_t          *nodes;
333
334 extern  int                     numlines;
335 extern  line_t          *lines;
336
337 extern  int                     numsides;
338 extern  side_t          *sides;
339
340
341
342 extern  fixed_t         viewx, viewy, viewz;
343 extern  angle_t         viewangle;
344 extern  player_t        *viewplayer;
345
346 #ifdef RENDER3D
347 extern  float           viewpitch;
348 extern  int             sbarscale;
349 #endif
350
351 extern  angle_t         clipangle;
352
353 extern  int                     viewangletox[FINEANGLES/2];
354 extern  angle_t         xtoviewangle[SCREENWIDTH+1];
355 extern  fixed_t         finetangent[FINEANGLES/2];
356
357 extern  fixed_t         rw_distance;
358 extern  angle_t         rw_normalangle;
359
360 //
361 // R_main.c
362 //
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;
369
370 extern  int                             validcount;
371
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];
376
377 extern  int                             extralight;
378 extern  lighttable_t    *fixedcolormap;
379
380 extern  fixed_t                 viewcos, viewsin;
381
382 extern  int                             detailshift;            // 0 = high, 1 = low
383
384 extern  void            (*colfunc) (void);
385 extern  void            (*basecolfunc) (void);
386 extern  void            (*fuzzcolfunc) (void);
387 extern  void            (*spanfunc) (void);
388
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);
397
398
399 //
400 // R_bsp.c
401 //
402 extern  seg_t           *curline;
403 extern  side_t  *sidedef;
404 extern  line_t  *linedef;
405 extern  sector_t        *frontsector, *backsector;
406
407 extern  int     rw_x;
408 extern  int     rw_stopx;
409
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;
414
415 extern  drawseg_t       drawsegs[MAXDRAWSEGS], *ds_p;
416
417 extern  lighttable_t    **hscalelight, **vscalelight, **dscalelight;
418
419 typedef void (*drawfunc_t) (int start, int stop);
420 void R_ClearClipSegs (void);
421
422 void R_ClearDrawSegs (void);
423 void R_InitSkyMap (void);
424 void R_RenderBSPNode (int bspnum);
425
426 //
427 // R_segs.c
428 //
429 extern  int                     rw_angle1;              // angle to line origin
430 extern int TransTextureStart;
431 extern int TransTextureEnd;
432
433 void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2);
434
435 //
436 // R_plane.c
437 //
438 typedef void (*planefunction_t) (int top, int bottom);
439 extern  planefunction_t         floorfunc, ceilingfunc;
440
441 extern  int                     skyflatnum;
442
443 extern  short                   openings[MAXOPENINGS], *lastopening;
444
445 extern  short           floorclip[SCREENWIDTH];
446 extern  short           ceilingclip[SCREENWIDTH];
447
448 extern  fixed_t         yslope[SCREENHEIGHT];
449 extern  fixed_t         distscale[SCREENWIDTH];
450
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);
456
457 visplane_t *R_FindPlane (fixed_t height, int picnum, int lightlevel,
458         int special);
459 visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop);
460
461
462 //
463 // R_debug.m
464 //
465 extern  int     drawbsp;
466
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);
474
475
476 //
477 // R_data.c
478 //
479
480 typedef struct
481 {
482     int     originx;    // block origin (allways UL), which has allready
483     int     originy;    // accounted  for the patch's internal origin
484     int     patch;
485 } texpatch_t;
486
487 // a maptexturedef_t describes a rectangular texture, which is composed of one
488 // or more mappatch_t structures that arrange graphic patches
489 typedef struct
490 {
491     char        name[8];        // for switch changing, etc
492     short       width;
493     short       height;
494     short       patchcount;
495     texpatch_t  patches[1];     // [patchcount] drawn back to front
496                                 //  into the cached texture
497 #ifdef RENDER3D
498     boolean     masked;         // from maptexture_t
499 #endif
500
501 } texture_t;
502
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;
510 extern  int                     numflats;
511
512 extern  int                     *flattranslation;               // for global animation
513 extern  int                     *texturetranslation;    // for global animation
514
515 extern  int             firstspritelump, lastspritelump, numspritelumps;
516 extern boolean LevelUseFullBright;
517
518 byte    *R_GetColumn (int tex, int col);
519 void    R_InitData (void);
520 void R_PrecacheLevel (void);
521
522
523 //
524 // R_things.c
525 //
526 #define MAXVISSPRITES   192
527
528 extern  vissprite_t     vissprites[MAXVISSPRITES], *vissprite_p;
529 extern  vissprite_t     vsprsortedhead;
530
531 // constant arrays used for psprite clipping and initializing clipping
532 extern  short   negonearray[SCREENWIDTH];
533 extern  short   screenheightarray[SCREENWIDTH];
534
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;
541
542 extern  fixed_t         pspritescale, pspriteiscale;
543
544
545 void R_DrawMaskedColumn (column_t *column, signed int baseclip);
546
547
548 void    R_SortVisSprites (void);
549
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);
557
558 //=============================================================================
559 //
560 // R_draw.c
561 //
562 //=============================================================================
563
564 extern  lighttable_t    *dc_colormap;
565 extern  int                             dc_x;
566 extern  int                             dc_yl;
567 extern  int                             dc_yh;
568 extern  fixed_t                 dc_iscale;
569 extern  fixed_t                 dc_texturemid;
570 extern  byte                    *dc_source;             // first pixel in a column
571
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);
581
582 extern  int                             ds_y;
583 extern  int                             ds_x1;
584 extern  int                             ds_x2;
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
591
592 extern  byte    *translationtables;
593 extern  byte    *dc_translation;
594
595 void    R_DrawSpan (void);
596 void    R_DrawSpanLow (void);
597
598 void    R_InitBuffer (int width, int height);
599 void    R_InitTranslationTables (void);
600
601 #endif          // __R_LOCAL__
602