Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

aas_file.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

qboolean AAS_LoadAASFile (char *filename, int fpoffset, int fplength)
qboolean AAS_WriteAASFile (char *filename)


Function Documentation

qboolean AAS_LoadAASFile char *  filename,
int  fpoffset,
int  fplength
 

Definition at line 246 of file aas_file.c.

References aas_area_t, aas_areasettings_t, aas_bbox_t, aas_cluster_t, AAS_DData(), AAS_DumpAASData(), aas_edge_t, aas_edgeindex_t, AAS_Error, aas_face_t, aas_faceindex_t, aas_header_t, AAS_LoadAASLump(), aas_node_t, aas_plane_t, aas_portal_t, aas_portalindex_t, aas_reachability_t, AAS_SwapAASData(), aas_vertex_t, AASLUMP_AREAS, AASLUMP_AREASETTINGS, AASLUMP_BBOXES, AASLUMP_CLUSTERS, AASLUMP_EDGEINDEX, AASLUMP_EDGES, AASLUMP_FACEINDEX, AASLUMP_FACES, AASLUMP_NODES, AASLUMP_PLANES, AASLUMP_PORTALINDEX, AASLUMP_PORTALS, AASLUMP_REACHABILITY, AASLUMP_VERTEXES, AASVERSION, AASVERSION_OLD, aasworld, aas_s::areas, aas_s::areasettings, aas_s::bboxes, aas_s::bspchecksum, aas_s::clusters, aas_s::edgeindex, aas_s::edgeindexsize, aas_s::edges, aas_s::faceindex, aas_s::faceindexsize, aas_s::faces, fclose(), lump_t::filelen, lump_t::fileofs, fopen(), fp, fread(), fseek(), header, dheader_t::ident, length(), LittleLong(), aas_s::loaded, dheader_t::lumps, aas_s::nodes, aas_s::numareas, aas_s::numareasettings, aas_s::numbboxes, aas_s::numclusters, aas_s::numedges, aas_s::numfaces, aas_s::numnodes, aas_s::numplanes, aas_s::numportals, aas_s::numvertexes, offset, aas_s::planes, aas_s::portalindex, aas_s::portalindexsize, aas_s::portals, qboolean, aas_s::reachability, aas_s::reachabilitysize, SEEK_SET, dheader_t::version, and aas_s::vertexes.

Referenced by AAS_LoadFiles(), main(), and TH_AASToTetrahedrons().

