void AAS_CalcReachAndClusters( struct quakefile_s *qf ) { float time; Log_Print( "loading collision map...\n" ); // if ( !qf->pakfile[0] ) { strcpy( qf->pakfile, qf->filename ); } //load the map CM_LoadMap( (char *) qf, qfalse, &( *aasworld ).bspchecksum ); //get a handle to the world model worldmodel = CM_InlineModel( 0 ); // 0 = world, 1 + are bmodels //initialize bot import structure AAS_InitBotImport(); //load the BSP entity string AAS_LoadBSPFile(); //init physics settings AAS_InitSettings(); //initialize AAS link heap AAS_InitAASLinkHeap(); //initialize the AAS linked entities for the new map AAS_InitAASLinkedEntities(); //reset all reachabilities and clusters ( *aasworld ).reachabilitysize = 0; ( *aasworld ).numclusters = 0; //set all view portals as cluster portals in case we re-calculate the reachabilities and clusters (with -reach) AAS_SetViewPortalsAsClusterPortals(); //calculate reachabilities AAS_InitReachability(); time = 0; while ( AAS_ContinueInitReachability( time ) ) time++; //calculate clusters AAS_InitClustering(); } //end of the function AAS_CalcReachAndClusters
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AAS_InitClustering(void) { int i, removedPortalAreas; int n, total, numreachabilityareas; if (!aasworld.loaded) return; //if there are clusters if (aasworld.numclusters >= 1) { #ifndef BSPC //if clustering isn't forced if (!((int)LibVarGetValue("forceclustering")) && !((int)LibVarGetValue("forcereachability"))) return; #endif } //end if //set all view portals as cluster portals in case we re-calculate the reachabilities and clusters (with -reach) AAS_SetViewPortalsAsClusterPortals(); //count the number of forced cluster portals AAS_CountForcedClusterPortals(); //remove all area cluster marks AAS_RemoveClusterAreas(); //find possible cluster portals AAS_FindPossiblePortals(); //craete portals to for the bot view AAS_CreateViewPortals(); //remove all portals that are not closing a cluster //AAS_RemoveNotClusterClosingPortals(); //initialize portal memory if (aasworld.portals) FreeMemory(aasworld.portals); aasworld.portals = (aas_portal_t *) GetClearedMemory(AAS_MAX_PORTALS * sizeof(aas_portal_t)); //initialize portal index memory if (aasworld.portalindex) FreeMemory(aasworld.portalindex); aasworld.portalindex = (aas_portalindex_t *) GetClearedMemory(AAS_MAX_PORTALINDEXSIZE * sizeof(aas_portalindex_t)); //initialize cluster memory if (aasworld.clusters) FreeMemory(aasworld.clusters); aasworld.clusters = (aas_cluster_t *) GetClearedMemory(AAS_MAX_CLUSTERS * sizeof(aas_cluster_t)); // removedPortalAreas = 0; botimport.Print(PRT_MESSAGE, "\r%6d removed portal areas", removedPortalAreas); while(1) { botimport.Print(PRT_MESSAGE, "\r%6d", removedPortalAreas); //initialize the number of portals and clusters aasworld.numportals = 1; //portal 0 is a dummy aasworld.portalindexsize = 0; aasworld.numclusters = 1; //cluster 0 is a dummy //create the portals from the portal areas AAS_CreatePortals(); // removedPortalAreas++; //find the clusters if (!AAS_FindClusters()) continue; //test the portals if (!AAS_TestPortals()) continue; // break; } //end while botimport.Print(PRT_MESSAGE, "\n"); //the AAS file should be saved aasworld.savefile = qtrue; //write the portal areas to the log file for (i = 1; i < aasworld.numportals; i++) { Log_Write("portal %d: area %d\r\n", i, aasworld.portals[i].areanum); } //end for // report cluster info botimport.Print(PRT_MESSAGE, "%6d portals created\n", aasworld.numportals); botimport.Print(PRT_MESSAGE, "%6d clusters created\n", aasworld.numclusters); for (i = 1; i < aasworld.numclusters; i++) { botimport.Print(PRT_MESSAGE, "cluster %d has %d reachability areas\n", i, aasworld.clusters[i].numreachabilityareas); } //end for // report AAS file efficiency numreachabilityareas = 0; total = 0; for (i = 0; i < aasworld.numclusters; i++) { n = aasworld.clusters[i].numreachabilityareas; numreachabilityareas += n; total += n * n; } total += numreachabilityareas * aasworld.numportals; // botimport.Print(PRT_MESSAGE, "%6i total reachability areas\n", numreachabilityareas); botimport.Print(PRT_MESSAGE, "%6i AAS memory/CPU usage (the lower the better)\n", total * 3); } //end of the function AAS_InitClustering