/* ============= FreeTree ============= */ void FreeTree( tree_t *tree ) { if ( !tree ) { return; } FreeTreePortals_r (tree->headnode); FreeTree_r (tree->headnode); Mem_Free (tree); }
/* ============= FreeTree ============= */ void FreeTree (tree_t *tree) { if ( !tree ) return; FreeTreePortals_r (tree->headnode); FreeTree_r (tree->headnode); free (tree); }
static void FreeTreePortals_r (node_t *node) { portal_t *p, *nextp; /* free children */ if (node->planenum != PLANENUM_LEAF) { FreeTreePortals_r(node->children[0]); FreeTreePortals_r(node->children[1]); } /* free portals */ for (p = node->portals; p; p = nextp) { const int s = (p->nodes[1] == node); nextp = p->next[s]; RemovePortalFromNode(p, p->nodes[!s]); FreePortal(p); } node->portals = nullptr; }
/* ============= FreeTreePortals_r ============= */ void FreeTreePortals_r( node_t *node ){ portal_t *p, *nextp; int s; // free children if ( node->planenum != PLANENUM_LEAF ) { FreeTreePortals_r( node->children[0] ); FreeTreePortals_r( node->children[1] ); } // free portals for ( p = node->portals ; p ; p = nextp ) { s = ( p->nodes[1] == node ); nextp = p->next[s]; RemovePortalFromNode( p, p->nodes[!s] ); FreePortal( p ); } node->portals = NULL; }
/* ================ WritePortalFile ================ */ void WritePortalFile( tree_t *tree ){ char filename[1024]; node_t *headnode; Sys_FPrintf( SYS_VRB, "--- WritePortalFile ---\n" ); headnode = tree->headnode; num_visclusters = 0; num_visportals = 0; FreeTreePortals_r( headnode ); MakeHeadnodePortals( tree ); CreateVisPortals_r( headnode ); // set the cluster field in every leaf and count the total number of portals NumberLeafs_r( headnode ); // 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 ); Sys_FPrintf( SYS_VRB, "%5i visclusters\n", num_visclusters ); Sys_FPrintf( SYS_VRB, "%5i visportals\n", num_visportals ); WritePortalFile_r( headnode ); fclose( pf ); // we need to store the clusters out now because ordering // issues made us do this after writebsp... clusterleaf = 1; SaveClusters_r( headnode ); }
/* * @brief */ void WritePortalFile(tree_t *tree) { char filename[MAX_OSPATH]; node_t *head_node; Com_Verbose("--- WritePortalFile ---\n"); head_node = tree->head_node; num_visclusters = 0; num_visportals = 0; FreeTreePortals_r(head_node); MakeHeadnodePortals(tree); CreateVisPortals_r(head_node); // set the cluster field in every leaf and count the total number of portals NumberLeafs_r(head_node); // write the file StripExtension(map_name, filename); strcat(filename, ".prt"); if (!(prtfile = Fs_OpenWrite(filename))) Com_Error(ERR_FATAL, "Error opening %s\n", filename); Fs_Print(prtfile, "%s\n", PORTALFILE); Fs_Print(prtfile, "%i\n", num_visclusters); Fs_Print(prtfile, "%i\n", num_visportals); Com_Verbose("%5i visclusters\n", num_visclusters); Com_Verbose("%5i visportals\n", num_visportals); WritePortalFile_r(head_node); Fs_Close(prtfile); // we need to store the clusters out now because ordering // issues made us do this after writebsp... clusterleaf = 1; SaveClusters_r(head_node); Com_Verbose("--- WritePortalFile complete ---\n"); }
void FreeTree (tree_t *tree) { FreeTreePortals_r(tree->headnode); FreeTree_r(tree->headnode); Mem_Free(tree); }