00247 {
00248     FILE *fp;
00249     aas_header_t header;
00250     int offset, length;
00251 
00252     //dump current loaded aas file
00253     AAS_DumpAASData();
00254     //open the file
00255     fp = fopen(filename, "rb");
00256     if (!fp)
00257     {
00258         AAS_Error("can't open %s\n", filename);
00259         return false;
00260     } //end if
00261     //seek to the correct position (in the pak file)
00262     if (fseek(fp, fpoffset, SEEK_SET))
00263     {
00264         AAS_Error("can't seek to file %s\n");
00265         fclose(fp);
00266         return false;
00267     } //end if
00268     //read the header
00269     if (fread(&header, sizeof(aas_header_t), 1, fp) != 1)
00270     {
00271         AAS_Error("can't read header of file %s\n", filename);
00272         fclose(fp);
00273         return false;
00274     } //end if
00275     //check header identification
00276     header.ident = LittleLong(header.ident);
00277     if (header.ident != AASID)
00278     {
00279         AAS_Error("%s is not an AAS file\n", filename);
00280         fclose(fp);
00281         return false;
00282     } //end if
00283     //check the version
00284     header.version = LittleLong(header.version);
00285     if (header.version != AASVERSION_OLD && header.version != AASVERSION)
00286     {
00287         AAS_Error("%s is version %i, not %i\n", filename, header.version, AASVERSION);
00288         fclose(fp);
00289         return false;
00290     } //end if
00291     //
00292     if (header.version == AASVERSION)
00293     {
00294         AAS_DData((unsigned char *) &header + 8, sizeof(aas_header_t) - 8);
00295     } //end if
00296     aasworld.bspchecksum = LittleLong(header.bspchecksum);
00297     //load the lumps:
00298     //bounding boxes
00299     offset = fpoffset + LittleLong(header.lumps[AASLUMP_BBOXES].fileofs);
00300     length = LittleLong(header.lumps[AASLUMP_BBOXES].filelen);
00301     aasworld.bboxes = (aas_bbox_t *) AAS_LoadAASLump(fp, offset, length, aasworld.bboxes);
00302     if (!aasworld.bboxes) return false;
00303     aasworld.numbboxes = length / sizeof(aas_bbox_t);
00304     //vertexes
00305     offset = fpoffset + LittleLong(header.lumps[AASLUMP_VERTEXES].fileofs);
00306     length = LittleLong(header.lumps[AASLUMP_VERTEXES].filelen);
00307     aasworld.vertexes = (aas_vertex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.vertexes);
00308     if (!aasworld.vertexes) return false;
00309     aasworld.numvertexes = length / sizeof(aas_vertex_t);
00310     //planes
00311     offset = fpoffset + LittleLong(header.lumps[AASLUMP_PLANES].fileofs);
00312     length = LittleLong(header.lumps[AASLUMP_PLANES].filelen);
00313     aasworld.planes = (aas_plane_t *) AAS_LoadAASLump(fp, offset, length, aasworld.planes);
00314     if (!aasworld.planes) return false;
00315     aasworld.numplanes = length / sizeof(aas_plane_t);
00316     //edges
00317     offset = fpoffset + LittleLong(header.lumps[AASLUMP_EDGES].fileofs);
00318     length = LittleLong(header.lumps[AASLUMP_EDGES].filelen);
00319     aasworld.edges = (aas_edge_t *) AAS_LoadAASLump(fp, offset, length, aasworld.edges);
00320     if (!aasworld.edges) return false;
00321     aasworld.numedges = length / sizeof(aas_edge_t);
00322     //edgeindex
00323     offset = fpoffset + LittleLong(header.lumps[AASLUMP_EDGEINDEX].fileofs);
00324     length = LittleLong(header.lumps[AASLUMP_EDGEINDEX].filelen);
00325     aasworld.edgeindex = (aas_edgeindex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.edgeindex);
00326     if (!aasworld.edgeindex) return false;
00327     aasworld.edgeindexsize = length / sizeof(aas_edgeindex_t);
00328     //faces
00329     offset = fpoffset + LittleLong(header.lumps[AASLUMP_FACES].fileofs);
00330     length = LittleLong(header.lumps[AASLUMP_FACES].filelen);
00331     aasworld.faces = (aas_face_t *) AAS_LoadAASLump(fp, offset, length, aasworld.faces);
00332     if (!aasworld.faces) return false;
00333     aasworld.numfaces = length / sizeof(aas_face_t);
00334     //faceindex
00335     offset = fpoffset + LittleLong(header.lumps[AASLUMP_FACEINDEX].fileofs);
00336     length = LittleLong(header.lumps[AASLUMP_FACEINDEX].filelen);
00337     aasworld.faceindex = (aas_faceindex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.faceindex);
00338     if (!aasworld.faceindex) return false;
00339     aasworld.faceindexsize = length / sizeof(int);
00340     //convex areas
00341     offset = fpoffset + LittleLong(header.lumps[AASLUMP_AREAS].fileofs);
00342     length = LittleLong(header.lumps[AASLUMP_AREAS].filelen);
00343     aasworld.areas = (aas_area_t *) AAS_LoadAASLump(fp, offset, length, aasworld.areas);
00344     if (!aasworld.areas) return false;
00345     aasworld.numareas = length / sizeof(aas_area_t);
00346     //area settings
00347     offset = fpoffset + LittleLong(header.lumps[AASLUMP_AREASETTINGS].fileofs);
00348     length = LittleLong(header.lumps[AASLUMP_AREASETTINGS].filelen);
00349     aasworld.areasettings = (aas_areasettings_t *) AAS_LoadAASLump(fp, offset, length, aasworld.areasettings);
00350     if (!aasworld.areasettings) return false;
00351     aasworld.numareasettings = length / sizeof(aas_areasettings_t);
00352     //reachability list
00353     offset = fpoffset + LittleLong(header.lumps[AASLUMP_REACHABILITY].fileofs);
00354     length = LittleLong(header.lumps[AASLUMP_REACHABILITY].filelen);
00355     aasworld.reachability = (aas_reachability_t *) AAS_LoadAASLump(fp, offset, length, aasworld.reachability);
00356     if (length && !aasworld.reachability) return false;
00357     aasworld.reachabilitysize = length / sizeof(aas_reachability_t);
00358     //nodes
00359     offset = fpoffset + LittleLong(header.lumps[AASLUMP_NODES].fileofs);
00360     length = LittleLong(header.lumps[AASLUMP_NODES].filelen);
00361     aasworld.nodes = (aas_node_t *) AAS_LoadAASLump(fp, offset, length, aasworld.nodes);
00362     if (!aasworld.nodes) return false;
00363     aasworld.numnodes = length / sizeof(aas_node_t);
00364     //cluster portals
00365     offset = fpoffset + LittleLong(header.lumps[AASLUMP_PORTALS].fileofs);
00366     length = LittleLong(header.lumps[AASLUMP_PORTALS].filelen);
00367     aasworld.portals = (aas_portal_t *) AAS_LoadAASLump(fp, offset, length, aasworld.portals);
00368     if (length && !aasworld.portals) return false;
00369     aasworld.numportals = length / sizeof(aas_portal_t);
00370     //cluster portal index
00371     offset = fpoffset + LittleLong(header.lumps[AASLUMP_PORTALINDEX].fileofs);
00372     length = LittleLong(header.lumps[AASLUMP_PORTALINDEX].filelen);
00373     aasworld.portalindex = (aas_portalindex_t *) AAS_LoadAASLump(fp, offset, length, aasworld.portalindex);
00374     if (length && !aasworld.portalindex) return false;
00375     aasworld.portalindexsize = length / sizeof(aas_portalindex_t);
00376     //clusters
00377     offset = fpoffset + LittleLong(header.lumps[AASLUMP_CLUSTERS].fileofs);
00378     length = LittleLong(header.lumps[AASLUMP_CLUSTERS].filelen);
00379     aasworld.clusters = (aas_cluster_t *) AAS_LoadAASLump(fp, offset, length, aasworld.clusters);
00380     if (length && !aasworld.clusters) return false;
00381     aasworld.numclusters = length / sizeof(aas_cluster_t);
00382     //swap everything
00383     AAS_SwapAASData();
00384     //aas file is loaded
00385     aasworld.loaded = true;
00386     //close the file
00387     fclose(fp);
00388     return true;
00389 } //end of the function AAS_LoadAASFile

