2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code 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 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
33 ===============================================================================
37 ===============================================================================
41 #define BRUSH_PLANESIDE_FRONT 1
42 #define BRUSH_PLANESIDE_BACK 2
43 #define BRUSH_PLANESIDE_BOTH ( BRUSH_PLANESIDE_FRONT | BRUSH_PLANESIDE_BACK )
44 #define BRUSH_PLANESIDE_FACING 4
49 void DisplayRealTimeString( char *string, ... ) id_attribute((format(printf,1,2)));
52 //===============================================================
56 //===============================================================
58 #define SFL_SPLIT 0x0001
59 #define SFL_BEVEL 0x0002
60 #define SFL_USED_SPLITTER 0x0004
61 #define SFL_TESTED_SPLITTER 0x0008
69 idBrushSide( const idPlane &plane, int planeNum );
72 int GetFlags( void ) const { return flags; }
73 void SetFlag( int flag ) { flags |= flag; }
74 void RemoveFlag( int flag ) { flags &= ~flag; }
75 const idPlane & GetPlane( void ) const { return plane; }
76 void SetPlaneNum( int num ) { planeNum = num; }
77 int GetPlaneNum( void ) { return planeNum; }
78 const idWinding * GetWinding( void ) const { return winding; }
79 idBrushSide * Copy( void ) const;
80 int Split( const idPlane &splitPlane, idBrushSide **front, idBrushSide **back ) const;
90 //===============================================================
94 //===============================================================
96 #define BFL_NO_VALID_SPLITTERS 0x0001
100 friend class idBrushList;
106 int GetFlags( void ) const { return flags; }
107 void SetFlag( int flag ) { flags |= flag; }
108 void RemoveFlag( int flag ) { flags &= ~flag; }
109 void SetEntityNum( int num ) { entityNum = num; }
110 void SetPrimitiveNum( int num ) { primitiveNum = num; }
111 void SetContents( int contents ) { this->contents = contents; }
112 int GetContents( void ) const { return contents; }
113 const idBounds & GetBounds( void ) const { return bounds; }
114 float GetVolume( void ) const;
115 int GetNumSides( void ) const { return sides.Num(); }
116 idBrushSide * GetSide( int i ) const { return sides[i]; }
117 void SetPlaneSide( int s ) { planeSide = s; }
118 void SavePlaneSide( void ) { savedPlaneSide = planeSide; }
119 int GetSavedPlaneSide( void ) const { return savedPlaneSide; }
120 bool FromSides( idList<idBrushSide *> &sideList );
121 bool FromWinding( const idWinding &w, const idPlane &windingPlane );
122 bool FromBounds( const idBounds &bounds );
123 void Transform( const idVec3 &origin, const idMat3 &axis );
124 idBrush * Copy( void ) const;
125 bool TryMerge( const idBrush *brush, const idPlaneSet &planeList );
126 // returns true if the brushes did intersect
127 bool Subtract( const idBrush *b, idBrushList &list ) const;
128 // split the brush into a front and back brush
129 int Split( const idPlane &plane, int planeNum, idBrush **front, idBrush **back ) const;
130 // expand the brush for an axial bounding box
131 void ExpandForAxialBox( const idBounds &bounds );
132 // next brush in list
133 idBrush * Next( void ) const { return next; }
136 mutable idBrush * next; // next brush in list
137 int entityNum; // entity number in editor
138 int primitiveNum; // primitive number in editor
139 int flags; // brush flags
140 bool windingsValid; // set when side windings are valid
141 int contents; // contents of brush
142 int planeSide; // side of a plane this brush is on
143 int savedPlaneSide; // saved plane side
144 idBounds bounds; // brush bounds
145 idList<idBrushSide *> sides; // list with sides
148 bool CreateWindings( void );
149 void BoundBrush( const idBrush *original = NULL );
150 void AddBevelsForAxialBox( void );
151 bool RemoveSidesWithoutWinding( void );
155 //===============================================================
159 //===============================================================
164 ~idBrushList( void );
166 int Num( void ) const { return numBrushes; }
167 int NumSides( void ) const { return numBrushSides; }
168 idBrush * Head( void ) const { return head; }
169 idBrush * Tail( void ) const { return tail; }
170 void Clear( void ) { head = tail = NULL; numBrushes = 0; }
171 bool IsEmpty( void ) const { return (numBrushes == 0); }
172 idBounds GetBounds( void ) const;
173 // add brush to the tail of the list
174 void AddToTail( idBrush *brush );
175 // add list to the tail of the list
176 void AddToTail( idBrushList &list );
177 // add brush to the front of the list
178 void AddToFront( idBrush *brush );
179 // add list to the front of the list
180 void AddToFront( idBrushList &list );
181 // remove the brush from the list
182 void Remove( idBrush *brush );
183 // remove the brush from the list and delete the brush
184 void Delete( idBrush *brush);
185 // returns a copy of the brush list
186 idBrushList * Copy( void ) const;
187 // delete all brushes in the list
189 // split the brushes in the list into two lists
190 void Split( const idPlane &plane, int planeNum, idBrushList &frontList, idBrushList &backList, bool useBrushSavedPlaneSide = false );
191 // chop away all brush overlap
192 void Chop( bool (*ChopAllowed)( idBrush *b1, idBrush *b2 ) );
194 void Merge( bool (*MergeAllowed)( idBrush *b1, idBrush *b2 ) );
195 // set the given flag on all brush sides facing the plane
196 void SetFlagOnFacingBrushSides( const idPlane &plane, int flag );
197 // get a list with planes for all brushes in the list
198 void CreatePlaneList( idPlaneSet &planeList ) const;
199 // write a brush map with the brushes in the list
200 void WriteBrushMap( const idStr &fileName, const idStr &ext ) const;
210 //===============================================================
214 //===============================================================
219 idBrushMap( const idStr &fileName, const idStr &ext );
221 void SetTexture( const idStr &textureName ) { texture = textureName; }
222 void WriteBrush( const idBrush *brush );
223 void WriteBrushList( const idBrushList &brushList );
231 #endif /* !__BRUSH_H__ */