void AreaEntities_r(worldSector_t node, AreaParams ap) { svEntity_t check, next = null; sharedEntity gcheck; for (check = node.entities; check != null; check = next ) { next = check.nextEntityInWorldSector; gcheck = 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.list.Length == ap.count) { Common.Instance.WriteLine("AreaEntities: MAXCOUNT"); return; } ap.list[ap.count] = check.id; ap.count++; } if (node.axis == -1) return; // terminal node // recurse down both sides if (ap.maxs[node.axis] > node.dist) AreaEntities_r(node.children[0], ap); if (ap.mins[node.axis] < node.dist) AreaEntities_r(node.children[1], ap); }
private worldSector_t CreateWorldSector(int depth, Vector3 mins, Vector3 maxs) { worldSector_t anode = new worldSector_t(); sv_worldSectors[sv_numworldSectors++] = anode; if (depth == 4) // AREA_DEPTH = 4 { anode.axis = -1; anode.children[0] = anode.children[1] = null; return anode; } Vector3 size = maxs - mins; if (size[0] > size[1]) anode.axis = 0; else anode.axis = 1; anode.dist = 0.5f * (maxs[anode.axis] + mins[anode.axis]); Vector3 maxs1 = maxs; Vector3 mins2 = mins; maxs1[anode.axis] = mins2[anode.axis] = anode.dist; anode.children[0] = CreateWorldSector(depth + 1, mins2, maxs); anode.children[1] = CreateWorldSector(depth + 1, mins, maxs1); return anode; }
private void ClearWorld() { for (int i = 0; i < sv_worldSectors.Length; i++) { sv_worldSectors[i] = new worldSector_t(); } sv_numworldSectors = 0; Vector3 mins = Vector3.Zero, maxs = Vector3.Zero; dnode_t node = ClipMap.Instance.nodes[0]; ClipMap.Instance.ModelBounds(0, ref mins, ref maxs); mins = node.mins; maxs = node.maxs; CreateWorldSector(0, mins, maxs); }