~ubuntu-branches/ubuntu/precise/glbsp/precise

« back to all changes in this revision

Viewing changes to level.h

  • Committer: Bazaar Package Importer
  • Author(s): Darren Salt
  • Date: 2008-01-30 13:33:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080130133349-kgojg33vyiu8xbvp
Tags: 2.24-1
* New upstream release.
* Bumped the lib soname and the library package name due to one silly
  little binary incompatibility caused by changes in an exported struct.
  (Safe; nothing else currently in the archive has ever used libglbsp2.)
* Removed my patches since they're all applied upstream.
* Updated the list of documentation files.
* Build-time changes:
  - Switched from dh_movefiles to dh_install.
  - Updated my makefile to cope with upstream changes.
  - Corrected for debian-rules-ignores-make-clean-error.
  - Corrected for substvar-source-version-is-deprecated.
  - Link libglbsp, rather than glbsp, with libm and libz.
* Fixed shlibdeps. (Closes: #460387)
* Bumped standards version to 3.7.3 (no other changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//------------------------------------------------------------------------
2
 
// LEVEL : Level structures & read/write functions.
3
 
//------------------------------------------------------------------------
4
 
//
5
 
//  GL-Friendly Node Builder (C) 2000-2005 Andrew Apted
6
 
//
7
 
//  Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
8
 
//
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.
13
 
//
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.
18
 
//
19
 
//------------------------------------------------------------------------
20
 
 
21
 
#ifndef __GLBSP_LEVEL_H__
22
 
#define __GLBSP_LEVEL_H__
23
 
 
24
 
#include "structs.h"
25
 
#include "wad.h"
26
 
 
27
 
 
28
 
struct node_s;
29
 
struct sector_s;
30
 
struct superblock_s;
31
 
 
32
 
 
33
 
// a wall_tip is where a wall meets a vertex
34
 
typedef struct wall_tip_s
35
 
{
36
 
  // link in list.  List is kept in ANTI-clockwise order.
37
 
  struct wall_tip_s *next;
38
 
  struct wall_tip_s *prev;
39
 
  
40
 
  // angle that line makes at vertex (degrees).
41
 
  angle_g angle;
42
 
 
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;
48
 
}
49
 
wall_tip_t;
50
 
 
51
 
 
52
 
typedef struct vertex_s
53
 
{
54
 
  // coordinates
55
 
  float_g x, y;
56
 
 
57
 
  // vertex index.  Always valid after loading and pruning of unused
58
 
  // vertices has occurred.  For GL vertices, bit 30 will be set.
59
 
  int index;
60
 
 
61
 
  // reference count.  When building normal node info, unused vertices
62
 
  // will be pruned.
63
 
  int ref_count;
64
 
 
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;
68
 
 
69
 
  // set of wall_tips
70
 
  wall_tip_t *tip_set;
71
 
 
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;
77
 
}
78
 
vertex_t;
79
 
 
80
 
#define IS_GL_VERTEX  (1 << 30)
81
 
 
82
 
 
83
 
typedef struct sector_s
84
 
{
85
 
  // sector index.  Always valid after loading & pruning.
86
 
  int index;
87
 
 
88
 
  // allow segs from other sectors to coexist in a subsector.
89
 
  char coalesce;
90
 
 
91
 
  // -JL- non-zero if this sector contains a polyobj.
92
 
  int has_polyobj;
93
 
 
94
 
  // reference count.  When building normal nodes, unused sectors will
95
 
  // be pruned.
96
 
  int ref_count;
97
 
 
98
 
  // heights
99
 
  int floor_h, ceil_h;
100
 
 
101
 
  // textures
102
 
  char floor_tex[8];
103
 
  char ceil_tex[8];
104
 
 
105
 
  // attributes
106
 
  int light;
107
 
  int special;
108
 
  int tag;
109
 
 
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.
115
 
  int rej_group;
116
 
 
117
 
  struct sector_s *rej_next;
118
 
  struct sector_s *rej_prev;
119
 
 
120
 
  // suppress superfluous mini warnings
121
 
  int warned_facing;
122
 
  char warned_unclosed;
123
 
}
124
 
sector_t;
125
 
 
126
 
 
127
 
typedef struct sidedef_s
128
 
{
129
 
  // adjacent sector.  Can be NULL (invalid sidedef)
130
 
  sector_t *sector;
131
 
 
132
 
  // offset values
133
 
  int x_offset, y_offset;
134
 
 
135
 
  // texture names
136
 
  char upper_tex[8];
137
 
  char lower_tex[8];
138
 
  char mid_tex[8];
139
 
  
140
 
  // sidedef index.  Always valid after loading & pruning.
141
 
  int index;
142
 
 
143
 
  // reference count.  When building normal nodes, unused sidedefs will
144
 
  // be pruned.
145
 
  int ref_count;
146
 
 
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;
150
 
 
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.
154
 
  int on_special;
155
 
}
156
 
sidedef_t;
157
 
 
158
 
 
159
 
typedef struct linedef_s
160
 
{
161
 
  // link for list
162
 
  struct linedef_s *next;
163
 
 
164
 
  vertex_t *start;    // from this vertex...
165
 
  vertex_t *end;      // ... to this vertex
166
 
 
167
 
  sidedef_t *right;   // right sidedef
168
 
  sidedef_t *left;    // left sidede, or NULL if none
169
 
 
170
 
  // line is marked two-sided
171
 
  char two_sided;
172
 
 
173
 
  // prefer not to split
174
 
  char is_precious;
175
 
 
176
 
  // zero length (line should be totally ignored)
177
 
  char zero_len;
178
 
 
179
 
  // sector is the same on both sides
180
 
  char self_ref;
181
 
 
182
 
  // one-sided linedef used for a special effect (windows)
183
 
  char window_effect;
184
 
 
185
 
  int flags;
186
 
  int type;
187
 
  int tag;
188
 
 
189
 
  // Hexen support
190
 
  int specials[5];
191
 
  
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;
196
 
 
197
 
  // linedef index.  Always valid after loading & pruning of zero
198
 
  // length lines has occurred.
199
 
  int index;
200
 
}
201
 
linedef_t;
202
 
 
203
 
 
204
 
typedef struct thing_s
205
 
{
206
 
  int x, y;
207
 
  int type;
208
 
  int options;
209
 
 
210
 
  // other info (angle, and hexen stuff) omitted.  We don't need to
211
 
  // write the THING lump, only read it.
212
 
 
213
 
  // Always valid (thing indices never change).
214
 
  int index;
215
 
}
216
 
thing_t;
217
 
 
218
 
 
219
 
typedef struct seg_s
220
 
{
221
 
  // link for list
222
 
  struct seg_s *next;
223
 
 
224
 
  vertex_t *start;   // from this vertex...
225
 
  vertex_t *end;     // ... to this vertex
226
 
 
227
 
  // linedef that this seg goes along, or NULL if miniseg
228
 
  linedef_t *linedef;
229
 
 
230
 
  // adjacent sector, or NULL if invalid sidedef or miniseg
231
 
  sector_t *sector;
232
 
 
233
 
  // 0 for right, 1 for left
234
 
  int side;
235
 
 
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;
240
 
 
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.
244
 
  int index;
245
 
 
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].
250
 
  int degenerate;
251
 
 
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;
255
 
 
256
 
  // precomputed data for faster calculations
257
 
  float_g psx, psy;
258
 
  float_g pex, pey;
259
 
  float_g pdx, pdy;
260
 
 
261
 
  float_g p_length;
262
 
  float_g p_angle;
263
 
  float_g p_para;
264
 
  float_g p_perp;
265
 
 
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;
270
 
}
271
 
seg_t;
272
 
 
273
 
 
274
 
typedef struct subsec_s
275
 
{
276
 
  // list of segs
277
 
  seg_t *seg_list;
278
 
 
279
 
  // count of segs
280
 
  int seg_count;
281
 
 
282
 
  // subsector index.  Always valid, set when the subsector is
283
 
  // initially created.
284
 
  int index;
285
 
 
286
 
  // approximate middle point
287
 
  float_g mid_x;
288
 
  float_g mid_y;
289
 
}
290
 
subsec_t;
291
 
 
292
 
 
293
 
typedef struct bbox_s
294
 
{
295
 
  int minx, miny;
296
 
  int maxx, maxy;
297
 
}
298
 
bbox_t;
299
 
 
300
 
 
301
 
typedef struct child_s
302
 
{
303
 
  // child node or subsector (one must be NULL)
304
 
  struct node_s *node;
305
 
  subsec_t *subsec;
306
 
 
307
 
  // child bounding box
308
 
  bbox_t bounds;
309
 
}
310
 
child_t;
311
 
 
312
 
 
313
 
typedef struct node_s
314
 
{
315
 
  int x, y;     // starting point
316
 
  int dx, dy;   // offset to ending point
317
 
 
318
 
  // right & left children
319
 
  child_t r;
320
 
  child_t l;
321
 
 
322
 
  // node index.  Only valid once the NODES or GL_NODES lump has been
323
 
  // created.
324
 
  int index;
325
 
 
326
 
  // the node is too long, and the (dx,dy) values should be halved
327
 
  // when writing into the NODES lump.
328
 
  int too_long;
329
 
}
330
 
node_t;
331
 
 
332
 
 
333
 
typedef struct superblock_s
334
 
{
335
 
  // parent of this block, or NULL for a top-level block
336
 
  struct superblock_s *parent;
337
 
 
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.
341
 
  int x1, y1;
342
 
  int x2, y2;
343
 
 
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];
348
 
 
349
 
  // number of real segs and minisegs contained by this block
350
 
  // (including all sub-blocks below it).
351
 
  int real_num;
352
 
  int mini_num;
353
 
 
354
 
  // list of segs completely contained by this block.
355
 
  seg_t *segs;
356
 
}
357
 
