2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../../../idlib/precompiled.h"
33 #include "AASFile_local.h"
36 //===============================================================
40 //===============================================================
44 idAASFileLocal::Optimize
47 void idAASFileLocal::Optimize( void ) {
48 int i, j, k, faceNum, edgeNum, areaFirstFace, faceFirstEdge;
52 idReachability *reach;
53 idList<int> vertexRemap;
54 idList<int> edgeRemap;
55 idList<int> faceRemap;
56 idList<aasVertex_t> newVertices;
57 idList<aasEdge_t> newEdges;
58 idList<aasIndex_t> newEdgeIndex;
59 idList<aasFace_t> newFaces;
60 idList<aasIndex_t> newFaceIndex;
62 vertexRemap.AssureSize( vertices.Num(), -1 );
63 edgeRemap.AssureSize( edges.Num(), 0 );
64 faceRemap.AssureSize( faces.Num(), 0 );
66 newVertices.Resize( vertices.Num() );
67 newEdges.Resize( edges.Num() );
68 newEdges.SetNum( 1, false );
69 newEdgeIndex.Resize( edgeIndex.Num() );
70 newFaces.Resize( faces.Num() );
71 newFaces.SetNum( 1, false );
72 newFaceIndex.Resize( faceIndex.Num() );
74 for ( i = 0; i < areas.Num(); i++ ) {
77 areaFirstFace = newFaceIndex.Num();
78 for ( j = 0; j < area->numFaces; j++ ) {
79 faceNum = faceIndex[area->firstFace + j];
80 face = &faces[ abs(faceNum) ];
83 if ( !faceRemap[ abs(faceNum) ] ) {
84 faceRemap[ abs(faceNum) ] = newFaces.Num();
85 newFaces.Append( *face );
87 // don't store edges for faces we don't care about
88 if ( !( face->flags & ( FACE_FLOOR|FACE_LADDER ) ) ) {
90 newFaces[ newFaces.Num()-1 ].firstEdge = 0;
91 newFaces[ newFaces.Num()-1 ].numEdges = 0;
96 faceFirstEdge = newEdgeIndex.Num();
97 for ( k = 0; k < face->numEdges; k++ ) {
98 edgeNum = edgeIndex[ face->firstEdge + k ];
99 edge = &edges[ abs(edgeNum) ];
101 if ( !edgeRemap[ abs(edgeNum) ] ) {
103 edgeRemap[ abs(edgeNum) ] = -newEdges.Num();
106 edgeRemap[ abs(edgeNum) ] = newEdges.Num();
109 // remap vertices if not yet remapped
110 if ( vertexRemap[ edge->vertexNum[0] ] == -1 ) {
111 vertexRemap[ edge->vertexNum[0] ] = newVertices.Num();
112 newVertices.Append( vertices[ edge->vertexNum[0] ] );
114 if ( vertexRemap[ edge->vertexNum[1] ] == -1 ) {
115 vertexRemap[ edge->vertexNum[1] ] = newVertices.Num();
116 newVertices.Append( vertices[ edge->vertexNum[1] ] );
119 newEdges.Append( *edge );
120 newEdges[ newEdges.Num()-1 ].vertexNum[0] = vertexRemap[ edge->vertexNum[0] ];
121 newEdges[ newEdges.Num()-1 ].vertexNum[1] = vertexRemap[ edge->vertexNum[1] ];
124 newEdgeIndex.Append( edgeRemap[ abs(edgeNum) ] );
127 newFaces[ newFaces.Num()-1 ].firstEdge = faceFirstEdge;
128 newFaces[ newFaces.Num()-1 ].numEdges = newEdgeIndex.Num() - faceFirstEdge;
133 newFaceIndex.Append( -faceRemap[ abs(faceNum) ] );
135 newFaceIndex.Append( faceRemap[ abs(faceNum) ] );
139 area->firstFace = areaFirstFace;
140 area->numFaces = newFaceIndex.Num() - areaFirstFace;
142 // remap the reachability edges
143 for ( reach = area->reach; reach; reach = reach->next ) {
144 reach->edgeNum = abs( edgeRemap[reach->edgeNum] );
149 vertices = newVertices;
151 edgeIndex = newEdgeIndex;
153 faceIndex = newFaceIndex;