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