Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

map.c File Reference

#include "qbsp.h"

Include dependency graph for map.c:

Include dependency graph

Go to the source code of this file.

Defines

#define DIST_EPSILON   0.01
#define NORMAL_EPSILON   0.00001
#define PLANE_HASHES   1024
#define USE_HASHING

Functions

void AddBackSides (void)
void AddBrushBevels (void)
void AddPlaneToHash (plane_t *p)
void AdjustBrushesForOrigin (entity_t *ent)
int CreateNewFloatPlane (vec3_t normal, vec_t dist)
int FindFloatPlane (vec3_t normal, vec_t dist)
bspbrush_tFinishBrush (void)
void LoadMapFile (char *filename)
int MapPlaneFromPoints (vec3_t p0, vec3_t p1, vec3_t p2)
void MoveBrushesToWorld (entity_t *mapent)
void ParseBrush (void)
qboolean ParseMapEntity (void)
void ParseRawBrush ()
void ParseTerrain (void)
qboolean PlaneEqual (plane_t *p, vec3_t normal, vec_t dist)
void QuakeTextureVecs (plane_t *plane, vec_t shift[2], vec_t rotate, vec_t scale[2], vec_t mappingVecs[2][4])
qboolean RemoveDuplicateBrushPlanes (bspbrush_t *b)
void SetBrushContents (bspbrush_t *b)
void SetTerrainTextures (void)
void SnapPlane (vec3_t normal, vec_t *dist)
void SnapVector (vec3_t normal)
void TestExpandBrushes (void)
void TextureAxisFromPlane (plane_t *pln, vec3_t xv, vec3_t yv)

Variables

vec3_t baseaxis [18]
bspbrush_tbuildBrush
int c_areaportals
int c_boxbevels
int c_detail
int c_edgebevels
int c_structural
int entitySourceBrushes
vec3_t map_maxs
vec3_t map_mins
entity_tmapent
char mapIndexedShaders [MAX_MAP_BRUSHSIDES][MAX_QPATH]
plane_t mapplanes [MAX_MAP_PLANES]
int numMapIndexedShaders
int numMapPatches
int nummapplanes
plane_tplanehash [PLANE_HASHES]


Define Documentation

#define DIST_EPSILON   0.01
 

Definition at line 84 of file map.c.

#define NORMAL_EPSILON   0.00001
 

Definition at line 83 of file map.c.

#define PLANE_HASHES   1024
 

Definition at line 33 of file map.c.

#define USE_HASHING
 

Definition at line 32 of file map.c.


Function Documentation

void AddBackSides void   ) 
 

Definition at line 518 of file map.c.

Referenced by FinishBrush().

00518                           {
00519 /*
00520     bspbrush_t  *b;
00521     int         i, originalSides;
00522     side_t      *s;
00523     side_t      *newSide;
00524 
00525     b = buildBrush;
00526     originalSides = b->numsides;
00527     for ( i = 0 ; i < originalSides ; i++ ) {
00528         s = &b->sides[i];
00529         if ( !s->shaderInfo ) {
00530             continue;
00531         }
00532         if ( !(s->shaderInfo->contents & CONTENTS_FOG) ) {
00533             continue;
00534         }
00535 
00536         // duplicate the up-facing side
00537         if ( mapplanes[ s->planenum ].normal[2] == 1 ) {
00538             newSide = &b->sides[ b->numsides ];
00539             b->numsides++;
00540 
00541             *newSide = *s;
00542             newSide->backSide = qtrue;
00543             newSide->planenum = s->planenum ^ 1;    // opposite side
00544         }
00545     }
00546 */
00547 }

void AddBrushBevels void   ) 
 

Definition at line 370 of file map.c.

References side_s::bevel, buildBrush, c_boxbevels, c_edgebevels, side_s::contents, bspbrush_s::contents, CrossProduct(), d, DotProduct, Error(), FindFloatPlane(), i, j, k, l, mapplanes, bspbrush_s::maxs, memset(), bspbrush_s::mins, plane_t::normal, winding_t::numpoints, bspbrush_s::numsides, order, winding_t::p, PlaneEqual(), side_s::planenum, s, side_t, bspbrush_s::sides, SnapVector, vec3_t, VectorClear, VectorNormalize(), VectorSubtract, w, and side_s::winding.

