AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Looking for large numbers of entities (https://forums.alliedmods.net/showthread.php?t=127057)

ProdigySim 05-16-2010 12:33

Looking for large numbers of entities
 
The L4D2 project I'm working on currently has to search for a number of different entities on round start and perform various operations on them.

Right now, we simply loop through all possible Entity Indexes, check for classnames we want, and perform different operations based on that.

Recently, however, I've learned of the sdktools function "FindEntityByClassname," which will simply find entity instances of a given classname.

I want to know which of these will be more efficient to use.

I know FindEntityByClassname is a Valve function, so we don't know exactly how it works. My fear is that it just stores an index for the "First" entity given a classname, searches for a new one, then returns and stores the the new one. This means finding all Entities given a classname would be an O(n) operation, and we would end up with an one O(n) loop for every classname we want to deal with.

Whereas, by simply looping through all possible entities, we can do everything in a single O(n) loop. By using keyvalues and other optimizations, we can make all of our processing essentially O(1). However, this code is still fairly ugly to look at, and condensing all of our entity processing operations into a single loop would combine a lot of different modules of our plugin at once.

So, does anyone know time complexity or general efficiency information about FindEntityByClassname?

rhelgeby 05-17-2010 05:07

Re: Looking for large numbers of entities
 
As far as I know FindEntityByClassname has a starting index parameter so you can continue searching from the previous result. Making it ideal to use in loops.


All times are GMT -4. The time now is 04:24.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.