Here is the call graph for this function:

qboolean AAS_WriteAASFile char *  filename  ) 
 

Definition at line 523 of file be_aas_file.c.

References aas_area_t, aas_areasettings_t, aas_bbox_t, aas_cluster_t, AAS_DData(), aas_edge_t, aas_edgeindex_t, aas_face_t, aas_faceindex_t, aas_header_t, aas_node_t, aas_plane_t, aas_portal_t, aas_portalindex_t, aas_reachability_t, AAS_ShowTotals(), AAS_SwapAASData(), aas_vertex_t, AAS_WriteAASLump(), AAS_WriteAASLump_offset, AASID, AASLUMP_AREAS, AASLUMP_AREASETTINGS, AASLUMP_BBOXES, AASLUMP_CLUSTERS, AASLUMP_EDGEINDEX, AASLUMP_EDGES, AASLUMP_FACEINDEX, AASLUMP_FACES, AASLUMP_NODES, AASLUMP_PLANES, AASLUMP_PORTALINDEX, AASLUMP_PORTALS, AASLUMP_REACHABILITY, AASLUMP_VERTEXES, AASVERSION, aasworld, aas_s::areas, aas_s::areasettings, aas_s::bboxes, botimport, aas_s::bspchecksum, aas_s::clusters, Com_Memset(), aas_s::edgeindex, aas_s::edgeindexsize, aas_s::edges, aas_s::faceindex, aas_s::faceindexsize, aas_s::faces, fclose(), fileHandle_t, fopen(), fp, botlib_import_s::FS_FCloseFile, botlib_import_s::FS_FOpenFile, botlib_import_s::FS_Seek, FS_SEEK_SET, botlib_import_s::FS_Write, FS_WRITE, fseek(), fwrite(), header, dheader_t::ident, LittleLong(), Log_Print(), memset(), aas_s::nodes, aas_s::numareas, aas_s::numareasettings, aas_s::numbboxes, aas_s::numclusters, aas_s::numedges, aas_s::numfaces, aas_s::numnodes, aas_s::numplanes, aas_s::numportals, aas_s::numvertexes, aas_s::planes, aas_s::portalindex, aas_s::portalindexsize, aas_s::portals, PRT_ERROR, PRT_MESSAGE, qboolean, aas_s::reachability, aas_s::reachabilitysize, SEEK_SET, dheader_t::version, and aas_s::vertexes.

Referenced by AAS_ContinueInit(), and main().