Referenced by AAS_CreateCurveBrushes(), AAS_CreateMapBrushes(), AAS_PositionFuncRotatingBrush(), FinishBrush(), HL_BSPBrushToMapBrush(), Q1_BSPBrushToMapBrush(), and Q2_ParseBrush().

00370                             {
00371     int     axis, dir;
00372     int     i, order;
00373     side_t  sidetemp;
00374     side_t  *s;
00375     vec3_t  normal;
00376     float   dist;
00377 
00378     //
00379     // add the axial planes
00380     //
00381     order = 0;
00382     for (axis=0 ; axis <3 ; axis++)
00383     {
00384         for (dir=-1 ; dir <= 1 ; dir+=2, order++)
00385         {
00386             // see if the plane is allready present
00387             for ( i=0, s=buildBrush->sides ; i < buildBrush->numsides ; i++,s++ ) {
00388                 if (mapplanes[s->planenum].normal[axis] == dir)
00389                     break;
00390             }
00391 
00392             if (i == buildBrush->numsides )
00393             {   // add a new side
00394                 if ( buildBrush->numsides == MAX_BUILD_SIDES ) {
00395                     Error( "MAX_BUILD_SIDES" );
00396                 }
00397                 memset( s, 0, sizeof( *s ) );
00398                 buildBrush->numsides++;
00399                 VectorClear (normal);
00400                 normal[axis] = dir;
00401                 if (dir == 1)
00402                     dist = buildBrush->maxs[axis];
00403                 else
00404                     dist = -buildBrush->mins[axis];
00405                 s->planenum = FindFloatPlane (normal, dist);
00406                 s->contents = buildBrush->sides[0].contents;
00407                 s->bevel = qtrue;
00408                 c_boxbevels++;
00409             }
00410 
00411             // if the plane is not in it canonical order, swap it
00412             if (i != order)
00413             {
00414                 sidetemp = buildBrush->sides[order];
00415                 buildBrush->sides[order] = buildBrush->sides[i];
00416                 buildBrush->sides[i] = sidetemp;
00417             }
00418         }
00419     }
00420 
00421     //
00422     // add the edge bevels
00423     //
00424     if ( buildBrush->numsides == 6 ) {
00425         return;     // pure axial
00426   } else {
00427       int           j, k, l;
00428       float     d;
00429       winding_t *w, *w2;
00430       side_t        *s2;
00431       vec3_t        vec, vec2;
00432 
00433       // test the non-axial plane edges
00434       // this code tends to cause some problems...
00435       for (i=6 ; i<buildBrush->numsides ; i++)
00436       {
00437           s = buildBrush->sides + i;
00438           w = s->winding;
00439           if (!w)
00440               continue;
00441           for (j=0 ; j<w->numpoints ; j++)
00442           {
00443               k = (j+1)%w->numpoints;
00444               VectorSubtract (w->p[j], w->p[k], vec);
00445               if (VectorNormalize (vec, vec) < 0.5)
00446                   continue;
00447               SnapVector (vec);
00448               for (k=0 ; k<3 ; k++)
00449                   if ( vec[k] == -1 || vec[k] == 1)
00450                       break;    // axial
00451               if (k != 3)
00452                   continue; // only test non-axial edges
00453 
00454               // try the six possible slanted axials from this edge
00455               for (axis=0 ; axis <3 ; axis++)
00456               {
00457                   for (dir=-1 ; dir <= 1 ; dir+=2)
00458                   {
00459                       // construct a plane
00460                       VectorClear (vec2);
00461                       vec2[axis] = dir;
00462                       CrossProduct (vec, vec2, normal);
00463                       if (VectorNormalize (normal, normal) < 0.5)
00464                           continue;
00465                       dist = DotProduct (w->p[j], normal);
00466 
00467                       // if all the points on all the sides are
00468                       // behind this plane, it is a proper edge bevel
00469                       for (k=0 ; k < buildBrush->numsides ; k++)
00470                       {
00471                           // if this plane has allready been used, skip it
00472                           if (PlaneEqual (&mapplanes[buildBrush->sides[k].planenum]
00473                               , normal, dist) )
00474                               break;
00475 
00476                           w2 = buildBrush->sides[k].winding;
00477                           if (!w2)
00478                               continue;
00479                           for (l=0 ; l<w2->numpoints ; l++)
00480                           {
00481                               d = DotProduct (w2->p[l], normal) - dist;
00482                               if (d > 0.1)
00483                                   break;    // point in front
00484                           }
00485                           if (l != w2->numpoints)
00486                               break;
00487                       }
00488 
00489                       if (k != buildBrush->numsides)
00490                           continue; // wasn't part of the outer hull
00491                       // add this plane
00492                       if ( buildBrush->numsides == MAX_BUILD_SIDES ) {
00493                           Error( "MAX_BUILD_SIDES" );
00494                       }
00495 
00496                       s2 = &buildBrush->sides[buildBrush->numsides];
00497                       buildBrush->numsides++;
00498                       memset( s2, 0, sizeof( *s2 ) );
00499 
00500                       s2->planenum = FindFloatPlane (normal, dist);
00501                       s2->contents = buildBrush->sides[0].contents;
00502                       s2->bevel = qtrue;
00503                       c_edgebevels++;
00504                   }
00505               }
00506           }
00507       }
00508   }
00509 }

