]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/prtfile.c
enable q3map2 out of tree compilation
[xonotic/netradiant.git] / tools / quake3 / q3map2 / prtfile.c
index ce8da91765eb3815bc388770dde0989786c3b876..2cd7015c35acb47090c90e996b8121cfcfdb9a25 100644 (file)
@@ -64,13 +64,45 @@ void WriteFloat( FILE *f, vec_t v ){
        }
 }
 
+void CountVisportals_r( node_t *node ){
+       int s;
+       portal_t    *p;
+       winding_t   *w;
+
+       // decision node
+       if ( node->planenum != PLANENUM_LEAF ) {
+               CountVisportals_r( node->children[0] );
+               CountVisportals_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;
+                       }
+                       if ( p->nodes[0]->cluster == p->nodes[1]->cluster ) {
+                               continue;
+                       }
+                       ++num_visportals;
+               }
+       }
+}
+
 /*
    =================
    WritePortalFile_r
    =================
  */
 void WritePortalFile_r( node_t *node ){
-       int i, s;
+       int i, s, flags;
        portal_t    *p;
        winding_t   *w;
        vec3_t normal;
@@ -95,6 +127,10 @@ void WritePortalFile_r( node_t *node ){
                        if ( !PortalPassable( p ) ) {
                                continue;
                        }
+                       if ( p->nodes[0]->cluster == p->nodes[1]->cluster ) {
+                               continue;
+                       }
+                       --num_visportals;
                        // write out to the file
 
                        // sometimes planes get turned around when they are very near
@@ -102,6 +138,7 @@ void WritePortalFile_r( node_t *node ){
                        // 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 );
                        }
@@ -109,14 +146,20 @@ void WritePortalFile_r( node_t *node ){
                                fprintf( pf,"%i %i %i ",w->numpoints, p->nodes[0]->cluster, p->nodes[1]->cluster );
                        }
 
+                       flags = 0;
+
                        /* ydnar: added this change to make antiportals work */
-                       if ( p->compileFlags & C_HINT ) {
-                               fprintf( pf, "1 " );
+                       if( p->compileFlags & C_HINT ) {
+                               flags |= 1;
                        }
-                       else{
-                               fprintf( pf, "0 " );
+
+                       /* divVerent: I want farplanedist to not kill skybox. So... */
+                       if( p->compileFlags & C_SKY ) {
+                               flags |= 2;
                        }
 
+                       fprintf( pf, "%d ", flags );
+
                        /* write the winding */
                        for ( i = 0 ; i < w->numpoints ; i++ )
                        {
@@ -132,6 +175,40 @@ void WritePortalFile_r( node_t *node ){
 
 }
 
+void CountSolidFaces_r( node_t *node ){
+       int s;
+       portal_t    *p;
+       winding_t   *w;
+
+       // decision node
+       if ( node->planenum != PLANENUM_LEAF ) {
+               CountSolidFaces_r( node->children[0] );
+               CountSolidFaces_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;
+                       }
+                       if ( p->nodes[0]->cluster == p->nodes[1]->cluster ) {
+                               continue;
+                       }
+                       // write out to the file
+
+                       ++num_solidfaces;
+               }
+       }
+}
+
 /*
    =================
    WriteFaceFile_r
@@ -161,6 +238,9 @@ void WriteFaceFile_r( node_t *node ){
                        if ( PortalPassable( p ) ) {
                                continue;
                        }
+                       if ( p->nodes[0]->cluster == p->nodes[1]->cluster ) {
+                               continue;
+                       }
                        // write out to the file
 
                        if ( p->nodes[0] == node ) {
@@ -197,14 +277,31 @@ void WriteFaceFile_r( node_t *node ){
    NumberLeafs_r
    ================
  */
-void NumberLeafs_r( node_t *node ){
+void NumberLeafs_r( node_t *node, int c ){
+#if 0
        portal_t    *p;
-
+#endif
        if ( node->planenum != PLANENUM_LEAF ) {
                // decision node
                node->cluster = -99;
-               NumberLeafs_r( node->children[0] );
-               NumberLeafs_r( node->children[1] );
+
+               if ( node->has_structural_children ) {
+#if 0
+                       if ( c >= 0 ) {
+                               Sys_FPrintf( SYS_ERR,"THIS CANNOT HAPPEN\n" );
+                       }
+#endif
+                       NumberLeafs_r( node->children[0], c );
+                       NumberLeafs_r( node->children[1], c );
+               }
+               else
+               {
+                       if ( c < 0 ) {
+                               c = num_visclusters++;
+                       }
+                       NumberLeafs_r( node->children[0], c );
+                       NumberLeafs_r( node->children[1], c );
+               }
                return;
        }
 
@@ -216,9 +313,13 @@ void NumberLeafs_r( node_t *node ){
                return;
        }
 
-       node->cluster = num_visclusters;
-       num_visclusters++;
+       if ( c < 0 ) {
+               c = num_visclusters++;
+       }
+
+       node->cluster = c;
 
+#if 0
        // count the portals
        for ( p = node->portals ; p ; )
        {
@@ -239,6 +340,7 @@ void NumberLeafs_r( node_t *node ){
                        p = p->next[1];
                }
        }
+#endif
 }
 
 
@@ -255,7 +357,9 @@ void NumberClusters( tree_t *tree ) {
        Sys_FPrintf( SYS_VRB,"--- NumberClusters ---\n" );
 
        // set the cluster field in every leaf and count the total number of portals
-       NumberLeafs_r( tree->headnode );
+       NumberLeafs_r( tree->headnode, -1 );
+       CountVisportals_r( tree->headnode );
+       CountSolidFaces_r( tree->headnode );
 
        Sys_FPrintf( SYS_VRB, "%9d visclusters\n", num_visclusters );
        Sys_FPrintf( SYS_VRB, "%9d visportals\n", num_visportals );
@@ -267,17 +371,15 @@ void NumberClusters( tree_t *tree ) {
    WritePortalFile
    ================
  */
-void WritePortalFile( tree_t *tree ){
-       char filename[1024];
+void WritePortalFile( tree_t *tree, const char *portalFilePath ){
 
        Sys_FPrintf( SYS_VRB,"--- WritePortalFile ---\n" );
 
        // write the file
-       sprintf( filename, "%s.prt", source );
-       Sys_Printf( "writing %s\n", filename );
-       pf = fopen( filename, "w" );
+       Sys_Printf( "writing %s\n", portalFilePath );
+       pf = fopen( portalFilePath, "w" );
        if ( !pf ) {
-               Error( "Error opening %s", filename );
+               Error( "Error opening %s", portalFilePath );
        }
 
        fprintf( pf, "%s\n", PORTALFILE );