superblock_t;
358
 
 
359
 
#define SUPER_IS_LEAF(s)  \
360
 
    ((s)->x2-(s)->x1 <= 256 && (s)->y2-(s)->y1 <= 256)
361
 
 
362
 
 
363
 
/* ----- Level data arrays ----------------------- */
364
 
 
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;
370
 
extern int num_segs;
371
 
extern int num_subsecs;
372
 
extern int num_nodes;
373
 
extern int num_stale_nodes;
374
 
 
375
 
extern int num_normal_vert;
376
 
extern int num_gl_vert;
377
 
extern int num_complete_seg;
378
 
 
379
 
 
380
 
/* ----- function prototypes ----------------------- */
381
 
 
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);
388
 
seg_t *NewSeg(void);
389
 
subsec_t *NewSubsec(void);
390
 
node_t *NewNode(void);
391
 
node_t *NewStaleNode(void);
392
 
wall_tip_t *NewWallTip(void);
393
 
 
394
 
// lookup routines
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);
404
 
 
405
 
// check whether the current level already has normal nodes
406
 
int CheckForNormalNodes(void);
407
 
 
408
 
// load all level data for the current level
409
 
void LoadLevel(void);
410
 
 
411
 
// free all level data
412
 
void FreeLevel(void);
413
 
 
414
 
// save the newly computed NODE info etc..
415
 
void SaveLevel(node_t *root_node);
416
 
 
417
 
#endif /* __GLBSP_LEVEL_H__ */