be_aas_bspc.c (9539B)
1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Foobar; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 23 #include "../game/q_shared.h" 24 #include "../bspc/l_log.h" 25 #include "../bspc/l_qfiles.h" 26 #include "../botlib/l_memory.h" 27 #include "../botlib/l_script.h" 28 #include "../botlib/l_precomp.h" 29 #include "../botlib/l_struct.h" 30 #include "../botlib/aasfile.h" 31 #include "../game/botlib.h" 32 #include "../game/be_aas.h" 33 #include "../botlib/be_aas_def.h" 34 #include "../qcommon/cm_public.h" 35 36 //#define BSPC 37 38 extern botlib_import_t botimport; 39 extern qboolean capsule_collision; 40 41 botlib_import_t botimport; 42 clipHandle_t worldmodel; 43 44 void Error (char *error, ...); 45 46 //=========================================================================== 47 // 48 // Parameter: - 49 // Returns: - 50 // Changes Globals: - 51 //=========================================================================== 52 void AAS_Error(char *fmt, ...) 53 { 54 va_list argptr; 55 char text[1024]; 56 57 va_start(argptr, fmt); 58 vsprintf(text, fmt, argptr); 59 va_end(argptr); 60 61 Error(text); 62 } //end of the function AAS_Error 63 //=========================================================================== 64 // 65 // Parameter: - 66 // Returns: - 67 // Changes Globals: - 68 //=========================================================================== 69 int Sys_MilliSeconds(void) 70 { 71 return clock() * 1000 / CLOCKS_PER_SEC; 72 } //end of the function Sys_MilliSeconds 73 //=========================================================================== 74 // 75 // Parameter: - 76 // Returns: - 77 // Changes Globals: - 78 //=========================================================================== 79 void AAS_DebugLine(vec3_t start, vec3_t end, int color) 80 { 81 } //end of the function AAS_DebugLine 82 //=========================================================================== 83 // 84 // Parameter: - 85 // Returns: - 86 // Changes Globals: - 87 //=========================================================================== 88 void AAS_ClearShownDebugLines(void) 89 { 90 } //end of the function AAS_ClearShownDebugLines 91 //=========================================================================== 92 // 93 // Parameter: - 94 // Returns: - 95 // Changes Globals: - 96 //=========================================================================== 97 char *BotImport_BSPEntityData(void) 98 { 99 return CM_EntityString(); 100 } //end of the function AAS_GetEntityData 101 //=========================================================================== 102 // 103 // Parameter: - 104 // Returns: - 105 // Changes Globals: - 106 //=========================================================================== 107 void BotImport_Trace(bsp_trace_t *bsptrace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask) 108 { 109 trace_t result; 110 111 CM_BoxTrace(&result, start, end, mins, maxs, worldmodel, contentmask, capsule_collision); 112 113 bsptrace->allsolid = result.allsolid; 114 bsptrace->contents = result.contents; 115 VectorCopy(result.endpos, bsptrace->endpos); 116 bsptrace->ent = result.entityNum; 117 bsptrace->fraction = result.fraction; 118 bsptrace->exp_dist = 0; 119 bsptrace->plane.dist = result.plane.dist; 120 VectorCopy(result.plane.normal, bsptrace->plane.normal); 121 bsptrace->plane.signbits = result.plane.signbits; 122 bsptrace->plane.type = result.plane.type; 123 bsptrace->sidenum = 0; 124 bsptrace->startsolid = result.startsolid; 125 bsptrace->surface.flags = result.surfaceFlags; 126 } //end of the function BotImport_Trace 127 //=========================================================================== 128 // 129 // Parameter: - 130 // Returns: - 131 // Changes Globals: - 132 //=========================================================================== 133 int BotImport_PointContents(vec3_t p) 134 { 135 return CM_PointContents(p, worldmodel); 136 } //end of the function BotImport_PointContents 137 //=========================================================================== 138 // 139 // Parameter: - 140 // Returns: - 141 // Changes Globals: - 142 //=========================================================================== 143 void *BotImport_GetMemory(int size) 144 { 145 return GetMemory(size); 146 } //end of the function BotImport_GetMemory 147 //=========================================================================== 148 // 149 // Parameter: - 150 // Returns: - 151 // Changes Globals: - 152 //=========================================================================== 153 void BotImport_Print(int type, char *fmt, ...) 154 { 155 va_list argptr; 156 char buf[1024]; 157 158 va_start(argptr, fmt); 159 vsprintf(buf, fmt, argptr); 160 printf(buf); 161 if (buf[0] != '\r') Log_Write(buf); 162 va_end(argptr); 163 } //end of the function BotImport_Print 164 //=========================================================================== 165 // 166 // Parameter: - 167 // Returns: - 168 // Changes Globals: - 169 //=========================================================================== 170 void BotImport_BSPModelMinsMaxsOrigin(int modelnum, vec3_t angles, vec3_t outmins, vec3_t outmaxs, vec3_t origin) 171 { 172 clipHandle_t h; 173 vec3_t mins, maxs; 174 float max; 175 int i; 176 177 h = CM_InlineModel(modelnum); 178 CM_ModelBounds(h, mins, maxs); 179 //if the model is rotated 180 if ((angles[0] || angles[1] || angles[2])) 181 { // expand for rotation 182 183 max = RadiusFromBounds(mins, maxs); 184 for (i = 0; i < 3; i++) 185 { 186 mins[i] = (mins[i] + maxs[i]) * 0.5 - max; 187 maxs[i] = (mins[i] + maxs[i]) * 0.5 + max; 188 } //end for 189 } //end if 190 if (outmins) VectorCopy(mins, outmins); 191 if (outmaxs) VectorCopy(maxs, outmaxs); 192 if (origin) VectorClear(origin); 193 } //end of the function BotImport_BSPModelMinsMaxsOrigin 194 //=========================================================================== 195 // 196 // Parameter: - 197 // Returns: - 198 // Changes Globals: - 199 //=========================================================================== 200 void Com_DPrintf(char *fmt, ...) 201 { 202 va_list argptr; 203 char buf[1024]; 204 205 va_start(argptr, fmt); 206 vsprintf(buf, fmt, argptr); 207 printf(buf); 208 if (buf[0] != '\r') Log_Write(buf); 209 va_end(argptr); 210 } //end of the function Com_DPrintf 211 //=========================================================================== 212 // 213 // Parameter: - 214 // Returns: - 215 // Changes Globals: - 216 //=========================================================================== 217 int COM_Compress( char *data_p ) { 218 return strlen(data_p); 219 } 220 //=========================================================================== 221 // 222 // Parameter: - 223 // Returns: - 224 // Changes Globals: - 225 //=========================================================================== 226 void Com_Memset (void* dest, const int val, const size_t count) { 227 memset(dest, val, count); 228 } 229 //=========================================================================== 230 // 231 // Parameter: - 232 // Returns: - 233 // Changes Globals: - 234 //=========================================================================== 235 void Com_Memcpy (void* dest, const void* src, const size_t count) { 236 memcpy(dest, src, count); 237 } 238 //=========================================================================== 239 // 240 // Parameter: - 241 // Returns: - 242 // Changes Globals: - 243 //=========================================================================== 244 void AAS_InitBotImport(void) 245 { 246 botimport.BSPEntityData = BotImport_BSPEntityData; 247 botimport.GetMemory = BotImport_GetMemory; 248 botimport.FreeMemory = FreeMemory; 249 botimport.Trace = BotImport_Trace; 250 botimport.PointContents = BotImport_PointContents; 251 botimport.Print = BotImport_Print; 252 botimport.BSPModelMinsMaxsOrigin = BotImport_BSPModelMinsMaxsOrigin; 253 } //end of the function AAS_InitBotImport 254 //=========================================================================== 255 // 256 // Parameter: - 257 // Returns: - 258 // Changes Globals: - 259 //=========================================================================== 260 void AAS_CalcReachAndClusters(struct quakefile_s *qf) 261 { 262 float time; 263 264 Log_Print("loading collision map...\n"); 265 // 266 if (!qf->pakfile[0]) strcpy(qf->pakfile, qf->filename); 267 //load the map 268 CM_LoadMap((char *) qf, qfalse, &aasworld.bspchecksum); 269 //get a handle to the world model 270 worldmodel = CM_InlineModel(0); // 0 = world, 1 + are bmodels 271 //initialize bot import structure 272 AAS_InitBotImport(); 273 //load the BSP entity string 274 AAS_LoadBSPFile(); 275 //init physics settings 276 AAS_InitSettings(); 277 //initialize AAS link heap 278 AAS_InitAASLinkHeap(); 279 //initialize the AAS linked entities for the new map 280 AAS_InitAASLinkedEntities(); 281 //reset all reachabilities and clusters 282 aasworld.reachabilitysize = 0; 283 aasworld.numclusters = 0; 284 //set all view portals as cluster portals in case we re-calculate the reachabilities and clusters (with -reach) 285 AAS_SetViewPortalsAsClusterPortals(); 286 //calculate reachabilities 287 AAS_InitReachability(); 288 time = 0; 289 while(AAS_ContinueInitReachability(time)) time++; 290 //calculate clusters 291 AAS_InitClustering(); 292 } //end of the function AAS_CalcReachAndClusters