Here is the call graph for this function:

void AddPlaneToHash plane_t p  ) 
 

Definition at line 109 of file map.c.

References plane_t::dist, fabs(), p, PLANE_HASHES, and planehash.

Referenced by CreateNewFloatPlane().

00110 {
00111     int     hash;
00112 
00113     hash = (int)fabs(p->dist) / 8;
00114     hash &= (PLANE_HASHES-1);
00115 
00116     p->hash_chain = planehash[hash];
00117     planehash[hash] = p;
00118 }

Here is the call graph for this function:

void AdjustBrushesForOrigin entity_t ent  ) 
 

Definition at line 1027 of file map.c.

References b, entity_t::brushes, bspbrush_t, CreateBrushWindings(), plane_t::dist, DotProduct, FindFloatPlane(), mesh_t::height, i, mapplanes, parseMesh_s::mesh, parseMesh_s::next, bspbrush_s::next, bspbrush_s::numsides, entity_t::origin, p, parseMesh_t, entity_t::patches, side_s::planenum, s, side_t, bspbrush_s::sides, vec_t, VectorSubtract, mesh_t::verts, mesh_t::width, and drawVert_t::xyz.

Referenced by ParseMapEntity().

01027                                              {
01028     bspbrush_t  *b;
01029     int         i;
01030     side_t      *s;
01031     vec_t       newdist;
01032     parseMesh_t *p;
01033 
01034     for ( b = ent->brushes ; b ; b = b->next ) {
01035         for (i=0 ; i<b->numsides ; i++) {
01036             s = &b->sides[i];
01037             newdist = mapplanes[s->planenum].dist -
01038                 DotProduct (mapplanes[s->planenum].normal, ent->origin);
01039             s->planenum = FindFloatPlane (mapplanes[s->planenum].normal, newdist);
01040         }
01041         CreateBrushWindings(b);
01042     }
01043 
01044     for ( p = ent->patches ; p ; p = p->next ) {
01045         for ( i = 0 ; i < p->mesh.width*p->mesh.height ; i++ ) {
01046             VectorSubtract( p->mesh.verts[i].xyz, ent->origin, p->mesh.verts[i].xyz );
01047         }
01048     }
01049 
01050 }

Here is the call graph for this function:

int CreateNewFloatPlane vec3_t  normal,
vec_t  dist
 

Definition at line 125 of file map.c.

References _printf(), AddPlaneToHash(), plane_t::dist, Error(), mapplanes, plane_t::normal, nummapplanes, p, PlaneTypeForNormal, plane_t::type, vec3_origin, VectorCopy, VectorLength(), and VectorSubtract.

Referenced by FindFloatPlane().

