1
//------------------------------------------------------------------------
2
// LEVEL : Level structures & read/write functions.
3
//------------------------------------------------------------------------
5
// GL-Friendly Node Builder (C) 2000-2005 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)
192
// normally NULL, except when this linedef directly overlaps an earlier
193
// one (a rarely-used trick to create higher mid-masked textures).
194
// No segs should be created for these overlapping linedefs.
195
struct linedef_s *overlap;
197
// linedef index. Always valid after loading & pruning of zero
198
// length lines has occurred.
204
typedef struct thing_s
210
// other info (angle, and hexen stuff) omitted. We don't need to
211
// write the THING lump, only read it.
213
// Always valid (thing indices never change).
224
vertex_t *start; // from this vertex...
225
vertex_t *end; // ... to this vertex
227
// linedef that this seg goes along, or NULL if miniseg
230
// adjacent sector, or NULL if invalid sidedef or miniseg
233
// 0 for right, 1 for left
236
// seg on other side, or NULL if one-sided. This relationship is
237
// always one-to-one -- if one of the segs is split, the partner seg
238
// must also be split.
239
struct seg_s *partner;
241
// seg index. Only valid once the seg has been added to a
242
// subsector. A negative value means it is invalid -- there
243
// shouldn't be any of these once the BSP tree has been built.
246
// when 1, this seg has become zero length (integer rounding of the
247
// start and end vertices produces the same location). It should be
248
// ignored when writing the SEGS or V1 GL_SEGS lumps. [Note: there
249
// won't be any of these when writing the V2 GL_SEGS lump].
252
// the superblock that contains this seg, or NULL if the seg is no
253
// longer in any superblock (e.g. now in a subsector).
254
struct superblock_s *block;
256
// precomputed data for faster calculations
266
// linedef that this seg initially comes from. For "real" segs,
267
// this is just the same as the 'linedef' field above. For
268
// "minisegs", this is the linedef of the partition line.
269
linedef_t *source_line;
274
typedef struct subsec_s
282
// subsector index. Always valid, set when the subsector is
283
// initially created.
286
// approximate middle point
293
typedef struct bbox_s
301
typedef struct child_s
303
// child node or subsector (one must be NULL)
307
// child bounding box
313
typedef struct node_s
315
int x, y; // starting point
316
int dx, dy; // offset to ending point
318
// right & left children
322
// node index. Only valid once the NODES or GL_NODES lump has been
326
// the node is too long, and the (dx,dy) values should be halved
327
// when writing into the NODES lump.
333
typedef struct superblock_s
335
// parent of this block, or NULL for a top-level block
336
struct superblock_s *parent;
338
// coordinates on map for this block, from lower-left corner to
339
// upper-right corner. Pseudo-inclusive, i.e (x,y) is inside block
340
// if and only if x1 <= x < x2 and y1 <= y < y2.
344
// sub-blocks. NULL when empty. [0] has the lower coordinates, and
345
// [1] has the higher coordinates. Division of a square always
346
// occurs horizontally (e.g. 512x512 -> 256x512 -> 256x256).
347
struct superblock_s *subs[2];
349
// number of real segs and minisegs contained by this block
350
// (including all sub-blocks below it).
354
// list of segs completely contained by this block.
359
#define SUPER_IS_LEAF(s) \
360
((s)->x2-(s)->x1 <= 256 && (s)->y2-(s)->y1 <= 256)
363
/* ----- Level data arrays ----------------------- */
365
extern int num_vertices;
366
extern int num_linedefs;
367
extern int num_sidedefs;
368
extern int num_sectors;
369
extern int num_things;
371
extern int num_subsecs;
372
extern int num_nodes;
373
extern int num_stale_nodes;
375
extern int num_normal_vert;
376
extern int num_gl_vert;
377
extern int num_complete_seg;
380
/* ----- function prototypes ----------------------- */
382
// allocation routines
383
vertex_t *NewVertex(void);
384
linedef_t *NewLinedef(void);
385
sidedef_t *NewSidedef(void);
386
sector_t *NewSector(void);
387
thing_t *NewThing(void);
389
subsec_t *NewSubsec(void);
390
node_t *NewNode(void);
391
node_t *NewStaleNode(void);
392
wall_tip_t *NewWallTip(void);
395
vertex_t *LookupVertex(int index);
396
linedef_t *LookupLinedef(int index);
397
sidedef_t *LookupSidedef(int index);
398
sector_t *LookupSector(int index);
399
thing_t *LookupThing(int index);
400
seg_t *LookupSeg(int index);
401
subsec_t *LookupSubsec(int index);
402
node_t *LookupNode(int index);
403
node_t *LookupStaleNode(int index);
405
// check whether the current level already has normal nodes
406
int CheckForNormalNodes(void);
408
// load all level data for the current level
409
void LoadLevel(void);
411
// free all level data
412
void FreeLevel(void);
414
// save the newly computed NODE info etc..
415
void SaveLevel(node_t *root_node);
417
#endif /* __GLBSP_LEVEL_H__ */