📄 aas_store.c
字号:
//add the planes to the hash
AAS_AddPlaneToHash(aasworld.numplanes - 1);
AAS_AddPlaneToHash(aasworld.numplanes - 2);
return false;
#else
plane = &aasworld.planes[aasworld.numplanes];
VectorCopy(normal, plane->normal);
plane->dist = dist;
plane->type = AAS_PlaneTypeForNormal(normal);
*planenum = aasworld.numplanes;
aasworld.numplanes++;
//add the plane to the hash
AAS_AddPlaneToHash(aasworld.numplanes - 1);
return false;
#endif //STOREPLANESDOUBLE
} //end of the function AAS_GetPlane
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
qboolean AAS_GetFace(winding_t *w, plane_t *p, int side, int *facenum)
{
int edgenum, i, j;
aas_face_t *face;
//face zero is a dummy, because of the face index with negative numbers
if (aasworld.numfaces == 0) aasworld.numfaces = 1;
if (aasworld.numfaces >= max_aas.max_faces)
{
Error("AAS_MAX_FACES = %d", max_aas.max_faces);
} //end if
face = &aasworld.faces[aasworld.numfaces];
AAS_GetPlane(p->normal, p->dist, &face->planenum);
face->faceflags = 0;
face->firstedge = aasworld.edgeindexsize;
face->frontarea = 0;
face->backarea = 0;
face->numedges = 0;
for (i = 0; i < w->numpoints; i++)
{
if (aasworld.edgeindexsize >= max_aas.max_edgeindexsize)
{
Error("AAS_MAX_EDGEINDEXSIZE = %d", max_aas.max_edgeindexsize);
} //end if
j = (i+1) % w->numpoints;
AAS_GetEdge(w->p[i], w->p[j], &edgenum);
//if the edge wasn't degenerate
if (edgenum)
{
aasworld.edgeindex[aasworld.edgeindexsize++] = edgenum;
face->numedges++;
} //end if
else if (verbose)
{
Log_Write("AAS_GetFace: face %d had degenerate edge %d-%d\r\n",
aasworld.numfaces, i, j);
} //end else
} //end for
if (face->numedges < 1
#ifdef NOTHREEVERTEXFACES
|| face->numedges < 3
#endif //NOTHREEVERTEXFACES
)
{
memset(&aasworld.faces[aasworld.numfaces], 0, sizeof(aas_face_t));
Log_Write("AAS_GetFace: face %d was tiny\r\n", aasworld.numfaces);
return false;
} //end if
*facenum = aasworld.numfaces;
aasworld.numfaces++;
return true;
} //end of the function AAS_GetFace
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
/*
qboolean AAS_GetFace(winding_t *w, plane_t *p, int side, int *facenum)
{
aas_edgeindex_t edges[1024];
int planenum, numedges, i;
int j, edgenum;
qboolean foundplane, foundedges;
aas_face_t *face;
//face zero is a dummy, because of the face index with negative numbers
if (aasworld.numfaces == 0) aasworld.numfaces = 1;
foundplane = AAS_GetPlane(p->normal, p->dist, &planenum);
foundedges = true;
numedges = w->numpoints;
for (i = 0; i < w->numpoints; i++)
{
if (i >= 1024) Error("AAS_GetFace: more than %d edges\n", 1024);
foundedges &= AAS_GetEdge(w->p[i], w->p[(i+1 >= w->numpoints ? 0 : i+1)], &edges[i]);
} //end for
//FIXME: use portal number instead of a search
//if the plane and all edges already existed
if (foundplane && foundedges)
{
for (i = 0; i < aasworld.numfaces; i++)
{
face = &aasworld.faces[i];
if (planenum == face->planenum)
{
if (numedges == face->numedges)
{
for (j = 0; j < numedges; j++)
{
edgenum = abs(aasworld.edgeindex[face->firstedge + j]);
if (abs(edges[i]) != edgenum) break;
} //end for
if (j == numedges)
{
//jippy found the face
*facenum = -i;
return true;
} //end if
} //end if
} //end if
} //end for
} //end if
if (aasworld.numfaces >= max_aas.max_faces)
{
Error("AAS_MAX_FACES = %d", max_aas.max_faces);
} //end if
face = &aasworld.faces[aasworld.numfaces];
face->planenum = planenum;
face->faceflags = 0;
face->numedges = numedges;
face->firstedge = aasworld.edgeindexsize;
face->frontarea = 0;
face->backarea = 0;
for (i = 0; i < numedges; i++)
{
if (aasworld.edgeindexsize >= max_aas.max_edgeindexsize)
{
Error("AAS_MAX_EDGEINDEXSIZE = %d", max_aas.max_edgeindexsize);
} //end if
aasworld.edgeindex[aasworld.edgeindexsize++] = edges[i];
} //end for
*facenum = aasworld.numfaces;
aasworld.numfaces++;
return false;
} //end of the function AAS_GetFace*/
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_StoreAreaSettings(tmp_areasettings_t *tmpareasettings)
{
aas_areasettings_t *areasettings;
if (aasworld.numareasettings == 0) aasworld.numareasettings = 1;
areasettings = &aasworld.areasettings[aasworld.numareasettings++];
areasettings->areaflags = tmpareasettings->areaflags;
areasettings->presencetype = tmpareasettings->presencetype;
areasettings->contents = tmpareasettings->contents;
if (tmpareasettings->modelnum > AREACONTENTS_MAXMODELNUM)
Log_Print("WARNING: more than %d mover models\n", AREACONTENTS_MAXMODELNUM);
areasettings->contents |= (tmpareasettings->modelnum & AREACONTENTS_MAXMODELNUM) << AREACONTENTS_MODELNUMSHIFT;
} //end of the function AAS_StoreAreaSettings
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_StoreArea(tmp_area_t *tmparea)
{
int side, edgenum, i;
plane_t *plane;
tmp_face_t *tmpface;
aas_area_t *aasarea;
aas_edge_t *edge;
aas_face_t *aasface;
aas_faceindex_t aasfacenum;
vec3_t facecenter;
winding_t *w;
//when the area is merged go to the merged area
//FIXME: this isn't necessary anymore because the tree
// is refreshed after area merging
while(tmparea->mergedarea) tmparea = tmparea->mergedarea;
//
if (tmparea->invalid) Error("AAS_StoreArea: tried to store invalid area");
//if there is an aas area already stored for this tmp area
if (tmparea->aasareanum) return -tmparea->aasareanum;
//
if (aasworld.numareas >= max_aas.max_areas)
{
Error("AAS_MAX_AREAS = %d", max_aas.max_areas);
} //end if
//area zero is a dummy
if (aasworld.numareas == 0) aasworld.numareas = 1;
//create an area from this leaf
aasarea = &aasworld.areas[aasworld.numareas];
aasarea->areanum = aasworld.numareas;
aasarea->numfaces = 0;
aasarea->firstface = aasworld.faceindexsize;
ClearBounds(aasarea->mins, aasarea->maxs);
VectorClear(aasarea->center);
//
// Log_Write("tmparea %d became aasarea %d\r\n", tmparea->areanum, aasarea->areanum);
//store the aas area number at the tmp area
tmparea->aasareanum = aasarea->areanum;
//
for (tmpface = tmparea->tmpfaces; tmpface; tmpface = tmpface->next[side])
{
side = tmpface->frontarea != tmparea;
//if there's an aas face created for the tmp face already
if (tmpface->aasfacenum)
{
//we're at the back of the face so use a negative index
aasfacenum = -tmpface->aasfacenum;
#ifdef DEBUG
if (tmpface->aasfacenum < 0 || tmpface->aasfacenum > max_aas.max_faces)
{
Error("AAS_CreateTree_r: face number out of range");
} //end if
#endif //DEBUG
aasface = &aasworld.faces[tmpface->aasfacenum];
aasface->backarea = aasarea->areanum;
} //end if
else
{
plane = &mapplanes[tmpface->planenum ^ side];
if (side)
{
w = tmpface->winding;
tmpface->winding = ReverseWinding(tmpface->winding);
} //end if
if (!AAS_GetFace(tmpface->winding, plane, 0, &aasfacenum)) continue;
if (side)
{
FreeWinding(tmpface->winding);
tmpface->winding = w;
} //end if
aasface = &aasworld.faces[aasfacenum];
aasface->frontarea = aasarea->areanum;
aasface->backarea = 0;
aasface->faceflags = tmpface->faceflags;
//set the face number at the tmp face
tmpface->aasfacenum = aasfacenum;
} //end else
//add face points to the area bounds and
//calculate the face 'center'
VectorClear(facecenter);
for (edgenum = 0; edgenum < aasface->numedges; edgenum++)
{
edge = &aasworld.edges[abs(aasworld.edgeindex[aasface->firstedge + edgenum])];
for (i = 0; i < 2; i++)
{
AddPointToBounds(aasworld.vertexes[edge->v[i]], aasarea->mins, aasarea->maxs);
VectorAdd(aasworld.vertexes[edge->v[i]], facecenter, facecenter);
} //end for
} //end for
VectorScale(facecenter, 1.0 / (aasface->numedges * 2.0), facecenter);
//add the face 'center' to the area 'center'
VectorAdd(aasarea->center, facecenter, aasarea->center);
//
if (aasworld.faceindexsize >= max_aas.max_faceindexsize)
{
Error("AAS_MAX_FACEINDEXSIZE = %d", max_aas.max_faceindexsize);
} //end if
aasworld.faceindex[aasworld.faceindexsize++] = aasfacenum;
aasarea->numfaces++;
} //end for
//if the area has no faces at all (return 0, = solid leaf)
if (!aasarea->numfaces) return 0;
//
VectorScale(aasarea->center, 1.0 / aasarea->numfaces, aasarea->center);
//Log_Write("area %d center %f %f %f\r\n", aasworld.numareas,
// aasarea->center[0], aasarea->center[1], aasarea->center[2]);
//store the area settings
AAS_StoreAreaSettings(tmparea->settings);
//
//Log_Write("tmp area %d became aas area %d\r\n", tmpareanum, aasarea->areanum);
qprintf("\r%6d", aasarea->areanum);
//
aasworld.numareas++;
return -(aasworld.numareas - 1);
} //end of the function AAS_StoreArea
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_StoreTree_r(tmp_node_t *tmpnode)
{
int aasnodenum;
plane_t *plane;
aas_node_t *aasnode;
//if it is a solid leaf
if (!tmpnode) return 0;
//negative so it's an area
if (tmpnode->tmparea) return AAS_StoreArea(tmpnode->tmparea);
//it's another node
//the first node is a dummy
if (aasworld.numnodes == 0) aasworld.numnodes = 1;
if (aasworld.numnodes >= max_aas.max_nodes)
{
Error("AAS_MAX_NODES = %d", max_aas.max_nodes);
} //end if
aasnodenum = aasworld.numnodes;
aasnode = &aasworld.nodes[aasworld.numnodes++];
plane = &mapplanes[tmpnode->planenum];
AAS_GetPlane(plane->normal, plane->dist, &aasnode->planenum);
aasnode->children[0] = AAS_StoreTree_r(tmpnode->children[0]);
aasnode->children[1] = AAS_StoreTree_r(tmpnode->children[1]);
return aasnodenum;
} //end of the function AAS_StoreTree_r
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_StoreBoundingBoxes(void)
{
if (cfg.numbboxes > max_aas.max_bboxes)
{
Error("more than %d bounding boxes", max_aas.max_bboxes);
} //end if
aasworld.numbboxes = cfg.numbboxes;
memcpy(aasworld.bboxes, cfg.bboxes, cfg.numbboxes * sizeof(aas_bbox_t));
} //end of the function AAS_StoreBoundingBoxes
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_StoreFile(char *filename)
{
AAS_AllocMaxAAS();
Log_Write("AAS_StoreFile\r\n");
//
AAS_StoreBoundingBoxes();
//
qprintf("%6d areas stored", 0);
//start with node 1 because node zero is a dummy
AAS_StoreTree_r(tmpaasworld.nodes);
qprintf("\n");
Log_Write("%6d areas stored\r\n", aasworld.numareas);
aasworld.loaded = true;
} //end of the function AAS_StoreFile
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -