doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AASFile_optimize.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
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.
13 
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.
18 
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/>.
21 
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.
23 
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.
25 
26 ===========================================================================
27 */
28 
29 #include "../../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "AASFile.h"
33 #include "AASFile_local.h"
34 
35 
36 //===============================================================
37 //
38 // optimize file
39 //
40 //===============================================================
41 
42 /*
43 ================
44 idAASFileLocal::Optimize
45 ================
46 */
48  int i, j, k, faceNum, edgeNum, areaFirstFace, faceFirstEdge;
49  aasArea_t *area;
50  aasFace_t *face;
51  aasEdge_t *edge;
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;
61 
62  vertexRemap.AssureSize( vertices.Num(), -1 );
63  edgeRemap.AssureSize( edges.Num(), 0 );
64  faceRemap.AssureSize( faces.Num(), 0 );
65 
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() );
73 
74  for ( i = 0; i < areas.Num(); i++ ) {
75  area = &areas[i];
76 
77  areaFirstFace = newFaceIndex.Num();
78  for ( j = 0; j < area->numFaces; j++ ) {
79  faceNum = faceIndex[area->firstFace + j];
80  face = &faces[ abs(faceNum) ];
81 
82  // store face
83  if ( !faceRemap[ abs(faceNum) ] ) {
84  faceRemap[ abs(faceNum) ] = newFaces.Num();
85  newFaces.Append( *face );
86 
87  // don't store edges for faces we don't care about
88  if ( !( face->flags & ( FACE_FLOOR|FACE_LADDER ) ) ) {
89 
90  newFaces[ newFaces.Num()-1 ].firstEdge = 0;
91  newFaces[ newFaces.Num()-1 ].numEdges = 0;
92 
93  } else {
94 
95  // store edges
96  faceFirstEdge = newEdgeIndex.Num();
97  for ( k = 0; k < face->numEdges; k++ ) {
98  edgeNum = edgeIndex[ face->firstEdge + k ];
99  edge = &edges[ abs(edgeNum) ];
100 
101  if ( !edgeRemap[ abs(edgeNum) ] ) {
102  if ( edgeNum < 0 ) {
103  edgeRemap[ abs(edgeNum) ] = -newEdges.Num();
104  }
105  else {
106  edgeRemap[ abs(edgeNum) ] = newEdges.Num();
107  }
108 
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] ] );
113  }
114  if ( vertexRemap[ edge->vertexNum[1] ] == -1 ) {
115  vertexRemap[ edge->vertexNum[1] ] = newVertices.Num();
116  newVertices.Append( vertices[ edge->vertexNum[1] ] );
117  }
118 
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] ];
122  }
123 
124  newEdgeIndex.Append( edgeRemap[ abs(edgeNum) ] );
125  }
126 
127  newFaces[ newFaces.Num()-1 ].firstEdge = faceFirstEdge;
128  newFaces[ newFaces.Num()-1 ].numEdges = newEdgeIndex.Num() - faceFirstEdge;
129  }
130  }
131 
132  if ( faceNum < 0 ) {
133  newFaceIndex.Append( -faceRemap[ abs(faceNum) ] );
134  } else {
135  newFaceIndex.Append( faceRemap[ abs(faceNum) ] );
136  }
137  }
138 
139  area->firstFace = areaFirstFace;
140  area->numFaces = newFaceIndex.Num() - areaFirstFace;
141 
142  // remap the reachability edges
143  for ( reach = area->reach; reach; reach = reach->next ) {
144  reach->edgeNum = abs( edgeRemap[reach->edgeNum] );
145  }
146  }
147 
148  // store new list
149  vertices = newVertices;
150  edges = newEdges;
151  edgeIndex = newEdgeIndex;
152  faces = newFaces;
153  faceIndex = newFaceIndex;
154 }
void SetNum(int newnum, bool resize=true)
Definition: List.h:289
void AssureSize(int newSize)
Definition: List.h:445
int vertexNum[2]
Definition: AASFile.h:142
idReachability * reach
Definition: AASFile.h:165
int i
Definition: process.py:33
idList< aasIndex_t > faceIndex
Definition: AASFile.h:342
int firstEdge
Definition: AASFile.h:150
idList< aasIndex_t > edgeIndex
Definition: AASFile.h:340
idList< aasFace_t > faces
Definition: AASFile.h:341
idReachability * next
Definition: AASFile.h:104
unsigned short flags
Definition: AASFile.h:148
int Append(const type &obj)
Definition: List.h:646
idList< aasEdge_t > edges
Definition: AASFile.h:339
idList< aasVertex_t > vertices
Definition: AASFile.h:338
int numEdges
Definition: AASFile.h:149
int Num(void) const
Definition: List.h:265
int firstFace
Definition: AASFile.h:157
idList< aasArea_t > areas
Definition: AASFile.h:343
int numFaces
Definition: AASFile.h:156
#define FACE_FLOOR
Definition: AASFile.h:63
GLint j
Definition: qgl.h:264
void Resize(int newsize)
Definition: List.h:360
#define FACE_LADDER
Definition: AASFile.h:62