00126 {
00127     plane_t *p, temp;
00128 
00129     if (VectorLength(normal) < 0.5)
00130     {
00131         _printf( "FloatPlane: bad normal\n");
00132         return -1;
00133     }
00134 
00135     // create a new plane
00136     if (nummapplanes+2 > MAX_MAP_PLANES)
00137         Error ("MAX_MAP_PLANES");
00138 
00139     p = &mapplanes[nummapplanes];
00140     VectorCopy (normal, p->normal);
00141     p->dist = dist;
00142     p->type = (p+1)->type = PlaneTypeForNormal (p->normal);
00143 
00144     VectorSubtract (vec3_origin, normal, (p+1)->normal);
00145     (p+1)->dist = -dist;
00146 
00147     nummapplanes += 2;
00148 
00149     // allways put axial planes facing positive first
00150     if (p->type < 3)
00151     {
00152         if (p->normal[0] < 0 || p->normal[1] < 0 || p->normal[2] < 0)
00153         {
00154             // flip order
00155             temp = *p;
00156             *p = *(p+1);
00157             *(p+1) = temp;
00158 
00159             AddPlaneToHash (p);
00160             AddPlaneToHash (p+1);
00161             return nummapplanes - 1;
00162         }
00163     }
00164 
00165     AddPlaneToHash (p);
00166     AddPlaneToHash (p+1);
00167     return nummapplanes - 2;
00168 }

Here is the call graph for this function:

int FindFloatPlane vec3_t  normal,
vec_t  dist
 

Definition at line 231 of file map.c.

References CreateNewFloatPlane(), fabs(), h(), i, mapplaneusers, p, PLANE_HASHES, PlaneEqual(), planehash, and SnapPlane().

Referenced by AAS_CreateCurveBrushes(), AAS_ExpandMapBrush(), AAS_FixMapBrush(), AAS_LadderSubdivideArea_r(), AAS_PositionBrush(), AAS_SubdivideArea_r(), AAS_TestSplitPlane(), AAS_TransformPlane(), AddBrushBevels(), AdjustBrushesForOrigin(), BrushFromBounds(), DPlanes2MapPlanes(), EmitBrushes(), EmitTerrainVerts(), EmitTerrainVerts2(), HL_CreateBrushes_r(), HL_SplitBrushWithFace(), MakeBspBrushList(), MapPlaneFromPoints(), PlaneFromPoints(), Q1_CreateBrushes_r(), Q1_SplitBrushWithFace(), Q2_BSPBrushToMapBrush(), Q2_ParseMapEntity(), Q3_BSPBrushToMapBrush(), Q3_DPlanes2MapPlanes(), SelectSplitPlaneNum(), Sin_BSPBrushToMapBrush(), and WriteMapBrush().

00232 {
00233     int     i;
00234     plane_t *p;
00235     int     hash, h;
00236 
00237     SnapPlane (normal, &dist);
00238     hash = (int)fabs(dist) / 8;
00239     hash &= (PLANE_HASHES-1);
00240 
00241     // search the border bins as well
00242     for (i=-1 ; i<=1 ; i++)
00243     {
00244         h = (hash+i)&(PLANE_HASHES-1);
00245         for (p = planehash[h] ; p ; p=p->hash_chain)
00246         {
00247             if (PlaneEqual (p, normal, dist))
00248                 return p-mapplanes;
00249         }
00250     }
00251 
00252     return CreateNewFloatPlane (normal, dist);
00253 }

Here is the call graph for this function:

bspbrush_t* FinishBrush void   ) 
 

Definition at line 557 of file map.c.

References _printf(), AddBackSides(), AddBrushBevels(), b, entity_t::brushes, bspbrush_s::brushnum, bspbrush_t, buildBrush, c_detail, bspbrush_s::contents, CONTENTS_PLAYERCLIP, CopyBrush(), CreateBrushWindings(), bspbrush_s::detail, entities, bspbrush_s::entitynum, entitySourceBrushes, mapent, bspbrush_s::maxs, bspbrush_s::mins, bspbrush_s::next, num_entities, bspbrush_s::original, SetKeyValue(), sprintf(), string(), vec3_t, VectorAdd, VectorCopy, and VectorScale.

Referenced by MakeBrushFromTriangle(), and ParseBrush().

