AAS.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "AAS_local.h"
  23. /*
  24. ============
  25. idAAS::Alloc
  26. ============
  27. */
  28. idAAS *idAAS::Alloc( void ) {
  29. return new idAASLocal;
  30. }
  31. /*
  32. ============
  33. idAAS::idAAS
  34. ============
  35. */
  36. idAAS::~idAAS( void ) {
  37. }
  38. /*
  39. ============
  40. idAASLocal::idAASLocal
  41. ============
  42. */
  43. idAASLocal::idAASLocal( void ) {
  44. file = NULL;
  45. }
  46. /*
  47. ============
  48. idAASLocal::~idAASLocal
  49. ============
  50. */
  51. idAASLocal::~idAASLocal( void ) {
  52. Shutdown();
  53. }
  54. /*
  55. ============
  56. idAASLocal::Init
  57. ============
  58. */
  59. bool idAASLocal::Init( const idStr &mapName, unsigned int mapFileCRC ) {
  60. if ( file && mapName.Icmp( file->GetName() ) == 0 && mapFileCRC == file->GetCRC() ) {
  61. common->Printf( "Keeping %s\n", file->GetName() );
  62. RemoveAllObstacles();
  63. }
  64. else {
  65. Shutdown();
  66. file = AASFileManager->LoadAAS( mapName, mapFileCRC );
  67. if ( !file ) {
  68. common->DWarning( "Couldn't load AAS file: '%s'", mapName.c_str() );
  69. return false;
  70. }
  71. SetupRouting();
  72. }
  73. return true;
  74. }
  75. /*
  76. ============
  77. idAASLocal::Shutdown
  78. ============
  79. */
  80. void idAASLocal::Shutdown( void ) {
  81. if ( file ) {
  82. ShutdownRouting();
  83. RemoveAllObstacles();
  84. AASFileManager->FreeAAS( file );
  85. file = NULL;
  86. }
  87. }
  88. /*
  89. ============
  90. idAASLocal::Stats
  91. ============
  92. */
  93. void idAASLocal::Stats( void ) const {
  94. if ( !file ) {
  95. return;
  96. }
  97. common->Printf( "[%s]\n", file->GetName() );
  98. file->PrintInfo();
  99. RoutingStats();
  100. }
  101. /*
  102. ============
  103. idAASLocal::GetSettings
  104. ============
  105. */
  106. const idAASSettings *idAASLocal::GetSettings( void ) const {
  107. if ( !file ) {
  108. return NULL;
  109. }
  110. return &file->GetSettings();
  111. }
  112. /*
  113. ============
  114. idAASLocal::PointAreaNum
  115. ============
  116. */
  117. int idAASLocal::PointAreaNum( const idVec3 &origin ) const {
  118. if ( !file ) {
  119. return 0;
  120. }
  121. return file->PointAreaNum( origin );
  122. }
  123. /*
  124. ============
  125. idAASLocal::PointReachableAreaNum
  126. ============
  127. */
  128. int idAASLocal::PointReachableAreaNum( const idVec3 &origin, const idBounds &searchBounds, const int areaFlags ) const {
  129. if ( !file ) {
  130. return 0;
  131. }
  132. return file->PointReachableAreaNum( origin, searchBounds, areaFlags, TFL_INVALID );
  133. }
  134. /*
  135. ============
  136. idAASLocal::BoundsReachableAreaNum
  137. ============
  138. */
  139. int idAASLocal::BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags ) const {
  140. if ( !file ) {
  141. return 0;
  142. }
  143. return file->BoundsReachableAreaNum( bounds, areaFlags, TFL_INVALID );
  144. }
  145. /*
  146. ============
  147. idAASLocal::PushPointIntoAreaNum
  148. ============
  149. */
  150. void idAASLocal::PushPointIntoAreaNum( int areaNum, idVec3 &origin ) const {
  151. if ( !file ) {
  152. return;
  153. }
  154. file->PushPointIntoAreaNum( areaNum, origin );
  155. }
  156. /*
  157. ============
  158. idAASLocal::AreaCenter
  159. ============
  160. */
  161. idVec3 idAASLocal::AreaCenter( int areaNum ) const {
  162. if ( !file ) {
  163. return vec3_origin;
  164. }
  165. return file->GetArea( areaNum ).center;
  166. }
  167. /*
  168. ============
  169. idAASLocal::AreaFlags
  170. ============
  171. */
  172. int idAASLocal::AreaFlags( int areaNum ) const {
  173. if ( !file ) {
  174. return 0;
  175. }
  176. return file->GetArea( areaNum ).flags;
  177. }
  178. /*
  179. ============
  180. idAASLocal::AreaTravelFlags
  181. ============
  182. */
  183. int idAASLocal::AreaTravelFlags( int areaNum ) const {
  184. if ( !file ) {
  185. return 0;
  186. }
  187. return file->GetArea( areaNum ).travelFlags;
  188. }
  189. /*
  190. ============
  191. idAASLocal::Trace
  192. ============
  193. */
  194. bool idAASLocal::Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const {
  195. if ( !file ) {
  196. trace.fraction = 0.0f;
  197. trace.lastAreaNum = 0;
  198. trace.numAreas = 0;
  199. return true;
  200. }
  201. return file->Trace( trace, start, end );
  202. }
  203. /*
  204. ============
  205. idAASLocal::GetPlane
  206. ============
  207. */
  208. const idPlane &idAASLocal::GetPlane( int planeNum ) const {
  209. if ( !file ) {
  210. static idPlane dummy;
  211. return dummy;
  212. }
  213. return file->GetPlane( planeNum );
  214. }
  215. /*
  216. ============
  217. idAASLocal::GetEdgeVertexNumbers
  218. ============
  219. */
  220. void idAASLocal::GetEdgeVertexNumbers( int edgeNum, int verts[2] ) const {
  221. if ( !file ) {
  222. verts[0] = verts[1] = 0;
  223. return;
  224. }
  225. const int *v = file->GetEdge( abs(edgeNum) ).vertexNum;
  226. verts[0] = v[INTSIGNBITSET(edgeNum)];
  227. verts[1] = v[INTSIGNBITNOTSET(edgeNum)];
  228. }
  229. /*
  230. ============
  231. idAASLocal::GetEdge
  232. ============
  233. */
  234. void idAASLocal::GetEdge( int edgeNum, idVec3 &start, idVec3 &end ) const {
  235. if ( !file ) {
  236. start.Zero();
  237. end.Zero();
  238. return;
  239. }
  240. const int *v = file->GetEdge( abs(edgeNum) ).vertexNum;
  241. start = file->GetVertex( v[INTSIGNBITSET(edgeNum)] );
  242. end = file->GetVertex( v[INTSIGNBITNOTSET(edgeNum)] );
  243. }