R_LOCAL.H 11 KB

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