]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/compilers/aas/Brush.h
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / tools / compilers / aas / Brush.h
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
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.
13
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.
18
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/>.
21
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.
23
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.
25
26 ===========================================================================
27 */
28
29 #ifndef __BRUSH_H__
30 #define __BRUSH_H__
31
32 /*
33 ===============================================================================
34
35         Brushes
36
37 ===============================================================================
38 */
39
40
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
45
46 class idBrush;
47 class idBrushList;
48
49 void DisplayRealTimeString( char *string, ... ) id_attribute((format(printf,1,2)));
50
51
52 //===============================================================
53 //
54 //      idBrushSide
55 //
56 //===============================================================
57
58 #define SFL_SPLIT                                       0x0001
59 #define SFL_BEVEL                                       0x0002
60 #define SFL_USED_SPLITTER                       0x0004
61 #define SFL_TESTED_SPLITTER                     0x0008
62
63 class idBrushSide {
64
65         friend class idBrush;
66
67 public:
68                                                         idBrushSide( void );
69                                                         idBrushSide( const idPlane &plane, int planeNum );
70                                                         ~idBrushSide( void );
71
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;
81
82 private:
83         int                                             flags;
84         int                                             planeNum;
85         idPlane                                 plane;
86         idWinding *                             winding;
87 };
88
89
90 //===============================================================
91 //
92 //      idBrush
93 //
94 //===============================================================
95
96 #define BFL_NO_VALID_SPLITTERS          0x0001
97
98 class idBrush {
99
100         friend class idBrushList;
101
102 public:
103                                                         idBrush( void );
104                                                         ~idBrush( void );
105
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; }
134
135 private:
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
146
147 private:
148         bool                                    CreateWindings( void );
149         void                                    BoundBrush( const idBrush *original = NULL );
150         void                                    AddBevelsForAxialBox( void );
151         bool                                    RemoveSidesWithoutWinding( void );
152 };
153
154
155 //===============================================================
156 //
157 //      idBrushList
158 //
159 //===============================================================
160
161 class idBrushList {
162 public:
163                                                         idBrushList( void );
164                                                         ~idBrushList( void );
165
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
188         void                                    Free( void );
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 ) );
193                                                         // merge brushes
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;
201
202 private:
203         idBrush *                               head;
204         idBrush *                               tail;
205         int                                             numBrushes;
206         int                                             numBrushSides;
207 };
208
209
210 //===============================================================
211 //
212 //      idBrushMap
213 //
214 //===============================================================
215
216 class idBrushMap {
217
218 public:
219                                                         idBrushMap( const idStr &fileName, const idStr &ext );
220                                                         ~idBrushMap( void );
221         void                                    SetTexture( const idStr &textureName ) { texture = textureName; }
222         void                                    WriteBrush( const idBrush *brush );
223         void                                    WriteBrushList( const idBrushList &brushList );
224
225 private:
226         idFile *                                fp;
227         idStr                                   texture;
228         int                                             brushCount;
229 };
230
231 #endif /* !__BRUSH_H__ */