File: Brush.h

package info (click to toggle)
dhewm3 1.5.1~pre%2Bgit20200905%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye
  • size: 21,664 kB
  • sloc: cpp: 408,868; ansic: 1,188; objc: 1,034; python: 330; sh: 94; makefile: 11
file content (234 lines) | stat: -rw-r--r-- 8,446 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
===========================================================================

Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.

This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").

Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.

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.

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.

===========================================================================
*/

#ifndef __BRUSH_H__
#define __BRUSH_H__

#include "idlib/containers/PlaneSet.h"
#include "idlib/geometry/Winding.h"

/*
===============================================================================

	Brushes

===============================================================================
*/


#define BRUSH_PLANESIDE_FRONT		1
#define BRUSH_PLANESIDE_BACK		2
#define BRUSH_PLANESIDE_BOTH		( BRUSH_PLANESIDE_FRONT | BRUSH_PLANESIDE_BACK )
#define BRUSH_PLANESIDE_FACING		4

class idBrush;
class idBrushList;

void DisplayRealTimeString( const char *string, ... ) id_attribute((format(printf,1,2)));


//===============================================================
//
//	idBrushSide
//
//===============================================================

#define SFL_SPLIT					0x0001
#define SFL_BEVEL					0x0002
#define SFL_USED_SPLITTER			0x0004
#define SFL_TESTED_SPLITTER			0x0008

class idBrushSide {

	friend class idBrush;

public:
							idBrushSide( void );
							idBrushSide( const idPlane &plane, int planeNum );
							~idBrushSide( void );

	int						GetFlags( void ) const { return flags; }
	void					SetFlag( int flag ) { flags |= flag; }
	void					RemoveFlag( int flag ) { flags &= ~flag; }
	const idPlane &			GetPlane( void ) const { return plane; }
	void					SetPlaneNum( int num ) { planeNum = num; }
	int						GetPlaneNum( void ) { return planeNum; }
	const idWinding *		GetWinding( void ) const { return winding; }
	idBrushSide *			Copy( void ) const;
	int						Split( const idPlane &splitPlane, idBrushSide **front, idBrushSide **back ) const;

private:
	int						flags;
	int						planeNum;
	idPlane					plane;
	idWinding *				winding;
};


//===============================================================
//
//	idBrush
//
//===============================================================

#define BFL_NO_VALID_SPLITTERS		0x0001

class idBrush {

	friend class idBrushList;

public:
							idBrush( void );
							~idBrush( void );

	int						GetFlags( void ) const { return flags; }
	void					SetFlag( int flag ) { flags |= flag; }
	void					RemoveFlag( int flag ) { flags &= ~flag; }
	void					SetEntityNum( int num ) { entityNum = num; }
	void					SetPrimitiveNum( int num ) { primitiveNum = num; }
	void					SetContents( int contents ) { this->contents = contents; }
	int						GetContents( void ) const { return contents; }
	const idBounds &		GetBounds( void ) const { return bounds; }
	float					GetVolume( void ) const;
	int						GetNumSides( void ) const { return sides.Num(); }
	idBrushSide *			GetSide( int i ) const { return sides[i]; }
	void					SetPlaneSide( int s ) { planeSide = s; }
	void					SavePlaneSide( void ) { savedPlaneSide = planeSide; }
	int						GetSavedPlaneSide( void ) const { return savedPlaneSide; }
	bool					FromSides( idList<idBrushSide *> &sideList );
	bool					FromWinding( const idWinding &w, const idPlane &windingPlane );
	bool					FromBounds( const idBounds &bounds );
	void					Transform( const idVec3 &origin, const idMat3 &axis );
	idBrush *				Copy( void ) const;
	bool					TryMerge( const idBrush *brush, const idPlaneSet &planeList );
							// returns true if the brushes did intersect
	bool					Subtract( const idBrush *b, idBrushList &list ) const;
							// split the brush into a front and back brush
	int						Split( const idPlane &plane, int planeNum, idBrush **front, idBrush **back ) const;
							// expand the brush for an axial bounding box
	void					ExpandForAxialBox( const idBounds &bounds );
							// next brush in list
	idBrush *				Next( void ) const { return next; }

private:
	mutable idBrush *		next;				// next brush in list
	int						entityNum;			// entity number in editor
	int						primitiveNum;		// primitive number in editor
	int						flags;				// brush flags
	bool					windingsValid;		// set when side windings are valid
	int						contents;			// contents of brush
	int						planeSide;			// side of a plane this brush is on
	int						savedPlaneSide;		// saved plane side
	idBounds				bounds;				// brush bounds
	idList<idBrushSide *>	sides;				// list with sides

private:
	bool					CreateWindings( void );
	void					BoundBrush( const idBrush *original = NULL );
	void					AddBevelsForAxialBox( void );
	bool					RemoveSidesWithoutWinding( void );
};


//===============================================================
//
//	idBrushList
//
//===============================================================

class idBrushList {
public:
							idBrushList( void );
							~idBrushList( void );

	int						Num( void ) const { return numBrushes; }
	int						NumSides( void ) const { return numBrushSides; }
	idBrush *				Head( void ) const { return head; }
	idBrush *				Tail( void ) const { return tail; }
	void					Clear( void ) { head = tail = NULL; numBrushes = 0; }
	bool					IsEmpty( void ) const { return (numBrushes == 0); }
	idBounds				GetBounds( void ) const;
							// add brush to the tail of the list
	void					AddToTail( idBrush *brush );
							// add list to the tail of the list
	void					AddToTail( idBrushList &list );
							// add brush to the front of the list
	void					AddToFront( idBrush *brush );
							// add list to the front of the list
	void					AddToFront( idBrushList &list );
							// remove the brush from the list
	void					Remove( idBrush *brush );
							// remove the brush from the list and delete the brush
	void					Delete( idBrush *brush);
							// returns a copy of the brush list
	idBrushList *			Copy( void ) const;
							// delete all brushes in the list
	void					Free( void );
							// split the brushes in the list into two lists
	void					Split( const idPlane &plane, int planeNum, idBrushList &frontList, idBrushList &backList, bool useBrushSavedPlaneSide = false );
							// chop away all brush overlap
	void					Chop( bool (*ChopAllowed)( idBrush *b1, idBrush *b2 ) );
							// merge brushes
	void					Merge( bool (*MergeAllowed)( idBrush *b1, idBrush *b2 ) );
							// set the given flag on all brush sides facing the plane
	void					SetFlagOnFacingBrushSides( const idPlane &plane, int flag );
							// get a list with planes for all brushes in the list
	void					CreatePlaneList( idPlaneSet &planeList ) const;
							// write a brush map with the brushes in the list
	void					WriteBrushMap( const idStr &fileName, const idStr &ext ) const;

private:
	idBrush *				head;
	idBrush *				tail;
	int						numBrushes;
	int						numBrushSides;
};


//===============================================================
//
//	idBrushMap
//
//===============================================================

class idBrushMap {

public:
							idBrushMap( const idStr &fileName, const idStr &ext );
							~idBrushMap( void );
	void					SetTexture( const idStr &textureName ) { texture = textureName; }
	void					WriteBrush( const idBrush *brush );
	void					WriteBrushList( const idBrushList &brushList );

private:
	idFile *				fp;
	idStr					texture;
	int						brushCount;
};

#endif /* !__BRUSH_H__ */