00557                                 {
00558     bspbrush_t  *b;
00559 
00560     // liquids may need to have extra sides created for back sides
00561     AddBackSides();
00562 
00563     // create windings for sides and bounds for brush
00564     if ( !CreateBrushWindings( buildBrush ) ) {
00565         // don't keep this brush
00566         return NULL;
00567     }
00568 
00569     // brushes that will not be visible at all are forced to be detail
00570     if ( buildBrush->contents & (CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP) )
00571     {
00572         buildBrush->detail = qtrue;
00573         c_detail++;
00574     }
00575 
00576     //
00577     // origin brushes are removed, but they set
00578     // the rotation origin for the rest of the brushes
00579     // in the entity.  After the entire entity is parsed,
00580     // the planenums and texinfos will be adjusted for
00581     // the origin brush
00582     //
00583     if ( buildBrush->contents & CONTENTS_ORIGIN )
00584     {
00585         char    string[32];
00586         vec3_t  origin;
00587 
00588         if (num_entities == 1) {
00589             _printf ("Entity %i, Brush %i: origin brushes not allowed in world\n"
00590                 ,  num_entities - 1, entitySourceBrushes);
00591             return NULL;
00592         }
00593 
00594         VectorAdd (buildBrush->mins, buildBrush->maxs, origin);
00595         VectorScale (origin, 0.5, origin);
00596 
00597         sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]);
00598         SetKeyValue (&entities[num_entities - 1], "origin", string);
00599 
00600         VectorCopy (origin, entities[num_entities - 1].origin);
00601 
00602         // don't keep this brush
00603         return NULL;
00604     }
00605 
00606     if ( buildBrush->contents & CONTENTS_AREAPORTAL ) {
00607         if (num_entities != 1) {
00608             _printf ("Entity %i, Brush %i: areaportals only allowed in world\n"
00609                 ,  num_entities - 1, entitySourceBrushes);
00610             return NULL;
00611         }
00612     }
00613 
00614     AddBrushBevels ();
00615 
00616     // keep it
00617     b = CopyBrush( buildBrush );
00618 
00619     b->entitynum = num_entities-1;
00620     b->brushnum = entitySourceBrushes;
00621 
00622     b->original = b;
00623 
00624     b->next = mapent->brushes;
00625     mapent->brushes = b;
00626 
00627     return b;
00628 }

Here is the call graph for this function:

void LoadMapFile char *  filename  ) 
 

Definition at line 1161 of file map.c.

References _printf(), AddPointToBounds(), AllocBrush(), b, entity_t::brushes, bspbrush_t, buildBrush, c_areaportals, c_boxbevels, c_detail, c_edgebevels, ClearBounds(), CountBrushList(), entities, g_bBrushPrimit, LoadScriptFile(), map_maxs, map_mins, MAX_BUILD_SIDES, bspbrush_s::maxs, bspbrush_s::mins, bspbrush_s::next, num_entities, numMapDrawSurfs, numMapPatches, nummapplanes, ParseMapEntity(), qprintf(), TestExpandBrushes(), and WriteBspBrushMap().

Referenced by main(), OnlyEnts(), and OnlyTextures().

01161                                   {     
01162     bspbrush_t  *b;
01163 
01164     qprintf ("--- LoadMapFile ---\n");
01165     _printf ("Loading map file %s\n", filename);
01166 
01167     LoadScriptFile (filename);
01168 
01169     num_entities = 0;
01170     numMapDrawSurfs = 0;
01171     c_detail = 0;
01172 
01173     g_bBrushPrimit = BPRIMIT_UNDEFINED;
01174 
01175     // allocate a very large temporary brush for building
01176     // the brushes as they are loaded
01177     buildBrush = AllocBrush( MAX_BUILD_SIDES );
01178 
01179     while (ParseMapEntity ())
01180     {
01181     }
01182 
01183     ClearBounds (map_mins, map_maxs);
01184     for ( b = entities[0].brushes ; b ; b=b->next ) {
01185         AddPointToBounds( b->mins, map_mins, map_maxs );
01186         AddPointToBounds( b->maxs, map_mins, map_maxs );
01187     }
01188 
01189     qprintf ("%5i total world brushes\n", CountBrushList( entities[0].brushes ) );
01190     qprintf ("%5i detail brushes\n", c_detail );
01191     qprintf ("%5i patches\n", numMapPatches);
01192     qprintf ("%5i boxbevels\n", c_boxbevels);
01193     qprintf ("%5i edgebevels\n", c_edgebevels);
01194     qprintf ("%5i entities\n", num_entities);
01195     qprintf ("%5i planes\n", nummapplanes);
01196     qprintf ("%5i areaportals\n", c_areaportals);
01197     qprintf ("size: %5.0f,%5.0f,%5.0f to %5.0f,%5.0f,%5.0f\n", map_mins[0],map_mins[1],map_mins[2],
01198         map_maxs[0],map_maxs[1],map_maxs[2]);
01199 
01200     if ( fakemap ) {
01201         WriteBspBrushMap ("fakemap.map", entities[0].brushes );
01202     }
01203 
01204     if ( testExpand ) {
01205         TestExpandBrushes ();
01206     }
01207 }

