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