#include "qbsp.h"
#include "../botlib/aasfile.h"
#include "aas_file.h"
#include "aas_store.h"
#include "aas_create.h"
#include "aas_cfg.h"
Include dependency graph for aas_store.c:

Go to the source code of this file.
Data Structures | |
| struct | max_aas_s |
Defines | |
| #define | DIST_EPSILON 0.05 |
| #define | EDGE_HASH_SIZE 1024 |
| #define | EDGE_HASHING |
| #define | INTEGRAL_EPSILON 0.01 |
| #define | NORMAL_EPSILON 0.0001 |
| #define | PLANE_HASH_SIZE 1024 |
| #define | PLANE_HASHING |
| #define | STOREPLANESDOUBLE |
| #define | VERTEX_EPSILON 0.1 |
| #define | VERTEX_HASH_SHIFT 7 |
| #define | VERTEX_HASH_SIZE ((MAX_MAP_BOUNDS>>(VERTEX_HASH_SHIFT-1))+1) |
| #define | VERTEX_HASHING |
Typedefs | |
| typedef max_aas_s | max_aas_t |
Functions | |
| void | AAS_AddEdgeToHash (int edgenum) |
| void | AAS_AddPlaneToHash (int planenum) |
| void | AAS_AllocMaxAAS (void) |
| int | AAS_CountTmpNodes (tmp_node_t *tmpnode) |
| qboolean | AAS_FindHashedEdge (int v1num, int v2num, int *edgenum) |
| qboolean | AAS_FindHashedPlane (vec3_t normal, float dist, int *planenum) |
| qboolean | AAS_FindPlane (vec3_t normal, float dist, int *planenum) |
| void | AAS_FreeMaxAAS (void) |
| qboolean | AAS_GetEdge (vec3_t v1, vec3_t v2, int *edgenum) |
| qboolean | AAS_GetFace (winding_t *w, plane_t *p, int side, int *facenum) |
| qboolean | AAS_GetPlane (vec3_t normal, vec_t dist, int *planenum) |
| qboolean | AAS_GetVertex (vec3_t v, int *vnum) |
| unsigned | AAS_HashEdge (int v1, int v2) |
| unsigned | AAS_HashVec (vec3_t vec) |
| void | AAS_InitMaxAAS (void) |
| int | AAS_PlaneEqual (vec3_t normal, float dist, int planenum) |
| int | AAS_PlaneTypeForNormal (vec3_t normal) |
| int | AAS_StoreArea (tmp_area_t *tmparea) |
| void | AAS_StoreAreaSettings (tmp_areasettings_t *tmpareasettings) |
| void | AAS_StoreBoundingBoxes (void) |
| void | AAS_StoreFile (char *filename) |
| int | AAS_StoreTree_r (tmp_node_t *tmpnode) |
Variables | |
| int * | aas_edgechain |
| int | aas_hashedges [EDGE_HASH_SIZE] |
| int | aas_hashplanes [PLANE_HASH_SIZE] |
| int | aas_hashverts [VERTEX_HASH_SIZE *VERTEX_HASH_SIZE] |
| int * | aas_planechain |
| int * | aas_vertexchain |
| aas_t | aasworld |
| int | allocatedaasmem = 0 |
| int | groundfacesonly = false |
| max_aas_t | max_aas |
|
|
Definition at line 36 of file aas_store.c. Referenced by AAS_PlaneEqual(). |
|
|
Definition at line 48 of file aas_store.c. Referenced by AAS_HashEdge(). |
|
|
Definition at line 47 of file aas_store.c. |
|
|
Definition at line 38 of file aas_store.c. |
|
|
Definition at line 37 of file aas_store.c. Referenced by AAS_PlaneEqual(), CM_PlaneEqual(), Plane_Equal(), PlaneEqual(), and TH_PlaneEqual(). |
|
|
Definition at line 45 of file aas_store.c. Referenced by AAS_AddPlaneToHash(), and AAS_FindHashedPlane(). |
|
|
Definition at line 44 of file aas_store.c. |
|
|
Definition at line 33 of file aas_store.c. |
|
|
Definition at line 35 of file aas_store.c. Referenced by AAS_GetVertex(), and TH_FindVertex(). |
|
|
Definition at line 41 of file aas_store.c. |
|
|
Definition at line 42 of file aas_store.c. Referenced by AAS_AllocMaxAAS(), and AAS_HashVec(). |
|
|
Definition at line 40 of file aas_store.c. |
|
|
|
|
|
Definition at line 433 of file aas_store.c. References aas_edge_t, aas_edgechain, AAS_HashEdge(), aas_hashedges, aasworld, aas_s::edges, and aas_edge_s::v. Referenced by AAS_GetEdge(). 00434 {
00435 int hash;
00436 aas_edge_t *edge;
00437
00438 edge = &aasworld.edges[edgenum];
00439
00440 hash = AAS_HashEdge(edge->v[0], edge->v[1]);
00441
00442 aas_edgechain[edgenum] = aas_hashedges[hash];
00443 aas_hashedges[hash] = edgenum;
00444 } //end of the function AAS_AddEdgeToHash
|
Here is the call graph for this function:

