Bounding a classname query over a large entity set in the Source Engine without O(n) stalls
0 reputation · 16 Apr 2025, 11:27 UTC
Goal
I am working with the Source SDK (2013-era codebase) and need to run a filtered search for entities by classname or targetname across a map that may contain several thousand active entities. The documented approach iterates the global entity linked list linearly, which is O(n) per call, and I want to bound that cost per frame rather than scan everything at once.
Constraints and uncertainty
The entity list is a simple linked structure with no built-in paging or index by classname as far as I can tell from the SDK headers. Spatial partitioning exists via the BSP tree and PVS, but those are tuned for visibility and networking, not for arbitrary gameplay queries, and BSP data is static so it does not reflect dynamic entity movement. I am considering chunking the iteration across server frames (a manual pagination approach), but I am unsure how this interacts with entities being created or deleted mid-iteration, and whether the engine's own find helpers already handle incremental searches safely.
Questions
Does the SDK expose any iterator or handle-based mechanism that lets a classname query resume safely across frames if the entity list mutates? Is there a documented pattern for bounding a spatial query (radius or box trace) so it only touches entities in relevant BSP leaves rather than the full list? At roughly what entity count does linear iteration become a measurable frame-time problem in practice?