?? aas_file.c
字號:
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_OLD && 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
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_WriteAASLump(FILE *fp, aas_header_t *h, int lumpnum, void *data, int length)
{
aas_lump_t *lump;
lump = &h->lumps[lumpnum];
lump->fileofs = LittleLong(ftell(fp));
lump->filelen = LittleLong(length);
if (length > 0)
{
if (fwrite(data, length, 1, fp) < 1)
{
Log_Print("error writing lump %s\n", lumpnum);
fclose(fp);
return false;
} //end if
} //end if
return true;
} //end of the function AAS_WriteAASLump
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ShowNumReachabilities(int tt, char *name)
{
int i, num;
num = 0;
for (i = 0; i < aasworld.reachabilitysize; i++)
{
if ((aasworld.reachability[i].traveltype & TRAVELTYPE_MASK) == tt)
num++;
} //end for
Log_Print("%6d %s\n", num, name);
} //end of the function AAS_ShowNumReachabilities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ShowTotals(void)
{
Log_Print("numvertexes = %d\r\n", aasworld.numvertexes);
Log_Print("numplanes = %d\r\n", aasworld.numplanes);
Log_Print("numedges = %d\r\n", aasworld.numedges);
Log_Print("edgeindexsize = %d\r\n", aasworld.edgeindexsize);
Log_Print("numfaces = %d\r\n", aasworld.numfaces);
Log_Print("faceindexsize = %d\r\n", aasworld.faceindexsize);
Log_Print("numareas = %d\r\n", aasworld.numareas);
Log_Print("numareasettings = %d\r\n", aasworld.numareasettings);
Log_Print("reachabilitysize = %d\r\n", aasworld.reachabilitysize);
Log_Print("numnodes = %d\r\n", aasworld.numnodes);
Log_Print("numportals = %d\r\n", aasworld.numportals);
Log_Print("portalindexsize = %d\r\n", aasworld.portalindexsize);
Log_Print("numclusters = %d\r\n", aasworld.numclusters);
AAS_ShowNumReachabilities(TRAVEL_WALK, "walk");
AAS_ShowNumReachabilities(TRAVEL_CROUCH, "crouch");
AAS_ShowNumReachabilities(TRAVEL_BARRIERJUMP, "barrier jump");
AAS_ShowNumReachabilities(TRAVEL_JUMP, "jump");
AAS_ShowNumReachabilities(TRAVEL_LADDER, "ladder");
AAS_ShowNumReachabilities(TRAVEL_WALKOFFLEDGE, "walk off ledge");
AAS_ShowNumReachabilities(TRAVEL_SWIM, "swim");
AAS_ShowNumReachabilities(TRAVEL_WATERJUMP, "water jump");
AAS_ShowNumReachabilities(TRAVEL_TELEPORT, "teleport");
AAS_ShowNumReachabilities(TRAVEL_ELEVATOR, "elevator");
AAS_ShowNumReachabilities(TRAVEL_ROCKETJUMP, "rocket jump");
AAS_ShowNumReachabilities(TRAVEL_BFGJUMP, "bfg jump");
AAS_ShowNumReachabilities(TRAVEL_GRAPPLEHOOK, "grapple hook");
AAS_ShowNumReachabilities(TRAVEL_DOUBLEJUMP, "double jump");
AAS_ShowNumReachabilities(TRAVEL_RAMPJUMP, "ramp jump");
AAS_ShowNumReachabilities(TRAVEL_STRAFEJUMP, "strafe jump");
AAS_ShowNumReachabilities(TRAVEL_JUMPPAD, "jump pad");
AAS_ShowNumReachabilities(TRAVEL_FUNCBOB, "func bob");
} //end of the function AAS_ShowTotals
//===========================================================================
// aas data is useless after writing to file because it is byte swapped
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
qboolean AAS_WriteAASFile(char *filename)
{
aas_header_t header;
FILE *fp;
Log_Print("writing %s\n", filename);
AAS_ShowTotals();
//swap the aas data
AAS_SwapAASData();
//initialize the file header
memset(&header, 0, sizeof(aas_header_t));
header.ident = LittleLong(AASID);
header.version = LittleLong(AASVERSION);
header.bspchecksum = LittleLong(aasworld.bspchecksum);
//open a new file
fp = fopen(filename, "wb");
if (!fp)
{
Log_Print("error opening %s\n", filename);
return false;
} //end if
//write the header
if (fwrite(&header, sizeof(aas_header_t), 1, fp) < 1)
{
fclose(fp);
return false;
} //end if
//add the data lumps to the file
if (!AAS_WriteAASLump(fp, &header, AASLUMP_BBOXES, aasworld.bboxes,
aasworld.numbboxes * sizeof(aas_bbox_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_VERTEXES, aasworld.vertexes,
aasworld.numvertexes * sizeof(aas_vertex_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_PLANES, aasworld.planes,
aasworld.numplanes * sizeof(aas_plane_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_EDGES, aasworld.edges,
aasworld.numedges * sizeof(aas_edge_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_EDGEINDEX, aasworld.edgeindex,
aasworld.edgeindexsize * sizeof(aas_edgeindex_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_FACES, aasworld.faces,
aasworld.numfaces * sizeof(aas_face_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_FACEINDEX, aasworld.faceindex,
aasworld.faceindexsize * sizeof(aas_faceindex_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_AREAS, aasworld.areas,
aasworld.numareas * sizeof(aas_area_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_AREASETTINGS, aasworld.areasettings,
aasworld.numareasettings * sizeof(aas_areasettings_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_REACHABILITY, aasworld.reachability,
aasworld.reachabilitysize * sizeof(aas_reachability_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_NODES, aasworld.nodes,
aasworld.numnodes * sizeof(aas_node_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_PORTALS, aasworld.portals,
aasworld.numportals * sizeof(aas_portal_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_PORTALINDEX, aasworld.portalindex,
aasworld.portalindexsize * sizeof(aas_portalindex_t))) return false;
if (!AAS_WriteAASLump(fp, &header, AASLUMP_CLUSTERS, aasworld.clusters,
aasworld.numclusters * sizeof(aas_cluster_t))) return false;
//rewrite the header with the added lumps
fseek(fp, 0, SEEK_SET);
AAS_DData((unsigned char *) &header + 8, sizeof(aas_header_t) - 8);
if (fwrite(&header, sizeof(aas_header_t), 1, fp) < 1)
{
fclose(fp);
return false;
} //end if
//close the file
fclose(fp);
return true;
} //end of the function AAS_WriteAASFile
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -