1
//------------------------------------------------------------------------
2
// LEVEL : Level structures & read/write functions.
3
//------------------------------------------------------------------------
5
// GL-Friendly Node Builder (C) 2000-2007 Andrew Apted
7
// Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
9
// This program is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
//------------------------------------------------------------------------
21
#ifndef __GLBSP_LEVEL_H__
22
#define __GLBSP_LEVEL_H__
33
// a wall_tip is where a wall meets a vertex
34
typedef struct wall_tip_s
36
// link in list. List is kept in ANTI-clockwise order.
37
struct wall_tip_s *next;
38
struct wall_tip_s *prev;
40
// angle that line makes at vertex (degrees).
43
// sectors on each side of wall. Left is the side of increasing
44
// angles, right is the side of decreasing angles. Either can be
45
// NULL for one sided walls.
46
struct sector_s *left;
47
struct sector_s *right;
52
typedef struct vertex_s
57
// vertex index. Always valid after loading and pruning of unused
58
// vertices has occurred. For GL vertices, bit 30 will be set.
61
// reference count. When building normal node info, unused vertices
65
// usually NULL, unless this vertex occupies the same location as a
66
// previous vertex. Only used during the pruning phase.
67
struct vertex_s *equiv;
72
// contains a duplicate vertex, needed when both normal and V2 GL
73
// nodes are being built at the same time (this is the vertex used
74
// for the normal segs). Normally NULL. Note: the wall tips on
75
// this vertex are not created.
76
struct vertex_s *normal_dup;
80
#define IS_GL_VERTEX (1 << 30)
83
typedef struct sector_s
85
// sector index. Always valid after loading & pruning.
88
// allow segs from other sectors to coexist in a subsector.
91
// -JL- non-zero if this sector contains a polyobj.
94
// reference count. When building normal nodes, unused sectors will
110
// used when building REJECT table. Each set of sectors that are
111
// isolated from other sectors will have a different group number.
112
// Thus: on every 2-sided linedef, the sectors on both sides will be
113
// in the same group. The rej_next, rej_prev fields are a link in a
114
// RING, containing all sectors of the same group.
117
struct sector_s *rej_next;
118
struct sector_s *rej_prev;
120
// suppress superfluous mini warnings
122
char warned_unclosed;
127
typedef struct sidedef_s
129
// adjacent sector. Can be NULL (invalid sidedef)
133
int x_offset, y_offset;
140
// sidedef index. Always valid after loading & pruning.
143
// reference count. When building normal nodes, unused sidedefs will
147
// usually NULL, unless this sidedef is exactly the same as a
148
// previous one. Only used during the pruning phase.
149
struct sidedef_s *equiv;
151
// this is true if the sidedef is on a special line. We don't merge
152
// these sidedefs together, as they might scroll, or change texture
153
// when a switch is pressed.
159
typedef struct linedef_s
162
struct linedef_s *next;
164
vertex_t *start; // from this vertex...
165
vertex_t *end; // ... to this vertex
167
sidedef_t *right; // right sidedef
168
sidedef_t *left; // left sidede, or NULL if none
170
// line is marked two-sided
173
// prefer not to split
176
// zero length (line should be totally ignored)
179
// sector is the same on both sides
182
// one-sided linedef used for a special effect (windows).
183
// The value refers to the opposite sector on the back side.
184
sector_t * window_effect;
193
// normally NULL, except when this linedef directly overlaps an earlier
194
// one (a rarely-used trick to create higher mid-masked textures).
195
// No segs should be created for these overlapping linedefs.
196
struct linedef_s *overlap;
198
// linedef index. Always valid after loading & pruning of zero
199
// length lines has occurred.
205
typedef struct thing_s
211
// other info (angle, and hexen stuff) omitted. We don't need to
212
// write the THING lump, only read it.
214
// Always valid (thing indices never change).
225
vertex_t *start; // from this vertex...
226
vertex_t *end; // ... to this vertex
228
// linedef that this seg goes along, or NULL if miniseg
231
// adjacent sector, or NULL if invalid sidedef or miniseg
234
// 0 for right, 1 for left
237
// seg on other side, or NULL if one-sided. This relationship is
238
// always one-to-one -- if one of the segs is split, the partner seg
239
// must also be split.
240
struct seg_s *partner;
242
// seg index. Only valid once the seg has been added to a
243
// subsector. A negative value means it is invalid -- there
244
// shouldn't be any of these once the BSP tree has been built.
247
// when 1, this seg has become zero length (integer rounding of the
248
// start and end vertices produces the same location). It should be
249
// ignored when writing the SEGS or V1 GL_SEGS lumps. [Note: there
250
// won't be any of these when writing the V2 GL_SEGS lump].
253
// the superblock that contains this seg, or NULL if the seg is no
254
// longer in any superblock (e.g. now in a subsector).
255
struct superblock_s *block;
257
// precomputed data for faster calculations
267
// linedef that this seg initially comes from. For "real" segs,
268
// this is just the same as the 'linedef' field above. For
269
// "minisegs", this is the linedef of the partition line.
270
linedef_t *source_line;
275
typedef struct subsec_s
283
// subsector index. Always valid, set when the subsector is
284
// initially created.
287
// approximate middle point
294
typedef struct bbox_s
302
typedef struct child_s
304
// child node or subsector (one must be NULL)
308
// child bounding box
314
typedef struct node_s
316
int x, y; // starting point
317
int dx, dy; // offset to ending point
319
// right & left children
323
// node index. Only valid once the NODES or GL_NODES lump has been
327
// the node is too long, and the (dx,dy) values should be halved
328
// when writing into the NODES lump.
334
typedef struct superblock_s
336
// parent of this block, or NULL for a top-level block
337
struct superblock_s *parent;
339
// coordinates on map for this block, from lower-left corner to
340
// upper-right corner. Pseudo-inclusive, i.e (x,y) is inside block
341
// if and only if x1 <= x < x2 and y1 <= y < y2.
345
// sub-blocks. NULL when empty. [0] has the lower coordinates, and
346
// [1] has the higher coordinates. Division of a square always
347
// occurs horizontally (e.g. 512x512 -> 256x512 -> 256x256).
348
struct superblock_s *subs[2];
350
// number of real segs and minisegs contained by this block
351
// (including all sub-blocks below it).
355
// list of segs completely contained by this block.
360
#define SUPER_IS_LEAF(s) \
361
((s)->x2-(s)->x1 <= 256 && (s)->y2-(s)->y1 <= 256)
364
/* ----- Level data arrays ----------------------- */
366
extern int num_vertices;
367
extern int num_linedefs;
368
extern int num_sidedefs;
369
extern int num_sectors;
370
extern int num_things;
372
extern int num_subsecs;
373
extern int num_nodes;
374
extern int num_stale_nodes;
376
extern int num_normal_vert;
377
extern int num_gl_vert;
378
extern int num_complete_seg;
381
/* ----- function prototypes ----------------------- */
383
// allocation routines
384
vertex_t *NewVertex(void);
385
linedef_t *NewLinedef(void);
386
sidedef_t *NewSidedef(void);
387
sector_t *NewSector(void);
388
thing_t *NewThing(void);
390
subsec_t *NewSubsec(void);
391
node_t *NewNode(void);
392
node_t *NewStaleNode(void);
393
wall_tip_t *NewWallTip(void);
396
vertex_t *LookupVertex(int index);
397
linedef_t *LookupLinedef(int index);
398
sidedef_t *LookupSidedef(int index);
399
sector_t *LookupSector(int index);
400
thing_t *LookupThing(int index);
401
seg_t *LookupSeg(int index);
402
subsec_t *LookupSubsec(int index);
403
node_t *LookupNode(int index);
404
node_t *LookupStaleNode(int index);
406
// check whether the current level already has normal nodes
407
int CheckForNormalNodes(void);
409
// load all level data for the current level
410
void LoadLevel(void);
412
// free all level data
413
void FreeLevel(void);
415
// save the newly computed NODE info etc..
416
void SaveLevel(node_t *root_node);
418
#endif /* __GLBSP_LEVEL_H__ */