more eol-style
[xonotic/netradiant.git] / radiant / filters.cpp
1 /*
2 Copyright (c) 2001, Loki software, inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification, 
6 are permitted provided that the following conditions are met:
7
8 Redistributions of source code must retain the above copyright notice, this list 
9 of conditions and the following disclaimer.
10
11 Redistributions in binary form must reproduce the above copyright notice, this
12 list of conditions and the following disclaimer in the documentation and/or
13 other materials provided with the distribution.
14
15 Neither the name of Loki software nor the names of its contributors may be used 
16 to endorse or promote products derived from this software without specific prior 
17 written permission. 
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
22 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY 
23 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
29 */
30
31 #include "stdafx.h"
32
33 bfilter_t *FilterAdd(bfilter_t *pFilter, int type, int bmask, char *str, int exclude)
34 {
35         bfilter_t *pNew = new bfilter_t;
36         pNew->next = pFilter;
37         pNew->attribute = type;
38         if (type == 1 || type == 3) pNew->string = str;
39         if (type == 2 || type == 4) pNew->mask = bmask;
40         if (g_qeglobals.d_savedinfo.exclude & exclude)
41                 pNew->active = true;
42         else
43                 pNew->active = false;
44         return pNew;
45 }
46
47   // removes the filter list at *pFilter, returns NULL pointer
48 bfilter_t *FilterListDelete(bfilter_t *pFilter)
49 {
50         if (pFilter != NULL)
51         {
52                 FilterListDelete(pFilter->next);
53                 delete pFilter;
54         }
55         return NULL;
56 }
57
58
59  //spog - FilterUpdate is called each time the filters are changed by menu or shortcuts
60 bfilter_t *FilterUpdate(bfilter_t *pFilter)
61 {
62         pFilter = FilterAdd(pFilter,1,0,"clip",EXCLUDE_CLIP);
63         pFilter = FilterAdd(pFilter,1,0,"caulk",EXCLUDE_CAULK);
64         pFilter = FilterAdd(pFilter,1,0,"liquids",EXCLUDE_LIQUIDS);
65         pFilter = FilterAdd(pFilter,1,0,"hint",EXCLUDE_HINTSSKIPS);
66         pFilter = FilterAdd(pFilter,1,0,"clusterportal",EXCLUDE_CLUSTERPORTALS);
67         pFilter = FilterAdd(pFilter,1,0,"areaportal",EXCLUDE_AREAPORTALS);
68         pFilter = FilterAdd(pFilter,2,QER_TRANS,NULL,EXCLUDE_TRANSLUCENT);
69         pFilter = FilterAdd(pFilter,3,0,"trigger",EXCLUDE_TRIGGERS);
70         pFilter = FilterAdd(pFilter,3,0,"misc_model",EXCLUDE_MODELS);
71         pFilter = FilterAdd(pFilter,3,0,"misc_gamemodel",EXCLUDE_MODELS);
72         pFilter = FilterAdd(pFilter,4,ECLASS_LIGHT,NULL,EXCLUDE_LIGHTS);
73         pFilter = FilterAdd(pFilter,4,ECLASS_PATH,NULL,EXCLUDE_PATHS);
74         pFilter = FilterAdd(pFilter,1,0,"lightgrid",EXCLUDE_LIGHTGRID);
75         pFilter = FilterAdd(pFilter,1,0,"botclip",EXCLUDE_BOTCLIP);
76   pFilter = FilterAdd(pFilter,1,0,"clipmonster",EXCLUDE_BOTCLIP);
77         return pFilter;
78 }
79
80 /*
81 ==================
82 FilterBrush
83 ==================
84 */
85
86 bool FilterBrush(brush_t *pb)
87 {
88         
89         if (!pb->owner)
90                 return FALSE;           // during construction
91         
92         if (pb->hiddenBrush)
93                 return TRUE;
94         
95         if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_WORLD)
96         {
97                 if (strcmp(pb->owner->eclass->name, "worldspawn") == 0 || !strcmp(pb->owner->eclass->name,"func_group")) // hack, treating func_group as world
98                 {
99                         return TRUE;
100                 }
101         }
102         
103         if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_ENT)
104         {
105                 if (strcmp(pb->owner->eclass->name, "worldspawn") != 0 && strcmp(pb->owner->eclass->name,"func_group")) // hack, treating func_group as world
106                 {
107                         return TRUE;
108                 }
109         }
110         
111         if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_CURVES )
112         {
113                 if (pb->patchBrush)
114                 {
115                         return TRUE;
116                 }
117         }
118         
119         
120         if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_DETAILS )
121         {
122                 if (!pb->patchBrush && pb->brush_faces->texdef.contents & CONTENTS_DETAIL )
123                 {
124                         return TRUE;
125                 }
126         }
127         if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_STRUCTURAL )
128         {
129                 if (!pb->patchBrush && !( pb->brush_faces->texdef.contents & CONTENTS_DETAIL ))
130                 {
131                         return TRUE;
132                 }
133         }
134                 
135         // if brush belongs to world entity or a brushmodel entity and is not a patch
136         if ( ( strcmp(pb->owner->eclass->name, "worldspawn") == 0
137                 || !strncmp( pb->owner->eclass->name, "func", 4)
138                 || !strncmp( pb->owner->eclass->name, "trigger", 7) ) && !pb->patchBrush )
139         {
140                 bool filterbrush;
141                 for (face_t *f=pb->brush_faces;f!=NULL;f = f->next)
142                 {
143                         filterbrush=false;
144                         for (bfilter_t *filters = g_qeglobals.d_savedinfo.filters;
145                         filters != NULL;
146                         filters = filters->next)
147                         {
148                                 // exclude by attribute 1 brush->face->pShader->getName()
149                                 if (filters->active && filters->attribute == 1)
150                                 {
151                                         if (strstr(f->pShader->getName(),filters->string))
152                                         {
153                                                 filterbrush=true;
154                                                 break;
155                                         }
156                                 }
157                                 // exclude by attribute 2 brush->face->pShader->getFlags()
158                                 else if (filters->active
159                                         && filters->attribute == 2)
160                                 {
161                                         if (f->pShader->getFlags() & filters->mask)
162                                         {
163                                                 filterbrush=true;
164                                                 break;
165                                         }
166                                 }
167                         }
168                         if (!filterbrush)
169                                 break;
170                 }
171                 if (filterbrush)// if no face is found that should not be excluded
172                         return true; // exclude this brush
173         }
174
175         // if brush is a patch
176         if ( pb->patchBrush )
177         {
178                 bool drawpatch=true;
179                 for (bfilter_t *filters = g_qeglobals.d_savedinfo.filters;
180                 filters != NULL;
181                 filters = filters->next)
182                 {
183                         // exclude by attribute 1 (for patch) brush->pPatch->pShader->getName()
184                         if (filters->active
185                                 && filters->attribute == 1)
186                         {
187                                 if (strstr(pb->pPatch->pShader->getName(),filters->string))
188                                 {
189                                         drawpatch=false;
190                                         break;
191                                 }
192                         }
193                         
194                         // exclude by attribute 2 (for patch) brush->pPatch->pShader->getFlags()
195                         if (filters->active
196                                 && filters->attribute == 2)
197                         {
198                                 if (pb->pPatch->pShader->getFlags() & filters->mask)
199                                 {
200                                         drawpatch=false;
201                                         break;
202                                 }
203                         }
204                 }
205                 if (!drawpatch) // if a shader is found that should be excluded
206                         return TRUE; // exclude this patch
207         }
208         
209         if (strcmp(pb->owner->eclass->name, "worldspawn") != 0) // if brush does not belong to world entity
210         {
211                 bool drawentity=true;
212                 for (bfilter_t *filters = g_qeglobals.d_savedinfo.filters;
213                 filters != NULL;
214                 filters = filters->next)
215                 {
216                         // exclude by attribute 3 brush->owner->eclass->name
217                         if (filters->active
218                                 && filters->attribute == 3)
219                         {
220                                 if (strstr(pb->owner->eclass->name,filters->string))
221                                 {
222                                         drawentity=false;
223                                         break;
224                                 }
225                         }
226                         
227                         // exclude by attribute 4 brush->owner->eclass->nShowFlags
228                         else if (filters->active
229                                 && filters->attribute == 4)
230                         {
231                                 if ( pb->owner->eclass->nShowFlags & filters->mask )
232                                 {
233                                         drawentity=false;
234                                         break;
235                                 }
236                         }
237                 }
238                 if (!drawentity) // if an eclass property is found that should be excluded
239                         return TRUE; // exclude this brush
240         }
241         return FALSE;
242 }