1 2 //************************************************************************** 3 //** 4 //** r_local.h : Heretic 2 : Raven Software, Corp. 5 //** 6 //** $RCSfile: r_local.h,v $ 7 //** $Revision: 1.12 $ 8 //** $Date: 96/01/06 18:37:38 $ 9 //** $Author: bgokey $ 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 } sector_t; 79 80 typedef struct 81 { 82 fixed_t textureoffset; // add this to the calculated texture col 83 fixed_t rowoffset; // add this to the calculated texture top 84 short toptexture, bottomtexture, midtexture; 85 sector_t *sector; 86 } side_t; 87 88 typedef enum 89 { 90 ST_HORIZONTAL, 91 ST_VERTICAL, 92 ST_POSITIVE, 93 ST_NEGATIVE 94 } slopetype_t; 95 96 /* 97 typedef struct line_s 98 { 99 vertex_t *v1, *v2; 100 fixed_t dx,dy; // v2 - v1 for side checking 101 short flags; 102 short special, tag; 103 short sidenum[2]; // sidenum[1] will be -1 if one sided 104 fixed_t bbox[4]; 105 slopetype_t slopetype; // to aid move clipping 106 sector_t *frontsector, *backsector; 107 int validcount; // if == validcount, already checked 108 void *specialdata; // thinker_t for reversable actions 109 } line_t; 110 */ 111 112 typedef struct line_s 113 { 114 vertex_t *v1; 115 vertex_t *v2; 116 fixed_t dx; 117 fixed_t dy; 118 short flags; 119 byte special; 120 byte arg1; 121 byte arg2; 122 byte arg3; 123 byte arg4; 124 byte arg5; 125 short sidenum[2]; 126 fixed_t bbox[4]; 127 slopetype_t slopetype; 128 sector_t *frontsector; 129 sector_t *backsector; 130 int validcount; 131 void *specialdata; 132 } line_t; 133 134 typedef struct 135 { 136 vertex_t *v1, *v2; 137 fixed_t offset; 138 angle_t angle; 139 side_t *sidedef; 140 line_t *linedef; 141 sector_t *frontsector; 142 sector_t *backsector; // NULL for one sided lines 143 } seg_t; 144 145 // ===== Polyobj data ===== 146 typedef struct 147 { 148 int numsegs; 149 seg_t **segs; 150 degenmobj_t startSpot; 151 vertex_t *originalPts; // used as the base for the rotations 152 vertex_t *prevPts; // use to restore the old point values 153 angle_t angle; 154 int tag; // reference tag assigned in HereticEd 155 int bbox[4]; 156 int validcount; 157 boolean crush; // should the polyobj attempt to crush mobjs? 158 int seqType; 159 fixed_t size; // polyobj size (area of POLY_AREAUNIT == size of FRACUNIT) 160 void *specialdata; // pointer a thinker, if the poly is moving 161 } polyobj_t; 162 163 typedef struct polyblock_s 164 { 165 polyobj_t *polyobj; 166 struct polyblock_s *prev; 167 struct polyblock_s *next; 168 } polyblock_t; 169 170 typedef struct subsector_s 171 { 172 sector_t *sector; 173 short numlines; 174 short firstline; 175 polyobj_t *poly; 176 } subsector_t; 177 178 typedef struct 179 { 180 fixed_t x,y,dx,dy; // partition line 181 fixed_t bbox[2][4]; // bounding box for each child 182 unsigned short children[2]; // if NF_SUBSECTOR its a subsector 183 } node_t; 184 185 186 /* 187 ============================================================================== 188 189 OTHER TYPES 190 191 ============================================================================== 192 */ 193 194 typedef byte lighttable_t; // this could be wider for >8 bit display 195 196 #define MAXVISPLANES 160 197 #define MAXOPENINGS SCREENWIDTH*64 198 199 typedef struct 200 { 201 fixed_t height; 202 int picnum; 203 int lightlevel; 204 int special; 205 int minx, maxx; 206 byte pad1; // leave pads for [minx-1]/[maxx+1] 207 byte top[SCREENWIDTH]; 208 byte pad2; 209 byte pad3; 210 byte bottom[SCREENWIDTH]; 211 byte pad4; 212 } visplane_t; 213 214 typedef struct drawseg_s 215 { 216 seg_t *curline; 217 int x1, x2; 218 fixed_t scale1, scale2, scalestep; 219 int silhouette; // 0=none, 1=bottom, 2=top, 3=both 220 fixed_t bsilheight; // don't clip sprites above this 221 fixed_t tsilheight; // don't clip sprites below this 222 // pointers to lists for sprite clipping 223 short *sprtopclip; // adjusted so [x1] is first value 224 short *sprbottomclip; // adjusted so [x1] is first value 225 short *maskedtexturecol; // adjusted so [x1] is first value 226 } drawseg_t; 227 228 #define SIL_NONE 0 229 #define SIL_BOTTOM 1 230 #define SIL_TOP 2 231 #define SIL_BOTH 3 232 233 #define MAXDRAWSEGS 256 234 235 // A vissprite_t is a thing that will be drawn during a refresh 236 typedef struct vissprite_s 237 { 238 struct vissprite_s *prev, *next; 239 int x1, x2; 240 fixed_t gx, gy; // for line side calculation 241 fixed_t gz, gzt; // global bottom / top for silhouette clipping 242 fixed_t startfrac; // horizontal position of x1 243 fixed_t scale; 244 fixed_t xiscale; // negative if flipped 245 fixed_t texturemid; 246 int patch; 247 lighttable_t *colormap; 248 int mobjflags; // for color translation and shadow draw 249 boolean psprite; // true if psprite 250 int class; // player class (used in translation) 251 fixed_t floorclip; 252 } vissprite_t; 253 254 255 extern visplane_t *floorplane, *ceilingplane; 256 257 // Sprites are patches with a special naming convention so they can be 258 // recognized by R_InitSprites. The sprite and frame specified by a 259 // thing_t is range checked at run time. 260 // a sprite is a patch_t that is assumed to represent a three dimensional 261 // object and may have multiple rotations pre drawn. Horizontal flipping 262 // is used to save space. Some sprites will only have one picture used 263 // for all views. 264 265 typedef struct 266 { 267 boolean rotate; // if false use 0 for any position 268 short lump[8]; // lump to use for view angles 0-7 269 byte flip[8]; // flip (1 = flip) to use for view angles 0-7 270 } spriteframe_t; 271 272 typedef struct 273 { 274 int numframes; 275 spriteframe_t *spriteframes; 276 } spritedef_t; 277 278 extern spritedef_t *sprites; 279 extern int numsprites; 280 281 //============================================================================= 282 283 extern int numvertexes; 284 extern vertex_t *vertexes; 285 286 extern int numsegs; 287 extern seg_t *segs; 288 289 extern int numsectors; 290 extern sector_t *sectors; 291 292 extern int numsubsectors; 293 extern subsector_t *subsectors; 294 295 extern int numnodes; 296 extern node_t *nodes; 297 298 extern int numlines; 299 extern line_t *lines; 300 301 extern int numsides; 302 extern side_t *sides; 303 304 305 306 extern fixed_t viewx, viewy, viewz; 307 extern angle_t viewangle; 308 extern player_t *viewplayer; 309 310 311 extern angle_t clipangle; 312 313 extern int viewangletox[FINEANGLES/2]; 314 extern angle_t xtoviewangle[SCREENWIDTH+1]; 315 extern fixed_t finetangent[FINEANGLES/2]; 316 317 extern fixed_t rw_distance; 318 extern angle_t rw_normalangle; 319 320 // 321 // R_main.c 322 // 323 extern int viewwidth, viewheight, viewwindowx, viewwindowy; 324 extern int centerx, centery; 325 extern int flyheight; 326 extern fixed_t centerxfrac; 327 extern fixed_t centeryfrac; 328 extern fixed_t projection; 329 330 extern int validcount; 331 332 extern int sscount, linecount, loopcount; 333 extern lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE]; 334 extern lighttable_t *scalelightfixed[MAXLIGHTSCALE]; 335 extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; 336 337 extern int extralight; 338 extern lighttable_t *fixedcolormap; 339 340 extern fixed_t viewcos, viewsin; 341 342 extern int detailshift; // 0 = high, 1 = low 343 344 extern void (*colfunc) (void); 345 extern void (*basecolfunc) (void); 346 extern void (*fuzzcolfunc) (void); 347 extern void (*spanfunc) (void); 348 349 int R_PointOnSide (fixed_t x, fixed_t y, node_t *node); 350 int R_PointOnSegSide (fixed_t x, fixed_t y, seg_t *line); 351 angle_t R_PointToAngle (fixed_t x, fixed_t y); 352 angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2); 353 fixed_t R_PointToDist (fixed_t x, fixed_t y); 354 fixed_t R_ScaleFromGlobalAngle (angle_t visangle); 355 subsector_t *R_PointInSubsector (fixed_t x, fixed_t y); 356 //void R_AddPointToBox (int x, int y, fixed_t *box); 357 358 359 // 360 // R_bsp.c 361 // 362 extern seg_t *curline; 363 extern side_t *sidedef; 364 extern line_t *linedef; 365 extern sector_t *frontsector, *backsector; 366 367 extern int rw_x; 368 extern int rw_stopx; 369 370 extern boolean segtextured; 371 extern boolean markfloor; // false if the back side is the same plane 372 extern boolean markceiling; 373 extern boolean skymap; 374 375 extern drawseg_t drawsegs[MAXDRAWSEGS], *ds_p; 376 377 extern lighttable_t **hscalelight, **vscalelight, **dscalelight; 378 379 typedef void (*drawfunc_t) (int start, int stop); 380 void R_ClearClipSegs (void); 381 382 void R_ClearDrawSegs (void); 383 void R_InitSkyMap (void); 384 void R_RenderBSPNode (int bspnum); 385 386 // 387 // R_segs.c 388 // 389 extern int rw_angle1; // angle to line origin 390 extern int TransTextureStart; 391 extern int TransTextureEnd; 392 393 void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2); 394 395 // 396 // R_plane.c 397 // 398 typedef void (*planefunction_t) (int top, int bottom); 399 extern planefunction_t floorfunc, ceilingfunc; 400 401 extern int skyflatnum; 402 403 extern short openings[MAXOPENINGS], *lastopening; 404 405 extern short floorclip[SCREENWIDTH]; 406 extern short ceilingclip[SCREENWIDTH]; 407 408 extern fixed_t yslope[SCREENHEIGHT]; 409 extern fixed_t distscale[SCREENWIDTH]; 410 411 void R_InitPlanes (void); 412 void R_ClearPlanes (void); 413 void R_MapPlane (int y, int x1, int x2); 414 void R_MakeSpans (int x, int t1, int b1, int t2, int b2); 415 void R_DrawPlanes (void); 416 417 visplane_t *R_FindPlane (fixed_t height, int picnum, int lightlevel, 418 int special); 419 visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop); 420 421 422 // 423 // R_debug.m 424 // 425 extern int drawbsp; 426 427 void RD_OpenMapWindow (void); 428 void RD_ClearMapWindow (void); 429 void RD_DisplayLine (int x1, int y1, int x2, int y2, float gray); 430 void RD_DrawNodeLine (node_t *node); 431 void RD_DrawLineCheck (seg_t *line); 432 void RD_DrawLine (seg_t *line); 433 void RD_DrawBBox (fixed_t *bbox); 434 435 436 // 437 // R_data.c 438 // 439 extern fixed_t *textureheight; // needed for texture pegging 440 extern fixed_t *spritewidth; // needed for pre rendering (fracs) 441 extern fixed_t *spriteoffset; 442 extern fixed_t *spritetopoffset; 443 extern lighttable_t *colormaps; 444 extern int viewwidth, scaledviewwidth, viewheight; 445 extern int firstflat; 446 extern int numflats; 447 448 extern int *flattranslation; // for global animation 449 extern int *texturetranslation; // for global animation 450 451 extern int firstspritelump, lastspritelump, numspritelumps; 452 extern boolean LevelUseFullBright; 453 454 byte *R_GetColumn (int tex, int col); 455 void R_InitData (void); 456 void R_PrecacheLevel (void); 457 458 459 // 460 // R_things.c 461 // 462 #define MAXVISSPRITES 192 463 464 extern vissprite_t vissprites[MAXVISSPRITES], *vissprite_p; 465 extern vissprite_t vsprsortedhead; 466 467 // constant arrays used for psprite clipping and initializing clipping 468 extern short negonearray[SCREENWIDTH]; 469 extern short screenheightarray[SCREENWIDTH]; 470 471 // vars for R_DrawMaskedColumn 472 extern short *mfloorclip; 473 extern short *mceilingclip; 474 extern fixed_t spryscale; 475 extern fixed_t sprtopscreen; 476 extern fixed_t sprbotscreen; 477 478 extern fixed_t pspritescale, pspriteiscale; 479 480 481 void R_DrawMaskedColumn (column_t *column, signed int baseclip); 482 483 484 void R_SortVisSprites (void); 485 486 void R_AddSprites (sector_t *sec); 487 void R_AddPSprites (void); 488 void R_DrawSprites (void); 489 void R_InitSprites (char **namelist); 490 void R_ClearSprites (void); 491 void R_DrawMasked (void); 492 void R_ClipVisSprite (vissprite_t *vis, int xl, int xh); 493 494 //============================================================================= 495 // 496 // R_draw.c 497 // 498 //============================================================================= 499 500 extern lighttable_t *dc_colormap; 501 extern int dc_x; 502 extern int dc_yl; 503 extern int dc_yh; 504 extern fixed_t dc_iscale; 505 extern fixed_t dc_texturemid; 506 extern byte *dc_source; // first pixel in a column 507 508 void R_DrawColumn (void); 509 void R_DrawColumnLow (void); 510 void R_DrawFuzzColumn (void); 511 void R_DrawFuzzColumnLow (void); 512 void R_DrawTranslatedColumn (void); 513 void R_DrawTranslatedFuzzColumn (void); 514 void R_DrawTranslatedColumnLow (void); 515 void R_DrawAltFuzzColumn(void); 516 //void R_DrawTranslatedAltFuzzColumn(void); 517 518 extern int ds_y; 519 extern int ds_x1; 520 extern int ds_x2; 521 extern lighttable_t *ds_colormap; 522 extern fixed_t ds_xfrac; 523 extern fixed_t ds_yfrac; 524 extern fixed_t ds_xstep; 525 extern fixed_t ds_ystep; 526 extern byte *ds_source; // start of a 64*64 tile image 527 528 extern byte *translationtables; 529 extern byte *dc_translation; 530 531 void R_DrawSpan (void); 532 void R_DrawSpanLow (void); 533 534 void R_InitBuffer (int width, int height); 535 void R_InitTranslationTables (void); 536 537 #endif // __R_LOCAL__ 538 539