Here is the call graph for this function:

int MapPlaneFromPoints vec3_t  p0,
vec3_t  p1,
vec3_t  p2
 

Definition at line 261 of file map.c.

References CrossProduct(), DotProduct, FindFloatPlane(), p2, vec3_t, vec_t, VectorNormalize(), and VectorSubtract.

Referenced by AddBrushSide(), and ParseRawBrush().

00261                                                          {
00262     vec3_t  t1, t2, normal;
00263     vec_t   dist;
00264 
00265     VectorSubtract (p0, p1, t1);
00266     VectorSubtract (p2, p1, t2);
00267     CrossProduct (t1, t2, normal);
00268     VectorNormalize (normal, normal);
00269 
00270     dist = DotProduct (p0, normal);
00271 
00272     return FindFloatPlane (normal, dist);
00273 }

Here is the call graph for this function:

void MoveBrushesToWorld entity_t mapent  ) 
 

Definition at line 995 of file map.c.

References b, entity_t::brushes, bspbrush_t, entities, mapent, bspbrush_s::next, next, parseMesh_t, entity_t::patches, and pm.

Referenced by ParseMapEntity().

00995                                            {
00996     bspbrush_t  *b, *next;
00997     parseMesh_t *pm;
00998 
00999     // move brushes
01000     for ( b = mapent->brushes ; b ; b = next ) {
01001         next = b->next;
01002 
01003         b->next = entities[0].brushes;
01004         entities[0].brushes = b;
01005     }
01006     mapent->brushes = NULL;
01007 
01008     // move patches
01009     if ( mapent->patches ) {
01010 
01011         for ( pm = mapent->patches ; pm->next ; pm = pm->next ) {
01012         }
01013 
01014         pm->next = entities[0].patches;
01015         entities[0].patches = mapent->patches;
01016 
01017         mapent->patches = NULL;
01018     }
01019 }

void ParseBrush void   ) 
 

Definition at line 948 of file map.c.

References b, bspbrush_s::brushnum, bspbrush_t, buildBrush, bspbrush_s::contents, CONTENTS_LAVA, CONTENTS_SLIME, bspbrush_s::entitynum, FinishBrush(), FreeBrush(), nodetail, nowater, num_entities, ParseRawBrush(), bspbrush_s::portalareas, RemoveDuplicateBrushPlanes(), and SetBrushContents().

Referenced by ParseMapEntity().

00948                        {
00949     bspbrush_t  *b;
00950 
00951     ParseRawBrush();
00952 
00953     buildBrush->portalareas[0] = -1;
00954     buildBrush->portalareas[1] = -1;
00955     buildBrush->entitynum = num_entities-1;
00956     buildBrush->brushnum = entitySourceBrushes;
00957 
00958     // if there are mirrored planes, the entire brush is invalid
00959     if ( !RemoveDuplicateBrushPlanes( buildBrush ) ) {
00960         return;
00961     }
00962 
00963     // get the content for the entire brush
00964     SetBrushContents( buildBrush );
00965 
00966     // allow detail brushes to be removed 
00967     if (nodetail && (buildBrush->contents & CONTENTS_DETAIL) ) {
00968         FreeBrush( buildBrush );
00969         return;
00970     }
00971 
00972     // allow water brushes to be removed
00973     if (nowater && (buildBrush->contents & (CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER)) ) {
00974         FreeBrush( buildBrush );
00975         return;
00976     }
00977 
00978     b = FinishBrush( );
00979     if ( !b ) {
00980         return;
00981     }
00982 }

Here is the call graph for this function:

qboolean ParseMapEntity void   ) 
 

Definition at line 1057 of file map.c.

References AdjustBrushesForOrigin(), e, entities, entitySourceBrushes, epair_t, entity_t::epairs, Error(), g_bBrushPrimit, GetToken(), GetVectorForKey(), mapent, memset(), MoveBrushesToWorld(), epair_s::next, num_entities, numMapPatches, entity_t::origin, ParseBrush(), ParseEpair(), ParsePatch(), ParseTerrain(), qboolean, qtrue, scriptline, SetTerrainTextures(), strcmp(), UnGetToken(), and ValueForKey().

