#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "l_libvar.h"
#include "l_utils.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_aas_def.h"
Include dependency graph for be_aas_file.c:

Go to the source code of this file.
Functions | |
| void | AAS_DData (unsigned char *data, int size) |
| void | AAS_DumpAASData (void) |
| int | AAS_LoadAASFile (char *filename) |
| char * | AAS_LoadAASLump (fileHandle_t fp, int offset, int length, int *lastoffset, int size) |
| void | AAS_SwapAASData (void) |
| qboolean | AAS_WriteAASFile (char *filename) |
| int | AAS_WriteAASLump (fileHandle_t fp, aas_header_t *h, int lumpnum, void *data, int length) |
Variables | |
| int | AAS_WriteAASLump_offset |
|
||||||||||||
|
Definition at line 327 of file be_aas_file.c. 00328 {
00329 int i;
00330
00331 for (i = 0; i < size; i++)
00332 {
00333 data[i] ^= (unsigned char) i * 119;
00334 } //end for
00335 } //end of the function AAS_DData
|
|
Here is the call graph for this function:

|
|
Definition at line 343 of file be_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, atoi, aas_s::bboxes, botimport, aas_s::bspchecksum, aas_s::clusters, aas_s::edgeindex, aas_s::edgeindexsize, aas_s::edges, aas_s::faceindex, aas_s::faceindexsize, aas_s::faces, fileHandle_t, lump_t::filelen, lump_t::fileofs, fp, botlib_import_s::FS_FCloseFile, botlib_import_s::FS_FOpenFile, botlib_import_s::FS_Read, FS_READ, header, dheader_t::ident, length(), LibVarGetString(), 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, PRT_MESSAGE, aas_s::reachability, aas_s::reachabilitysize, dheader_t::version, and aas_s::vertexes. 00344 {
00345 fileHandle_t fp;
00346 aas_header_t header;
00347 int offset, length, lastoffset;
00348
00349 botimport.Print(PRT_MESSAGE, "trying to load %s\n", filename);
00350 //dump current loaded aas file
00351 AAS_DumpAASData();
00352 //open the file
00353 botimport.FS_FOpenFile( filename, &fp, FS_READ );
00354 if (!fp)
00355 {
00356 AAS_Error("can't open %s\n", filename);
00357 return BLERR_CANNOTOPENAASFILE;
00358 } //end if
00359 //read the header
00360 botimport.FS_Read(&header, sizeof(aas_header_t), fp );
00361 lastoffset = sizeof(aas_header_t);
00362 //check header identification
00363 header.ident = LittleLong(header.ident);
00364 if (header.ident != AASID)
00365 {
00366 AAS_Error("%s is not an AAS file\n", filename);
00367 botimport.FS_FCloseFile(fp);
00368 return BLERR_WRONGAASFILEID;
00369 } //end if
00370 //check the version
00371 header.version = LittleLong(header.version);
00372 //
00373 if (header.version != AASVERSION_OLD && header.version != AASVERSION)
00374 {
00375 AAS_Error("aas file %s is version %i, not %i\n", filename, header.version, AASVERSION);
00376 botimport.FS_FCloseFile(fp);
00377 return BLERR_WRONGAASFILEVERSION;
00378 } //end if
00379 //
00380 if (header.version == AASVERSION)
00381 {
00382 AAS_DData((unsigned char *) &header + 8, sizeof(aas_header_t) - 8);
00383 } //end if
00384 //
00385 aasworld.bspchecksum = atoi(LibVarGetString( "sv_mapChecksum"));
00386 if (LittleLong(header.bspchecksum) != aasworld.bspchecksum)
00387 {
00388 AAS_Error("aas file %s is out of date\n", filename);
00389 botimport.FS_FCloseFile(fp);
00390 return BLERR_WRONGAASFILEVERSION;
00391 } //end if
00392 //load the lumps:
00393 //bounding boxes
00394 offset = LittleLong(header.lumps[AASLUMP_BBOXES].fileofs);
00395 length = LittleLong(header.lumps[AASLUMP_BBOXES].filelen);
00396 aasworld.bboxes = (aas_bbox_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_bbox_t));
00397 aasworld.numbboxes = length / sizeof(aas_bbox_t);
00398 if (aasworld.numbboxes && !aasworld.bboxes) return BLERR_CANNOTREADAASLUMP;
00399 //vertexes
00400 offset = LittleLong(header.lumps[AASLUMP_VERTEXES].fileofs);
00401 length = LittleLong(header.lumps[AASLUMP_VERTEXES].filelen);
00402 aasworld.vertexes = (aas_vertex_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_vertex_t));
00403 aasworld.numvertexes = length / sizeof(aas_vertex_t);
00404 if (aasworld.numvertexes && !aasworld.vertexes) return BLERR_CANNOTREADAASLUMP;
00405 //planes
00406 offset = LittleLong(header.lumps[AASLUMP_PLANES].fileofs);
00407 length = LittleLong(header.lumps[AASLUMP_PLANES].filelen);
00408 aasworld.planes = (aas_plane_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_plane_t));
00409 aasworld.numplanes = length / sizeof(aas_plane_t);
00410 if (aasworld.numplanes && !aasworld.planes) return BLERR_CANNOTREADAASLUMP;
00411 //edges
00412 offset = LittleLong(header.lumps[AASLUMP_EDGES].fileofs);
00413 length = LittleLong(header.lumps[AASLUMP_EDGES].filelen);
00414 aasworld.edges = (aas_edge_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_edge_t));
00415 aasworld.numedges = length / sizeof(aas_edge_t);
00416 if (aasworld.numedges && !aasworld.edges) return BLERR_CANNOTREADAASLUMP;
00417 //edgeindex
00418 offset = LittleLong(header.lumps[AASLUMP_EDGEINDEX].fileofs);
00419 length = LittleLong(header.lumps[AASLUMP_EDGEINDEX].filelen);
00420 aasworld.edgeindex = (aas_edgeindex_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_edgeindex_t));
00421 aasworld.edgeindexsize = length / sizeof(aas_edgeindex_t);
00422 if (aasworld.edgeindexsize && !aasworld.edgeindex) return BLERR_CANNOTREADAASLUMP;
00423 //faces
00424 offset = LittleLong(header.lumps[AASLUMP_FACES].fileofs);
00425 length = LittleLong(header.lumps[AASLUMP_FACES].filelen);
00426 aasworld.faces = (aas_face_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_face_t));
00427 aasworld.numfaces = length / sizeof(aas_face_t);
00428 if (aasworld.numfaces && !aasworld.faces) return BLERR_CANNOTREADAASLUMP;
00429 //faceindex
00430 offset = LittleLong(header.lumps[AASLUMP_FACEINDEX].fileofs);
00431 length = LittleLong(header.lumps[AASLUMP_FACEINDEX].filelen);
00432 aasworld.faceindex = (aas_faceindex_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_faceindex_t));
00433 aasworld.faceindexsize = length / sizeof(aas_faceindex_t);
00434 if (aasworld.faceindexsize && !aasworld.faceindex) return BLERR_CANNOTREADAASLUMP;
00435 //convex areas
00436 offset = LittleLong(header.lumps[AASLUMP_AREAS].fileofs);
00437 length = LittleLong(header.lumps[AASLUMP_AREAS].filelen);
00438 aasworld.areas = (aas_area_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_area_t));
00439 aasworld.numareas = length / sizeof(aas_area_t);
00440 if (aasworld.numareas && !aasworld.areas) return BLERR_CANNOTREADAASLUMP;
00441 //area settings
00442 offset = LittleLong(header.lumps[AASLUMP_AREASETTINGS].fileofs);
00443 length = LittleLong(header.lumps[AASLUMP_AREASETTINGS].filelen);
00444 aasworld.areasettings = (aas_areasettings_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_areasettings_t));
00445 aasworld.numareasettings = length / sizeof(aas_areasettings_t);
00446 if (aasworld.numareasettings && !aasworld.areasettings) return BLERR_CANNOTREADAASLUMP;
00447 //reachability list
00448 offset = LittleLong(header.lumps[AASLUMP_REACHABILITY].fileofs);
00449 length = LittleLong(header.lumps[AASLUMP_REACHABILITY].filelen);
00450 aasworld.reachability = (aas_reachability_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_reachability_t));
00451 aasworld.reachabilitysize = length / sizeof(aas_reachability_t);
00452 if (aasworld.reachabilitysize && !aasworld.reachability) return BLERR_CANNOTREADAASLUMP;
00453 //nodes
00454 offset = LittleLong(header.lumps[AASLUMP_NODES].fileofs);
00455 length = LittleLong(header.lumps[AASLUMP_NODES].filelen);
00456 aasworld.nodes = (aas_node_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_node_t));
00457 aasworld.numnodes = length / sizeof(aas_node_t);
00458 if (aasworld.numnodes && !aasworld.nodes) return BLERR_CANNOTREADAASLUMP;
00459 //cluster portals
00460 offset = LittleLong(header.lumps[AASLUMP_PORTALS].fileofs);
00461 length = LittleLong(header.lumps[AASLUMP_PORTALS].filelen);
00462 aasworld.portals = (aas_portal_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_portal_t));
00463 aasworld.numportals = length / sizeof(aas_portal_t);
00464 if (aasworld.numportals && !aasworld.portals) return BLERR_CANNOTREADAASLUMP;
00465 //cluster portal index
00466 offset = LittleLong(header.lumps[AASLUMP_PORTALINDEX].fileofs);
00467 length = LittleLong(header.lumps[AASLUMP_PORTALINDEX].filelen);
00468 aasworld.portalindex = (aas_portalindex_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_portalindex_t));
00469 aasworld.portalindexsize = length / sizeof(aas_portalindex_t);
00470 if (aasworld.portalindexsize && !aasworld.portalindex) return BLERR_CANNOTREADAASLUMP;
00471 //clusters
00472 offset = LittleLong(header.lumps[AASLUMP_CLUSTERS].fileofs);
00473 length = LittleLong(header.lumps[AASLUMP_CLUSTERS].filelen);
00474 aasworld.clusters = (aas_cluster_t *) AAS_LoadAASLump(fp, offset, length, &lastoffset, sizeof(aas_cluster_t));
00475 aasworld.numclusters = length / sizeof(aas_cluster_t);
00476 if (aasworld.numclusters && !aasworld.clusters) return BLERR_CANNOTREADAASLUMP;
00477 //swap everything
00478 AAS_SwapAASData();
00479 //aas file is loaded
00480 aasworld.loaded = qtrue;
00481 //close the file
00482 botimport.FS_FCloseFile(fp);
00483 //
00484 #ifdef AASFILEDEBUG
00485 AAS_FileInfo();
00486 #endif //AASFILEDEBUG
00487 //
00488 return BLERR_NOERROR;
00489 } //end of the function AAS_LoadAASFile
|
Here is the call graph for this function:

|
||||||||||||||||||||||||
|
Definition at line 290 of file be_aas_file.c. References AAS_DumpAASData(), AAS_Error, botimport, fp, botlib_import_s::FS_FCloseFile, botlib_import_s::FS_Read, botlib_import_s::FS_Seek, FS_SEEK_SET, GetClearedHunkMemory(), length(), offset, and PRT_WARNING. 00291 {
00292 char *buf;
00293 //
00294 if (!length)
00295 {
00296 //just alloc a dummy
00297 return (char *) GetClearedHunkMemory(size+1);
00298 } //end if
00299 //seek to the data
00300 if (offset != *lastoffset)
00301 {
00302 botimport.Print(PRT_WARNING, "AAS file not sequentially read\n");
00303 if (botimport.FS_Seek(fp, offset, FS_SEEK_SET))
00304 {
00305 AAS_Error("can't seek to aas lump\n");
00306 AAS_DumpAASData();
00307 botimport.FS_FCloseFile(fp);
00308 return 0;
00309 } //end if
00310 } //end if
00311 //allocate memory
00312 buf = (char *) GetClearedHunkMemory(length+1);
00313 //read the data
00314 if (length)
00315 {
00316 botimport.FS_Read(buf, length, fp );
00317 *lastoffset += length;
00318 } //end if
00319 return buf;
00320 } //end of the function AAS_LoadAASLump
|
Here is the call graph for this function:

|
Here is the call graph for this function:

|
|
Definition at line 523 of file be_aas_file.c. 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
|
|
||||||||||||||||||||||||
|
Definition at line 498 of file be_aas_file.c. References aas_header_t, AAS_WriteAASLump_offset, botimport, data, aas_lump_t::filelen, aas_lump_t::fileofs, fp, botlib_import_s::FS_Write, h(), length(), LittleLong(), and aas_header_s::lumps. 00499 {
00500 aas_lump_t *lump;
00501
00502 lump = &h->lumps[lumpnum];
00503
00504 lump->fileofs = LittleLong(AAS_WriteAASLump_offset); //LittleLong(ftell(fp));
00505 lump->filelen = LittleLong(length);
00506
00507 if (length > 0)
00508 {
00509 botimport.FS_Write(data, length, fp );
00510 } //end if
00511
00512 AAS_WriteAASLump_offset += length;
00513
00514 return qtrue;
00515 } //end of the function AAS_WriteAASLump
|
Here is the call graph for this function:

|
|
Definition at line 496 of file be_aas_file.c. Referenced by AAS_WriteAASFile(), and AAS_WriteAASLump(). |
1.3.9.1