2 BobToolz plugin for GtkRadiant
\r
3 Copyright (C) 2001 Gordon Biggans
\r
5 This library is free software; you can redistribute it and/or
\r
6 modify it under the terms of the GNU Lesser General Public
\r
7 License as published by the Free Software Foundation; either
\r
8 version 2.1 of the License, or (at your option) any later version.
\r
10 This library is distributed in the hope that it will be useful,
\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
13 Lesser General Public License for more details.
\r
15 You should have received a copy of the GNU Lesser General Public
\r
16 License along with this library; if not, write to the Free Software
\r
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
21 #include "CPortals.h"
\r
24 #define LINE_BUF 1000
\r
25 #define MSG_PREFIX "bobToolz plugin: "
\r
27 // these classes are far less of a mess than my code was,
\r
28 // thanq to G.DeWan 4 the prtview source on which it was based
\r
30 CBspPortal::CBspPortal()
\r
32 memset(this, 0, sizeof(CBspPortal));
\r
35 CBspPortal::~CBspPortal()
\r
40 void ClampFloat(float* p)
\r
43 double frac = modf(*p, &i);
\r
48 if(fabs(*p - ceil(*p)) < MAX_ROUND_ERROR)
\r
51 if(fabs(*p - floor(*p)) < MAX_ROUND_ERROR)
\r
55 bool CBspPortal::Build(char *def, unsigned int pointCnt, bool bInverse)
\r
60 point_count = pointCnt;
\r
65 point = new CBspPoint[point_count];
\r
67 for(n = 0; n < point_count; n++)
\r
69 for(; *c != 0 && *c != '('; c++);
\r
78 x = point_count - n - 1;
\r
82 sscanf(c, "%f %f %f", &point[x].p[0], &point[x].p[1], &point[x].p[2]);
\r
84 ClampFloat(&point[x].p[0]);
\r
85 ClampFloat(&point[x].p[1]);
\r
86 ClampFloat(&point[x].p[2]);
\r
92 CPortals::CPortals()
\r
94 memset(this, 0, sizeof(CPortals));
\r
97 CPortals::~CPortals()
\r
102 void CPortals::Purge()
\r
110 void CPortals::Load()
\r
112 char buf[LINE_BUF+1];
\r
114 memset(buf, 0, LINE_BUF + 1);
\r
118 Sys_Printf(MSG_PREFIX "Loading portal file %s.\n", fn);
\r
122 in = fopen(fn, "rt");
\r
126 Sys_Printf(" ERROR - could not open file.\n");
\r
131 if(!fgets(buf, LINE_BUF, in))
\r
135 Sys_Printf(" ERROR - File ended prematurely.\n");
\r
140 if(strncmp("PRT1", buf, 4) != 0)
\r
144 Sys_Printf(" ERROR - File header indicates wrong file type (should be \"PRT1\").\n");
\r
149 if(!fgets(buf, LINE_BUF, in))
\r
153 Sys_Printf(" ERROR - File ended prematurely.\n");
\r
158 sscanf(buf, "%u", &node_count);
\r
160 if(node_count > 0xFFFF)
\r
166 Sys_Printf(" ERROR - Extreme number of nodes, aborting.\n");
\r
171 if(!fgets(buf, LINE_BUF, in))
\r
177 Sys_Printf(" ERROR - File ended prematurely.\n");
\r
182 unsigned int p_count;
\r
183 sscanf(buf, "%u", &p_count);
\r
185 if(!fgets(buf, LINE_BUF, in))
\r
191 Sys_Printf(" ERROR - File ended prematurely.\n");
\r
196 unsigned int p_count2;
\r
197 sscanf(buf, "%u", &p_count2);
\r
199 node = new CBspNode[node_count];
\r
202 for(i = 0; i < p_count; i++)
\r
204 if(!fgets(buf, LINE_BUF, in))
\r
210 Sys_Printf(" ERROR - File ended prematurely.\n");
\r
215 unsigned int dummy, node1, node2;
\r
216 sscanf(buf, "%u %u %u", &dummy, &node1, &node2);
\r
218 node[node1].portal_count++;
\r
219 node[node2].portal_count++;
\r
222 for(i = 0; i < p_count2; i++)
\r
224 if(!fgets(buf, LINE_BUF, in))
\r
230 Sys_Printf(" ERROR - File ended prematurely.\n");
\r
235 unsigned int dummy, node1;
\r
236 sscanf(buf, "%u %u", &dummy, &node1);
\r
238 node[node1].portal_count++;
\r
241 for(i = 0; i < node_count; i++)
\r
242 node[i].portal = new CBspPortal[node[i].portal_count];
\r
246 in = fopen(fn, "rt");
\r
248 fgets(buf, LINE_BUF, in);
\r
249 fgets(buf, LINE_BUF, in);
\r
250 fgets(buf, LINE_BUF, in);
\r
251 fgets(buf, LINE_BUF, in);
\r
254 for(n = 0; n < p_count; n++)
\r
256 if(!fgets(buf, LINE_BUF, in))
\r
262 Sys_Printf(" ERROR - Could not find information for portal number %d of %d.\n", n + 1, p_count);
\r
267 unsigned int pCount, node1, node2;
\r
268 sscanf(buf, "%u %u %u", &pCount, &node1, &node2);
\r
270 if(!node[node1].AddPortal(buf, pCount, FALSE))
\r
276 Sys_Printf(" ERROR - Information for portal number %d of %d is not formatted correctly.\n", n + 1, p_count);
\r
281 if(!node[node2].AddPortal(buf, pCount, TRUE))
\r
287 Sys_Printf(" ERROR - Information for portal number %d of %d is not formatted correctly.\n", n + 1, p_count);
\r
293 for(n = 0; n < p_count2; n++)
\r
295 if(!fgets(buf, LINE_BUF, in))
\r
301 Sys_Printf(" ERROR - Could not find information for portal number %d of %d.\n", n + 1, p_count);
\r
306 unsigned int pCount, node1;
\r
307 sscanf(buf, "%u %u", &pCount, &node1);
\r
309 if(!node[node1].AddPortal(buf, pCount, FALSE))
\r
315 Sys_Printf(" ERROR - Information for portal number %d of %d is not formatted correctly.\n", n + 1, p_count);
\r
324 CBspNode::CBspNode()
\r
331 CBspNode::~CBspNode()
\r
337 bool CBspNode::AddPortal(char *def, unsigned int pointCnt, bool bInverse)
\r
339 return portal[portal_next++].Build(def, pointCnt, bInverse);
\r