Referenced by LoadMapFile().

01057                                   {
01058     epair_t     *e;
01059 
01060     if (!GetToken (qtrue))
01061         return qfalse;
01062 
01063     if (strcmp (token, "{") )
01064     {
01065         Error ("ParseEntity: { not found, found %s on line %d - last entity was at: <%4.2f, %4.2f, %4.2f>...", token, scriptline, entities[num_entities].origin[0], entities[num_entities].origin[1], entities[num_entities].origin[2]);
01066     }
01067     
01068     if (num_entities == MAX_MAP_ENTITIES)
01069         Error ("num_entities == MAX_MAP_ENTITIES");
01070 
01071     entitySourceBrushes = 0;
01072 
01073     mapent = &entities[num_entities];
01074     num_entities++;
01075     memset (mapent, 0, sizeof(*mapent));
01076 
01077     do
01078     {
01079         if (!GetToken (qtrue))
01080             Error ("ParseEntity: EOF without closing brace");
01081         if (!strcmp (token, "}") )
01082             break;
01083 
01084         if (!strcmp (token, "{") ) {
01085             // parse a brush or patch
01086             if (!GetToken (qtrue))
01087                 break;
01088             if ( !strcmp( token, "patchDef2" ) ) {
01089                 numMapPatches++;
01090                 ParsePatch();
01091             } else if ( !strcmp( token, "terrainDef" ) ) {
01092                 ParseTerrain();
01093             } else if ( !strcmp( token, "brushDef" ) ) {
01094                 if (g_bBrushPrimit==BPRIMIT_OLDBRUSHES)
01095                     Error("old brush format not allowed in new brush format map");
01096                 g_bBrushPrimit=BPRIMIT_NEWBRUSHES;
01097                 // parse brush primitive
01098                 ParseBrush();
01099             }
01100             else
01101             {
01102                 if (g_bBrushPrimit==BPRIMIT_NEWBRUSHES)
01103                     Error("new brush format not allowed in old brush format map");
01104                 g_bBrushPrimit=BPRIMIT_OLDBRUSHES;
01105                 // parse old brush format
01106                 UnGetToken();
01107                 ParseBrush();
01108             }
01109             entitySourceBrushes++;
01110         }
01111         else
01112         {
01113             // parse a key / value pair
01114             e = ParseEpair ();
01115             e->next = mapent->epairs;
01116             mapent->epairs = e;
01117         }
01118     } while (1);
01119 
01120     GetVectorForKey (mapent, "origin", mapent->origin);
01121 
01122     //
01123     // if there was an origin brush, offset all of the planes and texinfo
01124     // for all the brushes in the entity
01125     if (mapent->origin[0] || mapent->origin[1] || mapent->origin[2]) {
01126         AdjustBrushesForOrigin( mapent );
01127     }
01128 
01129   // group_info entities are just for editor grouping
01130   // ignored
01131   // FIXME: leak!
01132   if (!strcmp("group_info", ValueForKey (mapent, "classname")))
01133   {
01134     num_entities--;
01135     return qtrue;
01136   }
01137 
01138     // group entities are just for editor convenience
01139     // toss all brushes into the world entity
01140     if (!strcmp ("func_group", ValueForKey (mapent, "classname")))
01141     {
01142         if ( !strcmp ("1", ValueForKey (mapent, "terrain"))) {
01143             SetTerrainTextures();
01144         }
01145         MoveBrushesToWorld (mapent);
01146         num_entities--;
01147         return qtrue;
01148     }
01149 
01150     return qtrue;
01151 }

Here is the call graph for this function:

void ParseRawBrush  ) 
 

Definition at line 759 of file map.c.

References atof(), atoi, buildBrush, shaderInfo_s::contents, bspbrush_s::detail, Error(), g_bBrushPrimit, GetToken(), mapIndexedShaders, MapPlaneFromPoints(), mapplanes, MatchToken(), memset(), name, numMapIndexedShaders, bspbrush_s::numsides, Parse1DMatrix(), Parse2DMatrix(), qfalse, qtrue, QuakeTextureVecs(), shaderInfo_t, ShaderInfoForShader(), shift, side_t, bspbrush_s::sides, sprintf(), strcmp(), strcpy(), shaderInfo_s::surfaceFlags, TokenAvailable(), UnGetToken(), shaderInfo_s::value, vec3_t, and vec_t.

