View Single Post
psychonic

BAFFLED
Join Date: May 2008
Old 02-19-2016 , 08:02   Re: [IMPORTANT] Regarding CSGO's new Entity system
Reply With Quote #11

To further clarify, edicts are not entities, although they do share the same indexes as entities. Edicts exist in the engine, containing information about how and what to transmit for each networked entity. Entities exist in game logic and can be networked between client and server, or exist fully on one side.

I believe that the maximum number of edicts (and thus networked entity instances) is 2048 for all supported games, so indexes 0-2047. If another instanced of a networked entity is created after that point, the engine throws an error, causing the server to exit. The maximum number of total entity instances is 4096 or 8192 for all supported games (newer games use a higher limit). The CS:GO team stopped some entities from being networked, likely in an attempt to free up at least a small number of edict slots. For example, clients don't need to know where spawn points are - the server just teleports them to there upon spawn.

SourceMod did not always support working with non-networked, serverside entities. That support came in with Entity References. Due to the nature of most types non-networked entities being able to be rapidly created and destroyed, with quick index reuse, a reference system was implemented. Rather than just having an index, you have a reference that you can guarantee is the same entity it was when the reference was created (assuming that IsValidEntity passes), rather than a new entity at the same index. All first-party natives that accept an entity will take a reference. Similarly, all first-party forwards and natives that return entities will give a reference. That caveat with that is that raw entity indexes, also called "backwards-compatible references" are still used for networked entities, causing inconsistency and sometimes confusion.

The moral here is to never assume that the int representation of an entity is an index unless you know for sure it is. (ie. don't use it as an index into an array). Treat it as a reference if it's anything from first-party interfaces and convert to an index with EntRefToEntIndex if you require the actual index. The negative numbers are just a side effect of the implementation of references. The same conversion of reference to index is also required if you want to compare to 0 or the edict/entity limits. And to address the error above, don't call RemoveEdict on an index/reference for a non-networked entity. IsValidEdict and IsValidEntity are intentionally separate functions.

[/rambling]

Last edited by psychonic; 02-19-2016 at 08:09.
psychonic is offline