00524 {
00525     aas_header_t header;
00526     fileHandle_t fp;
00527 
00528     botimport.Print(PRT_MESSAGE, "writing %s\n", filename);
00529     //swap the aas data
00530     AAS_SwapAASData();
00531     //initialize the file header
00532     Com_Memset(&header, 0, sizeof(aas_header_t));
00533     header.ident = LittleLong(AASID);
00534     header.version = LittleLong(AASVERSION);
00535     header.bspchecksum = LittleLong(aasworld.bspchecksum);
00536     //open a new file
00537     botimport.FS_FOpenFile( filename, &fp, FS_WRITE );
00538     if (!fp)
00539     {
00540         botimport.Print(PRT_ERROR, "error opening %s\n", filename);
00541         return qfalse;
00542     } //end if
00543     //write the header
00544     botimport.FS_Write(&header, sizeof(aas_header_t), fp);
00545     AAS_WriteAASLump_offset = sizeof(aas_header_t);
00546     //add the data lumps to the file
00547     if (!AAS_WriteAASLump(fp, &header, AASLUMP_BBOXES, aasworld.bboxes,
00548         aasworld.numbboxes * sizeof(aas_bbox_t))) return qfalse;
00549     if (!AAS_WriteAASLump(fp, &header, AASLUMP_VERTEXES, aasworld.vertexes,
00550         aasworld.numvertexes * sizeof(aas_vertex_t))) return qfalse;
00551     if (!AAS_WriteAASLump(fp, &header, AASLUMP_PLANES, aasworld.planes,
00552         aasworld.numplanes * sizeof(aas_plane_t))) return qfalse;
00553     if (!AAS_WriteAASLump(fp, &header, AASLUMP_EDGES, aasworld.edges,
00554         aasworld.numedges * sizeof(aas_edge_t))) return qfalse;
00555     if (!AAS_WriteAASLump(fp, &header, AASLUMP_EDGEINDEX, aasworld.edgeindex,
00556         aasworld.edgeindexsize * sizeof(aas_edgeindex_t))) return qfalse;
00557     if (!AAS_WriteAASLump(fp, &header, AASLUMP_FACES, aasworld.faces,
00558         aasworld.numfaces * sizeof(aas_face_t))) return qfalse;
00559     if (!AAS_WriteAASLump(fp, &header, AASLUMP_FACEINDEX, aasworld.faceindex,
00560         aasworld.faceindexsize * sizeof(aas_faceindex_t))) return qfalse;
00561     if (!AAS_WriteAASLump(fp, &header, AASLUMP_AREAS, aasworld.areas,
00562         aasworld.numareas * sizeof(aas_area_t))) return qfalse;
00563     if (!AAS_WriteAASLump(fp, &header, AASLUMP_AREASETTINGS, aasworld.areasettings,
00564         aasworld.numareasettings * sizeof(aas_areasettings_t))) return qfalse;
00565     if (!AAS_WriteAASLump(fp, &header, AASLUMP_REACHABILITY, aasworld.reachability,
00566         aasworld.reachabilitysize * sizeof(aas_reachability_t))) return qfalse;
00567     if (!AAS_WriteAASLump(fp, &header, AASLUMP_NODES, aasworld.nodes,
00568         aasworld.numnodes * sizeof(aas_node_t))) return qfalse;
00569     if (!AAS_WriteAASLump(fp, &header, AASLUMP_PORTALS, aasworld.portals,
00570         aasworld.numportals * sizeof(aas_portal_t))) return qfalse;
00571     if (!AAS_WriteAASLump(fp, &header, AASLUMP_PORTALINDEX, aasworld.portalindex,
00572         aasworld.portalindexsize * sizeof(aas_portalindex_t))) return qfalse;
00573     if (!AAS_WriteAASLump(fp, &header, AASLUMP_CLUSTERS, aasworld.clusters,
00574         aasworld.numclusters * sizeof(aas_cluster_t))) return qfalse;
00575     //rewrite the header with the added lumps
00576     botimport.FS_Seek(fp, 0, FS_SEEK_SET);
00577     AAS_DData((unsigned char *) &header + 8, sizeof(aas_header_t) - 8);
00578     botimport.FS_Write(&header, sizeof(aas_header_t), fp);
00579     //close the file
00580     botimport.FS_FCloseFile(fp);
00581     return qtrue;
00582 } //end of the function AAS_WriteAASFile

Here is the call graph for this function:


Generated on Thu Aug 25 12:46:16 2005 for Quake III Arena by  doxygen 1.3.9.1