doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AAS.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 "AAS_local.h"
33 
34 /*
35 ============
36 idAAS::Alloc
37 ============
38 */
39 idAAS *idAAS::Alloc( void ) {
40  return new idAASLocal;
41 }
42 
43 /*
44 ============
45 idAAS::idAAS
46 ============
47 */
48 idAAS::~idAAS( void ) {
49 }
50 
51 /*
52 ============
53 idAASLocal::idAASLocal
54 ============
55 */
57  file = NULL;
58 }
59 
60 /*
61 ============
62 idAASLocal::~idAASLocal
63 ============
64 */
66  Shutdown();
67 }
68 
69 /*
70 ============
71 idAASLocal::Init
72 ============
73 */
74 bool idAASLocal::Init( const idStr &mapName, unsigned int mapFileCRC ) {
75  if ( file && mapName.Icmp( file->GetName() ) == 0 && mapFileCRC == file->GetCRC() ) {
76  common->Printf( "Keeping %s\n", file->GetName() );
78  }
79  else {
80  Shutdown();
81 
82  file = AASFileManager->LoadAAS( mapName, mapFileCRC );
83  if ( !file ) {
84  common->DWarning( "Couldn't load AAS file: '%s'", mapName.c_str() );
85  return false;
86  }
87  SetupRouting();
88  }
89  return true;
90 }
91 
92 /*
93 ============
94 idAASLocal::Shutdown
95 ============
96 */
97 void idAASLocal::Shutdown( void ) {
98  if ( file ) {
102  file = NULL;
103  }
104 }
105 
106 /*
107 ============
108 idAASLocal::Stats
109 ============
110 */
111 void idAASLocal::Stats( void ) const {
112  if ( !file ) {
113  return;
114  }
115  common->Printf( "[%s]\n", file->GetName() );
116  file->PrintInfo();
117  RoutingStats();
118 }
119 
120 /*
121 ============
122 idAASLocal::GetSettings
123 ============
124 */
126  if ( !file ) {
127  return NULL;
128  }
129  return &file->GetSettings();
130 }
131 
132 /*
133 ============
134 idAASLocal::PointAreaNum
135 ============
136 */
137 int idAASLocal::PointAreaNum( const idVec3 &origin ) const {
138  if ( !file ) {
139  return 0;
140  }
141  return file->PointAreaNum( origin );
142 }
143 
144 /*
145 ============
146 idAASLocal::PointReachableAreaNum
147 ============
148 */
149 int idAASLocal::PointReachableAreaNum( const idVec3 &origin, const idBounds &searchBounds, const int areaFlags ) const {
150  if ( !file ) {
151  return 0;
152  }
153 
154  return file->PointReachableAreaNum( origin, searchBounds, areaFlags, TFL_INVALID );
155 }
156 
157 /*
158 ============
159 idAASLocal::BoundsReachableAreaNum
160 ============
161 */
162 int idAASLocal::BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags ) const {
163  if ( !file ) {
164  return 0;
165  }
166 
167  return file->BoundsReachableAreaNum( bounds, areaFlags, TFL_INVALID );
168 }
169 
170 /*
171 ============
172 idAASLocal::PushPointIntoAreaNum
173 ============
174 */
175 void idAASLocal::PushPointIntoAreaNum( int areaNum, idVec3 &origin ) const {
176  if ( !file ) {
177  return;
178  }
179  file->PushPointIntoAreaNum( areaNum, origin );
180 }
181 
182 /*
183 ============
184 idAASLocal::AreaCenter
185 ============
186 */
187 idVec3 idAASLocal::AreaCenter( int areaNum ) const {
188  if ( !file ) {
189  return vec3_origin;
190  }
191  return file->GetArea( areaNum ).center;
192 }
193 
194 /*
195 ============
196 idAASLocal::AreaFlags
197 ============
198 */
199 int idAASLocal::AreaFlags( int areaNum ) const {
200  if ( !file ) {
201  return 0;
202  }
203  return file->GetArea( areaNum ).flags;
204 }
205 
206 /*
207 ============
208 idAASLocal::AreaTravelFlags
209 ============
210 */
211 int idAASLocal::AreaTravelFlags( int areaNum ) const {
212  if ( !file ) {
213  return 0;
214  }
215  return file->GetArea( areaNum ).travelFlags;
216 }
217 
218 /*
219 ============
220 idAASLocal::Trace
221 ============
222 */
223 bool idAASLocal::Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const {
224  if ( !file ) {
225  trace.fraction = 0.0f;
226  trace.lastAreaNum = 0;
227  trace.numAreas = 0;
228  return true;
229  }
230  return file->Trace( trace, start, end );
231 }
232 
233 /*
234 ============
235 idAASLocal::GetPlane
236 ============
237 */
238 const idPlane &idAASLocal::GetPlane( int planeNum ) const {
239  if ( !file ) {
240  static idPlane dummy;
241  return dummy;
242  }
243  return file->GetPlane( planeNum );
244 }
245 
246 /*
247 ============
248 idAASLocal::GetEdgeVertexNumbers
249 ============
250 */
251 void idAASLocal::GetEdgeVertexNumbers( int edgeNum, int verts[2] ) const {
252  if ( !file ) {
253  verts[0] = verts[1] = 0;
254  return;
255  }
256  const int *v = file->GetEdge( abs(edgeNum) ).vertexNum;
257  verts[0] = v[INTSIGNBITSET(edgeNum)];
258  verts[1] = v[INTSIGNBITNOTSET(edgeNum)];
259 }
260 
261 /*
262 ============
263 idAASLocal::GetEdge
264 ============
265 */
266 void idAASLocal::GetEdge( int edgeNum, idVec3 &start, idVec3 &end ) const {
267  if ( !file ) {
268  start.Zero();
269  end.Zero();
270  return;
271  }
272  const int *v = file->GetEdge( abs(edgeNum) ).vertexNum;
273  start = file->GetVertex( v[INTSIGNBITSET(edgeNum)] );
274  end = file->GetVertex( v[INTSIGNBITNOTSET(edgeNum)] );
275 }
virtual bool Trace(aasTrace_t &trace, const idVec3 &start, const idVec3 &end) const =0
virtual const idPlane & GetPlane(int planeNum) const
Definition: AAS.cpp:238
const idAASSettings & GetSettings(void) const
Definition: AASFile.h:312
idVec3 center
Definition: AASFile.h:159
virtual void Shutdown(void)
Definition: AAS.cpp:97
const aasEdge_t & GetEdge(int index) const
Definition: AASFile.h:294
const GLdouble * v
Definition: glext.h:2936
virtual void Stats(void) const
Definition: AAS.cpp:111
void RoutingStats(void) const
virtual int BoundsReachableAreaNum(const idBounds &bounds, const int areaFlags, const int excludeTravelFlags) const =0
virtual void PushPointIntoAreaNum(int areaNum, idVec3 &origin) const
Definition: AAS.cpp:175
virtual void GetEdge(int edgeNum, idVec3 &start, idVec3 &end) const
Definition: AAS.cpp:266
int numAreas
Definition: AASFile.h:204
int vertexNum[2]
Definition: AASFile.h:142
const aasVertex_t & GetVertex(int index) const
Definition: AASFile.h:292
Definition: Vector.h:316
const char * GetName(void) const
Definition: AASFile.h:286
virtual int AreaFlags(int areaNum) const
Definition: AAS.cpp:199
idAASLocal(void)
Definition: AAS.cpp:56
void ShutdownRouting(void)
int Icmp(const char *text) const
Definition: Str.h:667
idAASFile * file
Definition: AAS_local.h:123
virtual void GetEdgeVertexNumbers(int edgeNum, int verts[2]) const
Definition: AAS.cpp:251
unsigned short flags
Definition: AASFile.h:160
virtual idAASFile * LoadAAS(const char *fileName, unsigned int mapFileCRC)=0
virtual void RemoveAllObstacles(void)
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
GLuint GLuint end
Definition: glext.h:2845
virtual ~idAASLocal(void)
Definition: AAS.cpp:65
#define INTSIGNBITNOTSET(i)
Definition: Math.h:72
virtual void virtual void virtual void DWarning(const char *fmt,...) id_attribute((format(printf
idCommon * common
Definition: Common.cpp:206
#define NULL
Definition: Lib.h:88
Definition: Plane.h:71
virtual void PrintInfo(void) const =0
virtual void FreeAAS(idAASFile *file)=0
int lastAreaNum
Definition: AASFile.h:202
bool SetupRouting(void)
virtual void PushPointIntoAreaNum(int areaNum, idVec3 &point) const =0
unsigned int GetCRC(void) const
Definition: AASFile.h:287
float fraction
Definition: AASFile.h:199
virtual int PointAreaNum(const idVec3 &origin) const =0
virtual void Printf(const char *fmt,...) id_attribute((format(printf
virtual int PointReachableAreaNum(const idVec3 &origin, const idBounds &searchBounds, const int areaFlags) const
Definition: AAS.cpp:149
idAASFileManager * AASFileManager
virtual ~idAAS(void)=0
Definition: AAS.cpp:48
#define INTSIGNBITSET(i)
Definition: Math.h:71
virtual const idAASSettings * GetSettings(void) const
Definition: AAS.cpp:125
#define TFL_INVALID
Definition: AASFile.h:44
Definition: Str.h:116
const char * c_str(void) const
Definition: Str.h:487
virtual int PointReachableAreaNum(const idVec3 &origin, const idBounds &searchBounds, const int areaFlags, const int excludeTravelFlags) const =0
virtual int BoundsReachableAreaNum(const idBounds &bounds, const int areaFlags) const
Definition: AAS.cpp:162
static idAAS * Alloc(void)
Definition: AAS.cpp:39
const idPlane & GetPlane(int index) const
Definition: AASFile.h:290
virtual bool Init(const idStr &mapName, unsigned int mapFileCRC)
Definition: AAS.cpp:74
virtual int AreaTravelFlags(int areaNum) const
Definition: AAS.cpp:211
const aasArea_t & GetArea(int index)
Definition: AASFile.h:302
void Zero(void)
Definition: Vector.h:415
virtual int PointAreaNum(const idVec3 &origin) const
Definition: AAS.cpp:137
int travelFlags
Definition: AASFile.h:164
GLuint start
Definition: glext.h:2845
virtual bool Trace(aasTrace_t &trace, const idVec3 &start, const idVec3 &end) const
Definition: AAS.cpp:223
Definition: AAS.h:75
virtual idVec3 AreaCenter(int areaNum) const
Definition: AAS.cpp:187