doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Brush.h
Go to the documentation of this file.
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;
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; }
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:
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:
229 };
230 
231 #endif /* !__BRUSH_H__ */
idBrushMap(const idStr &fileName, const idStr &ext)
Definition: Brush.cpp:1505
void Clear(void)
Definition: Brush.h:170
int GetFlags(void) const
Definition: Brush.h:72
idBrush * next
Definition: Brush.h:136
void SavePlaneSide(void)
Definition: Brush.h:118
int contents
Definition: Brush.h:141
void AddBevelsForAxialBox(void)
Definition: Brush.cpp:812
void Transform(const idVec3 &origin, const idMat3 &axis)
Definition: Brush.cpp:406
idBrush * tail
Definition: Brush.h:204
idBrushList(void)
Definition: Brush.cpp:1021
idList< idBrushSide * > sides
Definition: Brush.h:145
GLenum GLsizei GLenum format
Definition: glext.h:2846
int numBrushSides
Definition: Brush.h:206
void CreatePlaneList(idPlaneSet &planeList) const
Definition: Brush.cpp:1466
idBounds bounds
Definition: Brush.h:144
int GetSavedPlaneSide(void) const
Definition: Brush.h:119
const idWinding * GetWinding(void) const
Definition: Brush.h:78
bool Subtract(const idBrush *b, idBrushList &list) const
Definition: Brush.cpp:471
idBrush * head
Definition: Brush.h:203
bool RemoveSidesWithoutWinding(void)
Definition: Brush.cpp:196
float GetVolume(void) const
Definition: Brush.cpp:432
void ExpandForAxialBox(const idBounds &bounds)
Definition: Brush.cpp:949
idBrush * Copy(void) const
Definition: Brush.cpp:993
int GetFlags(void) const
Definition: Brush.h:106
int primitiveNum
Definition: Brush.h:138
void Split(const idPlane &plane, int planeNum, idBrushList &frontList, idBrushList &backList, bool useBrushSavedPlaneSide=false)
Definition: Brush.cpp:1225
Definition: Vector.h:316
int Split(const idPlane &splitPlane, idBrushSide **front, idBrushSide **back) const
Definition: Brush.cpp:128
void DisplayRealTimeString(char *string,...) id_attribute((format(printf
int NumSides(void) const
Definition: Brush.h:167
void SetEntityNum(int num)
Definition: Brush.h:109
void Chop(bool(*ChopAllowed)(idBrush *b1, idBrush *b2))
Definition: Brush.cpp:1268
idBrushSide * Copy(void) const
Definition: Brush.cpp:109
int entityNum
Definition: Brush.h:137
void SetFlag(int flag)
Definition: Brush.h:107
idBrushSide * GetSide(int i) const
Definition: Brush.h:116
GLdouble s
Definition: glext.h:2935
void Free(void)
Definition: Brush.cpp:1209
bool windingsValid
Definition: Brush.h:140
int i
Definition: process.py:33
void SetPlaneSide(int s)
Definition: Brush.h:117
GLuint GLuint num
Definition: glext.h:5390
~idBrushList(void)
Definition: Brush.cpp:1031
idBrush * Tail(void) const
Definition: Brush.h:169
~idBrushSide(void)
Definition: Brush.cpp:98
int flags
Definition: Brush.h:83
~idBrushMap(void)
Definition: Brush.cpp:1535
Definition: File.h:50
int brushCount
Definition: Brush.h:228
void Delete(idBrush *brush)
Definition: Brush.cpp:1163
idBrush * Head(void) const
Definition: Brush.h:168
bool FromWinding(const idWinding &w, const idPlane &windingPlane)
Definition: Brush.cpp:330
void RemoveFlag(int flag)
Definition: Brush.h:74
bool CreateWindings(void)
Definition: Brush.cpp:217
idBrush(void)
Definition: Brush.cpp:172
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3454
void Remove(idBrush *brush)
Definition: Brush.cpp:1135
void AddToTail(idBrush *brush)
Definition: Brush.cpp:1055
#define NULL
Definition: Lib.h:88
const idBounds & GetBounds(void) const
Definition: Brush.h:113
int savedPlaneSide
Definition: Brush.h:143
void SetPrimitiveNum(int num)
Definition: Brush.h:110
void SetContents(int contents)
Definition: Brush.h:111
Definition: Plane.h:71
void SetFlag(int flag)
Definition: Brush.h:73
void RemoveFlag(int flag)
Definition: Brush.h:108
void WriteBrushList(const idBrushList &brushList)
Definition: Brush.cpp:1572
int GetContents(void) const
Definition: Brush.h:112
idWinding * winding
Definition: Brush.h:86
void WriteBrushMap(const idStr &fileName, const idStr &ext) const
Definition: Brush.cpp:1485
void AddToFront(idBrush *brush)
Definition: Brush.cpp:1098
GLubyte GLubyte b
Definition: glext.h:4662
void BoundBrush(const idBrush *original=NULL)
Definition: Brush.cpp:265
idBrush * Next(void) const
Definition: Brush.h:133
idBrushSide(void)
Definition: Brush.cpp:75
void SetTexture(const idStr &textureName)
Definition: Brush.h:221
Definition: Matrix.h:333
#define id_attribute(x)
Definition: sys_public.h:139
int planeSide
Definition: Brush.h:142
void SetPlaneNum(int num)
Definition: Brush.h:76
int Num(void) const
Definition: List.h:265
bool IsEmpty(void) const
Definition: Brush.h:171
idBrushList * Copy(void) const
Definition: Brush.cpp:1192
GLuint texture
Definition: glext.h:3871
Definition: Str.h:116
const idPlane & GetPlane(void) const
Definition: Brush.h:75
int GetPlaneNum(void)
Definition: Brush.h:77
int numBrushes
Definition: Brush.h:205
void SetFlagOnFacingBrushSides(const idPlane &plane, int flag)
Definition: Brush.cpp:1437
idStr texture
Definition: Brush.h:227
void Merge(bool(*MergeAllowed)(idBrush *b1, idBrush *b2))
Definition: Brush.cpp:1397
int planeNum
Definition: Brush.h:84
bool FromBounds(const idBounds &bounds)
Definition: Brush.cpp:383
int GetNumSides(void) const
Definition: Brush.h:115
bool MergeAllowed(idBrush *b1, idBrush *b2)
Definition: AASBuild.cpp:597
void WriteBrush(const idBrush *brush)
Definition: Brush.cpp:1548
idPlane plane
Definition: Brush.h:85
idBounds GetBounds(void) const
Definition: Brush.cpp:1039
Definition: Brush.h:98
int flags
Definition: Brush.h:139
bool FromSides(idList< idBrushSide * > &sideList)
Definition: Brush.cpp:313
bool TryMerge(const idBrush *brush, const idPlaneSet &planeList)
Definition: Brush.cpp:505
idFile * fp
Definition: Brush.h:226
int Num(void) const
Definition: Brush.h:166
int Split(const idPlane &plane, int planeNum, idBrush **front, idBrush **back) const
Definition: Brush.cpp:618
~idBrush(void)
Definition: Brush.cpp:185