]> icculus.org git repositories - theoddone33/hheretic.git/blob - include/r_local.h
Optimized blit functions.
[theoddone33/hheretic.git] / include / r_local.h
1 // R_local.h
2
3 #ifndef __R_LOCAL__
4 #define __R_LOCAL__
5
6 #define ANGLETOSKYSHIFT         22              // sky map is 256*128*4 maps
7
8 #define BASEYCENTER                     100
9
10 #define MAXWIDTH                        1120
11 #define MAXHEIGHT                       832
12
13 #define PI                                      3.141592657
14
15 #define CENTERY                         (SCREENHEIGHT/2)
16
17 #define MINZ                    (FRACUNIT*4)
18
19 #define FIELDOFVIEW             2048    // fineangles in the SCREENWIDTH wide window
20
21 //
22 // lighting constants
23 //
24 #define LIGHTLEVELS                     16
25 #define LIGHTSEGSHIFT           4
26 #define MAXLIGHTSCALE           48
27 #define LIGHTSCALESHIFT         12
28 #define MAXLIGHTZ                       128
29 #define LIGHTZSHIFT                     20
30 #define NUMCOLORMAPS            32              // number of diminishing
31 #define INVERSECOLORMAP         32
32
33 /*
34 ==============================================================================
35
36                                         INTERNAL MAP TYPES
37
38 ==============================================================================
39 */
40
41 //================ used by play and refresh
42
43 typedef struct
44 {
45         fixed_t         x,y;
46 } vertex_t;
47
48 struct line_s;
49
50 typedef struct
51 {
52         fixed_t         floorheight, ceilingheight;
53         short           floorpic, ceilingpic;
54         short           lightlevel;
55         short           special, tag;
56
57         int                     soundtraversed;         // 0 = untraversed, 1,2 = sndlines -1
58         mobj_t          *soundtarget;           // thing that made a sound (or null)
59         
60         int                     blockbox[4];            // mapblock bounding box for height changes
61         degenmobj_t     soundorg;                       // for any sounds played by the sector
62
63         int                     validcount;                     // if == validcount, already checked
64         mobj_t          *thinglist;                     // list of mobjs in sector
65         void            *specialdata;           // thinker_t for reversable actions
66         int                     linecount;
67         struct line_s   **lines;                        // [linecount] size
68 #ifdef RENDER3D
69     int     flatoffx, flatoffy;     // Scrolling flats.
70     int     skyfix;                 // Offset to ceiling height rendering w/sky.
71 #endif
72 } sector_t;
73
74 typedef struct
75 {
76         fixed_t         textureoffset;          // add this to the calculated texture col
77         fixed_t         rowoffset;                      // add this to the calculated texture top
78         short           toptexture, bottomtexture, midtexture;
79         sector_t        *sector;
80 } side_t;
81
82 typedef enum {ST_HORIZONTAL, ST_VERTICAL, ST_POSITIVE, ST_NEGATIVE} slopetype_t;
83
84 typedef struct line_s
85 {
86         vertex_t        *v1, *v2;
87         fixed_t         dx,dy;                          // v2 - v1 for side checking
88         short           flags;
89         short           special, tag;
90         short           sidenum[2];                     // sidenum[1] will be -1 if one sided
91         fixed_t         bbox[4];
92         slopetype_t     slopetype;                      // to aid move clipping
93         sector_t        *frontsector, *backsector;
94         int                     validcount;                     // if == validcount, already checked
95         void            *specialdata;           // thinker_t for reversable actions
96 } line_t;
97
98 #ifdef RENDER3D
99 typedef struct
100 {
101     float x, y;
102 } fvertex_t;
103 #endif
104
105 typedef struct subsector_s
106 {
107         sector_t        *sector;
108         short           numlines;
109         short           firstline;
110 #ifdef RENDER3D
111     // Sorted edge vertices for rendering floors and ceilings.
112     char numedgeverts;
113     fvertex_t* edgeverts;     // A list of edge vertices.
114     fvertex_t* origedgeverts; // Unmodified, accurate edge vertices.
115     fvertex_t bbox[2];        // Min and max points.
116     fvertex_t midpoint;       // Center of bounding box.
117 #endif
118
119 } subsector_t;
120
121 typedef struct
122 {
123         vertex_t        *v1, *v2;
124         fixed_t         offset;
125         angle_t         angle;
126         side_t          *sidedef;
127         line_t          *linedef;
128         sector_t        *frontsector;
129         sector_t        *backsector;            // NULL for one sided lines
130 #ifdef RENDER3D
131     float len;  // Length of the segment (v1 -> v2) for texture mapping.
132 #endif
133
134 } seg_t;
135
136 typedef struct
137 {
138         fixed_t         x,y,dx,dy;                      // partition line
139         fixed_t         bbox[2][4];                     // bounding box for each child
140         unsigned short  children[2];            // if NF_SUBSECTOR its a subsector
141 } node_t;
142
143 typedef struct
144 {
145         int             originx;        // block origin (allways UL), which has allready
146         int             originy;        // accounted  for the patch's internal origin
147         int             patch;
148 } texpatch_t;
149
150 // a maptexturedef_t describes a rectangular texture, which is composed of one
151 // or more mappatch_t structures that arrange graphic patches
152 typedef struct
153 {
154         char            name[8];                // for switch changing, etc
155         short           width;
156         short           height;
157         short           patchcount;
158         texpatch_t      patches[1];             // [patchcount] drawn back to front
159                                                                 //  into the cached texture
160 #ifdef RENDER3D
161         boolean     masked;         // from maptexture_t
162 #endif
163 } texture_t;
164
165 /*
166 ==============================================================================
167
168                                                 OTHER TYPES
169
170 ==============================================================================
171 */
172
173 typedef byte    lighttable_t;           // this could be wider for >8 bit display
174
175 #define MAXVISPLANES    128
176 #define MAXOPENINGS             SCREENWIDTH*64
177
178 typedef struct
179 {
180         fixed_t         height;
181         int                     picnum;
182         int                     lightlevel;
183         int                     special;
184         int                     minx, maxx;
185         byte            pad1;                                           // leave pads for [minx-1]/[maxx+1]
186         byte            top[SCREENWIDTH];
187         byte            pad2;
188         byte            pad3;
189         byte            bottom[SCREENWIDTH];
190         byte            pad4;
191 } visplane_t;
192
193 typedef struct drawseg_s
194 {
195         seg_t           *curline;
196         int                     x1, x2;
197         fixed_t         scale1, scale2, scalestep;
198         int                     silhouette;                     // 0=none, 1=bottom, 2=top, 3=both
199         fixed_t         bsilheight;                     // don't clip sprites above this
200         fixed_t         tsilheight;                     // don't clip sprites below this
201 // pointers to lists for sprite clipping
202         short           *sprtopclip;            // adjusted so [x1] is first value
203         short           *sprbottomclip;         // adjusted so [x1] is first value
204         short           *maskedtexturecol;      // adjusted so [x1] is first value
205 } drawseg_t;
206
207 #define SIL_NONE        0
208 #define SIL_BOTTOM      1
209 #define SIL_TOP         2
210 #define SIL_BOTH        3
211
212 #define MAXDRAWSEGS             256
213
214 // A vissprite_t is a thing that will be drawn during a refresh
215 typedef struct vissprite_s
216 {
217         struct vissprite_s      *prev, *next;
218         int                     x1, x2;
219         fixed_t         gx, gy;                 // for line side calculation
220         fixed_t         gz, gzt;                // global bottom / top for silhouette clipping
221         fixed_t         startfrac;              // horizontal position of x1
222         fixed_t         scale;
223         fixed_t         xiscale;                // negative if flipped
224         fixed_t         texturemid;
225         int                     patch;
226 #ifdef RENDER3D
227     int             lightlevel;
228     float           v1[2], v2[2];       // The vertices (v1 is the left one).
229     float           secfloor, secceil;
230 #else
231         lighttable_t    *colormap;
232 #endif
233         int                     mobjflags;              // for color translation and shadow draw
234         boolean         psprite;                // true if psprite
235         fixed_t         footclip;               // foot clipping
236 } vissprite_t;
237
238
239 extern  visplane_t      *floorplane, *ceilingplane;
240         
241 // Sprites are patches with a special naming convention so they can be 
242 // recognized by R_InitSprites.  The sprite and frame specified by a 
243 // thing_t is range checked at run time.
244 // a sprite is a patch_t that is assumed to represent a three dimensional
245 // object and may have multiple rotations pre drawn.  Horizontal flipping 
246 // is used to save space. Some sprites will only have one picture used
247 // for all views.  
248
249 typedef struct
250 {
251         boolean         rotate;         // if false use 0 for any position
252         short           lump[8];        // lump to use for view angles 0-7
253         byte            flip[8];        // flip (1 = flip) to use for view angles 0-7
254 } spriteframe_t;
255
256 typedef struct
257 {
258         int                             numframes;
259         spriteframe_t   *spriteframes;
260 } spritedef_t;
261
262 extern  spritedef_t             *sprites;
263 extern  int                             numsprites;
264
265 //=============================================================================
266
267 extern  int                     numvertexes;
268 extern  vertex_t        *vertexes;
269
270 extern  int                     numsegs;
271 extern  seg_t           *segs;
272
273 extern  int                     numsectors;
274 extern  sector_t        *sectors;
275
276 extern  int                     numsubsectors;
277 extern  subsector_t     *subsectors;
278
279 extern  int                     numnodes;
280 extern  node_t          *nodes;
281
282 extern  int                     numlines;
283 extern  line_t          *lines;
284
285 extern  int                     numsides;
286 extern  side_t          *sides;
287
288
289
290 extern  fixed_t         viewx, viewy, viewz;
291 extern  angle_t         viewangle;
292 extern  player_t        *viewplayer;
293
294 #ifdef RENDER3D
295 extern  float           viewpitch;
296 extern  int             sbarscale;
297 #endif
298
299 extern  angle_t         clipangle;
300
301 extern  int                     viewangletox[FINEANGLES/2];
302 extern  angle_t         xtoviewangle[SCREENWIDTH+1];
303 extern  fixed_t         finetangent[FINEANGLES/2];
304
305 extern  fixed_t         rw_distance;
306 extern  angle_t         rw_normalangle;
307
308 //
309 // R_main.c
310 //
311 extern  int                             viewwidth, viewheight, viewwindowx, viewwindowy;
312 extern  int                             centerx, centery;
313 extern  int                             flyheight;
314 extern  fixed_t                 centerxfrac;
315 extern  fixed_t                 centeryfrac;
316 extern  fixed_t                 projection;
317
318 extern  int                             validcount;
319
320 extern  int                             sscount, linecount, loopcount;
321 extern  lighttable_t    *scalelight[LIGHTLEVELS][MAXLIGHTSCALE];
322 extern  lighttable_t    *scalelightfixed[MAXLIGHTSCALE];
323 extern  lighttable_t    *zlight[LIGHTLEVELS][MAXLIGHTZ];
324
325 extern  int                             extralight;
326 extern  lighttable_t    *fixedcolormap;
327
328 extern  fixed_t                 viewcos, viewsin;
329
330 extern  int                             detailshift;            // 0 = high, 1 = low
331
332 extern  void            (*colfunc) (void);
333 extern  void            (*basecolfunc) (void);
334 extern  void            (*fuzzcolfunc) (void);
335 extern  void            (*spanfunc) (void);
336
337 int             R_PointOnSide (fixed_t x, fixed_t y, node_t *node);
338 int             R_PointOnSegSide (fixed_t x, fixed_t y, seg_t *line);
339 angle_t R_PointToAngle (fixed_t x, fixed_t y);
340 angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2);
341 fixed_t R_PointToDist (fixed_t x, fixed_t y);
342 fixed_t R_ScaleFromGlobalAngle (angle_t visangle);
343 subsector_t *R_PointInSubsector (fixed_t x, fixed_t y);
344 void R_AddPointToBox (int x, int y, fixed_t *box);
345
346
347 //
348 // R_bsp.c
349 //
350 extern  seg_t           *curline;
351 extern  side_t  *sidedef;
352 extern  line_t  *linedef;
353 extern  sector_t        *frontsector, *backsector;
354
355 extern  int     rw_x;
356 extern  int     rw_stopx;
357
358 extern  boolean         segtextured;
359 extern  boolean         markfloor;              // false if the back side is the same plane
360 extern  boolean         markceiling;
361 extern  boolean         skymap;
362
363 extern  drawseg_t       drawsegs[MAXDRAWSEGS], *ds_p;
364
365 extern  lighttable_t    **hscalelight, **vscalelight, **dscalelight;
366
367 typedef void (*drawfunc_t) (int start, int stop);
368 void R_ClearClipSegs (void);
369
370 void R_ClearDrawSegs (void);
371 void R_InitSkyMap (void);
372 void R_RenderBSPNode (int bspnum);
373
374 //
375 // R_segs.c
376 //
377 extern  int                     rw_angle1;              // angle to line origin
378
379 void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2);
380
381
382 //
383 // R_plane.c
384 //
385 typedef void (*planefunction_t) (int top, int bottom);
386 extern  planefunction_t         floorfunc, ceilingfunc;
387
388 extern  int                     skyflatnum;
389
390 extern  short                   openings[MAXOPENINGS], *lastopening;
391
392 extern  short           floorclip[SCREENWIDTH];
393 extern  short           ceilingclip[SCREENWIDTH];
394
395 extern  fixed_t         yslope[SCREENHEIGHT];
396 extern  fixed_t         distscale[SCREENWIDTH];
397
398 void R_InitPlanes (void);
399 void R_ClearPlanes (void);
400 void R_MapPlane (int y, int x1, int x2);
401 void R_MakeSpans (int x, int t1, int b1, int t2, int b2);
402 void R_DrawPlanes (void);
403
404 visplane_t *R_FindPlane (fixed_t height, int picnum, int lightlevel,
405         int special);
406 visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop);
407
408
409 //
410 // R_debug.m
411 //
412 extern  int     drawbsp;
413
414 void RD_OpenMapWindow (void);
415 void RD_ClearMapWindow (void);
416 void RD_DisplayLine (int x1, int y1, int x2, int y2, float gray);
417 void RD_DrawNodeLine (node_t *node);
418 void RD_DrawLineCheck (seg_t *line);
419 void RD_DrawLine (seg_t *line);
420 void RD_DrawBBox (fixed_t *bbox);
421
422
423 //
424 // R_data.c
425 //
426 extern  fixed_t         *textureheight;         // needed for texture pegging
427 extern  fixed_t         *spritewidth;           // needed for pre rendering (fracs)
428 extern  fixed_t         *spriteoffset;
429 extern  fixed_t         *spritetopoffset;
430 extern  lighttable_t    *colormaps;
431 extern  int             viewwidth, scaledviewwidth, viewheight;
432 extern  int                     firstflat;
433 extern  int                     numflats;
434
435 extern  int                     *flattranslation;               // for global animation
436 extern  int                     *texturetranslation;    // for global animation
437
438 extern  int             firstspritelump, lastspritelump, numspritelumps;
439
440 byte    *R_GetColumn (int tex, int col);
441 void    R_InitData (void);
442 void R_PrecacheLevel (void);
443
444
445 //
446 // R_things.c
447 //
448 #define MAXVISSPRITES   128
449
450 extern  vissprite_t     vissprites[MAXVISSPRITES], *vissprite_p;
451 extern  vissprite_t     vsprsortedhead;
452
453 // constant arrays used for psprite clipping and initializing clipping
454 extern  short   negonearray[SCREENWIDTH];
455 extern  short   screenheightarray[SCREENWIDTH];
456
457 // vars for R_DrawMaskedColumn
458 extern  short           *mfloorclip;
459 extern  short           *mceilingclip;
460 extern  fixed_t         spryscale;
461 extern  fixed_t         sprtopscreen;
462 extern  fixed_t         sprbotscreen;
463
464 extern  fixed_t         pspritescale, pspriteiscale;
465
466
467 void R_DrawMaskedColumn (column_t *column, signed int baseclip);
468
469
470 void    R_SortVisSprites (void);
471
472 void    R_AddSprites (sector_t *sec);
473 void    R_AddPSprites (void);
474 void    R_DrawSprites (void);
475 void    R_InitSprites (char **namelist);
476 void    R_ClearSprites (void);
477 void    R_DrawMasked (void);
478 void    R_ClipVisSprite (vissprite_t *vis, int xl, int xh);
479
480 //=============================================================================
481 //
482 // R_draw.c
483 //
484 //=============================================================================
485
486 extern  lighttable_t    *dc_colormap;
487 extern  int                             dc_x;
488 extern  int                             dc_yl;
489 extern  int                             dc_yh;
490 extern  fixed_t                 dc_iscale;
491 extern  fixed_t                 dc_texturemid;
492 extern  byte                    *dc_source;             // first pixel in a column
493
494 void    R_DrawColumn (void);
495 void    R_DrawColumnLow (void);
496 void    R_DrawFuzzColumn (void);
497 void    R_DrawFuzzColumnLow (void);
498 void    R_DrawTranslatedColumn (void);
499 void    R_DrawTranslatedFuzzColumn (void);
500 void    R_DrawTranslatedColumnLow (void);
501
502 extern  int                             ds_y;
503 extern  int                             ds_x1;
504 extern  int                             ds_x2;
505 extern  lighttable_t    *ds_colormap;
506 extern  fixed_t                 ds_xfrac;
507 extern  fixed_t                 ds_yfrac;
508 extern  fixed_t                 ds_xstep;
509 extern  fixed_t                 ds_ystep;
510 extern  byte                    *ds_source;             // start of a 64*64 tile image
511
512 extern  byte    *translationtables;
513 extern  byte    *dc_translation;
514
515 void    R_DrawSpan (void);
516 void    R_DrawSpanLow (void);
517
518 void    R_InitBuffer (int width, int height);
519 void    R_InitTranslationTables (void);
520
521 #endif          // __R_LOCAL__
522