]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/filters.cpp
* sample plugin toolbar bitmap
[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 // type 1 = texture filter (name)
34 // type 3 = entity filter (name)
35 // type 2 = QER_* shader flags
36 // type 4 = entity classes
37 bfilter_t *FilterAdd(bfilter_t *pFilter, int type, int bmask, char *str, int exclude)
38 {
39         bfilter_t *pNew = new bfilter_t;
40         pNew->next = pFilter;
41         pNew->attribute = type;
42         if (type == 1 || type == 3) pNew->string = str;
43         if (type == 2 || type == 4) pNew->mask = bmask;
44         if (g_qeglobals.d_savedinfo.exclude & exclude)
45                 pNew->active = true;
46         else
47                 pNew->active = false;
48         return pNew;
49 }
50
51 bfilter_t *FilterCreate (int type, int bmask, char *str, int exclude)
52 {
53         g_qeglobals.d_savedinfo.filters = FilterAdd(g_qeglobals.d_savedinfo.filters, type, bmask, str, exclude);
54         Syn_Printf("Added filter %s (type: %i, bmask: %i, exclude: %i)\n", str, type, bmask, exclude);
55         return g_qeglobals.d_savedinfo.filters;
56 }
57
58 extern void PerformFiltering();
59
60 void FiltersActivate (void)
61 {
62         PerformFiltering();
63         Sys_UpdateWindows(W_XY|W_CAMERA);
64 }
65
66   // removes the filter list at *pFilter, returns NULL pointer
67 bfilter_t *FilterListDelete(bfilter_t *pFilter)
68 {
69         if (pFilter != NULL)
70         {
71                 FilterListDelete(pFilter->next);
72                 delete pFilter;
73         }
74         return NULL;
75 }
76
77
78  //spog - FilterUpdate is called each time the filters are changed by menu or shortcuts
79 bfilter_t *FilterUpdate(bfilter_t *pFilter)
80 {
81         pFilter = FilterAdd(pFilter,1,0,"clip",EXCLUDE_CLIP);
82         pFilter = FilterAdd(pFilter,1,0,"caulk",EXCLUDE_CAULK);
83         pFilter = FilterAdd(pFilter,1,0,"liquids",EXCLUDE_LIQUIDS);
84         pFilter = FilterAdd(pFilter,1,0,"hint",EXCLUDE_HINTSSKIPS);
85         pFilter = FilterAdd(pFilter,1,0,"clusterportal",EXCLUDE_CLUSTERPORTALS);
86         pFilter = FilterAdd(pFilter,1,0,"areaportal",EXCLUDE_AREAPORTALS);
87         pFilter = FilterAdd(pFilter,2,QER_TRANS,NULL,EXCLUDE_TRANSLUCENT);
88         pFilter = FilterAdd(pFilter,3,0,"trigger",EXCLUDE_TRIGGERS);
89         pFilter = FilterAdd(pFilter,3,0,"misc_model",EXCLUDE_MODELS);
90         pFilter = FilterAdd(pFilter,3,0,"misc_gamemodel",EXCLUDE_MODELS);
91         pFilter = FilterAdd(pFilter,4,ECLASS_LIGHT,NULL,EXCLUDE_LIGHTS);
92         pFilter = FilterAdd(pFilter,4,ECLASS_PATH,NULL,EXCLUDE_PATHS);
93         pFilter = FilterAdd(pFilter,1,0,"lightgrid",EXCLUDE_LIGHTGRID);
94         pFilter = FilterAdd(pFilter,1,0,"botclip",EXCLUDE_BOTCLIP);
95   pFilter = FilterAdd(pFilter,1,0,"clipmonster",EXCLUDE_BOTCLIP);
96         return pFilter;
97 }
98
99 /*
100 ==================
101 FilterBrush
102 ==================
103 */
104
105 bool FilterBrush(brush_t *pb)
106 {
107         
108         if (!pb->owner)
109                 return FALSE;           // during construction
110         
111         if (pb->hiddenBrush)
112                 return TRUE;
113         
114         if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_WORLD)
115         {
116                 if (strcmp(pb->owner->eclass->name, "worldspawn") == 0 || !strcmp(pb->owner->eclass->name,"func_group")) // hack, treating func_group as world
117                 {
118                         return TRUE;
119                 }
120         }
121         
122         if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_ENT)
123         {
124                 if (strcmp(pb->owner->eclass->name, "worldspawn") != 0 && strcmp(pb->owner->eclass->name,"func_group")) // hack, treating func_group as world
125                 {
126                         return TRUE;
127                 }
128         }
129         
130         if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_CURVES )
131         {
132                 if (pb->patchBrush)
133                 {
134                         return TRUE;
135                 }
136         }
137         
138         
139         if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_DETAILS )
140         {
141                 if (!pb->patchBrush && pb->brush_faces->texdef.contents & CONTENTS_DETAIL )
142                 {
143                         return TRUE;
144                 }
145         }
146         if ( g_qeglobals.d_savedinfo.exclude & EXCLUDE_STRUCTURAL )
147         {
148                 if (!pb->patchBrush && !( pb->brush_faces->texdef.contents & CONTENTS_DETAIL ))
149                 {
150                         return TRUE;
151                 }
152         }
153                 
154         // if brush belongs to world entity or a brushmodel entity and is not a patch
155         if ( ( strcmp(pb->owner->eclass->name, "worldspawn") == 0
156                 || !strncmp( pb->owner->eclass->name, "func", 4)
157                 || !strncmp( pb->owner->eclass->name, "trigger", 7) ) && !pb->patchBrush )
158         {
159                 bool filterbrush = false;
160                 for (face_t *f=pb->brush_faces;f!=NULL;f = f->next)
161                 {
162                         filterbrush=false;
163                         for (bfilter_t *filters = g_qeglobals.d_savedinfo.filters;
164                         filters != NULL;
165                         filters = filters->next)
166                         {
167                                 // exclude by attribute 1 brush->face->pShader->getName()
168                                 if (filters->active && filters->attribute == 1)
169                                 {
170                                         if (strstr(f->pShader->getName(),filters->string))
171                                         {
172                                                 filterbrush=true;
173                                                 break;
174                                         }
175                                 }
176                                 // exclude by attribute 2 brush->face->pShader->getFlags()
177                                 else if (filters->active
178                                         && filters->attribute == 2)
179                                 {
180                                         if (f->pShader->getFlags() & filters->mask)
181                                         {
182                                                 filterbrush=true;
183                                                 break;
184                                         }
185                                 }
186                         }
187                         if (!filterbrush)
188                                 break;
189                 }
190                 if (filterbrush)// if no face is found that should not be excluded
191                         return true; // exclude this brush
192         }
193
194         // if brush is a patch
195         if ( pb->patchBrush )
196         {
197                 bool drawpatch=true;
198                 for (bfilter_t *filters = g_qeglobals.d_savedinfo.filters;
199                 filters != NULL;
200                 filters = filters->next)
201                 {
202                         // exclude by attribute 1 (for patch) brush->pPatch->pShader->getName()
203                         if (filters->active
204                                 && filters->attribute == 1)
205                         {
206                                 if (strstr(pb->pPatch->pShader->getName(),filters->string))
207                                 {
208                                         drawpatch=false;
209                                         break;
210                                 }
211                         }
212                         
213                         // exclude by attribute 2 (for patch) brush->pPatch->pShader->getFlags()
214                         if (filters->active
215                                 && filters->attribute == 2)
216                         {
217                                 if (pb->pPatch->pShader->getFlags() & filters->mask)
218                                 {
219                                         drawpatch=false;
220                                         break;
221                                 }
222                         }
223                 }
224                 if (!drawpatch) // if a shader is found that should be excluded
225                         return TRUE; // exclude this patch
226         }
227         
228         if (strcmp(pb->owner->eclass->name, "worldspawn") != 0) // if brush does not belong to world entity
229         {
230                 bool drawentity=true;
231                 for (bfilter_t *filters = g_qeglobals.d_savedinfo.filters;
232                 filters != NULL;
233                 filters = filters->next)
234                 {
235                         // exclude by attribute 3 brush->owner->eclass->name
236                         if (filters->active
237                                 && filters->attribute == 3)
238                         {
239                                 if (strstr(pb->owner->eclass->name,filters->string))
240                                 {
241                                         drawentity=false;
242                                         break;
243                                 }
244                         }
245                         
246                         // exclude by attribute 4 brush->owner->eclass->nShowFlags
247                         else if (filters->active
248                                 && filters->attribute == 4)
249                         {
250                                 if ( pb->owner->eclass->nShowFlags & filters->mask )
251                                 {
252                                         drawentity=false;
253                                         break;
254                                 }
255                         }
256                 }
257                 if (!drawentity) // if an eclass property is found that should be excluded
258                         return TRUE; // exclude this brush
259         }
260         return FALSE;
261 }