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