Ejemplo n.º 1
0
//===========================================================================
// allocate memory and read a lump of a AAS file
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
char *AAS_LoadAASLump( FILE *fp, int offset, int length, void *buf ) {
	if ( !length ) {
		printf( "lump size 0\n" );
		return buf;
	} //end if
	  //seek to the data
	if ( fseek( fp, offset, SEEK_SET ) ) {
		AAS_Error( "can't seek to lump\n" );
		AAS_DumpAASData();
		fclose( fp );
		return 0;
	} //end if
	  //allocate memory
	if ( !buf ) {
		buf = (void *) GetClearedMemory( length );
	}
	//read the data
	if ( fread( (char *) buf, 1, length, fp ) != length ) {
		AAS_Error( "can't read lump\n" );
		FreeMemory( buf );
		AAS_DumpAASData();
		fclose( fp );
		return NULL;
	} //end if
	return buf;
} //end of the function AAS_LoadAASLump
Ejemplo n.º 2
0
//===========================================================================
//
// Parameter:               -
// Returns:                 -
// Changes Globals:     -
//===========================================================================
void AAS_Shutdown(void)
{
	// Ridah, do each of the worlds
	int             i;

	for(i = 0; i < MAX_AAS_WORLDS; i++)
	{
		AAS_SetCurrentWorld(i);

		// Ridah, kill the route-table data
		AAS_RT_ShutdownRouteTable();

		AAS_ShutdownAlternativeRouting();
		AAS_DumpBSPData();
		//free routing caches
		AAS_FreeRoutingCaches();
		//free aas link heap
		AAS_FreeAASLinkHeap();
		//free aas linked entities
		AAS_FreeAASLinkedEntities();
		//free the aas data
		AAS_DumpAASData();

		if(i == 0)
		{
			//free the entities
			if((*aasworld).entities)
			{
				FreeMemory((*aasworld).entities);
			}
		}

		//clear the (*aasworld) structure
		memset(&(*aasworld), 0, sizeof(aas_t));
		//aas has not been initialized
		(*aasworld).initialized = qfalse;
	}

	//NOTE: as soon as a new .bsp file is loaded the .bsp file memory is
	// freed an reallocated, so there's no need to free that memory here
	//print shutdown
	botimport.Print(PRT_MESSAGE, "AAS shutdown.\n");
}								//end of the function AAS_Shutdown
Ejemplo n.º 3
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void AAS_Shutdown(void)
{
	AAS_ShutdownAlternativeRouting();
	//
	AAS_DumpBSPData();
	//free routing caches
	AAS_FreeRoutingCaches();
	//free aas link heap
	AAS_FreeAASLinkHeap();
	//free aas linked entities
	AAS_FreeAASLinkedEntities();
	//free the aas data
	AAS_DumpAASData();
	//free the entities
	if (aasworld.entities) FreeMemory(aasworld.entities);
	//clear the aasworld structure
	Com_Memset(&aasworld, 0, sizeof(aas_t));
	//aas has not been initialized
	aasworld.initialized = qfalse;
	//NOTE: as soon as a new .bsp file is loaded the .bsp file memory is
	// freed an reallocated, so there's no need to free that memory here
	//print shutdown
	botimport.Print(PRT_MESSAGE, "AAS shutdown.\n");
} //end of the function AAS_Shutdown
Ejemplo n.º 4
0
//===========================================================================
// load an aas file
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
qboolean AAS_LoadAASFile( char *filename, int fpoffset, int fplength ) {
	FILE *fp;
	aas_header_t header;
	int offset, length;

	//dump current loaded aas file
	AAS_DumpAASData();
	//open the file
	fp = fopen( filename, "rb" );
	if ( !fp ) {
		AAS_Error( "can't open %s\n", filename );
		return false;
	} //end if
	  //seek to the correct position (in the pak file)
	if ( fseek( fp, fpoffset, SEEK_SET ) ) {
		AAS_Error( "can't seek to file %s\n" );
		fclose( fp );
		return false;
	} //end if
	  //read the header
	if ( fread( &header, sizeof( aas_header_t ), 1, fp ) != 1 ) {
		AAS_Error( "can't read header of file %s\n", filename );
		fclose( fp );
		return false;
	} //end if
	  //check header identification
	header.ident = LittleLong( header.ident );
	if ( header.ident != AASID ) {
		AAS_Error( "%s is not an AAS file\n", filename );
		fclose( fp );
		return false;
	} //end if
	  //check the version
	header.version = LittleLong( header.version );
	if ( header.version != AASVERSION ) {
		AAS_Error( "%s is version %i, not %i\n", filename, header.version, AASVERSION );
		fclose( fp );
		return false;
	} //end if
	  //
	if ( header.version == AASVERSION ) {
		AAS_DData( (unsigned char *) &header + 8, sizeof( aas_header_t ) - 8 );
	} //end if
	( *aasworld ).bspchecksum = LittleLong( header.bspchecksum );
	//load the lumps:
	//bounding boxes
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_BBOXES].fileofs );
	length = LittleLong( header.lumps[AASLUMP_BBOXES].filelen );
	( *aasworld ).bboxes = (aas_bbox_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).bboxes );
	if ( !( *aasworld ).bboxes ) {
		return false;
	}
	( *aasworld ).numbboxes = length / sizeof( aas_bbox_t );
	//vertexes
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_VERTEXES].fileofs );
	length = LittleLong( header.lumps[AASLUMP_VERTEXES].filelen );
	( *aasworld ).vertexes = (aas_vertex_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).vertexes );
	if ( !( *aasworld ).vertexes ) {
		return false;
	}
	( *aasworld ).numvertexes = length / sizeof( aas_vertex_t );
	//planes
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_PLANES].fileofs );
	length = LittleLong( header.lumps[AASLUMP_PLANES].filelen );
	( *aasworld ).planes = (aas_plane_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).planes );
	if ( !( *aasworld ).planes ) {
		return false;
	}
	( *aasworld ).numplanes = length / sizeof( aas_plane_t );
	//edges
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_EDGES].fileofs );
	length = LittleLong( header.lumps[AASLUMP_EDGES].filelen );
	( *aasworld ).edges = (aas_edge_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).edges );
	if ( !( *aasworld ).edges ) {
		return false;
	}
	( *aasworld ).numedges = length / sizeof( aas_edge_t );
	//edgeindex
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_EDGEINDEX].fileofs );
	length = LittleLong( header.lumps[AASLUMP_EDGEINDEX].filelen );
	( *aasworld ).edgeindex = (aas_edgeindex_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).edgeindex );
	if ( !( *aasworld ).edgeindex ) {
		return false;
	}
	( *aasworld ).edgeindexsize = length / sizeof( aas_edgeindex_t );
	//faces
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_FACES].fileofs );
	length = LittleLong( header.lumps[AASLUMP_FACES].filelen );
	( *aasworld ).faces = (aas_face_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).faces );
	if ( !( *aasworld ).faces ) {
		return false;
	}
	( *aasworld ).numfaces = length / sizeof( aas_face_t );
	//faceindex
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_FACEINDEX].fileofs );
	length = LittleLong( header.lumps[AASLUMP_FACEINDEX].filelen );
	( *aasworld ).faceindex = (aas_faceindex_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).faceindex );
	if ( !( *aasworld ).faceindex ) {
		return false;
	}
	( *aasworld ).faceindexsize = length / sizeof( int );
	//convex areas
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_AREAS].fileofs );
	length = LittleLong( header.lumps[AASLUMP_AREAS].filelen );
	( *aasworld ).areas = (aas_area_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).areas );
	if ( !( *aasworld ).areas ) {
		return false;
	}
	( *aasworld ).numareas = length / sizeof( aas_area_t );
	//area settings
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_AREASETTINGS].fileofs );
	length = LittleLong( header.lumps[AASLUMP_AREASETTINGS].filelen );
	( *aasworld ).areasettings = (aas_areasettings_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).areasettings );
	if ( !( *aasworld ).areasettings ) {
		return false;
	}
	( *aasworld ).numareasettings = length / sizeof( aas_areasettings_t );
	//reachability list
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_REACHABILITY].fileofs );
	length = LittleLong( header.lumps[AASLUMP_REACHABILITY].filelen );
	( *aasworld ).reachability = (aas_reachability_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).reachability );
	if ( length && !( *aasworld ).reachability ) {
		return false;
	}
	( *aasworld ).reachabilitysize = length / sizeof( aas_reachability_t );
	//nodes
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_NODES].fileofs );
	length = LittleLong( header.lumps[AASLUMP_NODES].filelen );
	( *aasworld ).nodes = (aas_node_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).nodes );
	if ( !( *aasworld ).nodes ) {
		return false;
	}
	( *aasworld ).numnodes = length / sizeof( aas_node_t );
	//cluster portals
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_PORTALS].fileofs );
	length = LittleLong( header.lumps[AASLUMP_PORTALS].filelen );
	( *aasworld ).portals = (aas_portal_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).portals );
	if ( length && !( *aasworld ).portals ) {
		return false;
	}
	( *aasworld ).numportals = length / sizeof( aas_portal_t );
	//cluster portal index
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_PORTALINDEX].fileofs );
	length = LittleLong( header.lumps[AASLUMP_PORTALINDEX].filelen );
	( *aasworld ).portalindex = (aas_portalindex_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).portalindex );
	if ( length && !( *aasworld ).portalindex ) {
		return false;
	}
	( *aasworld ).portalindexsize = length / sizeof( aas_portalindex_t );
	//clusters
	offset = fpoffset + LittleLong( header.lumps[AASLUMP_CLUSTERS].fileofs );
	length = LittleLong( header.lumps[AASLUMP_CLUSTERS].filelen );
	( *aasworld ).clusters = (aas_cluster_t *) AAS_LoadAASLump( fp, offset, length, ( *aasworld ).clusters );
	if ( length && !( *aasworld ).clusters ) {
		return false;
	}
	( *aasworld ).numclusters = length / sizeof( aas_cluster_t );
	//swap everything
	AAS_SwapAASData();
	//aas file is loaded
	( *aasworld ).loaded = true;
	//close the file
	fclose( fp );
	return true;
} //end of the function AAS_LoadAASFile