|
|
Definition at line 586 of file aas_store.c. References aas_hashplanes, aas_plane_t, aas_planechain, aasworld, aas_plane_s::dist, fabs(), PLANE_HASH_SIZE, and aas_s::planes. Referenced by AAS_GetPlane(). 00587 {
00588 int hash;
00589 aas_plane_t *plane;
00590
00591 plane = &aasworld.planes[planenum];
00592
00593 hash = (int)fabs(plane->dist) / 8;
00594 hash &= (PLANE_HASH_SIZE-1);
00595
00596 aas_planechain[planenum] = aas_hashplanes[hash];
00597 aas_hashplanes[hash] = planenum;
00598 } //end of the function AAS_AddPlaneToHash
|
Here is the call graph for this function:

|
Here is the call graph for this function:

|
|
Definition at line 92 of file aas_store.c. References tmp_node_s::children, and tmp_node_t. Referenced by AAS_InitMaxAAS(). 00093 {
00094 if (!tmpnode) return 0;
00095 return AAS_CountTmpNodes(tmpnode->children[0]) +
00096 AAS_CountTmpNodes(tmpnode->children[1]) + 1;
00097 } //end of the function AAS_CountTmpNodes
|
|
||||||||||||||||
|
Definition at line 451 of file aas_store.c. References aas_edge_t, aas_edgechain, AAS_HashEdge(), aas_hashedges, aasworld, e, aas_s::edges, qboolean, and aas_edge_s::v. Referenced by AAS_GetEdge(). 00452 {
00453 int e, hash;
00454 aas_edge_t *edge;
00455
00456 hash = AAS_HashEdge(v1num, v2num);
00457 for (e = aas_hashedges[hash]; e >= 0; e = aas_edgechain[e])
00458 {
00459 edge = &aasworld.edges[e];
00460 if (edge->v[0] == v1num)
00461 {
00462 if (edge->v[1] == v2num)
00463 {
00464 *edgenum = e;
00465 return true;
00466 } //end if
00467 } //end if
00468 else if (edge->v[1] == v1num)
00469 {
00470 if (edge->v[0] == v2num)
00471 {
00472 //negative for a reversed edge
00473 *edgenum = -e;
00474 return true;
00475 } //end if
00476 } //end else
00477 } //end for
00478 return false;
00479 } //end of the function AAS_FindHashedPlane
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 654 of file aas_store.c. References aas_hashplanes, aas_plane_t, aas_planechain, AAS_PlaneEqual(), aasworld, fabs(), h(), i, p, PLANE_HASH_SIZE, aas_s::planes, and qboolean. Referenced by AAS_GetPlane(). 00655 {
00656 int i, p;
00657 aas_plane_t *plane;
00658 int hash, h;
00659
00660 hash = (int)fabs(dist) / 8;
00661 hash &= (PLANE_HASH_SIZE-1);
00662
00663 //search the border bins as well
00664 for (i = -1; i <= 1; i++)
00665 {
00666 h = (hash+i)&(PLANE_HASH_SIZE-1);
00667 for (p = aas_hashplanes[h]; p >= 0; p = aas_planechain[p])
00668 {
00669 plane = &aasworld.planes[p];
00670 if (AAS_PlaneEqual(normal, dist, p))
00671 {
00672 *planenum = p;
00673 return true;
00674 } //end if
00675 } //end for
00676 } //end for
00677 return false;
00678 } //end of the function AAS_FindHashedPlane
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 634 of file aas_store.c. References AAS_PlaneEqual(), aasworld, i, aas_s::numplanes, and qboolean. 00635 {
00636 int i;
00637
00638 for (i = 0; i < aasworld.numplanes; i++)
00639 {
00640 if (AAS_PlaneEqual(normal, dist, i))
00641 {
00642 *planenum = i;
00643 return true;
00644 } //end if
00645 } //end for
00646 return false;
00647 } //end of the function AAS_FindPlane
|
Here is the call graph for this function:

|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 490 of file aas_store.c. References AAS_AddEdgeToHash(), AAS_FindHashedEdge(), AAS_GetVertex(), aasworld, aas_s::edges, Error(), i, max_aas, max_aas_s::max_edges, aas_s::numedges, qboolean, aas_edge_s::v, v1, and v2. Referenced by AAS_GetFace(). 00491 {
00492 int v1num, v2num;
00493 qboolean found;
00494
00495 //the first edge is a dummy
00496 if (aasworld.numedges == 0) aasworld.numedges = 1;
00497
00498 found = AAS_GetVertex(v1, &v1num);
00499 found &= AAS_GetVertex(v2, &v2num);
00500 //if one of the vertexes was outside the valid range
00501 if (v1num == -1 || v2num == -1)
00502 {
00503 *edgenum = 0;
00504 return true;
00505 } //end if
00506 //if both vertexes are the same or snapped onto each other
00507 if (v1num == v2num)
00508 {
00509 *edgenum = 0;
00510 return true;
00511 } //end if
00512 //if both vertexes where already stored
00513 if (found)
00514 {
00515 #ifdef EDGE_HASHING
00516 if (AAS_FindHashedEdge(v1num, v2num, edgenum)) return true;
00517 #else
00518 int i;
00519 for (i = 1; i < aasworld.numedges; i++)
00520 {
00521 if (aasworld.edges[i].v[0] == v1num)
00522 {
00523 if (aasworld.edges[i].v[1] == v2num)
00524 {
00525 *edgenum = i;
00526 return true;
00527 } //end if
00528 } //end if
00529 else if (aasworld.edges[i].v[1] == v1num)
00530 {
00531 if (aasworld.edges[i].v[0] == v2num)
00532 {
00533 //negative for a reversed edge
00534 *edgenum = -i;
00535 return true;
00536 } //end if
00537 } //end else
00538 } //end for
00539 #endif //EDGE_HASHING
00540 } //end if
00541 if (aasworld.numedges >= max_aas.max_edges)
00542 {
00543 Error("AAS_MAX_EDGES = %d", max_aas.max_edges);
00544 } //end if
00545 aasworld.edges[aasworld.numedges].v[0] = v1num;
00546 aasworld.edges[aasworld.numedges].v[1] = v2num;
00547 *edgenum = aasworld.numedges;
00548 #ifdef EDGE_HASHING
00549 AAS_AddEdgeToHash(*edgenum);
00550 #endif //EDGE_HASHING
00551 aasworld.numedges++;
00552 return false;
00553 } //end of the function AAS_GetEdge
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 746 of file aas_store.c. References aas_face_t, AAS_GetEdge(), AAS_GetPlane(), aasworld, aas_face_s::backarea, plane_t::dist, aas_s::edgeindex, aas_s::edgeindexsize, Error(), aas_face_s::faceflags, aas_s::faces, aas_face_s::firstedge, aas_face_s::frontarea, i, j, Log_Write(), max_aas, max_aas_s::max_edgeindexsize, max_aas_s::max_faces, memset(), plane_t::normal, aas_face_s::numedges, aas_s::numfaces, winding_t::numpoints, winding_t::p, p, aas_face_s::planenum, qboolean, and w. Referenced by AAS_StoreArea(). 00747 {
00748 int edgenum, i, j;
00749 aas_face_t *face;
00750
00751 //face zero is a dummy, because of the face index with negative numbers
00752 if (aasworld.numfaces == 0) aasworld.numfaces = 1;
00753
00754 if (aasworld.numfaces >= max_aas.max_faces)
00755 {
00756 Error("AAS_MAX_FACES = %d", max_aas.max_faces);
00757 } //end if
00758 face = &aasworld.faces[aasworld.numfaces];
00759 AAS_GetPlane(p->normal, p->dist, &face->planenum);
00760 face->faceflags = 0;
00761 face->firstedge = aasworld.edgeindexsize;
00762 face->frontarea = 0;
00763 face->backarea = 0;
00764 face->numedges = 0;
00765 for (i = 0; i < w->numpoints; i++)
00766 {
00767 if (aasworld.edgeindexsize >= max_aas.max_edgeindexsize)
00768 {
00769 Error("AAS_MAX_EDGEINDEXSIZE = %d", max_aas.max_edgeindexsize);
00770 } //end if
00771 j = (i+1) % w->numpoints;
00772 AAS_GetEdge(w->p[i], w->p[j], &edgenum);
00773 //if the edge wasn't degenerate
00774 if (edgenum)
00775 {
00776 aasworld.edgeindex[aasworld.edgeindexsize++] = edgenum;
00777 face->numedges++;
00778 } //end if
00779 else if (verbose)
00780 {
00781 Log_Write("AAS_GetFace: face %d had degenerate edge %d-%d\r\n",
00782 aasworld.numfaces, i, j);
00783 } //end else
00784 } //end for
00785 if (face->numedges < 1
00786 #ifdef NOTHREEVERTEXFACES
00787 || face->numedges < 3
00788 #endif //NOTHREEVERTEXFACES
00789 )
00790 {
00791 memset(&aasworld.faces[aasworld.numfaces], 0, sizeof(aas_face_t));
00792 Log_Write("AAS_GetFace: face %d was tiny\r\n", aasworld.numfaces);
00793 return false;
00794 } //end if
00795 *facenum = aasworld.numfaces;
00796 aasworld.numfaces++;
00797 return true;
00798 } //end of the function AAS_GetFace
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 685 of file aas_store.c. References AAS_AddPlaneToHash(), AAS_FindHashedPlane(), aas_plane_t, AAS_PlaneTypeForNormal(), aasworld, aas_plane_s::dist, Error(), max_aas, max_aas_s::max_planes, aas_plane_s::normal, aas_s::numplanes, aas_s::planes, PlaneTypeForNormal, qboolean, aas_plane_s::type, VectorCopy, and VectorNegate. Referenced by AAS_GetFace(), and AAS_StoreTree_r(). 00686 {
00687 aas_plane_t *plane, temp;
00688
00689 //if (AAS_FindPlane(normal, dist, planenum)) return true;
00690 if (AAS_FindHashedPlane(normal, dist, planenum)) return true;
00691
00692 if (aasworld.numplanes >= max_aas.max_planes-1)
00693 {
00694 Error("AAS_MAX_PLANES = %d", max_aas.max_planes);
00695 } //end if
00696
00697 #ifdef STOREPLANESDOUBLE
00698 plane = &aasworld.planes[aasworld.numplanes];
00699 VectorCopy(normal, plane->normal);
00700 plane->dist = dist;
00701 plane->type = (plane+1)->type = PlaneTypeForNormal(plane->normal);
00702
00703 VectorCopy(normal, (plane+1)->normal);
00704 VectorNegate((plane+1)->normal, (plane+1)->normal);
00705 (plane+1)->dist = -dist;
00706
00707 aasworld.numplanes += 2;
00708
00709 //allways put axial planes facing positive first
00710 if (plane->type < 3)
00711 {
00712 if (plane->normal[0] < 0 || plane->normal[1] < 0 || plane->normal[2] < 0)
00713 {
00714 // flip order
00715 temp = *plane;
00716 *plane = *(plane+1);
00717 *(plane+1) = temp;
00718 *planenum = aasworld.numplanes - 1;
00719 return false;
00720 } //end if
00721 } //end if
00722 *planenum = aasworld.numplanes - 2;
00723 //add the planes to the hash
00724 AAS_AddPlaneToHash(aasworld.numplanes - 1);
00725 AAS_AddPlaneToHash(aasworld.numplanes - 2);
00726 return false;
00727 #else
00728 plane = &aasworld.planes[aasworld.numplanes];
00729 VectorCopy(normal, plane->normal);
00730 plane->dist = dist;
00731 plane->type = AAS_PlaneTypeForNormal(normal);
00732
00733 *planenum = aasworld.numplanes;
00734 aasworld.numplanes++;
00735 //add the plane to the hash
00736 AAS_AddPlaneToHash(aasworld.numplanes - 1);
00737 return false;
00738 #endif //STOREPLANESDOUBLE
00739 } //end of the function AAS_GetPlane
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 331 of file aas_store.c. References AAS_HashVec(), aas_hashverts, aas_vertexchain, aasworld, Error(), fabs(), h(), i, max_aas, max_aas_s::max_vertexes, aas_s::numvertexes, Q_rint(), qboolean, v, vec3_t, VectorCopy, VERTEX_EPSILON, aas_s::vertexes, and vn. Referenced by AAS_GetEdge(). 00332 {
00333 int i;
00334 #ifndef VERTEX_HASHING
00335 float diff;
00336 #endif //VERTEX_HASHING
00337
00338 #ifdef VERTEX_HASHING
00339 int h, vn;
00340 vec3_t vert;
00341
00342 for (i = 0; i < 3; i++)
00343 {
00344 if ( fabs(v[i] - Q_rint(v[i])) < INTEGRAL_EPSILON)
00345 vert[i] = Q_rint(v[i]);
00346 else
00347 vert[i] = v[i];
00348 } //end for
00349
00350 h = AAS_HashVec(vert);
00351 //if the vertex was outside the valid range
00352 if (h == -1)
00353 {
00354 *vnum = -1;
00355 return true;
00356 } //end if
00357
00358 for (vn = aas_hashverts[h]; vn >= 0; vn = aas_vertexchain[vn])
00359 {
00360 if (fabs(aasworld.vertexes[vn][0] - vert[0]) < VERTEX_EPSILON
00361 && fabs(aasworld.vertexes[vn][1] - vert[1]) < VERTEX_EPSILON
00362 && fabs(aasworld.vertexes[vn][2] - vert[2]) < VERTEX_EPSILON)
00363 {
00364 *vnum |