-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r
-\r
-----------------------------------------------------------------------------------\r
-\r
-This code has been altered significantly from its original form, to support\r
-several games based on the Quake III Arena engine, in the form of "Q3Map2."\r
-\r
-------------------------------------------------------------------------------- */\r
-\r
-\r
-\r
-/* marker */\r
-#define PRTFILE_C\r
-\r
-\r
-\r
-/* dependencies */\r
-#include "q3map2.h"\r
-\r
-\r
-\r
-/*\r
-==============================================================================\r
-\r
-PORTAL FILE GENERATION\r
-\r
-Save out name.prt for qvis to read\r
-==============================================================================\r
-*/\r
-\r
-\r
-#define PORTALFILE "PRT1"\r
-\r
-FILE *pf;\r
-int num_visclusters; // clusters the player can be in\r
-int num_visportals;\r
-int num_solidfaces;\r
-\r
-void WriteFloat (FILE *f, vec_t v)\r
-{\r
- if ( fabs(v - Q_rint(v)) < 0.001 )\r
- fprintf (f,"%i ",(int)Q_rint(v));\r
- else\r
- fprintf (f,"%f ",v);\r
-}\r
-\r
-/*\r
-=================\r
-WritePortalFile_r\r
-=================\r
-*/\r
-void WritePortalFile_r (node_t *node)\r
-{\r
- int i, s; \r
- portal_t *p;\r
- winding_t *w;\r
- vec3_t normal;\r
- vec_t dist;\r
-\r
- // decision node\r
- if (node->planenum != PLANENUM_LEAF) {\r
- WritePortalFile_r (node->children[0]);\r
- WritePortalFile_r (node->children[1]);\r
- return;\r
- }\r
- \r
- if (node->opaque) {\r
- return;\r
- }\r
-\r
- for (p = node->portals ; p ; p=p->next[s])\r
- {\r
- w = p->winding;\r
- s = (p->nodes[1] == node);\r
- if (w && p->nodes[0] == node)\r
- {\r
- if (!PortalPassable(p))\r
- continue;\r
- // write out to the file\r
- \r
- // sometimes planes get turned around when they are very near\r
- // the changeover point between different axis. interpret the\r
- // plane the same way vis will, and flip the side orders if needed\r
- // FIXME: is this still relevent?\r
- WindingPlane (w, normal, &dist);\r
- if ( DotProduct (p->plane.normal, normal) < 0.99 )\r
- { // backwards...\r
- fprintf (pf,"%i %i %i ",w->numpoints, p->nodes[1]->cluster, p->nodes[0]->cluster);\r
- }\r
- else\r
- fprintf (pf,"%i %i %i ",w->numpoints, p->nodes[0]->cluster, p->nodes[1]->cluster);\r
- \r
- /* ydnar: added this change to make antiportals work */\r
- if( p->compileFlags & C_HINT )\r
- fprintf( pf, "1 " );\r
- else\r
- fprintf( pf, "0 " );\r
- \r
- /* write the winding */\r
- for (i=0 ; i<w->numpoints ; i++)\r
- {\r
- fprintf (pf,"(");\r
- WriteFloat (pf, w->p[i][0]);\r
- WriteFloat (pf, w->p[i][1]);\r
- WriteFloat (pf, w->p[i][2]);\r
- fprintf (pf,") ");\r
- }\r
- fprintf (pf,"\n");\r
- }\r
- }\r
-\r
-}\r
-\r
-/*\r
-=================\r
-WriteFaceFile_r\r
-=================\r
-*/\r
-void WriteFaceFile_r (node_t *node)\r
-{\r
- int i, s; \r
- portal_t *p;\r
- winding_t *w;\r
-\r
- // decision node\r
- if (node->planenum != PLANENUM_LEAF) {\r
- WriteFaceFile_r (node->children[0]);\r
- WriteFaceFile_r (node->children[1]);\r
- return;\r
- }\r
- \r
- if (node->opaque) {\r
- return;\r
- }\r
-\r
- for (p = node->portals ; p ; p=p->next[s])\r
- {\r
- w = p->winding;\r
- s = (p->nodes[1] == node);\r
- if (w)\r
- {\r
- if (PortalPassable(p))\r
- continue;\r
- // write out to the file\r
-\r
- if (p->nodes[0] == node)\r
- {\r
- fprintf (pf,"%i %i ",w->numpoints, p->nodes[0]->cluster);\r
- for (i=0 ; i<w->numpoints ; i++)\r
- {\r
- fprintf (pf,"(");\r
- WriteFloat (pf, w->p[i][0]);\r
- WriteFloat (pf, w->p[i][1]);\r
- WriteFloat (pf, w->p[i][2]);\r
- fprintf (pf,") ");\r
- }\r
- fprintf (pf,"\n");\r
- }\r
- else\r
- {\r
- fprintf (pf,"%i %i ",w->numpoints, p->nodes[1]->cluster);\r
- for (i = w->numpoints-1; i >= 0; i--)\r
- {\r
- fprintf (pf,"(");\r
- WriteFloat (pf, w->p[i][0]);\r
- WriteFloat (pf, w->p[i][1]);\r
- WriteFloat (pf, w->p[i][2]);\r
- fprintf (pf,") ");\r
- }\r
- fprintf (pf,"\n");\r
- }\r
- }\r
- }\r
-}\r
-\r
-/*\r
-================\r
-NumberLeafs_r\r
-================\r
-*/\r
-void NumberLeafs_r (node_t *node)\r
-{\r
- portal_t *p;\r
-\r
- if ( node->planenum != PLANENUM_LEAF ) {\r
- // decision node\r
- node->cluster = -99;\r
- NumberLeafs_r (node->children[0]);\r
- NumberLeafs_r (node->children[1]);\r
- return;\r
- }\r
- \r
- node->area = -1;\r
-\r
- if ( node->opaque ) {\r
- // solid block, viewpoint never inside\r
- node->cluster = -1;\r
- return;\r
- }\r
-\r
- node->cluster = num_visclusters;\r
- num_visclusters++;\r
-\r
- // count the portals\r
- for (p = node->portals ; p ; )\r
- {\r
- if (p->nodes[0] == node) // only write out from first leaf\r
- {\r
- if (PortalPassable(p))\r
- num_visportals++;\r
- else\r
- num_solidfaces++;\r
- p = p->next[0];\r
- }\r
- else\r
- {\r
- if (!PortalPassable(p))\r
- num_solidfaces++;\r
- p = p->next[1]; \r
- }\r
- }\r
-}\r
-\r
-\r
-/*\r
-================\r
-NumberClusters\r
-================\r
-*/\r
-void NumberClusters(tree_t *tree) {\r
- num_visclusters = 0;\r
- num_visportals = 0;\r
- num_solidfaces = 0;\r
-\r
- Sys_FPrintf (SYS_VRB,"--- NumberClusters ---\n");\r
- \r
- // set the cluster field in every leaf and count the total number of portals\r
- NumberLeafs_r (tree->headnode);\r
-\r
- Sys_FPrintf( SYS_VRB, "%9d visclusters\n", num_visclusters );\r
- Sys_FPrintf( SYS_VRB, "%9d visportals\n", num_visportals );\r
- Sys_FPrintf( SYS_VRB, "%9d solidfaces\n", num_solidfaces );\r
-}\r
-\r
-/*\r
-================\r
-WritePortalFile\r
-================\r
-*/\r
-void WritePortalFile (tree_t *tree)\r
-{\r
- char filename[1024];\r
-\r
- Sys_FPrintf (SYS_VRB,"--- WritePortalFile ---\n");\r
- \r
- // write the file\r
- sprintf (filename, "%s.prt", source);\r
- Sys_Printf ("writing %s\n", filename);\r
- pf = fopen (filename, "w");\r
- if (!pf)\r
- Error ("Error opening %s", filename);\r
- \r
- fprintf (pf, "%s\n", PORTALFILE);\r
- fprintf (pf, "%i\n", num_visclusters);\r
- fprintf (pf, "%i\n", num_visportals);\r
- fprintf (pf, "%i\n", num_solidfaces);\r
-\r
- WritePortalFile_r(tree->headnode);\r
- WriteFaceFile_r(tree->headnode);\r
-\r
- fclose (pf);\r
-}\r
-\r
+/*
+Copyright (C) 1999-2007 id Software, Inc. and contributors.
+For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+This file is part of GtkRadiant.
+
+GtkRadiant 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 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant 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 GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+----------------------------------------------------------------------------------
+
+This code has been altered significantly from its original form, to support
+several games based on the Quake III Arena engine, in the form of "Q3Map2."
+
+------------------------------------------------------------------------------- */
+
+
+
+/* marker */
+#define PRTFILE_C
+
+
+
+/* dependencies */
+#include "q3map2.h"
+
+
+
+/*
+==============================================================================
+
+PORTAL FILE GENERATION
+
+Save out name.prt for qvis to read
+==============================================================================
+*/
+
+
+#define PORTALFILE "PRT1"
+
+FILE *pf;
+int num_visclusters; // clusters the player can be in
+int num_visportals;
+int num_solidfaces;
+
+void WriteFloat (FILE *f, vec_t v)
+{
+ if ( fabs(v - Q_rint(v)) < 0.001 )
+ fprintf (f,"%i ",(int)Q_rint(v));
+ else
+ fprintf (f,"%f ",v);
+}
+
+/*
+=================
+WritePortalFile_r
+=================
+*/
+void WritePortalFile_r (node_t *node)
+{
+ int i, s;
+ portal_t *p;
+ winding_t *w;
+ vec3_t normal;
+ vec_t dist;
+
+ // decision node
+ if (node->planenum != PLANENUM_LEAF) {
+ WritePortalFile_r (node->children[0]);
+ WritePortalFile_r (node->children[1]);
+ return;
+ }
+
+ if (node->opaque) {
+ return;
+ }
+
+ for (p = node->portals ; p ; p=p->next[s])
+ {
+ w = p->winding;
+ s = (p->nodes[1] == node);
+ if (w && p->nodes[0] == node)
+ {
+ if (!PortalPassable(p))
+ continue;
+ // write out to the file
+
+ // sometimes planes get turned around when they are very near
+ // the changeover point between different axis. interpret the
+ // plane the same way vis will, and flip the side orders if needed
+ // FIXME: is this still relevent?
+ WindingPlane (w, normal, &dist);
+ if ( DotProduct (p->plane.normal, normal) < 0.99 )
+ { // backwards...
+ fprintf (pf,"%i %i %i ",w->numpoints, p->nodes[1]->cluster, p->nodes[0]->cluster);
+ }
+ else
+ fprintf (pf,"%i %i %i ",w->numpoints, p->nodes[0]->cluster, p->nodes[1]->cluster);
+
+ /* ydnar: added this change to make antiportals work */
+ if( p->compileFlags & C_HINT )
+ fprintf( pf, "1 " );
+ else
+ fprintf( pf, "0 " );
+
+ /* write the winding */
+ for (i=0 ; i<w->numpoints ; i++)
+ {
+ fprintf (pf,"(");
+ WriteFloat (pf, w->p[i][0]);
+ WriteFloat (pf, w->p[i][1]);
+ WriteFloat (pf, w->p[i][2]);
+ fprintf (pf,") ");
+ }
+ fprintf (pf,"\n");
+ }
+ }
+
+}
+
+/*
+=================
+WriteFaceFile_r
+=================
+*/
+void WriteFaceFile_r (node_t *node)
+{
+ int i, s;
+ portal_t *p;
+ winding_t *w;
+
+ // decision node
+ if (node->planenum != PLANENUM_LEAF) {
+ WriteFaceFile_r (node->children[0]);
+ WriteFaceFile_r (node->children[1]);
+ return;
+ }
+
+ if (node->opaque) {
+ return;
+ }
+
+ for (p = node->portals ; p ; p=p->next[s])
+ {
+ w = p->winding;
+ s = (p->nodes[1] == node);
+ if (w)
+ {
+ if (PortalPassable(p))
+ continue;
+ // write out to the file
+
+ if (p->nodes[0] == node)
+ {
+ fprintf (pf,"%i %i ",w->numpoints, p->nodes[0]->cluster);
+ for (i=0 ; i<w->numpoints ; i++)
+ {
+ fprintf (pf,"(");
+ WriteFloat (pf, w->p[i][0]);
+ WriteFloat (pf, w->p[i][1]);
+ WriteFloat (pf, w->p[i][2]);
+ fprintf (pf,") ");
+ }
+ fprintf (pf,"\n");
+ }
+ else
+ {
+ fprintf (pf,"%i %i ",w->numpoints, p->nodes[1]->cluster);
+ for (i = w->numpoints-1; i >= 0; i--)
+ {
+ fprintf (pf,"(");
+ WriteFloat (pf, w->p[i][0]);
+ WriteFloat (pf, w->p[i][1]);
+ WriteFloat (pf, w->p[i][2]);
+ fprintf (pf,") ");
+ }
+ fprintf (pf,"\n");
+ }
+ }
+ }
+}
+
+/*
+================
+NumberLeafs_r
+================
+*/
+void NumberLeafs_r (node_t *node)
+{
+ portal_t *p;
+
+ if ( node->planenum != PLANENUM_LEAF ) {
+ // decision node
+ node->cluster = -99;
+ NumberLeafs_r (node->children[0]);
+ NumberLeafs_r (node->children[1]);
+ return;
+ }
+
+ node->area = -1;
+
+ if ( node->opaque ) {
+ // solid block, viewpoint never inside
+ node->cluster = -1;
+ return;
+ }
+
+ node->cluster = num_visclusters;
+ num_visclusters++;
+
+ // count the portals
+ for (p = node->portals ; p ; )
+ {
+ if (p->nodes[0] == node) // only write out from first leaf
+ {
+ if (PortalPassable(p))
+ num_visportals++;
+ else
+ num_solidfaces++;
+ p = p->next[0];
+ }
+ else
+ {
+ if (!PortalPassable(p))
+ num_solidfaces++;
+ p = p->next[1];
+ }
+ }
+}
+
+
+/*
+================
+NumberClusters
+================
+*/
+void NumberClusters(tree_t *tree) {
+ num_visclusters = 0;
+ num_visportals = 0;
+ num_solidfaces = 0;
+
+ Sys_FPrintf (SYS_VRB,"--- NumberClusters ---\n");
+
+ // set the cluster field in every leaf and count the total number of portals
+ NumberLeafs_r (tree->headnode);
+
+ Sys_FPrintf( SYS_VRB, "%9d visclusters\n", num_visclusters );
+ Sys_FPrintf( SYS_VRB, "%9d visportals\n", num_visportals );
+ Sys_FPrintf( SYS_VRB, "%9d solidfaces\n", num_solidfaces );
+}
+
+/*
+================
+WritePortalFile
+================
+*/
+void WritePortalFile (tree_t *tree)
+{
+ char filename[1024];
+
+ Sys_FPrintf (SYS_VRB,"--- WritePortalFile ---\n");
+
+ // write the file
+ sprintf (filename, "%s.prt", source);
+ Sys_Printf ("writing %s\n", filename);
+ pf = fopen (filename, "w");
+ if (!pf)
+ Error ("Error opening %s", filename);
+
+ fprintf (pf, "%s\n", PORTALFILE);
+ fprintf (pf, "%i\n", num_visclusters);
+ fprintf (pf, "%i\n", num_visportals);
+ fprintf (pf, "%i\n", num_solidfaces);
+
+ WritePortalFile_r(tree->headnode);
+ WriteFaceFile_r(tree->headnode);
+
+ fclose (pf);
+}
+