~ubuntu-branches/ubuntu/natty/alien-arena/natty

« back to all changes in this revision

Viewing changes to source/utils3/bsp/qbsp3/writebsp.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia, Barry deFreese, Ansgar Burchardt, Gonéri Le Bouder, Andres Mejia
  • Date: 2008-04-18 17:43:24 UTC
  • mfrom: (1.1.2 upstream) (3.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20080418174324-si1umi8dngglaha4
Tags: 7.0-1
[ Barry deFreese ]
* Escape - in alien-arena-server.6.
* Add myself to uploaders.

[ Ansgar Burchardt ]
* Remove deprecated Encoding key from .desktop file.

[ Gonéri Le Bouder ]
* Remove Homepage from package description.

[ Andres Mejia ]
* New upstream release.
* Removing XS- part for Vcs-* lines.
* Removing +ssh part of Vcs-Svn line.
* Bumped to Standards-Version 3.7.3.
* Test for existence of *-stamp stamps before removing them.
* Removed Encoding field in desktop file.
* Modify patch for upstream Makefile to make Makefile more useful in building
  Debian packages.
  + Also fixes problem not detecting the existence of libcurl.
* Remove debug packages for release. Will support nostrip option instead.
* Add description for fix-CVE-2007-4754-CVE-2007-4755.dpatch, silences
  lintian warning.
* Add new link for watchfile.
  + Closes: #453555
* Moved debian/scripts/alien-arena-tarball.sh to
  debian/alien-arena-get-orig-source.
* Modified alien-arena-data-get-orig-source to make it easier to maintain.
* Switched from dpatch to quilt.
* Cut down package description.
* Closing bug about mouse constantly looking up. The submitter could not
  reproduce the bug after deleting the ~/.alien-arena directory.
  + Closes: #457700
* Updated copyright file for new release.
* Updated README.Debian files.
* Adding new images for icons. Need build dependency on sharutils.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "qbsp.h"
 
2
 
 
3
int             c_nofaces;
 
4
int             c_facenodes;
 
5
 
 
6
 
 
7
/*
 
8
=========================================================
 
9
 
 
10
ONLY SAVE OUT PLANES THAT ARE ACTUALLY USED AS NODES
 
11
 
 
12
=========================================================
 
13
*/
 
14
 
 
15
int             planeused[MAX_MAP_PLANES];
 
16
 
 
17
/*
 
18
============
 
19
EmitPlanes
 
20
 
 
21
There is no oportunity to discard planes, because all of the original
 
22
brushes will be saved in the map.
 
23
============
 
24
*/
 
25
void EmitPlanes (void)
 
26
{
 
27
        int                     i;
 
28
        dplane_t        *dp;
 
29
        plane_t         *mp;
 
30
        int             planetranslate[MAX_MAP_PLANES];
 
31
 
 
32
        mp = mapplanes;
 
33
        for (i=0 ; i<nummapplanes ; i++, mp++)
 
34
        {
 
35
                dp = &dplanes[numplanes];
 
36
                planetranslate[i] = numplanes;
 
37
                VectorCopy ( mp->normal, dp->normal);
 
38
                dp->dist = mp->dist;
 
39
                dp->type = mp->type;
 
40
                numplanes++;
 
41
        }
 
42
}
 
43
 
 
44
 
 
45
//========================================================
 
46
 
 
47
void EmitMarkFace (dleaf_t *leaf_p, face_t *f)
 
48
{
 
49
        int                     i;
 
50
        int                     facenum;
 
51
 
 
52
        while (f->merged)
 
53
                f = f->merged;
 
54
 
 
55
        if (f->split[0])
 
56
        {
 
57
                EmitMarkFace (leaf_p, f->split[0]);
 
58
                EmitMarkFace (leaf_p, f->split[1]);
 
59
                return;
 
60
        }
 
61
 
 
62
        facenum = f->outputnumber;
 
63
        if (facenum == -1)
 
64
                return; // degenerate face
 
65
 
 
66
        if (facenum < 0 || facenum >= numfaces)
 
67
                Error ("Bad leafface");
 
68
        for (i=leaf_p->firstleafface ; i<numleaffaces ; i++)
 
69
                if (dleaffaces[i] == facenum)
 
70
                        break;          // merged out face
 
71
        if (i == numleaffaces)
 
72
        {
 
73
                if (numleaffaces >= MAX_MAP_LEAFFACES)
 
74
                        Error ("MAX_MAP_LEAFFACES");
 
75
 
 
76
                dleaffaces[numleaffaces] =  facenum;
 
77
                numleaffaces++;
 
78
        }
 
79
}
 
80
 
 
81
 
 
82
/*
 
83
==================
 
84
EmitLeaf
 
85
==================
 
86
*/
 
87
void EmitLeaf (node_t *node)
 
88
{
 
89
        dleaf_t         *leaf_p;
 
90
        portal_t        *p;
 
91
        int                     s;
 
92
        face_t          *f;
 
93
        bspbrush_t      *b;
 
94
        int                     i;
 
95
        int                     brushnum;
 
96
 
 
97
        // emit a leaf
 
98
        if (numleafs >= MAX_MAP_LEAFS)
 
99
                Error ("MAX_MAP_LEAFS");
 
100
 
 
101
        leaf_p = &dleafs[numleafs];
 
102
        numleafs++;
 
103
 
 
104
        leaf_p->contents = node->contents;
 
105
        leaf_p->cluster = node->cluster;
 
106
        leaf_p->area = node->area;
 
107
 
 
108
        //
 
109
        // write bounding box info
 
110
        //      
 
111
        VectorCopy (node->mins, leaf_p->mins);
 
112
        VectorCopy (node->maxs, leaf_p->maxs);
 
113
        
 
114
        //
 
115
        // write the leafbrushes
 
116
        //
 
117
        leaf_p->firstleafbrush = numleafbrushes;
 
118
        for (b=node->brushlist ; b ; b=b->next)
 
119
        {
 
120
                if (numleafbrushes >= MAX_MAP_LEAFBRUSHES)
 
121
                        Error ("MAX_MAP_LEAFBRUSHES");
 
122
 
 
123
                brushnum = b->original - mapbrushes;
 
124
                for (i=leaf_p->firstleafbrush ; i<numleafbrushes ; i++)
 
125
                        if (dleafbrushes[i] == brushnum)
 
126
                                break;
 
127
                if (i == numleafbrushes)
 
128
                {
 
129
                        dleafbrushes[numleafbrushes] = brushnum;
 
130
                        numleafbrushes++;
 
131
                }
 
132
        }
 
133
        leaf_p->numleafbrushes = numleafbrushes - leaf_p->firstleafbrush;
 
134
 
 
135
        //
 
136
        // write the leaffaces
 
137
        //
 
138
        if (leaf_p->contents & CONTENTS_SOLID)
 
139
                return;         // no leaffaces in solids
 
140
 
 
141
        leaf_p->firstleafface = numleaffaces;
 
142
 
 
143
        for (p = node->portals ; p ; p = p->next[s])    
 
144
        {
 
145
                s = (p->nodes[1] == node);
 
146
                f = p->face[s];
 
147
                if (!f)
 
148
                        continue;       // not a visible portal
 
149
 
 
150
                EmitMarkFace (leaf_p, f);
 
151
        }
 
152
        
 
153
        leaf_p->numleaffaces = numleaffaces - leaf_p->firstleafface;
 
154
}
 
155
 
 
156
 
 
157
/*
 
158
==================
 
159
EmitFace
 
160
==================
 
161
*/
 
162
void EmitFace (face_t *f)
 
163
{
 
164
        dface_t *df;
 
165
        int             i;
 
166
        int             e;
 
167
 
 
168
        f->outputnumber = -1;
 
169
 
 
170
        if (f->numpoints < 3)
 
171
        {
 
172
                return;         // degenerated
 
173
        }
 
174
        if (f->merged || f->split[0] || f->split[1])
 
175
        {
 
176
                return;         // not a final face
 
177
        }
 
178
 
 
179
        // save output number so leaffaces can use
 
180
        f->outputnumber = numfaces;
 
181
 
 
182
        if (numfaces >= MAX_MAP_FACES)
 
183
                Error ("numfaces == MAX_MAP_FACES");
 
184
        df = &dfaces[numfaces];
 
185
        numfaces++;
 
186
 
 
187
        // planenum is used by qlight, but not quake
 
188
        df->planenum = f->planenum & (~1);
 
189
        df->side = f->planenum & 1;
 
190
 
 
191
        df->firstedge = numsurfedges;
 
192
        df->numedges = f->numpoints;
 
193
        df->texinfo = f->texinfo;
 
194
        for (i=0 ; i<f->numpoints ; i++)
 
195
        {
 
196
//              e = GetEdge (f->pts[i], f->pts[(i+1)%f->numpoints], f);
 
197
                e = GetEdge2 (f->vertexnums[i], f->vertexnums[(i+1)%f->numpoints], f);
 
198
                if (numsurfedges >= MAX_MAP_SURFEDGES)
 
199
                        Error ("numsurfedges == MAX_MAP_SURFEDGES");
 
200
                dsurfedges[numsurfedges] = e;
 
201
                numsurfedges++;
 
202
        }
 
203
}
 
204
 
 
205
/*
 
206
============
 
207
EmitDrawingNode_r
 
208
============
 
209
*/
 
210
int EmitDrawNode_r (node_t *node)
 
211
{
 
212
        dnode_t *n;
 
213
        face_t  *f;
 
214
        int             i;
 
215
 
 
216
        if (node->planenum == PLANENUM_LEAF)
 
217
        {
 
218
                EmitLeaf (node);
 
219
                return -numleafs;
 
220
        }
 
221
 
 
222
        // emit a node  
 
223
        if (numnodes == MAX_MAP_NODES)
 
224
                Error ("MAX_MAP_NODES");
 
225
        n = &dnodes[numnodes];
 
226
        numnodes++;
 
227
 
 
228
        VectorCopy (node->mins, n->mins);
 
229
        VectorCopy (node->maxs, n->maxs);
 
230
 
 
231
        planeused[node->planenum]++;
 
232
        planeused[node->planenum^1]++;
 
233
 
 
234
        if (node->planenum & 1)
 
235
                Error ("WriteDrawNodes_r: odd planenum");
 
236
        n->planenum = node->planenum;
 
237
        n->firstface = numfaces;
 
238
 
 
239
        if (!node->faces)
 
240
                c_nofaces++;
 
241
        else
 
242
                c_facenodes++;
 
243
 
 
244
        for (f=node->faces ; f ; f=f->next)
 
245
                EmitFace (f);
 
246
 
 
247
        n->numfaces = numfaces - n->firstface;
 
248
 
 
249
 
 
250
        //
 
251
        // recursively output the other nodes
 
252
        //      
 
253
        for (i=0 ; i<2 ; i++)
 
254
        {
 
255
                if (node->children[i]->planenum == PLANENUM_LEAF)
 
256
                {
 
257
                        n->children[i] = -(numleafs + 1);
 
258
                        EmitLeaf (node->children[i]);
 
259
                }
 
260
                else
 
261
                {
 
262
                        n->children[i] = numnodes;      
 
263
                        EmitDrawNode_r (node->children[i]);
 
264
                }
 
265
        }
 
266
 
 
267
        return n - dnodes;
 
268
}
 
269
 
 
270
//=========================================================
 
271
 
 
272
 
 
273
/*
 
274
============
 
275
WriteBSP
 
276
============
 
277
*/
 
278
void WriteBSP (node_t *headnode)
 
279
{
 
280
        int             oldfaces;
 
281
 
 
282
        c_nofaces = 0;
 
283
        c_facenodes = 0;
 
284
 
 
285
        qprintf ("--- WriteBSP ---\n");
 
286
 
 
287
        oldfaces = numfaces;
 
288
        dmodels[nummodels].headnode = EmitDrawNode_r (headnode);
 
289
 
 
290
        // Workaround for bug in Quake 2. Make sure there is at least one leaf
 
291
        // with contents==0.
 
292
        {
 
293
                int i;
 
294
                dleaf_t *l;
 
295
 
 
296
                for (i=numleafs,l=dleafs;i;i--,l++)
 
297
 
 
298
                if (!l->contents)
 
299
                        break;
 
300
 
 
301
                if (!i)
 
302
                {
 
303
                        l->contents=0;
 
304
                        numleafs++;
 
305
                }
 
306
        }
 
307
                                                   
 
308
        EmitAreaPortals (headnode);
 
309
 
 
310
        qprintf ("%5i nodes with faces\n", c_facenodes);
 
311
        qprintf ("%5i nodes without faces\n", c_nofaces);
 
312
        qprintf ("%5i faces\n", numfaces-oldfaces);
 
313
}
 
314
 
 
315
//===========================================================
 
316
 
 
317
/*
 
318
============
 
319
SetModelNumbers
 
320
============
 
321
*/
 
322
void SetModelNumbers (void)
 
323
{
 
324
        int             i;
 
325
        int             models;
 
326
        char    value[10];
 
327
 
 
328
        models = 1;
 
329
        for (i=1 ; i<num_entities ; i++)
 
330
        {
 
331
                if (entities[i].numbrushes)
 
332
                {
 
333
                        sprintf (value, "*%i", models);
 
334
                        models++;
 
335
                        SetKeyValue (&entities[i], "model", value);
 
336
                }
 
337
        }
 
338
 
 
339
}
 
340
 
 
341
/*
 
342
============
 
343
SetLightStyles
 
344
============
 
345
*/
 
346
#define MAX_SWITCHED_LIGHTS     32
 
347
void SetLightStyles (void)
 
348
{
 
349
        int             stylenum;
 
350
        char    *t;
 
351
        entity_t        *e;
 
352
        int             i, j;
 
353
        char    value[10];
 
354
        char    lighttargets[MAX_SWITCHED_LIGHTS][64];
 
355
 
 
356
 
 
357
        // any light that is controlled (has a targetname)
 
358
        // must have a unique style number generated for it
 
359
 
 
360
        stylenum = 0;
 
361
        for (i=1 ; i<num_entities ; i++)
 
362
        {
 
363
                e = &entities[i];
 
364
 
 
365
                t = ValueForKey (e, "classname");
 
366
                if (Q_strncasecmp (t, "light", 5))
 
367
                        continue;
 
368
                t = ValueForKey (e, "targetname");
 
369
                if (!t[0])
 
370
                        continue;
 
371
                
 
372
                // find this targetname
 
373
                for (j=0 ; j<stylenum ; j++)
 
374
                        if (!strcmp (lighttargets[j], t))
 
375
                                break;
 
376
                if (j == stylenum)
 
377
                {
 
378
                        if (stylenum == MAX_SWITCHED_LIGHTS)
 
379
                                Error ("stylenum == MAX_SWITCHED_LIGHTS");
 
380
                        strcpy (lighttargets[j], t);
 
381
                        stylenum++;
 
382
                }
 
383
                sprintf (value, "%i", 32 + j);
 
384
                SetKeyValue (e, "style", value);
 
385
        }
 
386
 
 
387
}
 
388
 
 
389
//===========================================================
 
390
 
 
391
/*
 
392
============
 
393
EmitBrushes
 
394
============
 
395
*/
 
396
void EmitBrushes (void)
 
397
{
 
398
        int                     i, j, bnum, s, x;
 
399
        dbrush_t        *db;
 
400
        mapbrush_t              *b;
 
401
        dbrushside_t    *cp;
 
402
        vec3_t          normal;
 
403
        vec_t           dist;
 
404
        int                     planenum;
 
405
 
 
406
        numbrushsides = 0;
 
407
        numbrushes = nummapbrushes;
 
408
 
 
409
        for (bnum=0 ; bnum<nummapbrushes ; bnum++)
 
410
        {
 
411
                b = &mapbrushes[bnum];
 
412
                db = &dbrushes[bnum];
 
413
 
 
414
                db->contents = b->contents;
 
415
                db->firstside = numbrushsides;
 
416
                db->numsides = b->numsides;
 
417
                for (j=0 ; j<b->numsides ; j++)
 
418
                {
 
419
                        if (numbrushsides == MAX_MAP_BRUSHSIDES)
 
420
                                Error ("MAX_MAP_BRUSHSIDES");
 
421
                        cp = &dbrushsides[numbrushsides];
 
422
                        numbrushsides++;
 
423
                        cp->planenum = b->original_sides[j].planenum;
 
424
                        cp->texinfo = b->original_sides[j].texinfo;
 
425
                }
 
426
 
 
427
                // add any axis planes not contained in the brush to bevel off corners
 
428
                for (x=0 ; x<3 ; x++)
 
429
                        for (s=-1 ; s<=1 ; s+=2)
 
430
                        {
 
431
                        // add the plane
 
432
                                VectorCopy (vec3_origin, normal);
 
433
                                normal[x] = s;
 
434
                                if (s == -1)
 
435
                                        dist = -b->mins[x];
 
436
                                else
 
437
                                        dist = b->maxs[x];
 
438
                                planenum = FindFloatPlane (normal, dist);
 
439
                                for (i=0 ; i<b->numsides ; i++)
 
440
                                        if (b->original_sides[i].planenum == planenum)
 
441
                                                break;
 
442
                                if (i == b->numsides)
 
443
                                {
 
444
                                        if (numbrushsides >= MAX_MAP_BRUSHSIDES)
 
445
                                                Error ("MAX_MAP_BRUSHSIDES");
 
446
 
 
447
                                        dbrushsides[numbrushsides].planenum = planenum;
 
448
                                        dbrushsides[numbrushsides].texinfo =
 
449
                                                dbrushsides[numbrushsides-1].texinfo;
 
450
                                        numbrushsides++;
 
451
                                        db->numsides++;
 
452
                                }
 
453
                        }
 
454
        }
 
455
 
 
456
}
 
457
 
 
458
//===========================================================
 
459
 
 
460
/*
 
461
==================
 
462
BeginBSPFile
 
463
==================
 
464
*/
 
465
void BeginBSPFile (void)
 
466
{
 
467
        // these values may actually be initialized
 
468
        // if the file existed when loaded, so clear them explicitly
 
469
        nummodels = 0;
 
470
        numfaces = 0;
 
471
        numnodes = 0;
 
472
        numbrushsides = 0;
 
473
        numvertexes = 0;
 
474
        numleaffaces = 0;
 
475
        numleafbrushes = 0;
 
476
        numsurfedges = 0;
 
477
 
 
478
        // edge 0 is not used, because 0 can't be negated
 
479
        numedges = 1;
 
480
 
 
481
        // leave vertex 0 as an error
 
482
        numvertexes = 1;
 
483
 
 
484
        // leave leaf 0 as an error
 
485
        numleafs = 1;
 
486
        dleafs[0].contents = CONTENTS_SOLID;
 
487
}
 
488
 
 
489
 
 
490
/*
 
491
============
 
492
EndBSPFile
 
493
============
 
494
*/
 
495
void EndBSPFile (void)
 
496
{
 
497
        char    path[1024];
 
498
#if 0
 
499
        int             len;
 
500
        byte    *buf;
 
501
#endif
 
502
 
 
503
 
 
504
        EmitBrushes ();
 
505
        EmitPlanes ();
 
506
        UnparseEntities ();
 
507
 
 
508
        // load the pop
 
509
#if 0
 
510
        sprintf (path, "%s/pics/pop.lmp", gamedir);
 
511
        len = LoadFile (path, &buf);
 
512
        memcpy (dpop, buf, sizeof(dpop));
 
513
        free (buf);
 
514
#endif
 
515
 
 
516
        // write the map
 
517
        sprintf (path, "%s.bsp", source);
 
518
        printf ("Writing %s\n", path);
 
519
        WriteBSPFile (path);
 
520
}
 
521
 
 
522
 
 
523
/*
 
524
==================
 
525
BeginModel
 
526
==================
 
527
*/
 
528
int     firstmodleaf;
 
529
extern  int firstmodeledge;
 
530
extern  int     firstmodelface;
 
531
void BeginModel (void)
 
532
{
 
533
        dmodel_t        *mod;
 
534
        int                     start, end;
 
535
        mapbrush_t      *b;
 
536
        int                     j;
 
537
        entity_t        *e;
 
538
        vec3_t          mins, maxs;
 
539
 
 
540
        if (nummodels == MAX_MAP_MODELS)
 
541
                Error ("MAX_MAP_MODELS");
 
542
        mod = &dmodels[nummodels];
 
543
 
 
544
        mod->firstface = numfaces;
 
545
 
 
546
        firstmodleaf = numleafs;
 
547
        firstmodeledge = numedges;
 
548
        firstmodelface = numfaces;
 
549
 
 
550
        //
 
551
        // bound the brushes
 
552
        //
 
553
        e = &entities[entity_num];
 
554
 
 
555
        start = e->firstbrush;
 
556
        end = start + e->numbrushes;
 
557
        ClearBounds (mins, maxs);
 
558
 
 
559
        for (j=start ; j<end ; j++)
 
560
        {
 
561
                b = &mapbrushes[j];
 
562
                if (!b->numsides)
 
563
                        continue;       // not a real brush (origin brush)
 
564
                AddPointToBounds (b->mins, mins, maxs);
 
565
                AddPointToBounds (b->maxs, mins, maxs);
 
566
        }
 
567
 
 
568
        VectorCopy (mins, mod->mins);
 
569
        VectorCopy (maxs, mod->maxs);
 
570
}
 
571
 
 
572
 
 
573
/*
 
574
==================
 
575
EndModel
 
576
==================
 
577
*/
 
578
void EndModel (void)
 
579
{
 
580
        dmodel_t        *mod;
 
581
 
 
582
        mod = &dmodels[nummodels];
 
583
 
 
584
        mod->numfaces = numfaces - mod->firstface;
 
585
 
 
586
        nummodels++;
 
587
}
 
588