#include "qbsp.h"
Include dependency graph for writebsp.c:

Go to the source code of this file.
Defines | |
| #define | MAX_SWITCHED_LIGHTS 32 |
Functions | |
| void | BeginBSPFile (void) |
| void | BeginModel (void) |
| void | EmitBrushes (void) |
| int | EmitDrawNode_r (node_t *node) |
| void | EmitFace (face_t *f) |
| void | EmitLeaf (node_t *node) |
| void | EmitMarkFace (dleaf_t *leaf_p, face_t *f) |
| void | EmitPlanes (void) |
| void | EndBSPFile (void) |
| void | EndModel (void) |
| void | SetLightStyles (void) |
| void | SetModelNumbers (void) |
| void | WriteBSP (node_t *headnode) |
Variables | |
| int | c_facenodes |
| int | c_nofaces |
| int | firstmodeledge |
| int | firstmodelface |
| int | firstmodleaf |
| int | planeused [MAX_MAP_PLANES] |
|
|
Definition at line 352 of file writebsp.c. |
|
|
Definition at line 477 of file writebsp.c. Referenced by ProcessModels(). 00478 {
00479 // these values may actually be initialized
00480 // if the file existed when loaded, so clear them explicitly
00481 nummodels = 0;
00482 numfaces = 0;
00483 numnodes = 0;
00484 numbrushsides = 0;
00485 numvertexes = 0;
00486 numleaffaces = 0;
00487 numleafbrushes = 0;
00488 numsurfedges = 0;
00489
00490 // edge 0 is not used, because 0 can't be negated
00491 numedges = 1;
00492
00493 // leave vertex 0 as an error
00494 numvertexes = 1;
00495
00496 // leave leaf 0 as an error
00497 numleafs = 1;
00498 dleafs[0].contents = CONTENTS_SOLID;
00499 }
|
|
|
Definition at line 538 of file writebsp.c. Referenced by ProcessSubModel(), and ProcessWorldModel(). 00539 {
00540 dmodel_t *mod;
00541 int start, end;
00542 mapbrush_t *b;
00543 int j;
00544 entity_t *e;
00545 vec3_t mins, maxs;
00546
00547 if (nummodels == MAX_MAP_MODELS)
00548 Error ("MAX_MAP_MODELS");
00549 mod = &dmodels[nummodels];
00550
00551 mod->firstface = numfaces;
00552
00553 firstmodleaf = numleafs;
00554 firstmodeledge = numedges;
00555 firstmodelface = numfaces;
00556
00557 //
00558 // bound the brushes
00559 //
00560 e = &entities[entity_num];
00561
00562 start = e->firstbrush;
00563 end = start + e->numbrushes;
00564 ClearBounds (mins, maxs);
00565
00566 for (j=start ; j<end ; j++)
00567 {
00568 b = &mapbrushes[j];
00569 if (!b->numsides)
00570 continue; // not a real brush (origin brush)
00571 AddPointToBounds (b->mins, mins, maxs);
00572 AddPointToBounds (b->maxs, mins, maxs);
00573 }
00574
00575 VectorCopy (mins, mod->mins);
00576 VectorCopy (maxs, mod->maxs);
00577 }
|
|
|
Definition at line 402 of file writebsp.c. References b, mapbrush_s::contents, dbrush_t::contents, cp, dbrushes, dbrushsides, Error(), FindFloatPlane(), dbrush_t::firstside, i, j, mapbrush_t, mapbrushes, mapbrush_s::maxs, mapbrush_s::mins, numbrushes, numbrushsides, mapbrush_s::numsides, dbrush_t::numsides, mapbrush_s::original_sides, side_s::planenum, dbrushside_t::planenum, s, side_s::texinfo, dbrushside_t::texinfo, vec3_origin, vec3_t, vec_t, VectorCopy, and x. Referenced by BeginModel(), and EndBSPFile(). 00403 {
00404 int i, j, bnum, s, x;
00405 dbrush_t *db;
00406 mapbrush_t *b;
00407 dbrushside_t *cp;
00408 vec3_t normal;
00409 vec_t dist;
00410 int planenum;
00411
00412 numbrushsides = 0;
00413 numbrushes = nummapbrushes;
00414
00415 for (bnum=0 ; bnum<nummapbrushes ; bnum++)
00416 {
00417 b = &mapbrushes[bnum];
00418 db = &dbrushes[bnum];
00419
00420 db->contents = b->contents;
00421 db->firstside = numbrushsides;
00422 db->numsides = b->numsides;
00423 for (j=0 ; j<b->numsides ; j++)
00424 {
00425 if (numbrushsides == MAX_MAP_BRUSHSIDES)
00426 Error ("MAX_MAP_BRUSHSIDES");
00427 cp = &dbrushsides[numbrushsides];
00428 numbrushsides++;
00429 cp->planenum = b->original_sides[j].planenum;
00430 cp->texinfo = b->original_sides[j].texinfo;
00431 }
00432
00433 #ifdef ME
00434 //for collision detection, bounding boxes are axial :)
00435 //brushes are convex so just add dot or line touching planes on the sides of
00436 //the brush parallell to the axis planes
00437 #endif
00438 // add any axis planes not contained in the brush to bevel off corners
00439 for (x=0 ; x<3 ; x++)
00440 for (s=-1 ; s<=1 ; s+=2)
00441 {
00442 // add the plane
00443 VectorCopy (vec3_origin, normal);
00444 normal[x] = s;
00445 if (s == -1)
00446 dist = -b->mins[x];
00447 else
00448 dist = b->maxs[x];
00449 planenum = FindFloatPlane (normal, dist);
00450 for (i=0 ; i<b->numsides ; i++)
00451 if (b->original_sides[i].planenum == planenum)
00452 break;
00453 if (i == b->numsides)
00454 {
00455 if (numbrushsides >= MAX_MAP_BRUSHSIDES)
00456 Error ("MAX_MAP_BRUSHSIDES");
00457
00458 dbrushsides[numbrushsides].planenum = planenum;
00459 dbrushsides[numbrushsides].texinfo =
00460 dbrushsides[numbrushsides-1].texinfo;
00461 numbrushsides++;
00462 db->numsides++;
00463 }
00464 }
00465
00466 }
00467
00468 }
|
Here is the call graph for this function:

|
|
Definition at line 235 of file writebsp.c. References c_facenodes, c_nofaces, dnode_t::children, node_s::children, dnodes, EmitDrawNode_r(), EmitFace(), EmitLeaf(), Error(), f, face_t, node_s::faces, dnode_t::firstface, i, dnode_t::maxs, node_s::maxs, dnode_t::mins, node_s::mins, n, face_s::next, node_t, numfaces, dnode_t::numfaces, numleafs, numnodes, dnode_t::planenum, node_s::planenum, planeused, and VectorCopy. 00236 {
00237 dnode_t *n;
00238 face_t *f;
00239 int i;
00240
00241 if (node->planenum == PLANENUM_LEAF)
00242 {
00243 EmitLeaf (node);
00244 return -numleafs;
00245 }
00246
00247 // emit a node
00248 if (numnodes == MAX_MAP_NODES)
00249 Error ("MAX_MAP_NODES");
00250 n = &dnodes[numnodes];
00251 numnodes++;
00252
00253 VectorCopy (node->mins, n->mins);
00254 VectorCopy (node->maxs, n->maxs);
00255
00256 planeused[node->planenum]++;
00257 planeused[node->planenum^1]++;
00258
00259 if (node->planenum & 1)
00260 Error ("WriteDrawNodes_r: odd planenum");
00261 n->planenum = node->planenum;
00262 n->firstface = numfaces;
00263
00264 if (!node->faces)
00265 c_nofaces++;
00266 else
00267 c_facenodes++;
00268
00269 for (f=node->faces ; f ; f=f->next)
00270 EmitFace (f);
00271
00272 n->numfaces = numfaces - n->firstface;
00273
00274
00275 //
00276 // recursively output the other nodes
00277 //
00278 for (i=0 ; i<2 ; i++)
00279 {
00280 if (node->children[i]->planenum == PLANENUM_LEAF)
00281 {
00282 n->children[i] = -(numleafs + 1);
00283 EmitLeaf (node->children[i]);
00284 }
00285 else
00286 {
00287 n->children[i] = numnodes;
00288 EmitDrawNode_r (node->children[i]);
00289 }
00290 }
00291
00292 return n - dnodes;
00293 }
|
Here is the call graph for this function:

|
|
Definition at line 187 of file writebsp.c. References dfaces, dsurfedges, e, Error(), f, face_t, dface_t::firstedge, GetEdge2(), i, face_s::merged, dface_t::numedges, numfaces, face_s::numpoints, numsurfedges, face_s::outputnumber, face_s::planenum, dface_t::planenum, dface_t::side, face_s::split, face_s::texinfo, dface_t::texinfo, and face_s::vertexnums. Referenced by EmitDrawNode_r(). 00188 {
00189 dface_t *df;
00190 int i;
00191 int e;
00192
00193 f->outputnumber = -1;
00194
00195 if (f->numpoints < 3)
00196 {
00197 return; // degenerated
00198 }
00199 if (f->merged || f->split[0] || f->split[1])
00200 {
00201 return; // not a final face
00202 }
00203
00204 // save output number so leaffaces can use
00205 f->outputnumber = numfaces;
00206
00207 if (numfaces >= MAX_MAP_FACES)
00208 Error ("numfaces == MAX_MAP_FACES");
00209 df = &dfaces[numfaces];
00210 numfaces++;
00211
00212 // planenum is used by qlight, but not quake
00213 df->planenum = f->planenum & (~1);
00214 df->side = f->planenum & 1;
00215
00216 df->firstedge = numsurfedges;
00217 df->numedges = f->numpoints;
00218 df->texinfo = f->texinfo;
00219 for (i=0 ; i<f->numpoints ; i++)
00220 {
00221 // e = GetEdge (f->pts[i], f->pts[(i+1)%f->numpoints], f);
00222 e = GetEdge2 (f->vertexnums[i], f->vertexnums[(i+1)%f->numpoints], f);
00223 if (numsurfedges >= MAX_MAP_SURFEDGES)
00224 Error ("numsurfedges == MAX_MAP_SURFEDGES");
00225 dsurfedges[numsurfedges] = e;
00226 numsurfedges++;
00227 }
00228 }
|
Here is the call graph for this function:

|
|
Definition at line 112 of file writebsp.c. References node_s::area, dleaf_t::area, b, node_s::brushlist, bspbrush_t, node_s::cluster, dleaf_t::cluster, node_s::contents, dleaf_t::contents, dleafbrushes, dleafs, EmitMarkFace(), Error(), f, portal_s::face, face_t, dleaf_t::firstleafbrush, dleaf_t::firstleafface, i, dleaf_t::maxs, node_s::maxs, dleaf_t::mins, node_s::mins, portal_s::next, bspbrush_s::next, node_t, portal_s::nodes, dleaf_t::numleafbrushes, numleafbrushes, numleaffaces, dleaf_t::numleaffaces, numleafs, bspbrush_s::original, p, portal_t, node_s::portals, s, and VectorCopy. 00113 {
00114 dleaf_t *leaf_p;
00115 portal_t *p;
00116 int s;
00117 face_t *f;
00118 bspbrush_t *b;
00119 int i;
00120 int brushnum;
00121
00122 // emit a leaf
00123 if (numleafs >= MAX_MAP_LEAFS)
00124 Error ("MAX_MAP_LEAFS");
00125
00126 leaf_p = &dleafs[numleafs];
00127 numleafs++;
00128
00129 leaf_p->contents = node->contents;
00130 leaf_p->cluster = node->cluster;
00131 leaf_p->area = node->area;
00132
00133 //
00134 // write bounding box info
00135 //
00136 VectorCopy (node->mins, leaf_p->mins);
00137 VectorCopy (node->maxs, leaf_p->maxs);
00138
00139 //
00140 // write the leafbrushes
00141 //
00142 leaf_p->firstleafbrush = numleafbrushes;
00143 for (b=node->brushlist ; b ; b=b->next)
00144 {
00145 if (numleafbrushes >= MAX_MAP_LEAFBRUSHES)
00146 Error ("MAX_MAP_LEAFBRUSHES");
00147
00148 brushnum = b->original - mapbrushes;
00149 for (i=leaf_p->firstleafbrush ; i<numleafbrushes ; i++)
00150 if (dleafbrushes[i] == brushnum)
00151 break;
00152 if (i == numleafbrushes)
00153 {
00154 dleafbrushes[numleafbrushes] = brushnum;
00155 numleafbrushes++;
00156 }
00157 }
00158 leaf_p->numleafbrushes = numleafbrushes - leaf_p->firstleafbrush;
00159
00160 //
00161 // write the leaffaces
00162 //
00163 if (leaf_p->contents & CONTENTS_SOLID)
00164 return; // no leaffaces in solids
00165
00166 leaf_p->firstleafface = numleaffaces;
00167
00168 for (p = node->portals ; p ; p = p->next[s])
00169 {
00170 s = (p->nodes[1] == node);
00171 f = p->face[s];
00172 if (!f)
00173 continue; // not a visible portal
00174
00175 EmitMarkFace (leaf_p, f);
00176 }
00177
00178 leaf_p->numleaffaces = numleaffaces - leaf_p->firstleafface;
00179 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 71 of file writebsp.c. References dleaffaces, Error(), f, face_t, dleaf_t::firstleafface, i, face_s::merged, numleaffaces, face_s::outputnumber, and face_s::split. Referenced by EmitLeaf(). 00072 {
00073 int i;
00074 int facenum;
00075
00076 while (f->merged)
00077 f = f->merged;
00078
00079 if (f->split[0])
00080 {
00081 EmitMarkFace (leaf_p, f->split[0]);
00082 EmitMarkFace (leaf_p, f->split[1]);
00083 return;
00084 }
00085
00086 facenum = f->outputnumber;
00087 if (facenum == -1)
00088 return; // degenerate face
00089
00090 if (facenum < 0 || facenum >= numfaces)
00091 Error ("Bad leafface");
00092 for (i=leaf_p->firstleafface ; i<numleaffaces ; i++)
00093 if (dleaffaces[i] == facenum)
00094 break; // merged out face
00095 if (i == numleaffaces)
00096 {
00097 if (numleaffaces >= MAX_MAP_LEAFFACES)
00098 Error ("MAX_MAP_LEAFFACES");
00099
00100 dleaffaces[numleaffaces] = facenum;
00101 numleaffaces++;
00102 }
00103
00104 }
|
Here is the call graph for this function:

|
|
Definition at line 46 of file writebsp.c. References plane_t::dist, dplane_t::dist, dplanes, Error(), i, dplane_t::normal, plane_t::normal, numplanes, plane_t::type, dplane_t::type, and VectorCopy. Referenced by EndBSPFile(). 00047 {
00048 int i;
00049 dplane_t *dp;
00050 plane_t *mp;
00051 //ME: this causes a crash??
00052 // int planetranslate[MAX_MAP_PLANES];
00053
00054 mp = mapplanes;
00055 for (i=0 ; i<nummapplanes ; i++, mp++)
00056 {
00057 dp = &dplanes[numplanes];
00058 // planetranslate[i] = numplanes;
00059 VectorCopy ( mp->normal, dp->normal);
00060 dp->dist = mp->dist;
00061 dp->type = mp->type;
00062 numplanes++;
00063 if (numplanes >= MAX_MAP_PLANES)
00064 Error("MAX_MAP_PLANES");
00065 }
00066 }
|
Here is the call graph for this function:

|
|
Definition at line 507 of file writebsp.c. Referenced by main(). 00508 {
00509 #if 0
00510 char path[1024];
00511 int len;
00512 byte *buf;
00513 #endif
00514
00515
00516 EmitBrushes ();
00517 EmitPlanes ();
00518 Q2_UnparseEntities ();
00519
00520 // load the pop
00521 #if 0
00522 sprintf (path, "%s/pics/pop.lmp", gamedir);
00523 len = LoadFile (path, &buf);
00524 memcpy (dpop, buf, sizeof(dpop));
00525 FreeMemory(buf);
00526 #endif
00527 }
|
|
|
Definition at line 585 of file writebsp.c. References dmodels, dmodel_t::firstface, numfaces, dmodel_t::numfaces, and nummodels. Referenced by ProcessSubModel(), and ProcessWorldModel(). 00586 {
00587 dmodel_t *mod;
00588
00589 mod = &dmodels[nummodels];
00590
00591 mod->numfaces = numfaces - mod->firstface;
00592
00593 nummodels++;
00594 }
|
|
|
Definition at line 353 of file writebsp.c. Referenced by main(), and OnlyEnts(). 00354 {
00355 int stylenum;
00356 char *t;
00357 entity_t *e;
00358 int i, j;
00359 char value[10];
00360 char lighttargets[MAX_SWITCHED_LIGHTS][64];
00361
00362
00363 // any light that is controlled (has a targetname)
00364 // must have a unique style number generated for it
00365
00366 stylenum = 0;
00367 for (i=1 ; i<num_entities ; i++)
00368 {
00369 e = &entities[i];
00370
00371 t = ValueForKey (e, "classname");
00372 if (Q_strncasecmp (t, "light", 5))
00373 continue;
00374 t = ValueForKey (e, "targetname");
00375 if (!t[0])
00376 continue;
00377
00378 // find this targetname
00379 for (j=0 ; j<stylenum ; j++)
00380 if (!strcmp (lighttargets[j], t))
00381 break;
00382 if (j == stylenum)
00383 {
00384 if (stylenum == MAX_SWITCHED_LIGHTS)
00385 Error ("stylenum == MAX_SWITCHED_LIGHTS");
00386 strcpy (lighttargets[j], t);
00387 stylenum++;
00388 }
00389 sprintf (value, "%i", 32 + j);
00390 SetKeyValue (e, "style", value);
00391 }
00392
00393 }
|
|
|
Definition at line 328 of file writebsp.c. Referenced by main(), and OnlyEnts(). 00329 {
00330 int i;
00331 int models;
00332 char value[10];
00333
00334 models = 1;
00335 for (i=1 ; i<num_entities ; i++)
00336 {
00337 if (entities[i].numbrushes)
00338 {
00339 sprintf (value, "*%i", models);
00340 models++;
00341 SetKeyValue (&entities[i], "model", value);
00342 }
00343 }
00344
00345 }
|
|
|
Definition at line 303 of file writebsp.c. References c_facenodes, c_nofaces, dmodels, EmitAreaPortals(), EmitDrawNode_r(), dmodel_t::headnode, node_t, numfaces, and qprintf(). 00304 {
00305 int oldfaces;
00306
00307 c_nofaces = 0;
00308 c_facenodes = 0;
00309
00310 qprintf ("--- WriteBSP ---\n");
00311
00312 oldfaces = numfaces;
00313 dmodels[nummodels].headnode = EmitDrawNode_r (headnode);
00314 EmitAreaPortals (headnode);
00315
00316 qprintf ("%5i nodes with faces\n", c_facenodes);
00317 qprintf ("%5i nodes without faces\n", c_nofaces);
00318 qprintf ("%5i faces\n", numfaces-oldfaces);
00319 }
|
Here is the call graph for this function:

|
|
Definition at line 25 of file writebsp.c. Referenced by EmitDrawNode_r(), and WriteBSP(). |
|
|
Definition at line 24 of file writebsp.c. Referenced by EmitDrawNode_r(), and WriteBSP(). |
|
|
Definition at line 59 of file faces.c. Referenced by BeginModel(). |
|
|
Definition at line 60 of file faces.c. Referenced by BeginModel(). |
|
|
Definition at line 535 of file writebsp.c. Referenced by BeginModel(). |
|
|
Definition at line 36 of file writebsp.c. Referenced by EmitDrawNode_r(). |
1.3.9.1