/* ==================== SV_AreaEntities_r ==================== */ void SV_AreaEntities_r(worldSector_t * node, areaParms_t * ap) { svEntity_t *check, *next; sharedEntity_t *gcheck; int count; count = 0; for(check = node->entities; check; check = next) { next = check->nextEntityInWorldSector; gcheck = SV_GEntityForSvEntity(check); if(!gcheck->r.linked) { continue; } if(gcheck->r.absmin[0] > ap->maxs[0] || gcheck->r.absmin[1] > ap->maxs[1] || gcheck->r.absmin[2] > ap->maxs[2] || gcheck->r.absmax[0] < ap->mins[0] || gcheck->r.absmax[1] < ap->mins[1] || gcheck->r.absmax[2] < ap->mins[2]) { continue; } if(ap->count == ap->maxcount) { Com_Printf("SV_AreaEntities: MAXCOUNT\n"); return; } ap->list[ap->count] = check - sv.svEntities; ap->count++; } if(node->axis == -1) { return; // terminal node } // recurse down both sides if(ap->maxs[node->axis] > node->dist) { SV_AreaEntities_r(node->children[0], ap); } if(ap->mins[node->axis] < node->dist) { SV_AreaEntities_r(node->children[1], ap); } }
/* ======================================================================================================================================= SV_AreaEntities ======================================================================================================================================= */ int SV_AreaEntities(const vec3_t mins, const vec3_t maxs, int *entityList, int maxcount) { areaParms_t ap; ap.mins = mins; ap.maxs = maxs; ap.list = entityList; ap.count = 0; ap.maxcount = maxcount; SV_AreaEntities_r(sv_worldSectors, &ap); return ap.count; }
static void SV_AreaEntities_r( worldSector_t *node, areaParms_t *ap ) { svEntity_t *check, *next; sharedEntity_t *gcheck; for ( check = node->entities ; check ; check = next ) { next = check->nextEntityInWorldSector; gcheck = SV_GEntityForSvEntity( check ); if ( gcheck->r.absmin.x > ap->maxs->x || gcheck->r.absmin.y > ap->maxs->y || gcheck->r.absmin.z > ap->maxs->z || gcheck->r.absmax.x < ap->mins->x || gcheck->r.absmax.y < ap->mins->y || gcheck->r.absmax.z < ap->mins->z ) { continue; } if ( ap->count == ap->maxcount ) { Com_Printf ("SV_AreaEntities: MAXCOUNT\n"); return; } ap->list[ap->count] = ARRAY_INDEX( sv.svEntities, check ); ap->count++; } if (node->axis == -1) { return; // terminal node } // recurse down both sides if ( ap->maxs->data[node->axis] > node->dist ) { SV_AreaEntities_r ( node->children[0], ap ); } if ( ap->mins->data[node->axis] < node->dist ) { SV_AreaEntities_r ( node->children[1], ap ); } }
/* * SV_AreaEntities_r * */ static void SV_AreaEntities_r(worldSector_t *node, Areaparams *ap) { Svent *check, *next; Sharedent *gcheck; for(check = node->entities; check; check = next){ next = check->nextEntityInWorldSector; gcheck = SV_GEntityForSvEntity(check); if(gcheck->r.absmin[0] > ap->maxs[0] || gcheck->r.absmin[1] > ap->maxs[1] || gcheck->r.absmin[2] > ap->maxs[2] || gcheck->r.absmax[0] < ap->mins[0] || gcheck->r.absmax[1] < ap->mins[1] || gcheck->r.absmax[2] < ap->mins[2]) continue; if(ap->count == ap->maxcount){ comprintf ("SV_AreaEntities: MAXCOUNT\n"); return; } ap->list[ap->count] = check - sv.svEntities; ap->count++; } if(node->axis == -1) return; /* terminal node */ /* recurse down both sides */ if(ap->maxs[node->axis] > node->dist) SV_AreaEntities_r (node->children[0], ap); if(ap->mins[node->axis] < node->dist) SV_AreaEntities_r (node->children[1], ap); }
/* * SV_AreaEntities */ int SV_AreaEntities(const Vec3 mins, const Vec3 maxs, int *entityList, int maxcount) { Areaparams ap; ap.mins = mins; ap.maxs = maxs; ap.list = entityList; ap.count = 0; ap.maxcount = maxcount; SV_AreaEntities_r(sv_worldSectors, &ap); return ap.count; }