Referenced by ParseBrush().

00759                          {
00760     side_t      *side;
00761     vec3_t      planepts[3];
00762     int         planenum;
00763     shaderInfo_t    *si;
00764     // old brushes
00765     vec_t       shift[2];
00766     vec_t       rotate;
00767     vec_t       scale[2];
00768     char        name[MAX_QPATH];
00769     char        shader[MAX_QPATH];
00770     int         flags;
00771 
00772     buildBrush->numsides = 0;
00773     buildBrush->detail = qfalse;
00774 
00775     if (g_bBrushPrimit==BPRIMIT_NEWBRUSHES)
00776         MatchToken( "{" );
00777 
00778     do
00779     {
00780         if (!GetToken (qtrue))
00781             break;
00782         if (!strcmp (token, "}") )
00783             break;
00784         //Timo : brush primitive : here we may have to jump over brush epairs ( only used in editor )
00785         if (g_bBrushPrimit==BPRIMIT_NEWBRUSHES)
00786         {
00787             do
00788             {
00789                 if (strcmp (token, "(") )
00790                     GetToken( qfalse );
00791                 else
00792                     break;
00793                 GetToken( qtrue );
00794             } while (1);
00795         }
00796         UnGetToken();
00797 
00798         if ( buildBrush->numsides == MAX_BUILD_SIDES ) {
00799             Error( "MAX_BUILD_SIDES" );
00800         }
00801 
00802         side = &buildBrush->sides[ buildBrush->numsides ];
00803         memset( side, 0, sizeof( *side ) );
00804         buildBrush->numsides++;
00805 
00806         // read the three point plane definition
00807         Parse1DMatrix( 3, planepts[0] );
00808         Parse1DMatrix( 3, planepts[1] );
00809         Parse1DMatrix( 3, planepts[2] );
00810 
00811         if (g_bBrushPrimit==BPRIMIT_NEWBRUSHES)
00812             // read the texture matrix
00813             Parse2DMatrix( 2, 3, (float *)side->texMat );
00814 
00815         // read the texturedef
00816         GetToken (qfalse);
00817         strcpy (name, token);
00818 
00819         // save the shader name for retexturing
00820         if ( numMapIndexedShaders == MAX_MAP_BRUSHSIDES ) {
00821             Error( "MAX_MAP_BRUSHSIDES" );
00822         }
00823         strcpy( mapIndexedShaders[numMapIndexedShaders], name );
00824         numMapIndexedShaders++;
00825 
00826         if (g_bBrushPrimit==BPRIMIT_OLDBRUSHES)
00827         {
00828             GetToken (qfalse);
00829             shift[0] = atoi(token);
00830             GetToken (qfalse);
00831             shift[1] = atoi(token);
00832             GetToken (qfalse);
00833             rotate = atoi(token);   
00834             GetToken (qfalse);
00835             scale[0] = atof(token);
00836             GetToken (qfalse);
00837             scale[1] = atof(token);
00838         }
00839 
00840         // find default flags and values
00841         sprintf( shader, "textures/%s", name );
00842         si = ShaderInfoForShader( shader );
00843         side->shaderInfo = si;
00844         side->surfaceFlags = si->surfaceFlags;
00845         side->value = si->value;
00846         side->contents = si->contents;
00847 
00848         // allow override of default flags and values
00849         // in Q3, the only thing you can override is DETAIL
00850         if (TokenAvailable())
00851         {
00852             GetToken (qfalse);
00853 //          side->contents = atoi(token);
00854             flags = atoi(token);
00855             if ( flags & CONTENTS_DETAIL ) {
00856                 side->contents |= CONTENTS_DETAIL;
00857             }
00858 
00859             GetToken (qfalse);
00860 //          td.flags = atoi(token);
00861 
00862             GetToken (qfalse);
00863 //          td.value = atoi(token);
00864         }
00865 
00866 
00867         // find the plane number
00868         planenum = MapPlaneFromPoints (planepts[0], planepts[1], planepts[2]);
00869         side->planenum = planenum;
00870 
00871         if (g_bBrushPrimit==BPRIMIT_OLDBRUSHES)
00872             // get the texture mapping for this texturedef / plane combination
00873             QuakeTextureVecs(