1 /* Emacs style mode select   -*- C++ -*-
2  *-----------------------------------------------------------------------------
3  *
4  *
5  *  PrBoom: a Doom port merged with LxDoom and LSDLDoom
6  *  based on BOOM, a modified and improved DOOM engine
7  *  Copyright (C) 1999 by
8  *  id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9  *  Copyright (C) 1999-2000 by
10  *  Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11  *  Copyright 2005, 2006 by
12  *  Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13  *
14  *  This program is free software; you can redistribute it and/or
15  *  modify it under the terms of the GNU General Public License
16  *  as published by the Free Software Foundation; either version 2
17  *  of the License, or (at your option) any later version.
18  *
19  *  This program is distributed in the hope that it will be useful,
20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *  GNU General Public License for more details.
23  *
24  *  You should have received a copy of the GNU General Public License
25  *  along with this program; if not, write to the Free Software
26  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27  *  02111-1307, USA.
28  *
29  * DESCRIPTION:
30  *      Refresh/rendering module, shared data struct definitions.
31  *
32  *-----------------------------------------------------------------------------*/
33 
34 #ifndef __R_DEFS__
35 #define __R_DEFS__
36 
37 // Screenwidth.
38 #include "doomdef.h"
39 
40 // Some more or less basic data types
41 // we depend on.
42 #include "m_fixed.h"
43 
44 // We rely on the thinker data struct
45 // to handle sound origins in sectors.
46 #include "d_think.h"
47 
48 // SECTORS do store MObjs anyway.
49 #include "p_mobj.h"
50 
51 // Silhouette, needed for clipping Segs (mainly)
52 // and sprites representing things.
53 #define SIL_NONE    0
54 #define SIL_BOTTOM  1
55 #define SIL_TOP     2
56 #define SIL_BOTH    3
57 
58 #define MAXDRAWSEGS   256
59 
60 //
61 // INTERNAL MAP TYPES
62 //  used by play and refresh
63 //
64 
65 //
66 // Your plain vanilla vertex.
67 // Note: transformed values not buffered locally,
68 // like some DOOM-alikes ("wt", "WebView") do.
69 //
70 typedef struct
71 {
72   fixed_t x, y;
73 } vertex_t;
74 
75 // Each sector has a degenmobj_t in its center for sound origin purposes.
76 typedef struct
77 {
78   thinker_t thinker;  // not used for anything
79   fixed_t x, y, z;
80 } degenmobj_t;
81 
82 //
83 // The SECTORS record, at runtime.
84 // Stores things/mobjs.
85 //
86 
87 typedef struct
88 {
89   // [kb] for R_FixWiggle()
90   int	cachedheight;
91   int	scaleindex;
92 
93   int iSectorID; // proff 04/05/2000: needed for OpenGL and used in debugmode by the HUD to draw sectornum
94   dbool   no_toptextures;
95   dbool   no_bottomtextures;
96   fixed_t floorheight;
97   fixed_t ceilingheight;
98   int nexttag,firsttag;  // killough 1/30/98: improves searches for tags.
99   int soundtraversed;    // 0 = untraversed, 1,2 = sndlines-1
100   mobj_t *soundtarget;   // thing that made a sound (or null)
101   int blockbox[4];       // mapblock bounding box for height changes
102   degenmobj_t soundorg;  // origin for any sounds played by the sector
103   int validcount;        // if == validcount, already checked
104   mobj_t *thinglist;     // list of mobjs in sector
105 
106   /* killough 8/28/98: friction is a sector property, not an mobj property.
107    * these fields used to be in mobj_t, but presented performance problems
108    * when processed as mobj properties. Fix is to make them sector properties.
109    */
110   int friction,movefactor;
111 
112   // thinker_t for reversable actions
113   void *floordata;    // jff 2/22/98 make thinkers on
114   void *ceilingdata;  // floors, ceilings, lighting,
115   void *lightingdata; // independent of one another
116 
117   // jff 2/26/98 lockout machinery for stairbuilding
118   int stairlock;   // -2 on first locked -1 after thinker done 0 normally
119   int prevsec;     // -1 or number of sector for previous step
120   int nextsec;     // -1 or number of next step sector
121 
122   // killough 3/7/98: support flat heights drawn at another sector's heights
123   int heightsec;    // other sector, or -1 if no other sector
124 
125   int bottommap, midmap, topmap; // killough 4/4/98: dynamic colormaps
126 
127   // list of mobjs that are at least partially in the sector
128   // thinglist is a subset of touching_thinglist
129   struct msecnode_s *touching_thinglist;               // phares 3/14/98
130 
131   int linecount;
132   struct line_s **lines;
133 
134   // killough 10/98: support skies coming from sidedefs. Allows scrolling
135   // skies and other effects. No "level info" kind of lump is needed,
136   // because you can use an arbitrary number of skies per level with this
137   // method. This field only applies when skyflatnum is used for floorpic
138   // or ceilingpic, because the rest of Doom needs to know which is sky
139   // and which isn't, etc.
140 
141   int sky;
142 
143   // killough 3/7/98: floor and ceiling texture offsets
144   fixed_t   floor_xoffs,   floor_yoffs;
145   fixed_t ceiling_xoffs, ceiling_yoffs;
146 
147   // killough 4/11/98: support for lightlevels coming from another sector
148   int floorlightsec, ceilinglightsec;
149 
150   short floorpic;
151   short ceilingpic;
152   short lightlevel;
153   short special;
154   short oldspecial;      //jff 2/16/98 remembers if sector WAS secret (automap)
155   short tag;
156 } sector_t;
157 
158 //
159 // The SideDef.
160 //
161 
162 typedef struct
163 {
164   fixed_t textureoffset; // add this to the calculated texture column
165   fixed_t rowoffset;     // add this to the calculated texture top
166   short toptexture;      // Texture indices. We do not maintain names here.
167   short bottomtexture;
168   short midtexture;
169   sector_t* sector;      // Sector the SideDef is facing.
170 
171   // killough 4/4/98, 4/11/98: highest referencing special linedef's type,
172   // or lump number of special effect. Allows texture names to be overloaded
173   // for other functions.
174 
175   int special;
176 
177 } side_t;
178 
179 //
180 // Move clipping aid for LineDefs.
181 //
182 typedef enum
183 {
184   ST_HORIZONTAL,
185   ST_VERTICAL,
186   ST_POSITIVE,
187   ST_NEGATIVE
188 } slopetype_t;
189 
190 typedef struct line_s
191 {
192   int iLineID;           // proff 04/05/2000: needed for OpenGL
193   vertex_t *v1, *v2;     // Vertices, from v1 to v2.
194   fixed_t dx, dy;        // Precalculated v2 - v1 for side checking.
195   unsigned short flags;           // Animation related.
196   short special;
197   short tag;
198   unsigned short sidenum[2];        // Visual appearance: SideDefs.
199   fixed_t bbox[4];       // A bounding box, for the linedef's extent
200   slopetype_t slopetype; // To aid move clipping.
201   sector_t *frontsector; // Front and back sector.
202   sector_t *backsector;
203   int validcount;        // if == validcount, already checked
204   void *specialdata;     // thinker_t for reversable actions
205   int firsttag,nexttag;  // killough 4/17/98: improves searches for tags.
206   int r_validcount;      // cph: if == gametic, r_flags already done
207   enum {                 // cph:
208     RF_TOP_TILE  = 1,     // Upper texture needs tiling
209     RF_MID_TILE = 2,     // Mid texture needs tiling
210     RF_BOT_TILE = 4,     // Lower texture needs tiling
211     RF_IGNORE   = 8,     // Renderer can skip this line
212     RF_CLOSED   =16,     // Line blocks view
213   } r_flags;
214   degenmobj_t soundorg;  // sound origin for switches/buttons
215 } line_t;
216 
217 
218 // phares 3/14/98
219 //
220 // Sector list node showing all sectors an object appears in.
221 //
222 // There are two threads that flow through these nodes. The first thread
223 // starts at touching_thinglist in a sector_t and flows through the m_snext
224 // links to find all mobjs that are entirely or partially in the sector.
225 // The second thread starts at touching_sectorlist in an mobj_t and flows
226 // through the m_tnext links to find all sectors a thing touches. This is
227 // useful when applying friction or push effects to sectors. These effects
228 // can be done as thinkers that act upon all objects touching their sectors.
229 // As an mobj moves through the world, these nodes are created and
230 // destroyed, with the links changed appropriately.
231 //
232 // For the links, NULL means top or end of list.
233 
234 typedef struct msecnode_s
235 {
236   sector_t          *m_sector; // a sector containing this object
237   struct mobj_s     *m_thing;  // this object
238   struct msecnode_s *m_tprev;  // prev msecnode_t for this thing
239   struct msecnode_s *m_tnext;  // next msecnode_t for this thing
240   struct msecnode_s *m_sprev;  // prev msecnode_t for this sector
241   struct msecnode_s *m_snext;  // next msecnode_t for this sector
242   dbool   visited; // killough 4/4/98, 4/7/98: used in search algorithms
243 } msecnode_t;
244 
245 //
246 // The LineSeg.
247 //
248 typedef struct
249 {
250   vertex_t *v1, *v2;
251   fixed_t offset;
252   angle_t angle;
253   side_t* sidedef;
254   line_t* linedef;
255 
256   int iSegID; // proff 11/05/2000: needed for OpenGL
257   // figgi -- needed for glnodes
258   float     length;
259   dbool     miniseg;
260 
261 
262   // Sector references.
263   // Could be retrieved from linedef, too
264   // (but that would be slower -- killough)
265   // backsector is NULL for one sided lines
266 
267   sector_t *frontsector, *backsector;
268 } seg_t;
269 
270 
271 //
272 // A SubSector.
273 // References a Sector.
274 // Basically, this is a list of LineSegs,
275 //  indicating the visible walls that define
276 //  (all or some) sides of a convex BSP leaf.
277 //
278 
279 typedef struct subsector_s
280 {
281   sector_t *sector;
282   int numlines, firstline;
283 } subsector_t;
284 
285 
286 //
287 // BSP node.
288 //
289 typedef struct
290 {
291   fixed_t  x,  y, dx, dy;        // Partition line.
292   fixed_t bbox[2][4];            // Bounding box for each child.
293   unsigned int children[2];      // If NF_SUBSECTOR it is a subsector.
294 } node_t;
295 
296 //
297 // OTHER TYPES
298 //
299 
300 // This could be wider for >8 bit display.
301 // Indeed, true color support is posibble
302 // precalculating 24bpp lightmap/colormap LUT.
303 // from darkening PLAYPAL to all black.
304 // Could use even more than 32 levels.
305 
306 typedef uint8_t lighttable_t;
307 
308 //
309 // Masked 2s linedefs
310 //
311 
312 typedef struct drawseg_s
313 {
314   seg_t *curline;
315   int x1, x2;
316   fixed_t scale1, scale2, scalestep;
317   int silhouette;                       // 0=none, 1=bottom, 2=top, 3=both
318   fixed_t bsilheight;                   // do not clip sprites above this
319   fixed_t tsilheight;                   // do not clip sprites below this
320 
321   // Added for filtering (fractional texture u coord) support - POPE
322   fixed_t rw_offset, rw_distance, rw_centerangle;
323 
324   // Pointers to lists for sprite clipping,
325   // all three adjusted so [x1] is first value.
326 
327   int *sprtopclip, *sprbottomclip, *maskedtexturecol; // dropoff overflow
328 } drawseg_t;
329 
330 // proff: Added for OpenGL
331 typedef struct
332 {
333   int width,height;
334   int leftoffset,topoffset;
335   int lumpnum;
336 } patchnum_t;
337 
338 //
339 // A vissprite_t is a thing that will be drawn during a refresh.
340 // i.e. a sprite object that is partly visible.
341 //
342 
343 typedef struct vissprite_s
344 {
345   int x1, x2;
346   fixed_t gx, gy;              // for line side calculation
347   fixed_t gz, gzt;             // global bottom / top for silhouette clipping
348   fixed_t startfrac;           // horizontal position of x1
349   fixed_t scale;
350   fixed_t xiscale;             // negative if flipped
351   fixed_t texturemid;
352   int patch;
353   uint64_t mobjflags;
354 
355   // for color translation and shadow draw, maxbright frames as well
356   const lighttable_t *colormap;
357 
358   // killough 3/27/98: height sector for underwater/fake ceiling support
359   int heightsec;
360 } vissprite_t;
361 
362 //
363 // Sprites are patches with a special naming convention
364 //  so they can be recognized by R_InitSprites.
365 // The base name is NNNNFx or NNNNFxFx, with
366 //  x indicating the rotation, x = 0, 1-7.
367 // The sprite and frame specified by a thing_t
368 //  is range checked at run time.
369 // A sprite is a patch_t that is assumed to represent
370 //  a three dimensional object and may have multiple
371 //  rotations pre drawn.
372 // Horizontal flipping is used to save space,
373 //  thus NNNNF2F5 defines a mirrored patch.
374 // Some sprites will only have one picture used
375 // for all views: NNNNF0
376 //
377 
378 typedef struct
379 {
380   // If false use 0 for any position.
381   // Note: as eight entries are available,
382   //  we might as well insert the same name eight times.
383   dbool   rotate;
384 
385   // Lump to use for view angles 0-7.
386   short lump[8];
387 
388   // Flip bit (1 = flip) to use for view angles 0-7.
389   uint8_t flip[8];
390 
391 } spriteframe_t;
392 
393 //
394 // A sprite definition:
395 //  a number of animation frames.
396 //
397 
398 typedef struct
399 {
400   int numframes;
401   spriteframe_t *spriteframes;
402 } spritedef_t;
403 
404 //
405 // Now what is a visplane, anyway?
406 //
407 // Go to http://classicgaming.com/doom/editing/ to find out -- killough
408 //
409 
410 typedef struct visplane
411 {
412   struct visplane *next;        // Next visplane in hash chain -- killough
413   int picnum, lightlevel, minx, maxx;
414   fixed_t height;
415   fixed_t xoffs, yoffs;         // killough 2/28/98: Support scrolling flats
416   unsigned int pad1;          // leave pads for [minx-1]/[maxx+1]
417   unsigned int top[MAX_SCREENWIDTH];
418   unsigned int pad2, pad3;    // killough 2/8/98, 4/25/98
419   unsigned int bottom[MAX_SCREENWIDTH];
420   unsigned int pad4; // dropoff overflow
421 } visplane_t;
422 
423 #endif
424