R_LOCAL.H 16 KB

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